LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with com port when streaming data.

Hi banksey255, your benchmark code is telling me that opening and closing the modbus  session inside the loop takes 10.5 ms and outside takes 8.6ms, puzzling that your figures are so much different to mine!

 

0 Kudos
Message 21 of 28
(169 Views)

I'd interpret that to be pretty good evidence that the main contributor to not being able to achieve a 100ms iteration interval is not modbus, if all your modbus devices achieve similar results, because combined they will only require about 40ms.

 

The only other aspect I see in your loop is writing data to the file, so you might like to benchmark that aspect and see how long it takes. The "Write Delimited Spreadsheet (string).vi" is a relatively low performance way to write frequent small amounts of data. It seems unlikely that it would require so much time, but there's nothing else and I've seen systems that are apparently worse. Fortunately, if it does turn out to be the main contributor to the long iteration interval, then it's relatively trivial to solve.

 

I did see you're using an Ardiuno and if you're doing the modbus communication with it through its USB connection then LabVIEW VISA open (which the modbus library uses) will cause it to reset because it sets the DTR line. To solve that, I personally use the System.IO.Ports.SerialPort class to interface with Arduinos rather that LabVIEW VISA. Mind you, I also see you apparently tried not interfacing with the Arduino and it didn't solve the problem either.

 

On a side note, your different benchmark results are probably because your device's baud rate is double my device, and in my experience some modbus devices can take a relatively long time to respond to a request. The longer open / close may have something to do with the USB to RS485 adapter that was present on my system.

Message 22 of 28
(154 Views)

Thanks Xonmyth, 

The program seems to run very fast. I dont yet understand how it works just the output is the wrong way round. It should read each slave in sequence once then output the milisecond timer. I will get there eventually. One thing that would really help, How does it cycle between slaves?

 

This the output from your example set with slaves 2,3,4. 

71.114166,71.114174,71.114174,71.114174,71.114159,00:00:02.189 01/01/1904,2.18907 (slave 2)
72.588058,72.588058,72.588043,72.588043,72.588074,00:00:02.190 01/01/1904,2.19006 (slave 3)
73.470886,73.470886,73.470848,73.470848,73.470833,00:00:02.212 01/01/1904,2.21205 (slave 4)
0.000000,0.000000,0.000000,0.000000,0.000000,00:00:02.228 01/01/1904,2.22804 (endless?)
0.000000,0.000000,0.000000,0.000000,0.000000,00:00:00.200 01/01/1904,0.20018


below is what I hope to achieve; slave 5 (accelerometer geophone), slave 2, slave 3, slave 4, ms timer

 

0,0,71.116257,72.601601,73.475792,0.02408
0,0,71.116257,72.601639,73.475693,0.21198
0,0,71.116295,72.601601,73.475769,0.36739
0,0,71.116341,72.601639,73.475952,0.52874
0,0,71.116531,72.601562,73.476173,0.68994
0,0,71.116707,72.601578,73.476418,0.85341
0,0,71.116898,72.601471,73.476753,1.01185
0,0,71.116989,72.601402,73.477058,1.17064
0,0,71.116974,72.601227,73.477333,1.33905
0,0,71.116234,72.601166,73.477562,1.50079

0 Kudos
Message 23 of 28
(128 Views)

Hi Banksey255,

Can you suggest an alternative to using write delimited spreadsheet (string).vi?

0 Kudos
Message 24 of 28
(122 Views)

Hello EdHarris,

 

Good to hear. To your questions:

 

1) It cycles between the slaves using the "Auto-indexing" in the for loop. It goes through each device's reference in the array. This mirrors the value you enter for device settings on the front panel. Please read about autoindexing in for loop and maybe try to out some smaller scale examples to get a good understanding of it. It will help big time.

 

2) Out is the wrong way around, based on the example you provided, it looks like the output just needs to be transposed. I have implemented it in the updated example (attached).

 

3) Slave order 5, 2 , 3 ,4. When you populate the device settings array on the front panel, use this exact order. Device 5 value will be entered first then 2nd and so on.

 

I had some time and curiosity so I made an example state machine for you ( a crude example). It draws parallel to your Beam 4 Plas 2020.vi. Study the attached VI, EDIT: Start from connect case and go through each case. Hope it helps.

Message 25 of 28
(99 Views)

Regarding an alternative to "write delimited spreadsheet (string).vi", honestly, I still struggle to think that is the cause of your long iteration interval (even on the system I may be observing something like that on, I am doubtful, but haven't had time to explore it yet so can't dismiss it), but I presume you've explored the problem enough:

 

One way to make the file aspect orders of magnitude faster (at least based on my benchmarking of a similar sized write operation) is to open the file when you start data logging and keep it open, do all your write operations during data logging, then only close the file when you end data logging. If you explore the block diagram of "write delimited spreadsheet (string).vi", you'll notice that each time it runs, it opens the file, moves the file position to the end, writes the data, then closes the file. These open/close/position operations have overhead and impact optimising disk performance, so the fewer you can do when it matters, the better.

 

In any case, it sounds like the changes Xonmyth is helping you with may be solving the problem.

Message 26 of 28
(72 Views)

Thanks Xonmyth for taking the time to write that piece of code, I am studying and testing - might take a while.

I still need to make it read 4 slaves once in sequence 6000 times. Is it just a matter of changing the forloop from 6000 to 1 and adding another forloop for 6000? or is it already doing that? If so how do I get the data from each successive read on each slave on the same row is going to be the question.

0 Kudos
Message 27 of 28
(46 Views)

Hi EdHarris, 

 

To develop an understanding. Create a code like this one and study how it works:

Xonmyth_2-1762889192856.png

 


For you code, you will be making the same change which would look like this:

Xonmyth_0-1762889038043.png

 

Sorry, I only had time to share pictures. 

Message 28 of 28
(31 Views)