PDA

View Full Version : Serial Command from VB6.0 keep loop back



CGTan2020
08-30-2008, 02: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

stamptrol
08-30-2008, 07:49 PM
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
·

Unsoundcode
08-31-2008, 04:34 AM
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.

CGTan2020
08-31-2008, 07:26 AM
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?

Unsoundcode
08-31-2008, 07:35 AM
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.

CGTan2020
08-31-2008, 05:40 PM
Many thanks.


CG