Shop OBEX P1 Docs P2 Docs Learn Events
Serial Command from VB6.0 keep loop back — Parallax Forums

Serial Command from VB6.0 keep loop back

CGTan2020CGTan2020 Posts: 8
edited 2008-08-31 09:40 in BASIC Stamp
I am trying to do Send a command from PC to BS2 thru the Serin command.

When BS2 receive certain command like @GIXX*, it will reply with @XX* whereby XX is the hex code, the problem is after i read back from the PC side, it seem that the orginal command that I sent @GIXX* will be echo back, anything wrong with my code below.

I am using Board of Education Serial. PLEASE HELP!!

' {$STAMP BS2}
' {$PBASIC 2.5}
INPUT 0
INPUT 1
INPUT 2
INPUT 3
INPUT 4
INPUT 5
INPUT 6
INPUT 7
OUTPUT 8
OUTPUT 9
OUTPUT 10
OUTPUT 11
OUTPUT 12
OUTPUT 13
OUTPUT 14
OUTPUT 15
serStr··· VAR···· Byte(6)
bInput··· VAR···· Bit(7)
bOutput·· VAR···· Bit(7)
inputStr· VAR···· Byte
outputStr VAR···· Byte
SerialInputStr··· VAR·· Byte

[url=mailto:'@GIXX]'@GIXX[/url]* is Get Input
[url=mailto:'@SOXX]'@SOXX[/url]* is Set Output
[url=mailto:'@GOXX]'@GOXX[/url]* is Get Output
DO
'SEROUT 16, 16468, [noparse][[/noparse]65]
'SEROUT 16, 16468, [noparse][[/noparse]"Testing"]
· serStr(5) = 0
· SERIN 16, 16468,[noparse][[/noparse]STR serStr\6 ]··············· ' Get 4-byte string
· IF serStr(0) = "@" THEN ' find header first
··· IF serStr(1) = "G" THEN ' Get Operation
····· IF serStr(2) = "I" THEN ' Get Input Operation
······· SEROUT 16, 16468,· [noparse][[/noparse]"@",HEX INL]
······· PAUSE 1
······· SEROUT 16, 16468,· [noparse][[/noparse]"*"]
······· PAUSE 1
····· ENDIF
··· ENDIF
· ENDIF
· PAUSE 1
LOOP
END

Comments

  • stamptrolstamptrol Posts: 1,731
    edited 2008-08-30 11:49
    I think the issue is on the PC side. Because of the way the Stamp serial port is constructed, there is a hardware echo for everything received. The PC side must be programmed to check its buffer after a transmission and discard the echo.

    Jeff T. (Unsoundcode) has done a lot of work on Stamp to VB communication and I'm sure he can offer some specific steps to take.

    Cheers,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-08-30 20:34
    stamptrol said...
    The PC side must be programmed to check its buffer after a transmission and discard the echo.
    Tom is exactly right and there are a couple of ways you can tackle the problem. I am not familiar with all the members of MScomm but the objective is to discard the last string you sent from the buffer before you try to read the valid data.
    One way is to measure the length of the data you send from the VB application then program a loop to read and discard that number of bytes before you read the valid data.

    eg:
    MScomm.Output (MyString)
    Bytes_to_Discard=Len(MyString)
    For IDX=1 to Bytes_to_Discard
    MScomm.Input (junk) 'junk is sent to cyberspace
    Next
    MScomm.Input (MyInput)· 'Read valid data here

    thats the principal and depends on how you are transmitting and receiving data.

    Jeff T.
  • CGTan2020CGTan2020 Posts: 8
    edited 2008-08-30 23:26
    Thanks you all so much. I guess I will give it a try. How about if I use other pin for serial communication and not the default port for Debugging?
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-08-30 23:35
    Yes that will remove the echo problem, the best way is to use a RS232 to TTL line driver such as the MAX232 or MAX233, check this link by Chris Savage for a few ideas

    http://forums.parallax.com/showthread.php?p=640507

    Jeff T.
  • CGTan2020CGTan2020 Posts: 8
    edited 2008-08-31 09:40
    Many thanks.


    CG
Sign In or Register to comment.