wohltemperiert Posted December 12, 2020 Report Share Posted December 12, 2020 Dear al, I've got an architectural question for the serial communication. I am currently working on a machine which is communicating with LabVIEW program on PC. There are totally 4 COM ports that are involved. COM1 (RS485) is used and shared by multiple threads/users, where as COM2, 3 and 4 (RS232) are used only by a its own thread. I created a VI for send and receive with time out and so on. In order to prevent race condition of access to COM1, this send receive VI is not re-entrant. On the other hand, however, I need this VI to be re-entrant, so that it can be used by communications of COM 2, 3 and 4. Do you know how I can solve this dilemma? Thanks a lot! Quote Link to comment
crossrulz Posted December 12, 2020 Report Share Posted December 12, 2020 Sounds like you should be handling your serial communications with a Queued Message Handler. Use queues to send message to other loops (the QMH) telling it to send, query, or just read the port. Your message could include a queue reference for returning the data. I covered this at my VI Week presentation: Proper way to communicate over serial Quote Link to comment
wohltemperiert Posted December 12, 2020 Author Report Share Posted December 12, 2020 Thanks a lot for your quick reply and sharing your presentation! I'll watch it. Quote Link to comment
drjdpowell Posted December 12, 2020 Report Share Posted December 12, 2020 You could also use a DVR, or similar mechanism, to manage access to a com port, instead of using a non-reentrant subVI. Quote Link to comment
wohltemperiert Posted December 12, 2020 Author Report Share Posted December 12, 2020 Thank you very much for your reply! Quote Link to comment
wohltemperiert Posted December 12, 2020 Author Report Share Posted December 12, 2020 I talked to a friend of mine and his proposal is to use the VISA lock, which works in a similar way as DVR. Quote Link to comment
Porter Posted December 13, 2020 Report Share Posted December 13, 2020 VISA locks behave strangely in my opinion: I still use them but wrapped in a single element queue. This workaround was implemented in the Plasmionique Modbus Master's MB VISA Lock library. It is described in page 19 of the user guide: https://lavag.org/applications/core/interface/file/attachment.php?id=14276 I also describe use cases on page 10 and 11 if you are interested, I often use this VISA locking library for RS485 instruments that share the same COM port. Quote Link to comment
wohltemperiert Posted December 13, 2020 Author Report Share Posted December 13, 2020 7 hours ago, Porter said: VISA locks behave strangely in my opinion: I still use them but wrapped in a single element queue. This workaround was implemented in the Plasmionique Modbus Master's MB VISA Lock library. It is described in page 19 of the user guide: https://lavag.org/applications/core/interface/file/attachment.php?id=14276 1.08 MB · 1,807 downloads I also describe use cases on page 10 and 11 if you are interested, I often use this VISA locking library for RS485 instruments that share the same COM port. Wow, thanks for your information. I wasn't aware of this behaviour at all and I was just about to implement the VISA lock solution. I will read it. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.