Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Binary Data over Serial Port (Visa Write)

There are many discussion forums articles about how to transmit various data types - Binary, Hex, Ascii, over a standard PC  RS232 serial port. None of the articles and the solutions in them seem to meet my 'need'.. which is:

If a user will type a HEX character into a Control String (0-9, A-F) then the following will be xmitted over the 232 signal: 

'0000' if 0 was entered

'1000' if 1 was entered

'0001' if 8 was entered

'0101' if A was entered

'1111' If F was entered.

 

bit ordering is not important as I can manipulate it.

What functions are avail to me to accomplish that?

Closest thing I found in the forums is an example in that link. But it is kind of goofy and impractical.

 

http://digital.ni.com/public.nsf/allkb/2FA318A7B669954E86256FBE007FAA4E

 

Thanks

DaniDin
0 Kudos
Message 1 of 7
(7,082 Views)

So you want to transmit ASCII "1" "0" "0" "0" for a 1?

 

I would start with a numeric control, not a string control. Use U8 representation. Set display format to to Hex and data entry to limit values to 0..15. Then use Format into String with "%04b" as the format string.  Connect the output to the input of the VISA Write.

 

Note that this produces the reverse bit order from your example.

 

Lynn

 

hex to binary string.png

0 Kudos
Message 2 of 7
(7,076 Views)

taking Lynn's approach to the end.

!1.png


"Should be" isn't "Is" -Jay
0 Kudos
Message 3 of 7
(7,062 Views)

Thanks Lynn and Jeff.

Jeff - I could not obtain the result you did when I implemented your picture into a VI.

It took me a little while to find the Sort 1D-Array function(?) For the sample in your post, I am getting 0001 for '2'.

Must be something I am not configuring right in that function or elsewhere...

I am attaching the VI I created, if you could please check it out.

 

Also, when using Lynn's version toI xmit the resulting 0s and 1s binary string, it seems that the Visa Write function converts them BACK to ASCII, as with a scope probe on the COM port's TxD line I see bunch of '0000_0011' which IS ASCII for 0...

In the block diagram I am expanding the type to U64 and the format string to %048b so I can send the following binary string for example: 110089ABCDEF, hoping to see the following on the scope as the bits roll by: 1000_1000_0000_0000_0001_1001_0101_1101_0011_1011_0111_1111, or something similar.

 

DaniDin
0 Kudos
Message 4 of 7
(7,028 Views)

@DaniDin wrote:

It took me a little while to find the Sort 1D-Array function(?) For the sample in your post,

 


I think that's the Reverse 1D Array


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
0 Kudos
Message 5 of 7
(7,023 Views)

@crossrulz wrote:

@DaniDin wrote:

It took me a little while to find the Sort 1D-Array function(?) For the sample in your post,

 


I think that's the Reverse 1D Array


Yes that is reverse array not sort array.

 

That thing there is actually a "code snipette." Drag or copy it to your desktop then drag it onto an empty LabVIEW Block Diagram.  Identical code will be generatedSmiley Wink

 

Yeah, its really coolSmiley Wink

 

If you need to build bytes out of your nibbles we can use a "Locical shift" and an AND to merge nibbles


"Should be" isn't "Is" -Jay
0 Kudos
Message 6 of 7
(7,012 Views)

Worked fine once I replaced the sort array with reverse array!!

Thanks Jeff

 

DaniDin
0 Kudos
Message 7 of 7
(7,009 Views)