Shop OBEX P1 Docs P2 Docs Learn Events
serial time communications between 2 basicstamps — Parallax Forums

serial time communications between 2 basicstamps

maverhmaverh Posts: 7
edited 2009-02-16 06:55 in BASIC Stamp
Hi,

we use 2 basicstamps
basicstamp1 send time and date by serial communication to stamp2

Stamp1 Send
HIGH 11:SEROUT 10\11,16780,[noparse][[/noparse]"M",HEX2 Month]
HIGH 11:SEROUT 10\11,16780,[noparse][[/noparse]"D",HEX2 Date]
HIGH 11:SEROUT 10\11,16780,[noparse][[/noparse]"U",HEX2 Hours]
HIGH 11:SEROUT 10\11,16780,[noparse][[/noparse]"N",HEX2 Minutes]

stamp2 received
serial·············· VAR Byte(1)
SERIN 8\9,16780,1000,nodata,[noparse][[/noparse]STR serial\3]

i receive the following string in variable serial
M02
D14
U10
N46

IF (serial(0)="M") THEN '·month
····· Month = serial(1) & serial(2)
ENDIF
I want to remove the M,D,U,N and store the month in a integer variable, how can i do this

regards,
· Manu

Comments

  • MrBi11MrBi11 Posts: 117
    edited 2009-02-14 17:12
    IF (serial(0)="M") THEN ' month

    month=(serial(1)-$30) * 10 + (serial(2)-$30) ' this takes your second character "0" as in the month example subtracts $30 [noparse][[/noparse]converts if from ASCII to binary]

    ' multiples result by 10 then takes the third character "2" subtracts $30 [noparse][[/noparse]ASCII=>Binary] and adds that in

    ' Tmp now holds the value of 2 [noparse][[/noparse]for the month example]
    ENDIF

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Smile ... It increases your face value!

    Post Edited (MrBi11) : 2/14/2009 5:25:30 PM GMT
  • FORDFORD Posts: 221
    edited 2009-02-16 06:55
    Its off the top of my head, but you should be able to do something like this with a bit of playing around...
    it should be fine at 2400, otherwise try 1200 bps...



    'it takes advantage of the formatters in the SERIN command - very useful for this kind of thing...

    'sorry i cant test it first, anyone else feel free to chip in and correct it if need be [noparse]:)[/noparse]



    'STAMP 1 TRANSMIT...
    month var byte
    date var byte
    hours var byte
    minutes var byte

    'Stamp1 Send
    HIGH 11:SEROUT 10\11,16780,[noparse][[/noparse] Month,CR, date,CR,Hours,CR, Minutes,CR]
    '···the·CR's are just used to break the hex data bytes apart, they must be used...
    '·· the serin command below automatically moves the incoming byte to the next variable when a non numeric byte is received...


    STAMP·2 RECEIVE...
    month var byte
    date var byte
    hours var byte
    minutes var byte

    'stamp2 should receive and place the data into the variables as shown below,
    nodata:
    SERIN 8\9,16780,5000,nodata,[noparse][[/noparse]hex month, hex date, hex hours, hex minutes]
    debug cr, hex2 month, tab, hex2 date, tab, hex2 hours, tab, hex2 minutes
    goto nodata



    'see the manual for the SERIN instruction and appendix C for help (its a bit confusing though).
    'Once you get the gist of how this works, you will see what a very powerful instruction the SERIN command is 'with all of the formatters you can use with it.

    hope it works for you...

    cheers, Chris
Sign In or Register to comment.