LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to send decimal data using VISA from serial port?

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.

thanks,

Now on LabVIEW 10.0 on Win7
0 Kudos
Message 1 of 17
(4,215 Views)

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 Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 2 of 17
(4,211 Views)

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?

Now on LabVIEW 10.0 on Win7
0 Kudos
Message 3 of 17
(4,203 Views)

Here is an example of a typecast.

 

Typecast.png

 

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.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 4 of 17
(4,194 Views)

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...!!!! Smiley Mad

 

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!!

Now on LabVIEW 10.0 on Win7
0 Kudos
Message 5 of 17
(4,192 Views)

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.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 6 of 17
(4,187 Views)

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????????

0 Kudos
Message 7 of 17
(3,353 Views)
Instead of continuously polling the Boolean in a greedy loop (no wait function), use an event structure. Can't tell from an image but the mechanical action of the Boolean is probably incorrect as well.
0 Kudos
Message 8 of 17
(3,346 Views)

Event structure is not possible.

0 Kudos
Message 9 of 17
(3,330 Views)
Why is it not possible? Do you have the base version of an old version of LabVIEW? If so, upgrade. Otherwise, place a wait in your loop and change the mechanical action, as I already said.
Message 10 of 17
(3,324 Views)