need help for serial communication using vb
yngjng
Posts: 7
i m trying to send a command to bs2 from·a pc. it works if using the debug terminal but it doesn't work with vb code below. below is the vb source code.·hope someone can give me some advise. thank you.
·bs2 source code
Private Sub Form_Load() MSComm1.CommPort = 1 MSComm1.Settings = "9600,N,8,1" MSComm1.DTREnable = False If MSComm1.PortOpen = False Then MSComm1.PortOpen = True End Sub Private Sub form_KeyPress(KeyAscii As Integer) MSComm1.Output = KeyAscii Tex1.Text = KeyAscii End Sub Private Sub MSComm1_OnComm() If (MSComm1.CommEvent = comEvReceive) Then Text2.Text = MSComm1.Input End If End Sub Private Sub End_click() MSComm1.PortOpen = False End End Sub Private Sub Form_Unload(Cancel As Integer) MSComm1.PortOpen = False End Sub
·bs2 source code
' {$STAMP BS2} ' {$PBASIC 2.5}
dserial VAR Byte dreceive VAR Word baudmode VAR Word pulse_count VAR Word
LOW 12 LOW 13
baudmode=16468
DO SERIN 16, baudmode, [noparse][[/noparse]dserial] dreceive = dserial
IF dreceive = $31 THEN
forward:
FOR pulse_count = 1 TO 100 PULSOUT 12, 500 PULSOUT 13, 1000 PAUSE 20 NEXT PAUSE 500 SEROUT 16, baudmode, [noparse][[/noparse]"data received"]
ELSE
SEROUT 16, baudmode, [noparse][[/noparse]"no data received"] PAUSE 1000
ENDIF LOOP
Comments
1. In the VB Sub form_KeyPress you have: Tex1.Text = KeyAscii -- is there a typo for Tex1.Text?
2. Does the VB code successfully send to HyperTerminal? Checking this might narrow down where the problem is.
3. The PBasic help for SERIN states that there may be sync issues at 4800+ baud. You might try a lower setting.
4. Try setting timing / timeout options in VB and PBasic to eliminate possiblr discrepancy errors