Sending Data serially with the FullDuplexSerial.spin
Brian Carpenter
Posts: 728
I am totally new to spin and have just red through the propeller manual.· Nothing will really make sense however until i can actually make some things run.· I want to be able to send some data to a device via the fullduplexserial.spin code.· I know that i need to make·a top level object that will call the FullDuplexSerial.spin that will be lower in the hierarchy.· The device that i want to talk to requires 9600 baud and most likely mode 0 but will have to play with it to understand the mode thing.· So the data that i need to be able to send is something like this....
POST /Update.php HTTP/1.1
Host: 127.0.0.1
Content-type: application/x-www-form-urlencoded
Content-Length: 35
machine_id=999&item_id=(VAR1)&quantity=(VAR2)
I need to make sure that I also use the CR at the end of each line.
If that was the easy part, i also need to be able to get VAR1 and VAR2 inserted into the data stream before it is sent.·
Would I store the Data in a DATA block?
I was thinking that the Communications would run all in its own cog and be started and stoped as needed.·
Am i even on the right track?
Does anyone have any examples of using this object IN there code?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
Post Edited (Brian Carpenter) : 3/19/2007 4:31:45 AM GMT
POST /Update.php HTTP/1.1
Host: 127.0.0.1
Content-type: application/x-www-form-urlencoded
Content-Length: 35
machine_id=999&item_id=(VAR1)&quantity=(VAR2)
I need to make sure that I also use the CR at the end of each line.
If that was the easy part, i also need to be able to get VAR1 and VAR2 inserted into the data stream before it is sent.·
Would I store the Data in a DATA block?
I was thinking that the Communications would run all in its own cog and be started and stoped as needed.·
Am i even on the right track?
Does anyone have any examples of using this object IN there code?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
Post Edited (Brian Carpenter) : 3/19/2007 4:31:45 AM GMT
Comments
-Martin
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
StampPlot - GUI and Plotting, and XBee Wireless Adapters
Southern Illinois University Carbondale, Electronic Systems Technologies
Martin,· By using the
Ser.str.......
and having stated the obj of ser = FullDuplexSerial
will that make it work?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
Like most output drivers for the Propeller, the FullDuplexSerial.spin object has routines to output single characters, zero-terminated strings given their address, and hex/decimal/binary formatted numbers. If you're outputting zero-terminated strings, you can use the STRING() "pseudo-function" or the address operator ("@") to pass the address of the zero-terminated string. You can put strings in a DAT section or store them as byte arrays in a VAR section. The BYTEMOVE and BYTEFILL statements are also useful for copying strings and initializing them. STRSIZE will give you the length of a zero-terminated string and STRCOMP will allow you to compare two strings, but that's about it for built-in string support.
The FullDuplexSerial.spin routines mostly run in their own cog once started until they're stopped. Usually, this is started during program initialization and it's never stopped since most Propeller programs don't stop themselves once started.
i get an ERROR :expected ")" at the first comma.
An ideas??
changed it to this and all seems to be right with the universe again.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
Post Edited (Brian Carpenter) : 3/19/2007 5:17:00 AM GMT
-MH
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
in order to get them from the top object down to these, do i define them as constants in the top object.
Like·
·····
EDIT.· GOT this working.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
Post Edited (Brian Carpenter) : 3/19/2007 5:54:14 AM GMT
I am interested in the serial.rxstr(@myStr)
I need to be able to listen back for either a 2222 which i will send back from the server if i get the data or a 9999 from the server if i get bad data.·
This is what the response back looks like.
I need to try and understand how to listen to the entire response and just end up with the 9999.· If the data were good i would have recieved a 2222.· The dellema is that all this data comes back to me but all i want is the 9999 or the 2222. If 2222 i can clear my variables if 9999 i need to try again later.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
Glad you figured out the ser.start( ...) to get it rolling. Sorry, sounded like you had that when described the mode and such.
Is it just 2222 or is it 2222 plus a CR? The methods assumes data will end with a CR or some other delimiter you can define.
With values I'd recommend using Serial.RxDec since you are just accepting values.
i := serial.RxDec ' accept without timeout
Repeat until i == 2222
' code to try again
'clear variables
If it doesn't have a delimter, such as a CR, you may need to accept a byte at a time using serial.rx and get all 4 to be checked.
-Martin
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
StampPlot - GUI and Plotting, and XBee Wireless Adapters
Southern Illinois University Carbondale, Electronic Systems Technologies