Serial Command from VB6.0 keep loop back
CGTan2020
Posts: 8
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
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
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
·
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.
http://forums.parallax.com/showthread.php?p=640507
Jeff T.
CG