03-20-2013 05:08 PM
Hello, I am relatively new to LabVIEW and had a question about how to buffer data at the serial port before transmitting. I have attached what I have so far for a VI and this is how I expected it to work.
I basically need to place a buffer that fills up until my while loop finishes then transmits all the data at once. Right now there is enough delays between each for loop causes errors.
Any suggestions?
Solved! Go to Solution.
03-20-2013 05:52 PM
@everettpattison wrote:
Hello, I am relatively new to LabVIEW and had a question about how to buffer data at the serial port before transmitting. I have attached what I have so far for a VI and this is how I expected it to work.
- Read in hexadecimal string (Example: 001122334455)
- For loop repeats for half the length of the string because I am transmitting in byte size blocks (Example: 6F)
- Reads the first byte of the ascii string and converts it into hexadecimal equivalent byte and transmits.
- Repeats until string is completed.
I basically need to place a buffer that fills up until my while loop finishes then transmits all the data at once. Right now there is enough delays between each for loop causes errors.
Any suggestions?
I don't think you need a buffer so much as you probably should re-think your solution. Depending on what you want to do, there are much easier ways of accomplishing this...
What are you trying to do?
03-20-2013 05:56 PM - edited 03-20-2013 06:01 PM
@everettpattison wrote:
I basically need to place a buffer that fills up until my while loop finishes then transmits all the data at once. Right now there is enough delays between each for loop causes errors.
Do you mean while loop, or for loop? In the image you put the note that you need a buffer inside the for loop, not a while loop. The amount of computation happening inside that loop is so small that I can't imagine how it's causing delays, but you could easily change it to transmit an entire string at once. Put the VISA Write outside the for loop. Wire the string output from the typecast to the border of the for loop, creating a tunnel. Wire the output of that tunnel to Concatenate Strings, which will combine a string array into a single string. Then connect that to the VISA Write.
EDIT: even better, get rid of the typecast, wire the U8 directly to the for loop border, use Byte Array to String to convert to a string, send that string to VISA Write. There's probably an even easier approach but I didn't look too carefully.
03-20-2013 08:27 PM
I really just want to be able to put a string of any length of hex values and send it out serially. I can do it with the straight ascii to hex conversion found here:
http://digital.ni.com/public.nsf/allkb/894CF5FE064971BF8625758400014993
The problem with this though is that it is limited to 4 hex values (0xFFFF) bytes because of the i32.
03-20-2013 08:27 PM
I really just want to be able to put a string of any length of hex values and send it out serially. I can do it with the straight ascii to hex conversion found here:
http://digital.ni.com/public.nsf/allkb/894CF5FE064971BF8625758400014993
The problem with this though is that it is limited to 4 hex values (0xFFFF) bytes because of the i32.
03-21-2013 10:08 AM - edited 03-21-2013 10:09 AM
Here is a VI that converts the data in the form of <HEX: 00AE 0912 9876 5432> to it's binary equivalent. With a little tuning you should be able to use it to convert your data. This VI is very liberal in how the input data is formatted. The ASCII hex can contain any amount of white space or none at all.
03-21-2013 10:29 AM
Simplier solution to get your hex string into bytes, I wrote about it in a different thread:
@bsvare wrote:
There are ways to do it without a for loop for any size array. But the answer isn't as clean as using a for loop. (Not sure which performs faster)
Afterward, convert the byte array into a string, and send out via VISA Write.
"I won't be wronged. I won't be insulted. I won't be laid a-hand on. I don't do these things to other people, and I require the same from them." John Bernard Books