03-20-2016 01:15 PM
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.
Thanks for your suggestion, i learning these things, and now i have basic idea regarding shift registers. I am also reffering LabVIEW For Everyone Book to get better understanding, as we as practicing the things.
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.
Got Your Point, actually i saw a post on this on NI website from there i did that thing.
3. You do not need the wait because the VISA Read will limit the loop rate if no data is coming in.
Oh, so sorry for that, i forget to remove that 50ms delay from loop. Thanks for pointing this.
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.
Yes you are right and i see how you did this, a new thing for me, you use shift registers for this task as well.
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.
Okay thanks for this suggestion, right now i don't have any idea regarding type def, but i am studying things and practicing, once i reach that portion i will update the enums
The following is the block diagram of my VI and now it is working properly.
0x2C 0x03 0x02 0x01 0x24 0x04 -> UltraSonic Distance Packet 0x124 -> 292
0x2C 0x02 0x01 0x01 0x03 -> Turn On LED
0x2C 0x02 0x01 0x00 0x03 -> Turn Off LED
And this part is working properly, but i hadn't checked the cheksum.
Right now i am trying to calculate the Checksum in LabVIEW VI.
Checksum will simple addition or XOR.
Do i need to create a separate VI for this.
I am uploading my VI, please suggests about improvements.
03-20-2016 04:29 PM
@xpress_embedo wrote:0x2C 0x03 0x02 0x01 0x24 0x04 -> UltraSonic Distance Packet 0x124 -> 292
0x2C 0x02 0x01 0x01 0x03 -> Turn On LED
0x2C 0x02 0x01 0x00 0x03 -> Turn Off LED
And this part is working properly, but i hadn't checked the cheksum.
Right now i am trying to calculate the Checksum in LabVIEW VI.
Checksum will simple addition or XOR.
Do i need to create a separate VI for this.
I am uploading my VI, please suggests about improvements.
Which bytes are used for the checksum? I am not seeing any real pattern with your sample data. Assuming you are just doing a simple addition, there is the Add Array Elements that will do the job for you.
03-21-2016 12:47 AM
Which bytes are used for the checksum? I am not seeing any real pattern with your sample data. Assuming you are just doing a simple addition, there is the Add Array Elements that will do the job for you.
The last byte will be used as checksum, currently i used some random value.
My Packet Structure is as follow:
Header, Length, Op Code, Data, Checksum
Length = Op Code + Data
Checksum = XOR Checksum of Bytes from Op Code to Last Byte of Data
Example:-
0x2C 0x02 0x01 0x01 0x00 (Here 0x00 is XOR Checksum of 0x01 0x01)
0x2C 0x02 0x01 0x00 0x01 (Here 0x01 is XOR Checksum of 0x01 0x00)
0x2C 0x03 0x02 0x01 0x24 0x27 (Here 0x27 is XOR Checksum of 0x02 0x01 0x27)
XOR Checksum is not neccessary, its my choice to use XOR or Simple Addition Checksum.
I am thinking of creating a separate Sub VI, that VI will have two inputs and Boolean Output.
First Input is Array and Second Input is Checksum.
VI will calculate the Checksum of Array and compare it with Checksum, if equal it output True and otherwise False.
03-21-2016 05:06 AM
@xpress_embedo wrote:XOR Checksum is not neccessary, its my choice to use XOR or Simple Addition Checksum.
I am thinking of creating a separate Sub VI, that VI will have two inputs and Boolean Output.
First Input is Array and Second Input is Checksum.
VI will calculate the Checksum of Array and compare it with Checksum, if equal it output True and otherwise False.
That is what I would do. For the XOR, you will need a FOR loop and a shift register initialized to 0x00. You can then autoindex on the array and XOR with the current value from the shift register. Write the new value in the shift register. Then it is just a simple equals comparison.
03-21-2016 08:18 AM
One of the nice things about an XOR checksum is that you don't need to compare the XOR of the bytes up to the checksum with the checksum. You can XOR all the bytes together, including the checksum. If they match, the result will be zero. By definition, XORing any number with itself results in all bits being zero.
03-21-2016 10:49 AM - edited 03-21-2016 10:51 AM
Hey Thanks for your reply.
I did it, created a separate SUB VI to calculate the XOR Checksum.
Is it okay, please suggest if you find something worng in this.
Now i will use this Sub VI in my main project.
03-21-2016 12:07 PM
That will work.
But you don't need array size or to wire it to the N. With auto-indexing the For Loop will automatically the number of times for the number of elements in the array.
03-21-2016 12:53 PM
One of the nice things about an XOR checksum is that you don't need to compare the XOR of the bytes up to the checksum with the checksum. You can XOR all the bytes together, including the checksum. If they match, the result will be zero. By definition, XORing any number with itself results in all bits being zero.
Thanks for pointing this, i forget that things about XORing, this makes my life little bit easy.
That will work.
But you don't need array size or to wire it to the N. With auto-indexing the For Loop will automatically the number of times for the number of elements in the array.
Thanks for again pointing this thing.
I removed that array size block and it works perfectly.
03-21-2016 01:06 PM - edited 03-21-2016 01:07 PM
So here is my final VI, its working properly, but my stop button doesn't stops the VI.
Any reason behind this.
Apart from this how can i update the value of OP CODE case structures with some name rather than just number, like done in STATE case structure with the help of enum constants.
I am also attaching the VI below.
03-21-2016 01:22 PM
@xpress_embedo wrote:Apart from this how can i update the value of OP CODE case structures with some name rather than just number, like done in STATE case structure with the help of enum constants.
You can make an enum and then use Type Cast to cast your byte OpCode into the new enum.
@xpress_embedo wrote:So here is my final VI, its working properly, but my stop button doesn't stops the VI.
Any reason behind this.
My only thought here is if you do not have data constantly coming in. The VISA Read defaults to a 10 second timeout. So the VISA Read would have to timeout possibly before the button was even read and possibly another timeout before the loop can actually stop. So this would be up to 20 seconds of waiting. You could set your timeout to something shorter. I would not go much below 1 second.