Manage serial port from two processes simultaneosly

前端 未结 3 1513
情书的邮戳
情书的邮戳 2021-01-28 08:10

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 ca
3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-28 08:28

    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.

提交回复
热议问题