ASCII serial string formatting and conversion

Feb 4, 2007 at 6:37pm

ASCII serial string formatting and conversion

I’m generally confused about taking data (ASCII) I’m getting serially from a sensor, getting rid of data delimiters and checksums and converting what I’ve kept to usuable decimal (float) numbers.

An example of sensor output could be $C144.43*7E. Where the $C and the * are the delimiters and 7E is the checksum. What I really need is 144.43. The data can range from 0.00 to 359.99, so I’m working with numbers that don’t always have the same number of places.

Where I’m getting hung up is that the output from the serial object is, as one would suspect, serial i.e., I get one integer representing each ASCII symbol. What i need to do is get rid of the nonsense and convert and package the relevant data to individual floats with two decimal places, in this case 144.43.

I’ve been mucking about with the sprintf object as well as regexp. The regexp object, with the correct attributes seems to work when I feed it ASCII from a message box, successfully stripping out everything but the necessary characters.

Any help or musings would be great appreciated.

Thanks

#30106
Feb 4, 2007 at 8:31pm

#95518
Feb 5, 2007 at 6:22pm

Thanks I’ll give it a shot and let you know how it goes.
Best- Todd

#95519
Feb 7, 2007 at 7:26pm

Thanks so much!!! I twiddled around a bit and found my solution!

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P message 183 355 70 196617 12.31;
#P newex 183 312 62 196617 prepend set;
#P newex 183 278 104 196617 regexp \\$C(.+)\\*;
#P window linecount 2;
#P message 183 232 17 196617 $C1;
#P window linecount 1;
#P newex 183 198 62 196617 prepend set;
#P newex 183 154 40 196617 itoa;
#P button 146 129 15 0;
#P newex 68 157 62 196617 prepend set;
#P message 125 95 50 196617 chunk 12;
#P message 11 95 52 196617 99 63 13;
#P newex 68 132 71 196617 serial b 9600;
#P message 101 19 29 196617 stop;
#P button 73 20 15 0;
#P newex 68 64 58 196617 metro 125;
#P connect 0 0 4 0;
#P connect 0 0 3 0;
#P connect 0 0 5 0;
#P connect 0 0 7 0;
#P connect 3 0 6 0;
#P connect 3 0 8 0;
#P connect 7 0 10 0;
#P connect 2 0 0 0;
#P connect 1 0 0 0;
#P connect 5 0 3 0;
#P connect 4 0 3 0;
#P connect 8 0 9 0;
#P connect 9 0 10 0;
#P connect 10 0 11 0;
#P connect 11 1 12 0;
#P connect 12 0 13 0;
#P window clipboard copycount 14;

#95520

You must be logged in to reply to this topic.