LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing binary data on serial port

Does anyone can help me?
I must write/read binary data (and not ASCII data) to/from an external
device via a serial link, I must send/ receive a sequence of bytes having
exadecimal values: the standard vi's for serial communication
(serial port write/read ) requires a string ("string to write" for example)
as input.
How can I transmit (and receive) in binary format?
Do you know some other vi's I can use?
Thank you in advance.
Cesare
0 Kudos
Message 1 of 5
(7,465 Views)
To create a "binary" string using a text control or constant,
just pop up on it and select "hex display" from the menu. This
mode allows you to type in hexadecimal values for each byte in
the string. Then just wire the string to the serial write
function. Similarly, you wire the string output to an indicator
that is set to hex display and it will show you the hex values
of the bytes.

If you prefer or need to use numerical format, create a 1D array
of unsigned byte integers(U8)and use the "string to byte array"
and "byte array to string" functions to convert between the
string and byte array type. You can also use the typecast
function to convert from byte array to string and visa versa.
To set the numerical control to hexadecimal, pop up on it and go
to "format &
precision".




* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!
Message 2 of 5
(7,465 Views)
On 11 Feb 2000 11:02:45 -0600, "Cesare" wrote:

>
>Does anyone can help me?
>I must write/read binary data (and not ASCII data) to/from an external
>device via a serial link, I must send/ receive a sequence of bytes having
>exadecimal values: the standard vi's for serial communication
>(serial port write/read ) requires a string ("string to write" for example)

Hi, I had the same problem when I started. In LabView the word
string does not always mean just the ascii characters. Its how you
interpret the values. A string can be a binary stream, to convert to
a number look at "Numeric>Conversion>String to Byte Array".

I have the serial device read in a block of data then I convert it
using the above into an array of numbers that I then check.


Remember the number 20 is just a number in decimal or binary.

Hope this helps alittle.

Regards,

Steve Drake
0 Kudos
Message 3 of 5
(7,465 Views)
I'm having the most odd problem. I've drawn up my 1D array of U8, convert it to string using the U8-2-string converter and send it, but my device does not respond.

So I tap the line with an Oscope and I see that only some of the numbers are being sent out correctly. I send out a 32, it replies with a 32 (correct!). I send out a 30, it replies with a 34, 36 combination. Btw these are all hex values. I've checked and double checked that I'm sending out a hex 30. Anyway it started doing the same for the 32. What is happening??? I tell it to send two hex number, it sends four!!??!?
0 Kudos
Message 4 of 5
(7,465 Views)
ilan the amazing wrote:
> I'm having the most odd problem. I've drawn up my 1D array of U8,
> convert it to string using the U8-2-string converter and send it, but
> my device does not respond.
>
> So I tap the line with an Oscope and I see that only some of the
> numbers are being sent out correctly. I send out a 32, it replies
> with a 32 (correct!). I send out a 30, it replies with a 34, 36
> combination. Btw these are all hex values. I've checked and double
> checked that I'm sending out a hex 30. Anyway it started doing the
> same for the 32. What is happening??? I tell it to send two hex
> number, it sends four!!??!?

Isn't it doing what you ask ?

Sending a U8 value to a serial port will send 8bits=1character=0-255.
Converting t
hat U8 to a string and then sending it to the serial port will
send 2 characters, each in the range 0-9A-F.

Try leaving out the U8ToString conversion, what the serial line and
the instrument is expecting are actually U8s, its only for the convinience
of humans that we write the U8s as hex numbers.




--
Remove "spamkill." when replying to this message
0 Kudos
Message 5 of 5
(7,465 Views)