LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

send serial command in decimal format

I am trying to send a command through serial. I have to be able to send a decimal 27 105 to the serial port, but the port only supports strings. How can I do this.
0 Kudos
Message 1 of 6
(4,559 Views)
You need to split your decimal number into bytes. This way you can convert the bytes to a string and output them to the serial port. Take a look at the attached file, the code is easy to understand and commented.
Message 2 of 6
(4,559 Views)
Sci-Mech wrote in news:5065000000080000006CD40000-
1079395200000@exchange.ni.com:

> I am trying to send a command through serial. I have to be able to
> send a decimal 27 105 to the serial port, but the port only supports
> strings. How can I do this.
>

Is it one decimal twenty seven thousand and one hundred and five
or two numbers 27 and 105.

Anyway.
You can create an U8 array where you put your numbers and send it throug
the "Byte Array to String" function (palette "String -> String/Array/Path
Conversion")

If you have the number(s) represented as a string you have to use e.g.
"Scan From String" or "Decimal String to Number" (also takes as string
array) to create the U8 array.

--
Rolf
Message 3 of 6
(4,559 Views)
Thanks guys, but I still can't get it to work.

I am trying to send two numbers seperated by a space with a carriage return on the end.

27 105CR - this has to be in a decimal format (instead of the string format requested by the visa).

any ideas?

thanks
0 Kudos
Message 4 of 6
(4,559 Views)
Have you tried sending the string with the decimal data and appending a CR? Typically if an instrument expects a space between two numbers, the numbers are sent as ASCII numbers (i.e., in string format). Is the instrument you are communicating with similar to those NI has instrument drivers for (www.ni.com/idnet)? Instruments by the same manufacturer often have similar requirements. You might be able to look at those instrument drivers to understand how to communicate with your instrument.
0 Kudos
Message 5 of 6
(4,559 Views)
Sci-Mech wrote in news:50650000000500000038860100-
1079395200000@exchange.ni.com:

> Thanks guys, but I still can't get it to work.
>
> I am trying to send two numbers seperated by a space with a carriage
> return on the end.
>
> 27 105CR - this has to be in a decimal format (instead of the string
> format requested by the visa).
>
> any ideas?
>
> thanks

I may have been to quick with my previous answer but now i do not
understand what you mean.

VISA takes a string as it's input. Each character in the string can also be
represented by a U8 where the character A will have the value 65 in decimal
(or 0x41 in hexadecimal notation).

I am not shure what you mean by that the number need to be in decimal
format. In labview a num
ber indicator can show a number in different
notations, decimal, hexadesimal, binary. A number can also be shown in a
string as a decimal value.

Suggestion one.
Create a U8 byte array with the values 27, 32, 105 and 13 and use the
function "Byte Array to string" to get the string to send to the VISA
function.

Suggestion two.
Create a string with the contents "27 107" and concatenate the string
constant "Carriage Return" on the end (use the function "Concatenate
Strings").

Suggestion three.
Use the function "Format into string".
- Expand it so it has three inputs.
- Wire a string constant with contents "%d %d%s" to input "Format String"
- Wire your first number into "Input 1"
- Wire your second number into "Input 2"
- Wire the string constant "Carriage Return" into "Input 3"
- Wire Output string to the input of the VISA function.

If you still have problems it might help if you tell what type of equipment
you try to communicate with.

--
Rolf
0 Kudos
Message 6 of 6
(4,559 Views)