LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

read numerical data with visa serial read

Hi!

I will recieve numerical values (unsigned integers 0-255) from hardware via the
visa serial read function. This function only delivers data through a string!
My question is:
Is there a way to collect the values (read one byte at a time) in the way they come, as numerical
data, or will this readfunction in some way convert all data to ascii-values or does it only
"understand" asciivalues? This will make difference in code.

Lets say the numerical number 123 goes from hardware to LV:s visa serial read, Can I
collect this number directly through the string even though its a different datatype?

/thanks fred
0 Kudos
Message 1 of 12
(3,215 Views)


@Fred wrote:
Hi!

I will recieve numerical values (unsigned integers 0-255) from hardware via the
visa serial read function. This function only delivers data through a string!
My question is:
Is there a way to collect the values (read one byte at a time) in the way they come, as numerical
data, or will this readfunction in some way convert all data to ascii-values or does it only
"understand" asciivalues? This will make difference in code.

Lets say the numerical number 123 goes from hardware to LV:s visa serial read, Can I
collect this number directly through the string even though its a different datatype?

/thanks fred



Serial data are always transmitted as a series of bytes. Upon reception, you can convert the byte series to anything you want. There are a number of tools for that in LV. The most straightforward is probably the String To Byte Array function (in the Function>Strings>String/Array/Path conversion sub palette).
Come back and ask for more help if deeded...

CC
Chilly Charly    (aka CC)
0 Kudos
Message 2 of 12
(3,215 Views)
Hello again

Thanks!

So I Can use "string to byte array" function as you say and this output will be exact number from hardware?

My question is really in which form my unsigned 8 bit integer from hardware will "come out"
from the readfunction. If i want to get one whole value from hardware, lets say 123, how many bytes must
the readfunction take to read, one i hope?

Or is it so that the hardware must convert this value to strings,"1", "2" and "3" before sending so that the
readfunction must take three bytes and then you have to program a little to get those to one numerical value?

/Fred
0 Kudos
Message 3 of 12
(3,210 Views)

@Fred wrote:
So I Can use "string to byte array" function as you say and this output will be exact number from hardware?
My question is really in which form my unsigned 8 bit integer from hardware will "come out"
from the readfunction. If i want to get one whole value from hardware, lets say 123, how many bytes must
the readfunction take to read, one i hope?
Or is it so that the hardware must convert this value to strings,"1", "2" and "3" before sending so that the readfunction must take three bytes and then you have to program a little to get those to one numerical value?



The "123" value will be sent as a series of 1 and 0 (b01111011), in a single byte ($7B) (I prefer to think about serial data as series of hexadecimal numbers ($00 to $FF).
You should not worry about the conversion, usually, a byte is sent as a byte...That's a different story with real numbers !

CC
Chilly Charly    (aka CC)
0 Kudos
Message 4 of 12
(3,202 Views)
Hi again!

So your answer is I can use "string to byte array" function, and let
the readfunction take one byte, and i dont have to worry?

/Thanks Fred!
0 Kudos
Message 5 of 12
(3,201 Views)

@Fred wrote:
Hi again!

So your answer is I can use "string to byte array" function, and let
the readfunction take one byte, and i dont have to worry?

/Thanks Fred!



Yes !!!
However, remember that serial communication requires a proper configuration of the serial port parameters (speed, parity,...), and a proper communication protocol. How are the data sent on the line ? Upon request from the PC ? Or what ?
Why don't you try it, just to see what sort of problem you forgot to mention ? 😉
Have you see the serial communication examples shipped with LV ?

CC
Chilly Charly    (aka CC)
0 Kudos
Message 6 of 12
(3,196 Views)
Hi!
There is a protocol. The hardware sends me sampled measured values when recieving
parameters from LV (visa write-function). The reason im asking is that this hardware
is not made finished!

/thanks!
Fred
0 Kudos
Message 7 of 12
(3,189 Views)
So you can do exactly what you want. One more reason not to be worried 😄
Send bytes, upon receipt of a given char (sent by the PC), if you can have a bidirectionnal com.
Otherwise, send the byte string once every n seconds (or faster if you can afford it). The PC will have to be synchronized with the byte stream, but that's not a big issue.

CC
Chilly Charly    (aka CC)
0 Kudos
Message 8 of 12
(3,184 Views)
Hello!

In the sending string from PC (with parameters), do you think a "startbyte" (and stopbyte) is a good thing in the string,
or is that not needed?

And what do you mean with PC will have to be synchronized with the byte stream?

/Fred
0 Kudos
Message 9 of 12
(3,172 Views)
Things depend on how secure the communication should be :
If you can afford loosing some data, you could use a unidirectionnal connection (from system to PC), send your bytes as a stream, on a timed basis (for instance every second). The PC will listen and detect the beginning of "text", after a silence period. Means that it might lost a series before being synchronized.
If you need something more accurate, you should use a bidirectionnal connection. The system waits for a print order from the PC (for instance a char), before sending the byte stream. The PC knows the number of bytes to wait for, and can detect missing chars in case there are communication problems.
These are the most basic protocols.

CC
Chilly Charly    (aka CC)
0 Kudos
Message 10 of 12
(3,166 Views)