Shop OBEX P1 Docs P2 Docs Learn Events
serin — Parallax Forums

serin

KARIM102KARIM102 Posts: 75
edited 2010-08-26 12:45 in Learn with BlocklyProp
Hi everyone,
why this code is not working???




THRID:
PAUSE 500
SEROUT GPRS_TX, GPRS_Baud,["A",A,13,10] ' send word
SEROUT GPRS_TX, GPRS_Baud,["B",B,13,10] ' send word
SEROUT GPRS_TX, GPRS_Baud,["C",C,13,10] ' send word
SEROUT GPRS_TX, GPRS_Baud,["D",B,13,10] ' send word


RESURT:
DO
SERIN GPRS_RX, GPRS_Baud,3000,THRID, [WAIT("A")] ' recived word
SERIN GPRS_RX, GPRS_Baud,3000,THRID, [WAIT("B")] ' recived word
SERIN GPRS_RX, GPRS_Baud,3000,THRID, [WAIT("C")] ' recived word
SERIN GPRS_RX, GPRS_Baud,3000,THRID, [WAIT("D")] ' recived word


IF A =1 THEN ' when the word "A" recived

HIGH 15 ' relay "A" energized
LOW 14 ' other relays de-energized
LOW 13
LOW 12
GOTO START

ELSEIF B = 1 THEN ' relay "B" energized
HIGH 14 ' other relays de-energized
LOW 15
LOW 13
LOW 12
GOTO START

ELSEIF C = 1 THEN ' relay "C" energized
HIGH 13 ' other relays de-energized
LOW 14
LOW 15
LOW 12
GOTO START

ELSEIF D = 1 THEN ' relay "D" energized
HIGH 12 ' other relays de-energized
LOW 14
LOW 13
LOW 15
GOTO START

ELSE ' when there aren't any signls
HIGH 12 ' All relays de-energized
LOW 14
LOW 13
LOW 15
ENDIF
LOOP

Comments

  • FranklinFranklin Posts: 4,747
    edited 2010-08-24 15:54
    Don't know. What is it supposed to do and what is it actually doing. I noticed a few typos so that may be your problem.
  • KARIM102KARIM102 Posts: 75
    edited 2010-08-24 19:24
    the problem is when you send A is lach but then u couldn't send "b" or anyone else??? i guess the problem with srin!!!!!!!
  • FranklinFranklin Posts: 4,747
    edited 2010-08-24 19:36
    That must not be your actual code because you don't have any of your variables declared. Could you show us your actual code with comments?
  • KARIM102KARIM102 Posts: 75
    edited 2010-08-25 12:13
    OK MATE this is my code it's for sms reciving and controller
    ' {$STAMP BS2e}
    ' {$PBASIC 2.5}
    '
    [variables]

    A VAR Word
    B VAR Word
    C VAR Word
    D VAR Word
    E VAR Word
    F VAR Word

    '
    [Initializations]

    HELP:
    LOW 15
    LOW 14
    LOW 13
    LOW 12

    '=======================================================================================================
    '
    main routine
    '=======================================================================================================

    frist:
    A = 1

    PAUSE 500
    SEROUT 0 ,84, ["AT+CMGD=1,4",13,10] ' Delect All messages
    SERIN 1, 84 , [WAIT("OK")]

    MAIN:

    PAUSE 500
    SEROUT 0 , 84, ["AT+CMGF=1", 13,10] ' Text mode
    SERIN 1 , 84,3000,MAIN, [WAIT("OK")]

    SECOND:
    PAUSE 500
    SEROUT 0,84, ["AT+CNMI=1,2,0,0,0",13,10] ' Read all messages
    SERIN 1 , 84,3000,SECOND,[WAIT("OK") ]


    THRID:
    PAUSE 500
    SEROUT 0 , 84,["A",A,13,10] ' send word.


    DO
    SERIN 1 , 84,3000,THRID ,[WAIT("A")] ' recived word


    IF A =1 THEN

    HIGH 15
    LOW 14
    LOW 13
    LOW 12
    GOTO kok
    ENDIF
    LOOP

    kok:
    B = 1
    PAUSE 500
    SEROUT 0 ,84, ["AT+CMGD=1,4",13,10] ' Delect All messages
    SERIN 1, 84 , [WAIT("OK")]

    MAIN1:

    PAUSE 500
    SEROUT 0 , 84, ["AT+CMGF=1", 13,10] ' Text mode
    SERIN 1 , 84,3000,MAIN1, [WAIT("OK")]

    SECOND1:
    PAUSE 500
    SEROUT 0,84, ["AT+CNMI=1,2,0,0,0",13,10] ' Read all messages
    SERIN 1 , 84,3000,SECOND1,[WAIT("OK") ]


    THRID1:
    PAUSE 500
    SEROUT 0, 84,["B",B,13,10]

    DO
    SERIN 1 , 84,3000,THRID1, [WAIT("B")] ' recived word

    IF B =1 THEN

    HIGH 14
    LOW 15
    LOW 13
    LOW 12

    GOTO frist1
    ENDIF

    LOOP

    frist1:

    C = 1
    PAUSE 500
    SEROUT 0 ,84, ["AT+CMGD=1,4",13,10] ' Delect All messages
    SERIN 1, 84 , [WAIT("OK")]

    MAIN2:

    PAUSE 500
    SEROUT 0 , 84, ["AT+CMGF=1", 13,10] ' Text mode
    SERIN 1 , 84,3000,MAIN1, [WAIT("OK")]

    SECOND2:
    PAUSE 500
    SEROUT 0,84, ["AT+CNMI=1,2,0,0,0",13,10] ' Read all messages
    SERIN 1 , 84,3000,SECOND2,[WAIT("OK") ]


    THRID2:
    PAUSE 500
    SEROUT 0, 84,["C",C,13,10]

    DO
    SERIN 1 , 84,3000,THRID2, [WAIT("C")] ' recived word

    IF C =1 THEN

    HIGH 13
    LOW 15
    LOW 14
    LOW 12

    GOTO frist2
    ENDIF

    LOOP


    frist2:

    D = 1
    PAUSE 500
    SEROUT 0 ,84, ["AT+CMGD=1,4",13,10] ' Delect All messages
    SERIN 1, 84 , [WAIT("OK")]

    MAIN3:

    PAUSE 500
    SEROUT 0 , 84, ["AT+CMGF=1", 13,10] ' Text mode
    SERIN 1 , 84,3000,MAIN3, [WAIT("OK")]

    SECOND3:
    PAUSE 500
    SEROUT 0,84, ["AT+CNMI=1,2,0,0,0",13,10] ' Read all messages
    SERIN 1 , 84,3000,SECOND3,[WAIT("OK") ]


    THRID3:
    PAUSE 500
    SEROUT 0, 84,["D",D,13,10]

    DO
    SERIN 1 , 84,3000,THRID3, [WAIT("D")] ' recived word

    IF D =1 THEN

    HIGH 12
    LOW 15
    LOW 14
    LOW 13

    GOTO frist3
    ENDIF

    LOOP
    frist3:

    E = 1
    PAUSE 500
    SEROUT 0 ,84, ["AT+CMGD=1,4",13,10] ' Delect All messages
    SERIN 1, 84 , [WAIT("OK")]

    MAIN4:

    PAUSE 500
    SEROUT 0 , 84, ["AT+CMGF=1", 13,10] ' Text mode
    SERIN 1 , 84,3000,MAIN4, [WAIT("OK")]

    SECOND4:
    PAUSE 500
    SEROUT 0,84, ["AT+CNMI=1,2,0,0,0",13,10] ' Read all messages
    SERIN 1 , 84,3000,SECOND4,[WAIT("OK") ]


    THRID4:
    PAUSE 500
    SEROUT 0, 84,["ALL",E,13,10]

    DO
    SERIN 1 , 84,3000,THRID4, [WAIT("ALL")] ' recived word

    IF E =1 THEN

    HIGH 12
    HIGH 15
    HIGH 14
    HIGH 13

    GOTO frist4
    ENDIF

    LOOP

    frist4 :

    F = 1
    PAUSE 500
    SEROUT 0 ,84, ["AT+CMGD=1,4",13,10] ' Delect All messages
    SERIN 1, 84 , [WAIT("OK")]

    MAIN5:

    PAUSE 500
    SEROUT 0 , 84, ["AT+CMGF=1", 13,10] ' Text mode
    SERIN 1 , 84,3000,MAIN5, [WAIT("OK")]

    SECOND5:
    PAUSE 500
    SEROUT 0,84, ["AT+CNMI=1,2,0,0,0",13,10] ' Read all messages
    SERIN 1 , 84,3000,SECOND5,[WAIT("OK") ]


    THRID5:
    PAUSE 500
    SEROUT 0, 84,["CLOSE",F,13,10]

    DO
    SERIN 1 , 84,3000,THRID5, [WAIT("CLOSE")] ' recived word

    IF D =1 THEN
    GOTO HELP

    ENDIF
    LOOP


    '
    [END]
  • KARIM102KARIM102 Posts: 75
    edited 2010-08-25 12:17
    the problem when i send sms to the gsm model, it has to be in order to operate each circuit i mean i have to go to "A" frist then "B" then "C" THEN "D" THEN "ALL" THEN "CLOSE" what i wanna is how could i make it not in order that i could send C before A or close it before i use All....

    sorry but i tried serval way i still i couldn't find away could u tell me!!!!
  • Mike GreenMike Green Posts: 23,101
    edited 2010-08-25 13:09
    I still don't understand what you're trying to do. You have a statement in your code:

    SEROUT 0, 84,["B",B,13,10]

    This will send the character "B", then it will send the lower 8 bits of the variable B as a single byte, then it will send a carriage return (13) and line feed (10). I don't know if the modem requires the line feed. Most do not. They'll use the carriage return as the end of the command, then ignore the line feed.

    What do you want the modem to get? It's impossible to tell from your code or your description.
  • KARIM102KARIM102 Posts: 75
    edited 2010-08-25 13:30
    i see,, i have GE864 GSM, this coding which i made it, it read the sms which you send it and make the action like this statment.
    SEROUT 0 , 84,["A",A,13,10] '
    which will send throw the TX temail for GSM from Basic stamp and the wait for any phone which send A as sms message
    SERIN 1 , 84,3000,THRID ,[WAIT("A")] '
    when you send "A" for ur phone to this GSM it will RX it and make action to pin from stamp
    IF A =1 THEN

    HIGH 15
    LOW 14
    LOW 13
    LOW 12
    GOTO kok
    and then go to the next state.....

    the problem is i don't wanna the order which i should go through all these sms to reach for explain "D" SMS,,,, i wanna any of these sms message will be action without make them in order.....

    i wish u get what i am asking....
  • Mike GreenMike Green Posts: 23,101
    edited 2010-08-25 14:18
    You must show me what you want the SEROUT statement to send. For example, if A has the value 33, then the SEROUT statement

    SEROUT 0,84,["A",A,13,10]

    is the same as

    SEROUT 0,84,["A",33,13,10]

    Since 33 is the same as the character "!", the SEROUT is the same as

    SEROUT 0,84,["A","!",13,10]
  • KARIM102KARIM102 Posts: 75
    edited 2010-08-25 19:15
    i put each variable = 1, so when it recived the messges it will make A = 33, but how could i use two serout or more and in the same time how could i use two serin or more see the coding!!!
    ' {$STAMP BS2e}
    ' {$PBASIC 2.5}

    '
    [variables]
    A VAR Word ' INPUT FOR THE MIRCONTROLLER
    B VAR Word ' INPUT FOR THE MIRCONTROLLER
    C VAR Word ' INPUT FOR THE MIRCONTROLLER
    D VAR Word ' INPUT FOR THE MIRCONTROLLER
    '
    [ I/O Definitions ]
    GPRS_RX PIN 0
    GPRS_TX PIN 1

    '
    [ Constants ]
    GPRS_Baud CON 84

    '
    [Initializations]
    LOW 15
    LOW 14
    LOW 13
    LOW 12

    '=======================================================================================================
    '
    main routine
    '=======================================================================================================

    START:

    A = 1
    B = 1 ' MAKR ALL VARABLE ONE
    C = 1
    D = 1

    PAUSE 500
    SEROUT GPRS_TX, GPRS_Baud, ["AT+CMGD=1,4",13,10] ' Delect All messages
    SERIN GPRS_RX, GPRS_Baud,3000,START [WAIT("OK")]

    MAIN:

    PAUSE 500
    SEROUT GPRS_TX, GPRS_Baud, ["AT+CMGF=1", 13,10] ' Text mode
    SERIN GPRS_RX, GPRS_Baud,3000,MAIN, [WAIT("OK")]

    SECOND:

    SEROUT GPRS_TX, GPRS_Baud, ["AT+CNMI=1,2,0,0,0",13,10] ' Read all messages
    SERIN GPRS_RX, GPRS_Baud,3000,SECOND[WAIT("OK") ]


    THRID:

    PAUSE 500
    SEROUT GPRS_TX, GPRS_Baud,["A",A,13,10] ' send word
    SEROUT GPRS_TX, GPRS_Baud,["B",B,13,10] ' send word
    SEROUT GPRS_TX, GPRS_Baud,["C",C,13,10] ' send word
    SEROUT GPRS_TX, GPRS_Baud,["D",B,13,10] ' send word


    RESURT:
    DO
    SERIN GPRS_RX, GPRS_Baud,3000,THRID, [WAIT("A")] ' recived word
    SERIN GPRS_RX, GPRS_Baud,3000,THRID, [WAIT("B")] ' recived word
    SERIN GPRS_RX, GPRS_Baud,3000,THRID, [WAIT("C")] ' recived word
    SERIN GPRS_RX, GPRS_Baud,3000,THRID, [WAIT("D")] ' recived word


    IF A =1 THEN ' when the word "A" recived

    HIGH 15 ' relay "A" energized
    LOW 14 ' other relays de-energized
    LOW 13
    LOW 12
    GOTO START

    ELSEIF B = 1 THEN ' relay "B" energized
    HIGH 14 ' other relays de-energized
    LOW 15
    LOW 13
    LOW 12
    GOTO START

    ELSEIF C = 1 THEN ' relay "C" energized
    HIGH 13 ' other relays de-energized
    LOW 14
    LOW 15
    LOW 12
    GOTO START

    ELSEIF D = 1 THEN ' relay "D" energized
    HIGH 12 ' other relays de-energized
    LOW 14
    LOW 13
    LOW 15
    GOTO START

    ELSE ' when there aren't any signls
    HIGH 12 ' All relays de-energized
    LOW 14
    LOW 13
    LOW 15
    ENDIF
    LOOP


    i tried this but it doesn't work!!!!
    is cz the serin just may use once!!!! or there is a way out!!!

    thx
  • Mike GreenMike Green Posts: 23,101
    edited 2010-08-25 19:34
    Show me what the Stamp must send to the modem, then show me what you expect the modem will send to the Stamp. Forget all the rest for now.
  • KARIM102KARIM102 Posts: 75
    edited 2010-08-26 09:25
    i wanna the stamp to send 3 coding to the model that when the model received one of these it will send active to the stamp circut....

    for example i wanna the stamp to accept "A", "B", "C" letter which i send from my phone and received from the model!!!

    thx
  • Mike GreenMike Green Posts: 23,101
    edited 2010-08-26 09:59
    When receiving control information like this, it's best to use some kind of punctuation to mark what's important like this:
    code    VAR  BYTE
    marker VAR  BYTE
    
    lookForData:
    SERIN 0,84,[WAIT("<"),code,marker] ' Look for <A>, <B>, <C>, or <D>
    IF marker <> ">" THEN GOTO lookForData ' Ignore if punctuation not correct
    IF code = "A" THEN
    ' stuff to do if <A>
    ELSEIF code = "B" THEN
    ' stuff to do if <B>
    ELSEIF code = "C" THEN
    ' stuff to do if <C>
    ELSEIF code = "D" THEN
    ' stuff to do if <D>
    ENDIF
    GOTO lookForData
    
  • KARIM102KARIM102 Posts: 75
    edited 2010-08-26 12:45
    thx a lot
    but what will be the serout command????????

    thx
Sign In or Register to comment.