From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sending a floating point through serial using VISA

how do I send a floating point number through a serial port to my microcontroller using VISA Write

0 Kudos
Message 1 of 10
(2,699 Views)
How does the micro expect it? You can either typecast it or convert to ASCII string. Pick the conversion that the micro uses.
0 Kudos
Message 2 of 10
(2,691 Views)

The microcontroller which I am using takes it as a byte value.

0 Kudos
Message 3 of 10
(2,687 Views)
How many bytes? Typecast a sgl or dbl.
0 Kudos
Message 4 of 10
(2,674 Views)

okay i got a byte array. Now how do I pass that to the VISA write?

 

0 Kudos
Message 5 of 10
(2,663 Views)
How did you manage to get a byte array from the typecast? I have no idea what you are doing.
0 Kudos
Message 6 of 10
(2,659 Views)

OK let's start over. I am trying to send a floating point value to a C program which is expecting it as a 4 byte value rather than as an ASCII string. How can I force the serial port to send it as a 4byte value rather than a ASCII string?

I managed to get a byte array using string -> number function, and then setting it to sgl representation. Is that the right way to do it? Ive added an image for a better understanding

0 Kudos
Message 7 of 10
(2,640 Views)
Why are you using a string for the number. Just use a numeric control set for sgl. I already told you to use the typecast function. Why didn't you use that? I've said the same thing three times now. The default behavior for a typecast will convert the sgl to a string that you simply pass to the VISA Write.
0 Kudos
Message 8 of 10
(2,636 Views)
Another option is the flatten to string. You can specify the endianess with that.
0 Kudos
Message 9 of 10
(2,630 Views)

I would recommend the Flatten To String because of being able to change the endiness.  Some systems want Big Endian while others want Little Endian.  It is best to specify.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 10
(2,590 Views)