LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing a 32bit unsigned number to serial port

Hello, I am trying to fix a robot which was originally made on Matlab, and to control the speed of a spinning drum, there is a gain equation to convert mm/s into a number which should be assigned to a 32bit unsigned integer and then sent to the serial port following the character V. For Example, if I wanted 30mm/s, the number would be 71213, so on MatLab, I would send...

 

write(SR, 'V', "uint8");
write(SR, 71213 , "int32");

 

This would make the drum spin at the appropriate speed.

 

On LabVIEW, the Write function only accepts strings, and when I try converting my int32 number to a string and then give that to the write buffer, it does not work the same. I am assuming that MatLab and LabVIEW handle the number differently.

 

If anyone could help me try to get the same results on LabVIEW as I am on MatLab, that would be awesome. Or even if someone has a good understanding of how MatLab's write function works, so I could try to replicate it on LabVIEW.

 

Thanks

0 Kudos
Message 1 of 3
(630 Views)

@Accid3nts900 wrote:

write(SR, 71213 , "int32");


 

Well, int32 is NOT an unsigned integer, so you probably should have specified uint32. I assume it wants binary data (i.e. 4 bytes for U32) but you probably also need to know the required byte order (LabVIEW is big endian by default).

 

Take your U32 and try flatten to string and pick the correct byte order and see how far you get.

Message 2 of 3
(620 Views)

Matlab defaults to Little Endian while LabVIEW defaults to Big Endian.  So use the Flatten To String (one of my favorite functions) and set the byte order to Little Endian to convert to a I32.


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
Message 3 of 3
(582 Views)