Incoming command
bboy8012
Posts: 153
I am sending a·message with 2 commands·from C# to the propeller serially like this ("#", 1000, 1500, CR). My question is how do I go about splitting the message. I tried using the gpsIO_mini object well a form of it but no luck. Bytes 0-4 are for the first and 5-9 are the second. Thanks for the input
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Comments
from the info provided by you to it is not clear to me what is the first command ? what is the second ?
I guess "1000" is the first command "1500" is the second.
I would scan the string for commas.
after frist comma first command starts
after having found the second comma you know the position of second comma - 1 is end of command 1
position after second comma until CR is the second command
If the positions are fixed IN EVEREY CASE
you can use
Pseudocode
Command1[noparse][[/noparse] 0] := Commandstring[noparse][[/noparse] 4] ..Commandstring[noparse][[/noparse] 7]
Command1[noparse][[/noparse] 0] := Commandstring[noparse][[/noparse] 8] ..Commandstring[noparse][[/noparse] 11]
best regards
Stefan
Post Edited (StefanL38) : 4/5/2009 9:30:34 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I would prefer using the Extended_FDSerial-object from the obex.
inside this object is a method called "RxStr"
this methods does all the details for receiving a string and store the string into a bytearray
After RxStr has done this for you you can easily access the bytes in the bytearray as described above
your codeline
shows the first ASCII-code of the 4 received characters "1000"
It's not really dificult to interpret commands like "1000", "1500"
it takes 2-4 hours to code (AND TEST!) something like that
But to be honest: I'm not in the mood to code it right now.
Do you have a chance to modify the C-code of the sending device that it sends SINGLE bytes ?
this would make things easier
best regards
Stefan
My starting poind would be:
Receive all data without changing anything and echo it to a display to check if you really get what you expect.
If you receive the right data it's easy to split it up in seperate strings.
For example: if you receive a comma, you can immediately replace it with a 0 in the receive buffer, which is stringend in SPIN.
Then the buffer-adress points to the first string, which is the #
2nd string-adress := buffer-adress + strlen(buffer-adress)+1
3rd string-adress := 2nd string-adress + strlen(2nd string-adress)+1
CR string-adress := 3rd string-adress + strlen(3rd string-adress)+1
It is giving me the random numbers like this 105601000 which is the to slider positions on the C# form. But the positions are coming once every three times I move them. Attached is the file·for more insight. Thanks MagI02 I will try that method, thanks.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I put your code into my PPDB and started analysing it.
I'm willing to help but in a special manner.
I want you to learn debugging
If somebody else would like to help in a more dircect way feel free to do it.
Post me a suggestion how you can ANALYSE the received string BYTE BY BYTE
if the analysing does not work post me a question
As a hint: Do you have an working example where the DecimalToNumber-method is working properly ?
analyse this example byte for byte
best regards
Stefan
Post Edited (StefanL38) : 4/6/2009 5:35:03 PM GMT
The incoming number was 4 bytes, and the inBuffer array was 5 bytes giving it the extra zero it needed to terminate that string. This worked flawlessly when I moved the slider on my C# form it the numbers that prop output was the same. My problem is with comma delimited commands. But now when that I have added an extra command, and the commas, I get random output. i.e.
slider postions, (1276, 1490)·I get 1276014901. My first thought is the array sizes. But I ultimately want to get away from using the DecimalToNumber method, and create my own. Let me start the process from scratch to learn what is happening. I will post what I have in like an hour.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Results:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
results were what I wanted, minus the comma. I·guess the rxStr() removes them for you?·Next problem is how to get @cmdBuff[noparse][[/noparse]0] only to display the first command instead of the whole command?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Post Edited (bboy8012) : 4/6/2009 9:10:35 PM GMT
I don't understand why you convert it from integer to string on C# side and then you convert it back from string to integer on propeller side and complain about the conversation. As long as the data send is only to be read by processors you simply can send raw binary data. This has several advantages:
No conversion needed
fixed size
shorter messages
Say your numbers are in a range of 0-65535 you only transfer 2 bytes per number.
I don't know what other data you want to transfer. So, it might make sense to send one byte in front showing which data comes and then the two numbers in this case. If you send other data as well you give that data package another number.
All in all this would make 5 bytes for this package.
That's what you call a protocoll.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
After rereading you reply, I get ya. I guess this is just to verify the correct values are coming through. Of course I could do it on the C# side, which I will, but seeing as I got this far and only thing left for me to do is figure out how to get just the first bit of the command I am done. But I am going to do what you suggested once i am comfortable sending data from PC to prop. Still a beginner!
@All
Another question, how do I just get the first say 4 bytes of an array?
Have tried yaw := @cmdBuff[noparse][[/noparse]0] + 1, and understand it just shifts it one.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔