CGTan2020
08-30-2008, 01:37 PM
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
'@GIXX (mailto:'@GIXX)* is Get Input
'@SOXX (mailto:'@SOXX)* is Set Output
'@GOXX (mailto:'@GOXX)* is Get Output
DO
'SEROUT 16, 16468, [65]
'SEROUT 16, 16468, ["Testing"]
· serStr(5) = 0
· SERIN 16, 16468,[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,· ["@",HEX INL]
······· PAUSE 1
······· SEROUT 16, 16468,· ["*"]
······· 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
'@GIXX (mailto:'@GIXX)* is Get Input
'@SOXX (mailto:'@SOXX)* is Set Output
'@GOXX (mailto:'@GOXX)* is Get Output
DO
'SEROUT 16, 16468, [65]
'SEROUT 16, 16468, ["Testing"]
· serStr(5) = 0
· SERIN 16, 16468,[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,· ["@",HEX INL]
······· PAUSE 1
······· SEROUT 16, 16468,· ["*"]
······· PAUSE 1
····· ENDIF
··· ENDIF
· ENDIF
· PAUSE 1
LOOP
END