LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with com port when streaming data.

I have been using modbus with the Plasmionic library to read data from a number of servers for some time but several months ago I changed to streaming the data at intervals of 100ms. I have found though that to get the program to run at an acceptable speed I have to abuse the system. I discovered that if you stop the program whilst it is running, the com port address box shows ASRL5::INSTR along side the other com ports (the com port in use is 5). If ASRL5::INSTR is not showing in the comport address box it runs slow, if there is an  ASRL5::INSTR in the comport list it runs at a suitable speed but if there are extra copies present "ASRL5::INSTR(1)" modbus will not run. I am using a RS485 bus which will run at this speed or faster it is just getting it to do it in a straight forward way is the challenge.

 

Any suggestions how I can correct this or what might be the cause gratefully received.

 

 

0 Kudos
Message 1 of 9
(243 Views)

I don't have that same Modbus library and don't feel like downloading it, so I just get ??? boxes, but I think I see a likely problem.

 

You're reading 3 different things each loop, opening and closing the session each time.  It's not obvious to me whether you're reading 3 things from the same COM port each time or 3 things from 3 different ports.

 

Whichever it is, if you "stop the program whilst it is running" it causes problems, you say.  There is no mechanism in your code to stop running things on either of the inner 2 loops, so I have to conclude that your method of stopping is pressing the little stop sign button on the toolbar.  This is very bad practice.  I've heard it best described as "it's like stopping your car by driving it into a tree".  It is a hard stop, immediately, and does not do any cleanup, nor does it wait for a loop to finish or any other nice stopping point.  So it's likely that when you stop the program, it quite often is in the middle of a communication session, and that somehow jams up the port because it doesn't finish communicating.  

 

So the main thing I would suggest as an immediate change is that you add a conditional terminal to your inner 2 FOR loops, and move the Stop button read to the innermost loop, and then connect it to all 3 stop terminals, and then stop using the little "stop sign" button.

 

The other suggestion I would make would be to move the "Open session" and "Close session" VIs out of the loop, and just run them once at the start and end.  Here's a mock-up of what I mean, using VISA reads:

Kyle97330_0-1753894963703.png

There are plenty of other things that could be improved but those are the big two that I think could assist with your immediate problem.

Message 2 of 9
(215 Views)

The issue with ASRL5::INSTR(1), (2), etc. is that you're not closing the COM ports after using them. Implement an actual "graceful stop" function in your code with a button or something that halts the loop, and make sure VISA Close gets called.

 

Also, don't open and close in the loop- do it once at the start of the "fast stuff" then ONLY do reads from then on.

Message 3 of 9
(206 Views)

Thanks for your suggestions, I will do what you suggest about the stopping routine in the future but as it stands the appearance of ARSL::instr codes in the com port is the only way to get the program running at correct speed. Also unfortunately as you suggested to open the and close the session outside the loop but I am reading four different servers and the server address designation is in the open session vi. There appears to be no way to put it into the read holding register VI so that I could do what you suggest. Well I tried copying and editing that VI but tricky things happen like it requires you to de-link it from the library and then some of the functions dont work. 

Anyway I am not sure that is the problem because the program will run at the correct speed (or faster) just not without coercion. here is a picture of the modbus master open serial session vi where the reference to ARSL::instr appears but it is a property node and I dont understand what that it is doing.

 

MB Master open serial session.png

0 Kudos
Message 4 of 9
(170 Views)

@EdHarris wrote:

Thanks for your suggestions, I will do what you suggest about the stopping routine in the future but as it stands the appearance of ARSL::instr codes in the com port is the only way to get the program running at correct speed.

 


I can't comment on the speed issues, but to clarify my comment, I meant that the number in parentheses comes from not closing the port after using it (leaving it hanging open). Not the existence of ASRL:INSTR itself.

 

For what it's worth, I see the "extra number" thing happen for ports labeled as COM5/COM10/whatever.

0 Kudos
Message 5 of 9
(130 Views)

@EdHarris wrote:

Thanks for your suggestions, I will do what you suggest about the stopping routine in the future

<mega/snip>


I wouldn't wait for the future because the future is now.  Not stopping your program correctly is the entire cause of your issue.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 9
(119 Views)

@EdHarris wrote:

Also unfortunately as you suggested to open the and close the session outside the loop but I am reading four different servers and the server address designation is in the open session vi. There appears to be no way to put it into the read holding register VI so that I could do what you suggest.

 


Well, that may be a limitation of the "Plasmionique" Modbus library, but there are at least 2 other options for LabVIEW and Modbus.  

 

Option #1:  NI Modbus Library

https://github.com/NISystemsEngineering/LabVIEW-Modbus-API

 

Option #2:  Older VISA-based library.

https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z0000019LP9SAM&l=en-US

 

I use the 2nd one myself, slightly modified to fit inside my standard hardware model.  Both haven't been updated in a while, but also the Modbus protocol hasn't been changed in even longer, so it's not like they won't work.

Message 7 of 9
(114 Views)

By server address, do you mean the slave address or the COM port?

 

You can change the slave address after initialization using Set Slave ID.vi.

Spoiler
cordm_1-1754033539837.png

 

 

If you need need multiple COM ports, you can create multiple Modbus master instances and reuse them in the loops.

Spoiler
cordm_2-1754033901542.png

 

Message 8 of 9
(83 Views)

Thanks now I have plenty of options, I have already started trialling the NI-modbus library. I couldnt get it working before and that is why I used plasmionique but I have it working on a small scale now. but the set slave ID vi is also a good option.

0 Kudos
Message 9 of 9
(72 Views)