LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Buffer Serial Data before Transmit

Solved!
Go to solution

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.

 

    1. Read in hexadecimal string (Example: 001122334455)
    2. For loop repeats for half the length of the string because I am transmitting in byte size blocks (Example: 6F)
    3. Reads the first byte of the ascii string and converts it into hexadecimal equivalent byte and transmits.
    4. 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?

0 Kudos
Message 1 of 7
(3,561 Views)

@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.

 

    1. Read in hexadecimal string (Example: 001122334455)
    2. For loop repeats for half the length of the string because I am transmitting in byte size blocks (Example: 6F)
    3. Reads the first byte of the ascii string and converts it into hexadecimal equivalent byte and transmits.
    4. 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?

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 7
(3,536 Views)
Solution
Accepted by topic author everettpattison

@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.

0 Kudos
Message 3 of 7
(3,531 Views)

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.

0 Kudos
Message 4 of 7
(3,510 Views)

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.

0 Kudos
Message 5 of 7
(3,510 Views)

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.

 

Convert ASCII Hex to binary.png



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Download All
0 Kudos
Message 6 of 7
(3,484 Views)

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)

 

 

original.png


Afterward, convert the byte array into a string, and send out via VISA Write.

Certified-LabVIEW-Architect_rgb.jpgCertified_TestStand_Architect_rgb.jpg


"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

0 Kudos
Message 7 of 7
(3,475 Views)