Jump to content

Serial Communication non-reentrant and reentrant


wohltemperiert

Recommended Posts

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!

Link to comment

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

Link to comment

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.

Link to comment
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.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.