LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Visa write in reverse order

Solved!
Go to solution

I have an application that communicates with a custom made device through serial. I have implemented VIs for writing and reading messages to/from the device. They work well on my own computer, but when trying with another computer, the VISA write seems to write everything in reverse order. The communication is done with a custom protocol, so I am sending messages as HEX characters. When I want to send e.g. 0x01 0x02 0x03, I actually seem to be sending 0x03 0x02 0x01. Does this have something to do with the endianness of different computers or is there some sort of configuration that I need to do in order to get this working? I can get everything working on the second computer if I add a reverse string function to my message before wiring it to VISA write. Does anyone have knowledge or an explanation to why this is behaving the way it does?

 

Attached is a picture of my send&read function that send a message and then reads the response.

0 Kudos
Message 1 of 6
(3,124 Views)

Hi jmog,

 

are you sure you are "appending" payload data after the header? Are you really sure?

Whenever you want to append data to an array you should use BuildArray instead of InsertIntoArray!

 

How are you sending the data? You only show the receiver part of your problem!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 6
(3,103 Views)

Hi GerdW,

 

Good point, I will have to check that. Although everything seems to work as intended on my own laptop.

 

The sending part of the data is right in the start of my attachment. I am basically sending the content of my string control named "Telegram". I have changed the display to HEX ('Hex Display' selected in the right click menu) so I can just type in e.g. 0102 03.

 

I have debugged this by connecting my laptop to the PC with problems with a serial cable, and observed the content of my message being reversed. This could have something to do with the RS-485 card that I am using in the PC, since the communication seems to work normally with both computers, when using my debug cable (USB to RS-485) to connect to my device. So the problems arise when using the RS-485 card.

0 Kudos
Message 3 of 6
(3,084 Views)
Solution
Accepted by topic author jmog

My solution in case someone else faces similar issues: I was not able to find any settings in the RS-485 card or its drivers that changes the endianness, so I modified my code so that each byte is sent separately in a loop. So instead of sending the whole string control content, I converted it to a byte array and then typecast each byte to (HEX) string. VISA write only accepts strings so I had to convert the data back and forth a little bit, but now the solution should ignore endianness. If there was an easier way to convert a string to a character array, I was not able to find it...

0 Kudos
Message 4 of 6
(3,035 Views)

Hi jmog,

 

conversion of string to char array:

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 5 of 6
(3,029 Views)

The lower part is exactly what I did 😉

 

But thanks anyway!

0 Kudos
Message 6 of 6
(3,026 Views)