hello, i am trying to send decimal data from labview into uC using VISA write. suppose I want to send 1024, i should be able to send it in 2 bytes, right!!, however, labview sends 1024in 4 bytes(1,0,2,4) using the VISA write. how can i program to make sure labview sends values from 0-1024 in 2 bytes only and not 4 different bytes.
Use a U16 number and simply typecast the number to a string. The string you wire to the VISA write will then contain binary representation of the number. The VISA wrie will accept any value (0x00-0xFF) for each byte of the string therefore it is capable of sending binary data. You simply need to use the correct "string".
Mark, thanks for the suggestion, but what do you mean by "typecast the number to string"? can you please show me an example of what you mean?
Here is an example of a typecast.
The typecast will work with any number. If you have a 16 bit number the resulting string will be 2 bytes. If you have a 32 bit number the resulting string is 4 bytes and so on.
hmm... yeah i figured that out, but another problem is the array that i have declared in uC is a char array, so, it doesn't record the 16-bit int value from LV, it ignores the 1st 8bits and saves only the last 8 bits... any idea how can i split this 16 bit into 2 seperate 8-bits...!!!!
EDITED: i figured how to send 2 seperate bytes... now the next task remains, converting the hex values into decimal in uC!!! or else sending decimal values from LV itself!!
LabVIEW is simply sending a stream of bytes. It is really up to the receiver to interpret them correctly. If you number happens to be less than 255 the first byte will be 0x0. (LabVIEW will send the data in network byte order so the 16-but number 255 would be sent as 0x00, 0xFF). Make sure that you are using the same byte order on the receiving end. If all of your data will be 16-bit value than have your reading process in the C code read 2 bytes at a time. If you may need to send different types of data I generally like to use a simple protocol where the first n-bytes is a type identifer (can be 1, 2 or 4 bytes), the next 4 bytes indicates the length of the data and the remaing x-bytes is the data itself. Whether you are using LabVIEW on both ends or a mix of LabVIEW and other programming languages both sides of the conversation need to know what the data will look like. If you use a network analyzer to capture what your LabVIEW application is sending I am sure you will see that it is sending the data correctly. I am confident the problem is on how you are reading and interprettig the data. In C be careful using string functions to read the binary data. Any NULL byte will be interpretted as the end of the string.
HI, I want to write to VISA serial write only 1byte ( exmple 1) . BUt with this program i am gettting 1111111 continuesly.
Bcoz if i send '1' send microcontroler the realy will be on. if send '2' realy will off
i am putting while loop to change values like '1' '2' '3' '4'
i want to send '1' one time only.
Can any one Help????????