繁体   English   中英

使用环境变量的两个应用程序之间的通信

[英]Communication between two applications using Environment Variables

如何通过环境变量(而不是系统或用户变量)与另一个程序(例如,Windows服务程序)通信?

我们有什么

好吧,对于数据记录器,我有以下方案:

-------------------------          --------------------------------
| the things to measure |          | the things that do something |
-------------------------          --------------------------------
     |                                  ^
     | sensors                          | switches
     V                                  |
-------------------------------------------------------------------
|                     dedicated hardware                          |
-------------------------------------------------------------------
     | ^
     | |  serial communication 
     V |
---------------                                       -------------
|   Windows   | ------------------------------------> |   user    |
|   service   | <------------------------------------ | interface |
---------------           udp communication           -------------
                                                            |^  keyboard
                                                            V| and screen
                                                         --------
                                                         | user |
                                                         --------

关于当前的发展:

  • Windows运行时Windows服务始终运行
  • 用户可以打开和关闭用户界面(当然:p)
  • Windows服务从传感器获取数据
  • 用户界面每100毫秒自动向Windows服务请求数据,并通过一些已实现的协议通过udp通信向用户显示数据(我们称其为GetData()命令并对其进行响应)
  • 用户可以发送其他命令来更改要通过已实现的协议获取的数据(我们将其SetSensors()命令并对其进行响应)

用户界面和Windows服务都在Borland C + Builder 6上开发,并使用FastNet选项卡中的NMUDP组件进行UDP通信。

我们在想做什么

由于某些缓冲区问题,并且为了释放udp通道而仅用于发送SetSensors()命令并对其进行响应,我们正在考虑代替使用GetData()

  • Windows服务将从传感器获取数据并将其放在环境变量中
  • 用户界面将读取它们以显示给用户

做完我们想过的计划

-------------------------          --------------------------------
| the things to measure |          | the things that do something |
-------------------------          --------------------------------
     |                                  ^
     | sensors                          | switches
     V                                  |
-------------------------------------------------------------------
|                     dedicated hardware                          |
-------------------------------------------------------------------
     | ^
     | |  serial communication 
     V |
---------------                                       -------------
|             | ------------------------------------> |           |
|             |         environment variables         |           |
|             |         (get data from sensors)       |           |
|   Windows   |                                       |   user    |
|   service   |                                       | interface |
|             |                                       |           |
|             | ------------------------------------> |           |
|             | <------------------------------------ |           |
---------------           udp communication           -------------
                        (send commands to service)          |^  keyboard
                                                            V| and screen
                                                         --------
                                                         | user |
                                                         --------

有什么办法吗?

我们不会使用系统和用户环境变量,因为它是在Windows注册表上编写的,即它将保存到硬盘驱动器并且变得越来越慢...

正如@HansPassant所说,我不能直接这样做。 尽管我看到了一些通过内存映射文件执行此操作的方法,但仅通过另一个端口添加一个udp通信通道非常容易。 所以:

-------------------------          --------------------------------
| the things to measure |          | the things that do something |
-------------------------          --------------------------------
     |                                  ^
     | sensors                          | switches
     V                                  |
-------------------------------------------------------------------
|                     dedicated hardware                          |
-------------------------------------------------------------------
     | ^
     | |  serial communication 
     V |
---------------                                       -------------
|             | ------------------------------------> |           |
|             |           udp communication (port 3)  |           |
|             |         (get data from sensors)       |           |
|   Windows   |                                       |   user    |
|   service   |                                       | interface |
|             |                             (port 1)  |           |
|             | ------------------------------------> |           |
|             | <------------------------------------ |           |
---------------           udp communication (port 2)  -------------
                        (send commands to service)          |^  keyboard
                                                            V| and screen
                                                         --------
                                                         | user |
                                                         --------

如果有人提供更好的解决方案,我会在以后将其标记为解决方案。

暂无
暂无

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

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