简体   繁体   English

共享SerialPort(PRISM / MEF)的复合WPF GUI

[英]Composite WPF GUI sharing SerialPort (PRISM/MEF)

I do have the following scenario: I do have a shell and two modules(moduleA.dll,moduleB.dll included via bootstrapper), this I created using PRISM4. 我确实有以下情形:我确实有一个外壳和两个模块(通过引导程序包含了moduleA.dll,moduleB.dll),这是我使用PRISM4创建的。

ModuleA reads a database and from that information it should open a serial port. ModuleA读取数据库,并从该信息中打开一个串行端口。 This module offers also to send commands via the serial connection. 该模块还提供通过串行连接发送命令的功能。

ModuleB can also send data to the same serial connection, the moduleA already openend. ModuleB也可以将数据发送到相同的串行连接,而ModuleA已经开放。 Furthermore moduleB should contain a plot which plots data coming from the serial port. 此外,moduleB应该包含一个绘图,该绘图绘制来自串行端口的数据。

Eg: ModuleA sends "Setting1,Setting2" ModuleB sends "Start" -->ModuleB receives data (-->Plot data) ModuleB sends "Stop" 例如:ModuleA发送“ Setting1,Setting2” ModuleB发送“ Start”-> ModuleB接收数据(-> Plot数据)ModuleB发送“ Stop”

So for my understanding they should somehow share the this serial port instance. 因此,以我的理解,他们应该以某种方式共享此串行端口实例。 Any ideas how to setup this scenario? 任何想法如何设置这种情况?

Thanks in advance. 提前致谢。

Your initial modules/class setup seems wrong. 您的初始模块/类设置似乎错误。 The concept of modules is mainly useful for pluggable, optional functionality, not what you describe here: it seems ModuleB can't exist without ModuleA (as it needs the port A has and probably needs the settings to be sent first etc), and vice-versa having only ModuleA without ModuleB makes no sense either (only sending settings but no data communication). 模块的概念主要用于可插拔的可选功能,而不是此处介绍的内容:似乎没有ModuleA的情况下ModuleB就不存在(因为它需要端口A拥有并且可能需要先发送设置等),反之亦然-versa仅具有ModuleA而没有ModuleB也没有意义(仅发送设置,但没有数据通信)。

If the setup you have is really as simple as what you write, just use a single module for all serial port communication. 如果您的设置确实和编写的一样简单,则只需使用单个模块进行所有串行端口通信。 What you can do then, is abstract the database away into a seperate module and eventually the plotting as well. 然后,您可以做的是将数据库抽象到一个单独的模块中,并最终进行绘图。 Then if you ever switch to another database, you just provide a new module. 然后,如果您切换到另一个数据库,则只需提供一个新模块。 Likewise for the plot. 对于情节也是如此。 (note, this is just an example of what you could do and by no means this is inteded to be the solution to your particular problem). (注意,这仅仅是你可以做一个例子,绝不该是inteded 解决您的特定问题)。 For the 'abstracting away' part you use dependency injection with MEF/Unity: create interfaces in a common project, export an implementation of the interface in a module, import it in another module. 对于“抽象”部分,您可以将依赖注入与MEF / Unity结合使用:在一个公共项目中创建接口,在一个模块中导出该接口的实现,在另一个模块中导入它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM