LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

TCP/IP decode c++

No, I don't have an example for one package because my partner said I should first write the server with LabVIEW and then he will program the c++ packages (so that his code conforms to my program).
The only information I have is the following:
The first byte contains the information whether the package contains a value of acceleration or a value of velocity. So I thought of maybe eight numbers where the last two numbers define whether it's a velocity value or an acceleration value.
Maybe 00000011 is velocity and 11111100 is acceleration.
Then the next 8 bytes contain one or more measurement values (of velocity or acceleration, accordingly to the first byte). The last 8 bytes should contain the time corresponding to the values.
So, I don't know how to tell LabVIEW with the first byte that the package includes velocity or acceleration values. If I wire the first byte to the case structure where can I tell LabVIEW to read and distinguish between the last two numbers. How can I say that two '0s' at the end correspond to acceleration and two '1s' to velocity.

Do you understand my question? I wasn't very articulate, sorry.
0 Kudos
Message 11 of 39
(1,741 Views)
Yes, I understand. The protocol is not full defined yet. Than you have to define it. Say Velocity is 0h and acceleration is 1h., what means the first byte is either 0 hexadecimal or 1 hexadecimal. 0h is 00000000b and 1h is 00000001b. I don't understand what is "0s" and "1s" ??? The next question is which representation has velocity, acceleration and time values? Double?
0 Kudos
Message 12 of 39
(1,740 Views)
I just talked to my partner, which made it a little bit more complicated (at least for me: )):
Well, he wants to send with every package 18bytes, but they could include both (acceleration and velocity). We defined velocity as a '1' and acceleration as a '0'. So the first byte is always a '1' or a '0'. Then the corresponding values with the time will follow. The values should represent one byte. But in the same package there could suddenly be an "identification" byte again and then the case structure has to switch to the the other case.
E.g. one packages could look like this: 0(for acceleration), acceleration value, value, value, value, value, time, time, time, time, time, 1(for velocity)), velocity value, value, value, time, time, time.

Did you get an idea?
THANKS FOR YOUR HELP!
0 Kudos
Message 13 of 39
(1,732 Views)
Not really, if your protocol has no defined length, than you have to include the length of following bytes in the package header, else you can't detect where a new package begins.
0 Kudos
Message 14 of 39
(1,728 Views)
Every package has the length of 18bytes, but he wants to have the possibility to send e.g. 10 values for velocity (which makes 11 bytes including the identification byte) and 8 values for acceleration (which makes 9 bytes incl. identification byte) within ONE package. Isn't that possible?

Thanks
0 Kudos
Message 15 of 39
(1,724 Views)
Of couse it is possible, but than you don't need a case structuere and you don't need the identifier for vel or acc. You have to read 16 bytes, where the first 10 are acc and next 6 vel. Than easy split your received string on the 11th character and unflatten into values.
0 Kudos
Message 16 of 39
(1,722 Views)
Hi Eugen,

sorry for the confusion. Finally we chose the way I mentioned at the beginning, for which you created the vi (so that's perfect, thank you!).
So, one packet will inlcude 1 byte for the header (identifier for vel or acc) and one double for one value and corresponding time each.
My question now is the following:
If we choose a '1' as identification for velocity and a '2' for acceleration, will LabVIEW automatically recognize this as case 1 or case 2? Or how can I tell LabVIEW that a '1' in the c++-code should be allocated to case 1?
The timer in the while loop determines how often one value will be read. Maybe you can tell me what happens if the c++-program sends the values faster than the setting of the timer in LabVIEW is? Is there a buffer anywhere? Is it possible that values "vanish" or get in wrong order?
It doesn't matter if the c++-program sends values slower then the setting of the timer of the while-loop is, does it? Is it right that for this case the setting of the timeout is important?

Thank you very much for your help.

Steffi

0 Kudos
Message 17 of 39
(1,688 Views)
Make 3 Cases in LabVIEW:
 
Case = 1:   Parse and show Velocity
Case = 2:   Parse and show Acceleration
Case = default:  Do nothing
 
To say LV which number means Vel or Acc, write 1 or two in the Case Selector Value.
 
TCP timeout means:
try to read count of bytes from TCP stack in this time.
If bytes comes faster the while loop will work faster.
If bytes will come slower, than you will get a timeout error from this VI
 
So set this value to a little bigger than your packages will come over TCP.
0 Kudos
Message 18 of 39
(1,685 Views)
ok, great! Thanks a lot!
0 Kudos
Message 19 of 39
(1,681 Views)
Hello Eugen,

it's me again (sorry).
I thought of a small program to test my server vi, but (as I'm not a c-programmer) I have difficulties in creating a datagram (with LabVIEW) which looks the same as the c++-code will do (which my partner still has to program). Should I create an array and write ASCII-signs to it? Do you know that? Or would you prefer another way to test it?

Thank you very much.
0 Kudos
Message 20 of 39
(1,659 Views)