01-30-2009 11:41 AM
Hello,
I am trying to get some advice on how to parse data from a device. The device in question is a piece of equipment that my company has developed. It sends and receives all messages over ethernet in a defined format. The data getting sent to the device is user initiated and is asyncronous. The data coming from the device is both asyncronous and syncronous. The asyncronous data consist of things like error messages and status can occur anytime after powerup. The syncronous messages happen at a 100Hz rate when initiated by the user and can be anywhere between 10-1000 bytes (depending on the command sent by the user). So, what I am trying to do is figure out an efficent way to parse the data coming from the device. All messages adhere to a message format as follows
<MSG SIZE (2 bytes - U16)><MSG ID (2 bytes - U16)><MSG Data (mixed data set consisting of U8, I8, U16, I16, Single, and Double)>
In total there are about 40 messages
Here are my goals:
1) Be able to capture and efficently parse all the asyncronous message from the system
2) Efficently encode messages to send to the device.
3) Make the code as easy to follow as possible so that people with relatively little experience can understand and update it.
I have created some VI's already, but my implementation is clunky at best. Issues that I would like specific advice on include
1) I am using a for loop to index through a 1D array which contans a number which I use to tell me what data type the next piece of the MSG DATA is. This method is very difficult to update and is not at all clear to the uninitiated.
2) I dont currently have a good way to pass the data I have parsed to other loops of my VI.
3) I use multiple loops, and had to resort to using globals (Eek!) to exit from all the various loops.
4) I have only used my VI with a very reduced data rate 4Hz per message. I have doubts as to the ability of my VI to handle 100Hz.
I can post code if needed, but I dont have it accessable at this moment.
Any help would be great. Thanks
01-30-2009 12:14 PM - edited 01-30-2009 12:15 PM
Without seeing your code we can only provide limited suggestion. It seems as if you're trying to parse while you read the bytes. I would suggest not doing this. Read the whole message as an array of U8 and then parse the message - it will be a lot cleaner. Parsing the message is relatively easy - if you know about the Type Cast function. For example, here's a simple way to parse a message:
Depending on how you code is set up you will probably want to use separate subVI to handle each message type.
To prove to yourself that the Type Cast work you can try the following:
As you can see, the array of bytes that is the message data get correctly interpreted back into something meaningful.
If you post your code other suggestions can be made.
02-02-2009
10:07 AM
- last edited on
06-24-2024
06:44 PM
by
Content Cleaner
bigeeguy,
An excellent way to pass information to other loops is by implementing a Producer/Consumer Design. This type of architecture will send your data to another loop in the order that it came in.
Also, it will be easiest to help you if we can see a screenshot of your code.