03-21-2016 01:29 PM
A couple other tips.
Equal to 0 has it's own primitive that would allow you to get rid of the zero constant.
Index from Array automatically starts from 0 and increments downward. So you can get rid of the 0 and 1 constants.
Enums could work for OP codes, but enums require all numbers to be consecutive. If if you'd have op codes 1, 2, and 40 with names for instance. You'd have to fill in something between 2 and 40 so that the number 40 could exist as a value in an enum. I'd recommend just putting labels in each case, or use the subdiagram label in each case.
For the distance calculation, you don't need to convert to doubles and do all the math of multiplying by 256 and adding. Use the Join Numbers function. It will take two U8 bytes and join them into a U16 integer in one step.
03-22-2016 06:07 AM
You can make an enum and then use Type Cast to cast your byte OpCode into the new enum.
Thanks I got your point, will try when i reach home.
03-24-2016 12:57 AM
Equal to 0 has it's own primitive that would allow you to get rid of the zero constant.
Thanks for the suggestion, i replaced the equal to with comparision with zero.
Index from Array automatically starts from 0 and increments downward. So you can get rid of the 0 and 1 constants.
Thanks, now those constants are removed.
Enums could work for OP codes, but enums require all numbers to be consecutive. If if you'd have op codes 1, 2, and 40 with names for instance. You'd have to fill in something between 2 and 40 so that the number 40 could exist as a value in an enum. I'd recommend just putting labels in each case, or use the subdiagram label in each case.
OP_Code will be in sequential format and if required i will put some random names, but still that part is not working.
For the distance calculation, you don't need to convert to doubles and do all the math of multiplying by 256 and adding. Use the Join Numbers function. It will take two U8 bytes and join them into a U16 integer in one step
Thanks, this simplied my block diagram
VI attached below with the changes suggested and is working properly.
But that type cast doesn't work for me.
I type cast the Op_Code data coming from serial port to typecast block and used constant enums to define my Op_Codes which are as follow:
0 - OP_SYNC
1 - OP_LED
2 - OP_SENSOR
3 - OP_FUTURE
and then connected the output with case structure, i got all these values in Case Structure but whenever i receive any data type cast block converts it to 3, OP_FUTURE i did't get that why this is happening.
03-24-2016 05:28 AM
@xpress_embedo wrote:and then connected the output with case structure, i got all these values in Case Structure but whenever i receive any data type cast block converts it to 3, OP_FUTURE i did't get that why this is happening.
If the recieved value is above 3, it will coerce to 3.
03-24-2016 06:38 AM
But i am not sending Op Code greater than 2.
0 - OP_SYNC
1 - OP_LED
2 - OP_SENSOR
3 - OP_FUTURE
I separate out that section in new VI even then for 0 type casting is correct but when i change that to input to 1 i get output as OP_FUTURE
I am attaching the VI also.
03-24-2016 07:28 AM
Change the representation of your enum to a U8. It defaults to a U16.
The reason this is happening is that LabVIEW uses Big Endian. Therefore the single byte you supply is used as the most significant byte and the lower byte is filled in with 0. So your 1 is really 256 after casting to a U16, which is way above the range of the enum. Therefore you get the last item in the enum.
03-24-2016 07:39 AM - edited 03-24-2016 07:40 AM
Change the representation of your enum to a U8. It defaults to a U16.
Right Click on Enum Constant and then clicked on Edit Items and then change to U8
@crossrulz wrote:
The reason this is happening is that LabVIEW uses Big Endian. Therefore the single byte you supply is used as the most significant byte and the lower byte is filled in with 0. So your 1 is really 256 after casting to a U16, which is way above the range of the enum. Therefore you get the last item in the enum.
Thanks alot for the explaination, this makes me clear why that was happening.