VB strings to Stamp
bennettdan
Posts: 614
Hello,
······· I have wrote a Visual Basic program and I am outputting the data to my stamp I can send and recieve the data eaisly I just need to be able to extract certin variables out of the string.
My program will send "AxxxE" or "BxxxE to the stamp A,B is STX start of text·xxx is value I want to use and E is the end of text to know I have recieved all the data.
What I want is to use the A or B to pick what value in the stamp to set and then use the xxx to set it to that value.
I plan to control a servo position or motor speed. Thanks for any help...
······· I have wrote a Visual Basic program and I am outputting the data to my stamp I can send and recieve the data eaisly I just need to be able to extract certin variables out of the string.
My program will send "AxxxE" or "BxxxE to the stamp A,B is STX start of text·xxx is value I want to use and E is the end of text to know I have recieved all the data.
What I want is to use the A or B to pick what value in the stamp to set and then use the xxx to set it to that value.
I plan to control a servo position or motor speed. Thanks for any help...
Comments
·
·· Depending on the Model BASIC Stamp you’re using you could use the STR or SPSTR functions to buffer the string and then extract the relevant information from there.· If the string is a fixed length it makes things easier.· Of course, if you had a known header byte it would be easier to detect the packet altogether.· Anyway, the value could easily be put into a variable, but I have to ask…Is it fixed at 3 digits?· Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
STX start of text =H
What to set =A motor 1, B Motor 2, C LED
Speed value= 500-999
End of Text= E
But how can I extract the 500-999 value out of the string? Or the A,B,C for what to set?
Post Edited (bennettdan) : 12/13/2006 11:39:52 PM GMT
·
·· If the values are in an array you can easily extract them and assign to them to a single variable.· Again this would be easier with a header and binary values, but here’s the general idea if these are ASCII digits (numbers)…Threw this together, but it should work...Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
·
·· I saw one error so I wrote a small quick & dirty demo program to show removing the characters from the array/string.· The error was in the part that grabs the A/B/C.· It should translate to a 0/1/2 respectively, but I subtracted the offset for a numeral show it was actually doing 1/2/3.· Anyway, here’s a demo not using SERIN…
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
The Serin 0,84, [noparse][[/noparse]STR instring\5] brings in the string and looks for 5 digits before it does anything correct?
the
targetPin = instring(0) - $30 which means it is looking at the LSB right?
But what does the - $30 mean?
Sorry to ask so much but thanks for the help.
·
·· Look above…I revised the code…That value should be $41…What I am doing is removing the ASCII offset from the character to get the value.· Subtracting $30 from the ASCII character “2” gives you a value of 2.· This works for all numbers.· For alpha characters the offset is different.· That is why I posted the second code.· I hope this helps.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
One more question if I break the string down to
inString(0) = "A"
inString(1) = "5"
inString(2) = "2"
inString(3) = "4"
inString(4) = "E"
Could I actually just use an If Then statement to set my value of A,B or C like this
MotorSel VAR Nib
Instring(0)= MotorSel
If MotorSel= "A" Then Pin3 High
Else If MotorSel= "B" Then Pin4 High
End IF
Instead of converting the value to a Dec # with this statement
targetPin = inString(0) - $41
Post Edited (bennettdan) : 12/14/2006 2:28:01 AM GMT
Could you post your VB code? You could simply copy it into Notepad and attach the file to your response thread or paste it directly into the thread. Thanks.
I am still Working on the VB code but plan to Share it in the Projects forum when it is finished. But if you need some help with something let me know.
·
·· Yes, you can use a conditional if you prefer…You don’t have to decode everything the way I did…It’s just the way I may have done it.· I hope it gave you a few ideas.· Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
Thanks..