04-10-2011 01:33 PM
Hi I am having quite an issue with this problem. I am using XBEE devices in API mode and the way it works it sends a API packet string containing the address, length, and data. I have no problem separating those its just when the data comes in. If the devices times out or is interupted by another node it send the packet but it may not send a complete data packet. As an example this is just the data part it is sending:
02CB 33FA FFD4 331D 00AF 3304 00CA 33FB FFD3 331D 00AF 3303
The start of each data byte is either 0x33 or 0x34 followed by 3 more bytes. As you can see though it didn't finish the last data byte (3303) The rest of the data is contained in the beginning of the next packet which would be:
02CB 33FA FFD4 331D 00AF 3304 00CA 34FB FFD3 331D 00AF 3305
So the finished data would be 3303 02CB. I am having alot of trouble with separating each data packet and also appending on an unfinished data string.
Solved! Go to Solution.
04-10-2011 01:55 PM
That should not be too difficult. Usually it is helpful to append the partial strings in a shift register.
Please post your attempt so far along with some typical data and a description of what does not work and the desired result.
Lynn
04-10-2011 02:10 PM - edited 04-10-2011 02:13 PM
I Did have it working with just searching for 33 but I had to add 34 and now its screwed up. I should only recieve 34 every 10 seconds otherwise it will always be 33 before the 3 data bytes
It should putthese into the queue
33FA FFD4
331D 00AF
3303 00CB
ect and it needs to also work with 34.
04-10-2011 03:27 PM - edited 04-10-2011 03:28 PM
That is an interesting way to use the delimiter input of the Spreadsheet string to array function.
The images below will show a simple approach which I think does what you want. The part of the code not shown is a shift register. The string coming in from the left is connected to the left shift register terminal. The top string going to the right connects to the right shift register terminal. The shift register is initialized with an empty string. The lower string on the right connects to an autoindexing terminal and creates the array shown in results. The constant connected to the Regular Expression terminal is set to 'Hex Display' mode. Read the help for the Match Pattern for details on how it works. Rather than the array you would connect your Enqueue function where the Match Substring indicator is.
This code replaces everything in your case structure.
Lynn
04-10-2011 03:33 PM
Thank you for your reply. I was trying to use the function you used but I could not get it to reconize anything in the string. I new I was making it harder than it needed to be. So I basically don't even need the case structure then
04-10-2011 03:50 PM
Right. The only place you may need a case structure is where you are receiving the data. The parsing process requires more iterations than the data receiving process. Thus you may want to verify that data is actually present rather than appending default values. If your process produces empty strings when no data is received, then go ahead and append the empty string as it does nothing.
Lynn
04-10-2011 04:07 PM
Do I place your code within a For loop within the while loop to make sure it separates all of the data?
04-10-2011 04:17 PM
Ok I figured it out. I knew I was over thinking it I just couldn't get the right sytax when I used that function. Thanks alot. Here is what i got from what you said and it seems to work. Is this what you had
04-10-2011 06:14 PM
I don't know if your still watching this but It seems I didn't quite do what you are doing in your method. Mine is producing an array that looks like this.
04-10-2011 07:00 PM
Sorry Nevermind I got it. no for loop. So the loop has to execute alot more times than there is actually I see that now. I inserted this into my program and it works great but It is very slow. The node I am connected to send very large packets every time so the length of the string in the shift register is huge and my program does have to run much faster than that because it will eventually have 3 nodes sending all at once. Can you steer me in the right direction for how to speed up this method? I'll play around with for loops and such to see what I can do. hopfully I can figure it out