LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

binary visa transfers

I am looking for help doing binary transfers using Visa (Viwrite & Viread).  I have found only a few things but they pertain to Labview only:
How do I write a bit array to a serial port:

Writing bits to the Serial Port Instead of Writing ASCII Strings:

I am wondering if there is any examples for Labwindows?  Will I have to use the ASCII chart to convert binary to ASCII and vice versa?  This seems to have inherent problems like sending 00.  What if I want to send a transfer that is not a multiple of four?    Isnt there a property in visa that I can simply write something like
ViWrite (handle_serial, "0101", 1, VI_NULL)
I will be using the serial port on the PC but the RS-232 Library doesnt seem to buy you anything either because it also works with strings.
Please advise, thanks
0 Kudos
Message 1 of 4
(4,188 Views)

The value passed to viWrite() and from viRead() is simply a data buffer of bytes.  If you pass in a string value you will output the data as a string.  If you pass binary data in the buffer, you will output binary values.

viWrite (handle, "123", 3, &count); will output the equivalent ascii values of the string 0x31, 0x32, 0x33

Data[3]={0x01,0x02,0x03}
viWrite (handle, Data, 3, &count); will output the raw binary data values for 0x01, 0x02, 0x03

CVI or C does not need to use the kind of conversion routines you see in the Labview examples, but if you need to do numeric to string conversions there are the Fmt() and Scan() functions in the CVI library which are very powerfull and flexible and also the standard C functions like sprintf(), scan(), atoi() etc.

Message Edited by mvr on 09-05-2006 02:59 PM

0 Kudos
Message 2 of 4
(4,185 Views)
Thanks for your reply, but I am still not clear.  What makes your 2nd example different from your 1st?  The elements of your array are represented in hex so somehow they will be sent using binary?  As well this doesnt solve the problem with ViRead; when the buffer inside the function is looking to be declared as a 'unsigned char'.  I will have to convert the char to decimal first using sprintf() or scanf().  For the Viwrite I was looking to do something like this using the ASCII chart
 
to send binary 1:
 
viWrite (handle_serial,"\0001",1, VI_NULL)
 
Thanks for your help.
0 Kudos
Message 3 of 4
(4,169 Views)
OK I see what your getting at now.  Your right, the second example is really no different than the first.  The data was simply declared differently in the data buffer. The data that is in the buffer is what viWrite() will send.  The vi functions do not perform any conversion on the data.  While the data buffer in the viWrite() and viRead() functions is prototyped to something that originates with unsigned char, it could just as well be a void type.  The data that they send and receive over the serial port is ultimately binary bytes, there is no data type at the hardware level. 
 
You can pass any type of buffer to the vi functions by using a cast.  Conversions between different types of binary formats are not needed as long as you are not transfering data between systems with different "endian" formats for data representation.
int myData[5];
 
myData={0x0001,0x0002,0x0003}
viWrite (handle, (ViBuf*)Data, sizeof(myData), &count); 
 
viRead(handle, (ViBuf*)Data, sizeof(myData), &count); 
 
 
Any conversion of data between string/char and binary formats must be handled before the buffer is sent to the vi functions.  This is where Scan and Fmt can be useful.
 
As far as declaring a bit field as a string type, that does not exist in C outside of bit fields used in structures.  It would seem that most C programmers are comfortable enough with hex representations that there has never been a need to add binary formats  to standard c.  I have seen representations like 0b0101 used in embedded compilers, since bit level manipulation is more common in microcontrollers, but the formats vary from vendor to vendor.
 
It probably would not be too difficult to modify the bin2dec or dec2bin routines commonly found in basic code to c.  You can find examples of them through Google.  I also came across this very simple example in c
and this which is in c++ but the nuts and bolts part is in c
 
 
 

Message Edited by mvr on 09-06-2006 08:48 AM

0 Kudos
Message 4 of 4
(4,151 Views)