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: 

VISA RS232 data read continous graph

Hello,

 

Im communicating AVR device with my computer using RS232 and VISA toolbox

AVR is sending numeric data (positionfrom encoder) via RS232 and i want to plot incoming data in real time using waveform chart (since data is double type).

 

Here is my program:

VISA RS232.png

 

Currently there are two things that are not really working as i would like to. 

 

1st is that incoming data from VISA read appearing in Response string indicator is being erased with every read and replaced with new reading. I cant find a way to make it appear one below another and so on.

 

2nd problem is that the data i read appears in the moment of read and then it dissapears instead of being displayed untill new data is received. Im sending packet of data from microcontroller every ~400 ms and im reading it in labview every ~100 ms but it was happening as well when i was reading it every ~400ms and i was sending it every ~100 ms (so there was always a data to read).

Because of that when i plot incoming data in Waveform chart they appear as spikes with 0 value in between each other. I was expecting to see a stepped graph.

 

Beside those two problem, data (floating point 5 digits of precision numeric value converted to string before sending) is being received correctly.

Thank you in advance for help.

 

0 Kudos
Message 1 of 6
(4,185 Views)

For #1, you would use a Shift Register on the WHILE loop and use the Build Array to keep appending data to it.

Message 2 of 6
(4,168 Views)

Ok, you are talking to a microcontroller.  It sounds like you are doing the microcontroller as well.  You have full control over the communications protocol.  So let's get some details of how this protocol works.

 

Do you need the request for data or does the microcontroller just spit out the data at a regular rate?  If it just spits out the data at the regular rate, there is no need for the VISA Write or the Wait.  That would also eliminate the sequence structure.

 

It looks like your microcontroller is passing the value out in ASCII text.  You are also setup to use a termination character (by default, an End Of Line character).  So with that information, you need to eliminate that stupid Bytes At Port.  With the Termination Character enabled, your VISA Read will wait for the number of characters you requested, the timeout, or the termination character, whichever happens first.  So you just set the bytes to read to something stupidly high (like 50).  When that termination character is found, the VISA Read will pass along all of the characters recieved up to that termination character.  So your VISA Read will limit your loop rate.  Therefore, again, no need for the Wait.

 

Just to clarify, what is happening is that if there is no data at the port, the bytes at port returns a 0.  So you tell the VISA Read to read 0 bytes.  It immediately returns 0 bytes.  Oh, your response was just cleared by the empty string that was returned by the VISA Read.  And you likely also get a 0 in your chart.

 

And one last note.  Move the VISA Close to run after the loop.  This eliminates the need for that case structure.


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 3 of 6
(4,155 Views)

Hello,

 

Thank you both for answer i applied your advices to my design.  I modified both my microcontroller program and VI program.

 

Now it works in a "question and answer" way. So microcontroller does not send anything unless a command 0 is sent.

 

I also tried to create that shift register but there is problem.  This is how my program looks:

loggingv2.png

 

Thanks to the delay between write and read and that microcontroller will send data only if asked by application, i have more control over frequency of incoming data.

 

The problem that appeared now is that when i lower the time between read and write to less than 16 miliseconds (i changed it to control  before saving this snipped) im getting false readings, every now and then i have spikes with very high values like 50 000 000 (while the maximum of signal im measuring is 359). But i guess this is caused by my microcontroller program.

0 Kudos
Message 4 of 6
(4,088 Views)

with for loop , shift register and feedback  node you have made a mess.

get rid of those things and use one simple idea.

history.png

 

Courtesy for this goes to altenbach.

Message 5 of 6
(4,073 Views)

You shouldn't need a delay precisely between the Write and the Read.  The termination character takes care of all of that.  However, you need need a delay in your loop just so your microcontroller can keep up (or so it sounds).  You don't need that sequence structure either.


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 6 of 6
(4,056 Views)