Manage serial port from two processes simultaneosly

半世苍凉 提交于 2021-02-17 05:28:25

问题


I have the following scenario:

  • Rasperry pi connected to a device via Serial port
  • 3g Dongle connected to the raspberry (with the ability to make/recieve calls)
  • One process reading the data from the serial port and redirecting it to a server (using 3g)
  • Another process waiting for a incoming call, and when someone calls the program takes the data from the serial port and redirect it via the 3g dongle using AT commands ( like fax-call). When someone calls, the call is made using AT commands and the caller should be able to "speak" with the final device connected to the serial port.

The problem is that the two processes can not live together since they are using the same serial port, and when one process is already started, the other can not read the data from the serial (port busy).

Is there a way to achieve this ? Can i make like a "fake" serial port, or something that redirects the data?

Thank you very much


回答1:


You may write a single service that communicates with the real serial port but offers two virtual serial ports itself like described here Virtual Serial Port for Linux




回答2:


Like all good GSM things there's a specification for that :)

GSM 07.10 is the specification and there are libraries out there for some time that can support you. Some are libraries you can build into your server systems and some are actual daemons.

A quick google for "gsm multiplexing" will get your started that I am sure.




回答3:


I had a similar problem managing a serial port between some independent processes. Finally my best solution was to use Redis to listen for calls to the port.

The process that wants to send something, publishes through redis, in the channel 'uart_request' a json with the arguments to make the call to the serial port, and also a hash ('hash_message') made with the timestamp. Just before posting the json, the process subscribes to 'hash_message'.

Finally, a process listens for the posts in 'uart_request'. When a post arrives, take the 'hash_message' from the json, make the call to the serial port, wait for the response and post the response in 'hash_message'.

The point is that there is just one process that control the serial port, so its not necessary to open and close. Works really good.



来源:https://stackoverflow.com/questions/30187375/manage-serial-port-from-two-processes-simultaneosly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!