LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

swapped hex string for serial port write

Hello, 

for a serial write following format is required that i mentioned in vi.

actual constructed in loop from signal out vi: byte1 byte2 byte3 byte4

Before write to serial port (swapped 3 and 4th byte) : byte1 byte2 byte4 byte3

my question is if  we swap like this in a loop which is 30ms sample time in every iteration . does it overhead the processor , or is there any good and efficient practice.

 

thanks

 

 

0 Kudos
Message 1 of 9
(2,539 Views)

At the U16 output, use Swap Bytes before the Format Into Hex String.  But I feel like I have to ask the stupid question: are you trying to send raw data (ie the sent data is 4 bytes, including the EBE0) or data formatted into ASCII?  It is weird to be seeing this type of data in an ASCII format, so what I am thinking you really want to use is Flatten Into String and then add the EBEO to the start of the data (make sure the constant for EBE0 is in Hex display mode).


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 2 of 9
(2,524 Views)

my intention is that receiving end should read EBEO.....

please see my vi file

0 Kudos
Message 3 of 9
(2,436 Views)

I see EB90 in your file, not EBEO, so I'm afraid it's still not clear what you are asking for.

 

Please use Block Diagram cleanup.  No need for those crazy wire bends.

0 Kudos
Message 4 of 9
(2,429 Views)

i did clean up . 

i am sending EB90....

but on the reeving end it reads 235, 144, 

like this 

0 Kudos
Message 5 of 9
(2,426 Views)

You do know that EB in hex is 235 in decimal, and 90 in hex is 144 in decimal, don't you?

 

Maybe you just need to change the display format of your indicators.  Your EB and 90 in the string constants are in hex display mode.

You should make the display mode visible in strings, and the radix in numerics, whenever the value in there are different than normal.

 

Message 6 of 9
(2,420 Views)

is there another way to do the same without type cast 

0 Kudos
Message 7 of 9
(2,391 Views)

What is wrong with typecast?

 

There a lot of functions on data manipulation and numeric palettes.  There is probably a couple other ways to do what you want.  But unfortunately I don't know exactly what you are trying to do because the question seems to evolve with each post.  It started out with swapping bytes, and now it seems to be a display format issue.

0 Kudos
Message 8 of 9
(2,382 Views)

Looking at your VI again after the weekend, I would use Flatten To String to convert your U16 into a string.  Just set the Byte Order to be Little Endian and it will do the swap for you.

 

Other notes:

As RavensFan stated, make sure you as showing the display mode and radix when you are not using the default display mode.  You will thank yourself later.

You don't have to use multiple string constants to send your EB90.  Make it one.

A simple U8 will truncate your I32 index.  From there, a simple Build Array and Byte Array To String can use used.  Or you could use the Flatten To String again.

EDIT: I just realized that I should have wired a FALSE to the Prepend Array Or String Size input on the Flatten To String.


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 9 of 9
(2,361 Views)