From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
03-12-2016 12:24 PM
Hello! Everyone,
I am new to LabVIEW and i am taking help from various videos and stuffs available online to get started with LabVIEW.
But i have to complete an assignment, that's why need help.
initially i had see some of the videos tutorial and learnt about the LabVIEW interface and done one small project from communicating with Serial Port (Receiving and Sending Data).
Now coming to my task.
My LabVIEW application will send some packet to query state to my device or to control and based on the response packet i have to display values.
The Packet Structure is as
Header, Length, Op_Code, Data, Checksum
There is no terminator like Carriage Return or Line Feed or anything else.
In C language i read data coming from the Serial Port, and based on Length i conclude whether i receive the complete packet or not and then by recalculating the checksum value, integrity of packet is checked, and then based on which Op-Code was sent decision will be made.
(I am dealing with hexadecimal data)
But how can i do this in LabVIEW.
Any tutorial or any referece will be helpful for me.
Solved! Go to Solution.
03-12-2016 12:41 PM
@xpress_embedo wrote:In C language i read data coming from the Serial Port, and based on Length i conclude whether i receive the complete packet or not and then by recalculating the checksum value, integrity of packet is checked, and then based on which Op-Code was sent decision will be made.
You do the exact same thing with LabVIEW. A quick way to get started with using a serial port is to look at the Simple Serial Write/Read example in the LabVIEW Example Finder (Help->Find Examples). It shows the basics, but I would not use it as part of your program. And since you are decing with hex/binary data, make sure the Termination Character is turned OFF (boolean input on the Configure Serial Port).
03-15-2016 01:33 PM
Thanks for your reply.
I had done basic serial read write program, i read the Serial Data and displayed it on string indicator.
My problem is that how to decode the packet and based on decoding how to take action.
And since you are decing with hex/binary data, make sure the Termination Character is turned OFF (boolean input on the Configure Serial Port).
As per your comments i did this with the help of this link.
http://digital.ni.com/public.nsf/allkb/6E2C88C43C76A77386256975006DB10A
Any Suggestion please on decoding part.
I saw on this forum that typecast can be used.
Any tutorial on this or reference will be helpful.
03-15-2016 02:25 PM
@xpress_embedo wrote:Any Suggestion please on decoding part.
That part depends on the instrument and the data inside the packet. A LOT more details are needed to be able to help any there.
03-16-2016 12:02 PM
The device which sends data is Arduino UNO (Microcontroller Based Open Source Hardware).
The data will be as follow:
Header (0x2B) Length Op Code Data Checksum
Right Now i just have to two Op Code but in future it will be added for other things.
So Op Code = 0x01 then packet is like
0x2B 0x02 0x01 0x01 (Calculated Checksum) (Turn on a Led on Board and LabVIEW Front Panel)
So Op Code = 0x02 then packet is like
0x2B 0x03 0x02 0x01 0x55 (Calculated Checksum) (in this packet 0x155 is ultrasonic sensor value )
So when this pakcet is received by LabVIEW, it must decode it based on the length and then check its integrity using checksum.
And the based on Op Code and Data Value front panel will be updated.
03-16-2016 12:43 PM
Read one byte at a time until it is equal to x2B.
Read one byte to get the length.
Read X bytes to data and checksum.
Run the collected data through whatever algorithm the checksum is based on to verify the received data is good.
Repeat for the next commands.
03-16-2016 05:33 PM
And use a Case Structure to perform the different commands based on the opcode. After reading the message, use the String To Byte Array and the Index Array to get the opcode out of the data. That integer value can then be wired to the case selector tunnel.
03-17-2016 11:13 AM
Thanks for your suggestion.
Now i got some idea, how to do it.
I will try to implement my C code in LabVIEW. (I will read data 1 byte at a time)
Will tell my progress on this soon.
03-19-2016 08:14 AM
Finnaly I did Something, which is as follow
I created four states using enum -> IDLE_STATE, LENGTH_STATE, OP_CODE, DATA, CHECKSUM
Whenever i receive data serialy, based on the Current State i checked which type of data it is, like if i am in IDLE_STATE then i will check for header, if it is header then i will move to the next length state and if not then IDLE_STATE will remain idle.
To change the state of enum automatically in code i use local variables. (Will Hide the front panel control of enum as it is not required there)
Then in LENGTH state i do nothing just incrementing the enum state to OP_CODE State.
Then in Op_Code state if Op_Code is 1 then i light the led control otherwise not.
So this packet
0x2C 0x12 0x02 -> Turn off LED
and
0x2C 0x12 0x01 -> Turn on LED
Length has no meaning right now, i think declaring length as global variable will work for me.
03-19-2016 08:58 AM - edited 03-19-2016 08:59 AM
1. I suggest you learn how to use Shift Registers instead of locals and globals. They are a lot more efficient (memory and execution speed) and make it a lot easier to read the diagram.
2. You do not need that property node inside of the loop. There is an input to the Configure Serial Port for turning off the termination character.
3. You do not need the wait because the VISA Read will limit the loop rate if no data is coming in.
4. Once you have the length, you can just read the rest of the entire message and process it all at once. This will make things A LOT faster.
5. You really should make that enum a type def so that you can make sure all of your enum constants have the same possible values. If you have to add a state later, you only have to update your enum in one location then.