LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sensor Output 0 using VISA Read

Hello,

I’m using the VISA Read to read data from 3 sensors, and occasionally, the graph is plotting sensor output of 0.   I believe the issue has to do with timing in my Labview 2017's while loop (see attached pic 0 for my Labview block diagram).  Has anyone experienced this issue and how to solve it?

-----------------

Here is a detailed description of my issue:

 

Hardware configuration:

  1. Using a microcontroller (MSP430F5529) to read 3 accelerometer sensors (MC3672)
  2. Using UART at baud rate of 115200 bit per second to capture sensor output data
  3. Using Labview’s VISA Configure Serial Port to capture and graph sensor output data

Problem:

  1. If the while loop waits 2ms (or 3ms…or 10ms) to run, then occasionally, the graph shows that the sensor has an output of 0 (see pic 1 in attachment)
  2. Pic 1 shows the 0-issue occurring at sensor accelerometer #1 in the Z-axis, but I’ve seen it occur for sensor #2 and sensor #3 as well.
  3. If the while loop waits 1ms (or no wait at all), then I see the 0 occurring a LOT more (pic 2). This leads me to think that the issue is this while loop’s wait time.

Other Troubleshooting techniques:

  1. I don’t think the issue is the sensor outputting the 0’s because I am constantly polling the output of the sensor in my microcontroller code, putting a breakpoint in the code if the sensor outputs 0, and I have never been able to capture this sensor reading of 0’s (see pic 3 for a snippet of my microcontroller code)
  2. I am also attaching a picture of the I2C capture from an oscilloscope (pic 4) if that’s helpful. This picture just shows that each sensor reading takes about 2ms
0 Kudos
Message 1 of 8
(3,770 Views)

I think your first problem is you are using Bytes at Port.

 

Does your incoming data have a termination character?  I would guess it does since you have enabled the termination character in your VISA Serial Configure.  Take advantage of it! Get rid of Bytes at Port and wire in a constant that is larger than the longest message you ever expect to receive.  That way you know you are getting complete messages.  Right now, you might be getting incomplete messages which would cause some to channels to be interpreted as zero.

 

Also, Index Array is resizable.  Just drag down the bottom border.  The indices will automatically be 0, 1, 2, 3, ... without wiring up any constants.  That saves you lots of extra Index Array nodes, wires, and constants.

0 Kudos
Message 2 of 8
(3,765 Views)

In addition to what Ravens Fan pointed out.

 

Use join numbers to convert 2 U8s to a U16.   that will simplify your 2's complement vi Better yet use split array to return the 0th element and the array of sensor data then cat the sensor data array of U8s to an array of I16s (as Altenbach will point out - there is way too much code there you could fit it on a postage stamp!)

 

The VISA Close is unnecessary but the way you are using it is "Wrong"  Did you know you are tring to close a Session with the name of the read buffer? 

Try something like this:

The chart is  set to "Stack Plots"The chart is set to "Stack Plots"


"Should be" isn't "Is" -Jay
0 Kudos
Message 3 of 8
(3,754 Views)

Thank you for all of your help.  We found out the issue is that VISA READ may be misinterpreting my sensor output as a new line of data, and therefore, VISA READ is sometimes grabbing incomplete transfers, and Labview is graphing the incomplete data as 0's. 

 

We solved this issue by creating a while loop, adding shift registers, and making sure I always get 9 bytes of data before plotting them.  See attached block diagram for my solution.  

 

 

Message 4 of 8
(3,698 Views)

Hi amyle,

 

there seems to something wrong with your "solution"…

 

We found out the issue is that VISA READ may be misinterpreting my sensor output as a new line of data

Because YOU explicitely enabled the TermChar at SerialPortInit, using a default LF termchar!

When your communication protocol doesn't use a TermChar then DISABLE it…

 

Get rid of BytesAtPort! When you want to read exactly 9 bytes then set VISARead to read 9 chars (after disabling the TermChar)! No loop needed, no shift register, no ConcatString, no StringLength…

 

Are you sure you want to build an array containing a timestamp and 4 zero values when "write to file" is FALSE?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 5 of 8
(3,690 Views)

@amyle wrote:

Thank you for all of your help.  We found out the issue is that VISA READ may be misinterpreting my sensor output as a new line of data


Lesson to learn here: If you are using binary/hex data, turn the termination character off.

 

And since you know every message is 9 bytes, just tell the VISA Read to read 9 bytes.  You are making life way too difficult on yourself.



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
0 Kudos
Message 6 of 8
(3,676 Views)

Thanks, I definitely have to clean up my code a bit, but the 0 issue has not returned. 

0 Kudos
Message 7 of 8
(3,655 Views)

hello,

Can you share your final VI???

 

0 Kudos
Message 8 of 8
(2,172 Views)