From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to implement multiple commands for serial communication?

 Hi. I am trying to do serial communication with a machine where i have to send commands to receive data back from the machine. The machine has 6 cylinders. I have to collect three types of data

1) Cylinder's flow rate (command to be passed is "b" and data returned for example is "b 32 43 76 34 12 76" )

2) Temperature (command to be passed is "t" and data returned for example is "t 35")

3) Rpm (command to be passed is "c" and data returned for example is "c 400 32.5 23.1" , first value is rpm, other two values are some average)

 

My requirement is to capture all these data at once and displaying it into a table and to generate report. Is it possible to pass mutiple commands at once for serial communication? If not is there any other way to get all 3 types of data one after another by passing one command after another in a loop?

0 Kudos
Message 1 of 7
(4,612 Views)

That depends on the equipment you're using.  Some hardware allows for multiple commands to be separated by some character (like a semicolon) while others do not.  You'll have to check the manual or ask the company.

 

Performing each step is series is certainly possible and can be implemented in various ways.  Each step in the sequence should occur in order by ensure proper data flow (you won't need a flat/stacked structure).  multiple measurements can then be handled with a for loop OR while loop.

   Another option is to use a State Machine architecture where each acquisition (rpm, temperature, flow rate) is it's own state.  You can just as easily measure all 3 in sequence, OR you can change the frequency of the measurements (say you only need temperature every third acquisition).  How you implement your code depends largely on your requirements.

Message 2 of 7
(4,603 Views)

Hi madara,

 

why do you create double posts on the same topic? Stick with one thread per topic!

 

What's wrong with the answer you already got?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 7
(4,585 Views)

Hi.The machine accepts "btc" command and send the data for command "b" , "t" and "c" one after other. But when individual command "b" or "t" or "c" is given and after a period of time if the command is changed in write buffer the read buffer shows data of older command . How to clear the data in read buffer and to instantly get data for new command given?

Another problem is when running the vi if stop button which is inside while loop is pressed the loop does not stop instantly, sometimes we have to stop the whole vi. Is there a solution for this?

0 Kudos
Message 4 of 7
(4,548 Views)

This is completely normal behavior.  The buffer of the machine will hold the data until it is read, overwritten, or cleared.  Whether or not the machine will overwrite the buffer or append to it, is machine specific.  Whether or not the machine has a "clear buffer" command is machine specific.

 

If you are concerned of data being left in the buffer, it is up to you to ensure the buffer is cleared before you make a query.

 

In regards to the VI not "stopping" instantly, you must understand that NOTHING in reality happens instantly.  Your code will be running a certain operation when you hit the stop button.  If it is in a subvi, you must wait for the subvi to finish.  if it is in a portion of the code with a time-out (lets say a read function) you either have to wait for the data to be read or the time-out to occur.

 

It is your responsibility as the programmer to ensure that communication functions smoothly and error free.  In regards to stopping the program in a timely manner, you can reduce the time-out periods to make it seem more responsive to the user.

0 Kudos
Message 5 of 7
(4,545 Views)

I would suggest that you change your design to something like the producer/consumer design pattern (events) template but change the consumer loop to a queued state machine.  This will allow you to respond to send commands and then actively read from the port when data is available.  This will also let you stop your loop like you want.

 

You can use a property node to check for data in the read buffer.

0 Kudos
Message 6 of 7
(4,533 Views)

Hi. I have made a vi such that if i press a "ok" button in front panel data is collected from visa serial. But when i press "ok" button after few seconds i won't get dynamic data (real time data) instead i get data which is already stored in the buffer. Is there a way to set size of I/O buffer or read buffer so i can get real time data when i press "ok" button . Will this be solved if i keep visa serial inside while loop?

0 Kudos
Message 7 of 7
(4,499 Views)