Parsing sub-strings from serial input of fixed length
Benj
Posts: 66
I am fairly new to Propeller and I am starting on a new project. I will be taking serial input from an old piece of lab equipment and will need to parse out certain sub-strings and then append them to what will eventually be a URL GET request by a Wifly. The length of the string is fixed (24 characters), and the position of the pertinent pieces of data does not change from string to string. For instance, one of the pieces of data is the motor RPM. It always is in characters 7, 8, 9, and 10. I need to be able to parse those characters to send a serial out string to the Wifly, that would be something like this:
http://www.myserver.com/datainput.php?rpm=char7char8char9char10
Also, the lab equipment doesn't have any way for me to change the string it sends out, i.e. to add comma separation or the like.
Can someone point me in the right direction for the commands I would use?
Benj
http://www.myserver.com/datainput.php?rpm=char7char8char9char10
Also, the lab equipment doesn't have any way for me to change the string it sends out, i.e. to add comma separation or the like.
Can someone point me in the right direction for the commands I would use?
Benj
Comments
http://forums.parallax.com/showthread.php/151780-Split-string-after-first-character?highlight=chap
It is not really clear if how you are connecting to the lab equipment? It seems you need get some data from the equipment and then send a GET via the Wifly? When you say serial, have you already been successful getting the serial data into the Prop?
Parsing means understanding, what you need is a simple copy. You did not tell anything about the size of the string that you receive by the lab device, so I used 100 for demonstration.
I guess I always thought of parsing as extracting out or replacing a certain portion of a string. Either way, I see what I need is a simple copy.
So, first have a serial object read the device. I use the serial 4 port object so that you get 4 instances of a serial object. One instance for the lab device, one for the wifly uart, one for a serial terminal for debug or feedback if you need it. After you read the data in from the device, since you already know the positions(elements) you can then send the GET with whatever content you want, versus just a relay of the devices output.
In the example below, I have already created a php webpage on a server that will take the GET and variables, and forward that to a mysql database and store the info. This is probably not your plan but you can see how I communicated with the wifly to the server successfully. I like using the server to deal direct with the database, much easier in my opinion.
You will need to determine if the lab device is sending ascii or hex so that you can be sure of how and what you are sending with the GET. In the other thread linked, there were examples of converting strings to decimals.