Shop OBEX P1 Docs P2 Docs Learn Events
Sending Data serially with the FullDuplexSerial.spin — Parallax Forums

Sending Data serially with the FullDuplexSerial.spin

Brian CarpenterBrian Carpenter Posts: 728
edited 2007-03-19 07:35 in Propeller 1
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

Comments

  • Martin HebelMartin Hebel Posts: 1,239
    edited 2007-03-19 04:31
    You sound like you're on the right track, once you have it running, you can send some data like these examples:

    ser.str(string("POST /Update.php HTTP/1.1"),13)  ' string with CR
    ser.str(string("My data = "))                     ' text for data
    ser.dec(myData)                                  ' variable data - decimal value
    ser.tx(13)                                       ' ending CR - byte value
    
    

    -Martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    StampPlot - GUI and Plotting, and XBee Wireless Adapters
    Southern Illinois University Carbondale, Electronic Systems Technologies
  • Brian CarpenterBrian Carpenter Posts: 728
    edited 2007-03-19 04:33
    Thanks Martin, Give me some time with this and i will repost.

    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!!
  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-19 04:35
    Brian,
    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.
  • Brian CarpenterBrian Carpenter Posts: 728
    edited 2007-03-19 05:01
    when compiling this

      ser.str(string("POST /Update.php HTTP/1.1"),13)  ' string with CR
      ser.str(string("Host: 127.0.0.1"),13)
      ser.str(string("Content-Type: application/x-www-form-urlencoded"),13)
      ser.str(string("Content-Lenght: 39"),13)
      ser.str(string("Machine_ID="))
      ser.dec(MachID)
      ser.str(string("&item_ID="))
      ser.dec(ItemID)
      ser.str(string("&quantity="))
      ser.dec(Quant)                                        ' variable data - decimal value
      ser.tx(13)                                            ' ending CR - byte value
    
    

    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.
      ser.str(string("POST /Update.php HTTP/1.1"))  ' string with CR
      ser.tx(13)
      ser.str(string("Host: 127.0.0.1"))
      ser.tx(13)
      ser.str(string("Content-Type: application/x-www-form-urlencoded"))
      ser.tx(13)  
      ser.str(string("Content-Lenght: 39"))
      ser.tx(13)  
      ser.str(string("Machine_ID="))
      ser.dec(MachID)
      ser.str(string("&item_ID="))
      ser.dec(ItemID)
      ser.str(string("&quantity="))
      ser.dec(Quant)                                        ' variable data - decimal value
      ser.tx(13)    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    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
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2007-03-19 05:06
    My Goof, 13 goes inside.

    ser.str(string("POST /Update.php HTTP/1.1",13))
    
    

    -MH
  • Brian CarpenterBrian Carpenter Posts: 728
    edited 2007-03-19 05:15
    Thanks Martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    It's Only A Stupid Question If You Have Not Googled It First!!
  • Brian CarpenterBrian Carpenter Posts: 728
    edited 2007-03-19 05:22
    so this is at the beginnig of the FullDuplexSerial.spin
    VAR
      long  cog                     'cog flag/id
      long  rx_head                 '9 contiguous longs
      long  rx_tail
      long  tx_head
      long  tx_tail
      long  rx_pin
      long  tx_pin
      long  rxtx_mode
      long  bit_ticks
      long  buffer_ptr
                         
      byte  rx_buffer[noparse][[/noparse]16]           'transmit and receive buffers
      byte  tx_buffer[noparse][[/noparse]16]  
    
    PUB start(rxpin, txpin, mode, baudrate) : okay
    
    

    in order to get them from the top object down to these, do i define them as constants in the top object.

    Like·
    con 
     rxpin = 16
     txpin = 17
     mode = 0
     baudrate = 9600
    

    ·····

    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
  • Brian CarpenterBrian Carpenter Posts: 728
    edited 2007-03-19 05:52
    Martin, in using your extended FDSerial.spin
    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.
    HTTP/1.1 200 OK               
    Date: Mon, 19 Mar 2007 05:49:03 GMT                                   
    Server: Apache              
    X-Powered-By: PHP/4.3.9                       
    Content-Length: 262                   
    Content-Type: text/html
    

    <html>
    

    <head>
    <title>Updating Data To Server</title>
    </head>
    

    <body>
    

    <h1>Updating Vending Machine Data Tables</h1>
    

    9999
    


    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!!
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2007-03-19 07:35
    Hi Brian,
    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
Sign In or Register to comment.