Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

serial port read strings to numbers

Hello. I have a Teensy 3.1 ADC sending out data at a rate of 1KHz to the serial port , and i have a while  loop that reads the port by using "Bytes at port " as counts to "read serial " block with a time delay of 1 milliseconds inside the while loop.It seems though i read with or withot the time delay inside while loop ,i miss the data in between in a random manner. 

The data after converting into numbers using "spreadsheet string to array" function in a waveform chart, i see random spikes and dips for a sinusoidal wave fed as an input which is of 1 Hz frequency.

I doubt that while reading itself ,the strings are being concatenated with one another which creates these random spikes.,since a continuous sine wave input should provide a smooth waveform output in the chart.

I have taken ADC data from Teensy directly and plot them in Excel sheet, and no spikes at all. 

Can the problem arise from labview not in synch with ADC outputrate ? or the conversion from strings to numbers?

Please have a look at the VI i have attched.

Thanks .

0 Kudos
Message 1 of 6
(3,719 Views)

roopesh689,

 

Your description gives no details on how the Teensy is transmitting the data.

  • Is the data be transmitted as ASCII or Hex?  
  • Tab character is the delimeter between characters?
0 Kudos
Message 2 of 6
(3,718 Views)

The Bytes At Port is an almost guaranteed way to get out of sync with your data messages.  Mind sharing the code you have for your Teensy?  That would tell us what the messages it is sending are and we can make a lot better suggestions from there.


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

You can see the Teensy code attached below.

We get AsCII characters from Teensy.

The delay of 1000 microseconds are kept in code for samping frequency of 1 Khz.

0 Kudos
Message 4 of 6
(3,632 Views)

The strings miss in between and after concatenate them the result is some like this

 

16112 65536 65536 65536

16114 65536 65536 65536

65536 65536 65536

16118 65536 65536 65536

 

The ADC data are send sequentialy at 1 khz samples .After concatenate them the channel data are not in order since in between channel reading is lost somehow.Hence it creates a sudden drop or spike in waveform plot as well.

 

0 Kudos
Message 5 of 6
(3,630 Views)

1. It looks like your Teensy is actually performing the read twice per iteration.  Is that by design?

2. You are using a PrintLn at the ench of each 4 measurements.  This shows that you are using a termination character and it should be a carriage return (0xA).  So enable using the termination character and tell the VISA Read to use more bytes than you would expect in a single read.  This way you know you got the full message.


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