LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

separate ADCs values from UART for many string

Hi, 

I am transferring DAC created and ADCs acquired using PSoC UART, I have created for loop to send signal. Each string sent to UART has the form: DAC[space]ADC[CR]

I have successfully send this string through UART using VISA Read as in the Examples and I used Match Pattern Function to separate the signal but in only ONE FIRST LINE of the read buffer. I have also used String Subset but the results are the same. 

I want to separate DAC and ADC in each line, put them in array and use them to build a XY graph but I am stuck at the separation stage. 

I attached my VI below. Please take a look and give me some advice, I have spent a few days to read some thread on the forum related to my subject but I couldn't find a proper answer. 

I am newbie to LabView so any suggestion would be appreciated. Thanks in advance! 

0 Kudos
Message 1 of 10
(4,060 Views)

Bytes at Port is usually the wrong way of determining how many bytes to read.  Since you are expecting a termination character of carriage return, you should take advantage of that and read a large number of bytes.  You have the termination character enabled by default at the Serial Config function.  The termination character is at its default of Linefeed.  You should change it to a carriage return by creating a constant at the the Serial Config function and changing it to decimal 13.

 

It is odd that you are writing a single string to your port, then trying to do 18 reads in a row.  Is that how your device is supposed to work?  Usually you would expect to be able to read a single value for every single command that you write to the serial port.

Message 2 of 10
(4,046 Views)

your post is not clearify what you are upto. unfortunately my LV is opening your vi beacuse of ver issue. any how if you send the image of your vi block diagram then it will be easy to understand the problem

 

have you put your reading UART and then aray matching patteren in a while loop

0 Kudos
Message 3 of 10
(4,045 Views)

Thank you for your help.

I realized that I have made a mistake, the termination character in my uC code should be newline, but I used CR instead. However, the signal still come in different line so I didn't recognize it. 

It's not that I write a single string to my port, I want to read single value for each command as you said and put them in array to build graph. Maybe my code is wrong so you misunderstood it. 

Edit: I changed the termination char to NL in my code. It seems to work better 😄 now my read buffer only receive a single line for each FOR loop. 

 

Capture.JPG

Tirmizi: Here is my block diagram. I read the data from each command so I think I can put them in a FOR loop. Do I really have to put them in a WHILE loop? 

0 Kudos
Message 4 of 10
(4,022 Views)

Still, get rid of Bytes at Port.  Just wire a constant into the VISA read that is larger than the longest response you ever expect to get.  Once you do that, you can also get rid of the wait statement.

 

So is it completely working for you now, or not?

 

It seems to me that the VISA Write should be in the loop as well if you are expecting to get a single response for each single comand that you write.  If you expect to get 18 responses for each command that you write, then you are just fine with the Write outside the loop.

Message 5 of 10
(4,018 Views)

Ok, I got rid of the Instrument Bytes Port, thanks. 

About the Write, I only have to write once to the uC and all the responses will go back, I think it's okay as you said. 

One more thing, I want to build an array based on the string separated from each line and then use them to draw a graph. I used the Build Array function and tried putting it both inside and outside the loop (for the outside case, I used concatenating tunnel mode), but both of them don't work, the array just update the zero-index with each new line received. Do you have any suggestion? 

Edit: In case I want the loop read all the values received and automatically ends when the port is empty, how can I use a WHILE loop? 

0 Kudos
Message 6 of 10
(4,003 Views)

Show what you have now.  It should be as simple as using an autoindexing tunnel.

0 Kudos
Message 7 of 10
(3,998 Views)

When I use auto-indexed tunnel, I got the error below:

Screenshot 2014-04-10 10.53.52.png

why do the separated strings have dimensions of 2? And about the while loop, what should be my end loop condition to stop when the port is empty 😞

Edit: I put the array in the while loop and the error is vanished but the array always updates at index 1 like this: Screenshot 2014-04-10 11.11.14.png

0 Kudos
Message 8 of 10
(3,992 Views)
You wonder why you get a 2D array? You use the build array inside the loop and exit the for loop! The build array inside the loop is just silly. The other code is just as silly because you create a new array with each iteration!
Message 9 of 10
(3,964 Views)

Well, I checked out the help session and found out what I have been doing is wrong. I did as you say, put the Build Array outside the loop and got the indexed array of values transferred. 

To be honest, my work is pretty finished but I want to improve it a bit. Now I am using a WHILE loop and whenever I want to stop the loop and get the array, I will just push the T/F Boolean control. However, in my real code, there will be about 1000 lines of values transferred and I don't want to wait until it's complete to push the button. I want the loop automatically stops when the port is empty. Do you guys have any idea on doing this? Should I use a FOR loop? 

Anw, thanks very much for all your help Smiley Tongue

0 Kudos
Message 10 of 10
(3,951 Views)