Problems with Ping))), VB6 and extra RS-232 connection on PDB
clemen2
Posts: 10
Hi
·
I am having trouble with my ping))) sensor when using the extra RS-232 connection on the PDB (with BS2px stamp).· My goal is to send the distance data to a VB 6 program.· The Ping sensor works fine when using the programming RS-232 and the debug window.· My stamp program and VB can exchange data without a problem through the extra RS232 connection (thanks to an excellent Nuts and Volts article #89, September 2002).· But when I try to use the extra RS232 connection and the Ping))) together the VB program does not receive the correct distances just a bunch of ascii 9’s or 10’s.
·
Here is the program that fails to work properly:
·
'{$STAMP BS2px}
' {$PORT COM1}
' {$PBASIC 2.5}
·
Ping··········· PIN···· 8
·
·
RX············· CON···· 9······················ ' receive (from PC)
TX············· CON···· 10······················ ' transmit (to PC)
RTS············ CON···· 11····················· ' Request To Send (from PC)
CTS············ CON···· 12······················ ' Clear To Send (to PC)
Trigger········ CON···· 13
Scale·········· CON···· $0CD··················· ' raw x 0.80 = uS
RawToCm ········CON···· 2257··················· ' 1 / 29.034 (with **)
Baud··········· CON···· 396···················· 'N9600 for BS2px
IsHigh········· CON···· 1······················ ' for PULSOUT
'IsLow·········· CON···· 0
·
i·············· VAR···· Word
rawDist· ·······VAR···· Word··················· ' raw measurement
cm············· VAR···· Word
·
Main:
SERIN RX, Baud, [noparse][[/noparse]WAIT("p")]
·
FOR i = 1 TO 300
· PULSOUT Ping, Trigger························ ' activate sensor
· PULSIN· Ping, 1, rawDist················ ' measure echo pulse
· rawDist = rawDist */ Scale··················· ' convert to uS
· rawDist = rawDist / 2························ ' remove return trip
· Cm = rawDist ** RawToCm
· PAUSE 10
· 'Cm.LOWBYTE = 121
· 'Cm.HIGHBYTE = 122
· SEROUT TX\RTS, Baud, [noparse][[/noparse]Cm.LOWBYTE,Cm.HIGHBYTE]
NEXT
GOTO Main
END
·
· Note that if I remove comment ticks from lines ·'Cm.LOWBYTE = 121 and 'Cm.HIGHBYTE = 122, VB correctly receives the 121 and 122 data (300 pairs) without hitch.
·
Any ideas?
Cliff
·
I am having trouble with my ping))) sensor when using the extra RS-232 connection on the PDB (with BS2px stamp).· My goal is to send the distance data to a VB 6 program.· The Ping sensor works fine when using the programming RS-232 and the debug window.· My stamp program and VB can exchange data without a problem through the extra RS232 connection (thanks to an excellent Nuts and Volts article #89, September 2002).· But when I try to use the extra RS232 connection and the Ping))) together the VB program does not receive the correct distances just a bunch of ascii 9’s or 10’s.
·
Here is the program that fails to work properly:
·
'{$STAMP BS2px}
' {$PORT COM1}
' {$PBASIC 2.5}
·
Ping··········· PIN···· 8
·
·
RX············· CON···· 9······················ ' receive (from PC)
TX············· CON···· 10······················ ' transmit (to PC)
RTS············ CON···· 11····················· ' Request To Send (from PC)
CTS············ CON···· 12······················ ' Clear To Send (to PC)
Trigger········ CON···· 13
Scale·········· CON···· $0CD··················· ' raw x 0.80 = uS
RawToCm ········CON···· 2257··················· ' 1 / 29.034 (with **)
Baud··········· CON···· 396···················· 'N9600 for BS2px
IsHigh········· CON···· 1······················ ' for PULSOUT
'IsLow·········· CON···· 0
·
i·············· VAR···· Word
rawDist· ·······VAR···· Word··················· ' raw measurement
cm············· VAR···· Word
·
Main:
SERIN RX, Baud, [noparse][[/noparse]WAIT("p")]
·
FOR i = 1 TO 300
· PULSOUT Ping, Trigger························ ' activate sensor
· PULSIN· Ping, 1, rawDist················ ' measure echo pulse
· rawDist = rawDist */ Scale··················· ' convert to uS
· rawDist = rawDist / 2························ ' remove return trip
· Cm = rawDist ** RawToCm
· PAUSE 10
· 'Cm.LOWBYTE = 121
· 'Cm.HIGHBYTE = 122
· SEROUT TX\RTS, Baud, [noparse][[/noparse]Cm.LOWBYTE,Cm.HIGHBYTE]
NEXT
GOTO Main
END
·
· Note that if I remove comment ticks from lines ·'Cm.LOWBYTE = 121 and 'Cm.HIGHBYTE = 122, VB correctly receives the 121 and 122 data (300 pairs) without hitch.
·
Any ideas?
Cliff
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
·
That’s a good guess- but I think my VB code does handle this problem, here is the code (adapted· from the Nuts and Volts program):
·
··· ' activation code &H70 is sent
··· MSComm1.Output = Chr$(CmdTxN)
··· ' clear input buffer
··· Call FlushTxBuf
··· ' wait for series of two-byte value
··· For i = 1 To 30
··· Do
····· DoEvents
··· Loop Until (MSComm1.InBufferCount = 2)
··· TheTime = MyMilliSeconds()
··· ' grab input buffer
··· rxBuf = MSComm1.Input
··· ' unpack two bytes
··· Value1 = Asc(Mid$(rxBuf, 1, 1))
··· Value2 = Asc(Mid$(rxBuf, 2, 1))
··· Value = Value1 + 256 * Value2
·· ' update Data field with timestamp and distance
··· Text1.Text = Text1.Text & TheTime & "· " & Value & vbCrLf
··· Next
Private Sub FlushTxBuf()
· ' flush transmit buffer
· Do
··· DoEvents
· Loop Until (MSComm1.OutBufferCount = 0)
End Sub
·
So when the dummy values of 121, 122 are sent the Value parameter becomes 121 + 122*256 or 31353.· When the program is supposed to be sending distance data typically Value is 8 or 9 (hence Value1 = 8 or 9 and Value2 = 0) and shows no variation no matter what the object distance is to Ping))).
·
Also I have inserted numerous pause statements into the pBasic code to let Ping))) have plenty of time but this had no effect so I deleted all but one Pause 10 from the posted code.
·
Cliff
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com