LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial Commands

Solved!
Go to solution

Hi,

I am trying to control my device using a RS232 Control Box with Visa. The device requires HEX commands to run. When i run my VI the visa write has no errors but then the read times out. The device works with the supplied software so the connection isnt the problem. what I think is wrong is that im not sending the commands in HEX. In my VI I have different inputs (Numeric control, boolean and constant)  being converted into hex string then concatenated to form the command (cmd eg: 020F0F07000D) when I send this to a string indicator on hex display I get 303030304646 which obviously isnt right. The Problem Could be that I am not converting the inputs to HEX correctly?? I have attached my VI and the manual for the control box. Any help or advice would would be appreciated.... 

 

0 Kudos
Message 1 of 15
(2,677 Views)
Solution
Accepted by topic author Kane13

Hi Kane,

 

so you are the "number to HEX conversion" guy of the month (or is it week?)! Smiley Wink

 

You should read your manual carefully and try something like this:

check.png

This one will build an array of U8 numbers (=BYTES!) and convert them to a string. Just look at the string in hex display...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO
Message 2 of 15
(2,665 Views)

Thanks GerdW,

 

Yea that worked! but i have come across another problem the command goes through the visa write and the return count says their is 6 bytes there. which is correct.. ive wired a property node: bytes to read into the visa read but that says 0 bytes and i get a warning saying there could be more bytes at port.. when i wire a constant 7 to Visa read i just get a timeout error..  Any ideas as to why this is happening and how to get it to work???

 

Cheers

Kane

0 Kudos
Message 3 of 15
(2,639 Views)

Hi Kane,

 

have you tried the "Basic serial read and write" example that comes with your LabVIEW installation?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO
0 Kudos
Message 4 of 15
(2,627 Views)

Dear GerdW,

 

Greetings...!!!

I have a problem

 

Concatenated.jpg

 

 

Please see the image above... This is for Modbus communication...

 

In the first VI, i have simply concatenated the three Hex strings... and the concatenated string is showing the correct string... This is what the result i need..

 

But in the second VI, I have simply converted the number (300) to the same hex string of first (012C), But the concatenated string 2 is showing a different value. Whenever I am trying to convert the number to hex string, i am getting this problem...

 

I need to implement the second option in my program but i dont know how to correct it...

 

Please help me and Kindly help me to get it corrected...

 

Thanks in advance...

 

 

0 Kudos
Message 5 of 15
(2,483 Views)

In your second piece of code, you are not converting correctly. If you had probed the output, you would see an ASCII string of "012C". Not at all the same thing when you select a string for hex display. You should be using a U16 and type cast. And please, post actual code. An image makes it harder to know what you are doing.

Message 6 of 15
(2,471 Views)

My ascii chart shows  String litteral "012C"  would be char array [0x30, 0x31, 0x32, 0x43]

 

Seams thats exactly what you are getting.


"Should be" isn't "Is" -Jay
0 Kudos
Message 7 of 15
(2,457 Views)
Spoiler
 

 

Dear

 

How to attach the VI here...? When I try to attach it, it shows "The contents of the attachment doesnt match its file type"

0 Kudos
Message 8 of 15
(2,444 Views)

What are you trying to attach? A VI should attach fine. So should a zip file. There were some recent problems but I think they are all straightened out. Another option is attaching a snippet. Snippets are special png files and are explained in the help.

 

In any case, your problem should be solved.

0 Kudos
Message 9 of 15
(2,439 Views)

 

Herewith I am attaching the VI

0 Kudos
Message 10 of 15
(2,431 Views)