12-16-2016 11:26 AM
Hello,
I'm replying to this thread because I have the same problem as was reported before. I'm reading voltage values from an STM32 microprocessor via FTDI cable, so accessible in Labview as a COM port. If I set the delay in the while loop to 0, I get errors where the data tends to sometimes be chopped in half (e.g. a voltage of 0.0013 could be split into 2 parts and read in separately as 0.00 and 13). I have programmed the micro to output the voltage values with a * termination character, but despite this, the 0.00 will be read in by Serial Read. This chopping of data happens less if I increase the delay to maybe 50 us, but it still happens.
I read above that a delay shouldn't be needed at all, and that Bytes at port shouldn't be used (I tried just wiring 1 into the 'number of bytes' entry in Visa Read but it didn't work properly).
So basically I'm going about trying a lot of different things to improve this behaviour but my understanding is not great as I don't work often with Labview, I'm hoping a kind expert can offer some help 🙂
I attach my code.
Thanks
Robert
12-16-2016 12:16 PM
Why would you enter 1? You know the message is longer than that.
Reread messages #2 and #6 in this thread. You want to enter a number that is larger than the longest message you expect to receive.
(I can't open your VI because I don't have LV 16 installed to be able to comment any further.)
12-16-2016 12:20 PM
DItto what Ravens Fan posted but while I am thinking about...
"13" in decimal is a "CR" in ASCII.
Ben
12-16-2016 12:28 PM
1. Only set the termination character at one place - VISA Configure Serial Port.
2. You probably do not need the Flush Buffer. It is almost never necessary.
3. You do not need VISA Open.
4. You never need Bytes at Port if you have a termination character. Set the byte count to a value larger than the longest message you expect to receive. The Read will end when one of three conditions occurs: The number of bytes is received, the termination character is received, or timeout.
5. Read with termination character does not return the termination character in read buffer. So, your match may never occur because you are searching for the termination character.
6. Use of Build Array inside loops (especially nested loops) is generally not a good idea because the growing array forces memory reallocations and can lead to slow performance and crashes. Preallocate space for the arrays using Initialize Array outside the loops and use Replace Array Subset inside.
7. Since you know the size of the 1D arrays (5), use a for loop rather than the while loop.
******
8. Combine 6 and 7 for further simplification. Just use auto-indexing to generate the output arrays.
******
9. Converting the string to both an integer and a floating point number seems unusual. Why not just use the floating point conversion and wire it to both the numeric indicator and the chart?
10. No need for the Wait. The Read function will wait until one of thr criteria specified in 4 occurs.
11. We do not care what colors you use but many of us find colored block diagram distracting at least and difficult to read in many cases. Color blind persons may find certain combinations tend to obscure wires or other objects. Please use default colors when posting VIs.
Lynn
12-16-2016 12:44 PM
wow - thanks so much for the detailed reply and for fixing the vi for me.. I'm going to learn a lot from going through your comments, and it's going to be so useful for other projects too.
much appreciated all posters
Robert