LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

When highlight execution is "ON" i get the output but when highlight execution is "OFF" i am not getting output.

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)

 

These values should be put into table separately. I am using VISA for communication and data is dynamic and keep coming continously. When highlight execution is "ON" i get the output but when highlight execution is "OFF" i am not getting output.

 

Another problem is the data obtained in the table is getting updated in 1st row itself , i want the next set of data sent by the machine to be stored in next row. I have attatched the vi for reference. It would be very helpful if i get solution to both the problems.

 

Thank you. 

0 Kudos
Message 1 of 7
(3,664 Views)

@madara77 wrote:

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)

 

These values should be put into table separately. I am using VISA for communication and data is dynamic and keep coming continously. When highlight execution is "ON" i get the output but when highlight execution is "OFF" i am not getting output.

 

Another problem is the data obtained in the table is getting updated in 1st row itself , i want the next set of data sent by the machine to be stored in next row. I have attatched the vi for reference. It would be very helpful if i get solution to both the problems.

 

Thank you. 


When the lightbulb makes your communications programs work, it's almost always because of some timing issues with your communications.  Your first thought might be "I'm not waiting long enough" and put some delays between writes and reads, but the real reason is you are not quite understanding how the equimpment wants to communicate.

 

If the message returns is ASCII - which certainly seems to be the case - it is probably terminated with a character (or at worst, characters) and we can approach the communications in a much more robust and efficient way.

 

I wish NI would update their serial port examples to include an example where a termination character is expected.  If they did, we would likely not be having this conversation.

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 2 of 7
(3,646 Views)

You don't need the bytes at port if you are using a termination character.  The function will read until it sees that character or a timeout occurs.   Check out some of the examples that ship with Labview.

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 3 of 7
(3,645 Views)

The easiest way to fix this is to add a delay after the write and before the read. The correct way would be to stop using bytes at port to determine your read size. Your device probably uses a termination character, you should configure the read to look for that and set the bytes to read to a bigger number than a response will be.

0 Kudos
Message 4 of 7
(3,644 Views)

billko wrote
I wish NI would update their serial port examples to include an example where a termination character is expected.  If they did, we would likely not be having this conversation.

 Check the Advanced Serial Write and Read VI.  It shows how to use termination characters.

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 5 of 7
(3,636 Views)

@aputman wrote:

billko wrote
I wish NI would update their serial port examples to include an example where a termination character is expected.  If they did, we would likely not be having this conversation.

 Check the Advanced Serial Write and Read VI.  It shows how to use termination characters.


I did see that - but I wish they would have a "Simple Serial Port With Term Chars.vi" to complement their "Simple Serial.vi".

 

But then, they do have the "Continuous Serial Write and Read.vi".

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 7
(3,631 Views)

Without even looking at your code, I knew you were using the Bytes At Port, which introduces some very interesting race conditions.

 

So my first question is does the machine send out a termination character?  The termination character is typically a Line Feed (0xA).  Your code is currently set up to use the termination character.  So if the machine does send this, then what you should do is get rid of the Bytes At Port and just tell the VISA Read to read more bytes than you would ever expect from a message, something like 100.  The VISA Read will stop reading when it encounters the termination character, it reads the number of designated bytes, or has a timeout, whichever happens first.

 

So with the termination character, you can now ensure that you have the entire message and than therefore process it.

 

To further help you clean up your code, did you know that the case structure can accept strings?  So you can use a single case structure to choose which table to write to.

 

To append to your table, you will need to use shift registers.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 7 of 7
(3,619 Views)