VB6 and BASIC STAMP
Downs
Posts: 30
Hello all,
Can anyone point me in the right direction for learning how to send a command from Visual Basic 6 to a BASIC STAMP? Say I have a push button installed on my homework board and that push button starts a line of code once it pressed. How do I send a command from VB6 to tell that push button to fire? Sofar I'm able to link VB6 to my stamp and my stamp will send Text to my App. but it always sends a funny character for every CR command fired off by the BASIC STAMP. I think I'm some what on the right track but need some more help. All if any, would be greatly appreciated. Thanks!!!
Can anyone point me in the right direction for learning how to send a command from Visual Basic 6 to a BASIC STAMP? Say I have a push button installed on my homework board and that push button starts a line of code once it pressed. How do I send a command from VB6 to tell that push button to fire? Sofar I'm able to link VB6 to my stamp and my stamp will send Text to my App. but it always sends a funny character for every CR command fired off by the BASIC STAMP. I think I'm some what on the right track but need some more help. All if any, would be greatly appreciated. Thanks!!!
Comments
Thanks,
Tom
I'm using the HomeWork Board and using the Parallax USB to Serial Adapter. Below is my code to my little project I'm working on. I have commented what's not working.
Rex .....
Visual Basic 6.0 Professional Side of the project:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''VB6 Pro.''''''''''''''''''''''''''''''''''''''''''''
' '
' Example of controlling an LED on a BASIC STAMP '
' board, via Visual Basic 6.0 Professional '
' '
' BS HomeWork Board, USB to Serial Adapter '
' By Rex A. Downs '
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit
Dim PinNumber As Long
Dim PinState As Long
Private Sub Form_Load()
' Use COM1
MSComm1.CommPort = 4
' 2400 baud, no parity, 8 data bits, 1 stop bit
MSComm1.Settings = "2400,N,8,1"
' Make sure DTR line is low to prevent Stamp reset
MSComm1.DTREnable = False
' Open the port
MSComm1.PortOpen = True
End Sub
Private Sub cmdOn_Click()
'Turn LED ON
PinNumber = 14 ' PIN # on Basic Stamp Board Where LED is connected.
PinState = 1 ' PIN State of Above PIN #.....( 1 = HIGH (On))
MSComm1.Output = Chr$(255) & Chr$(PinNumber) & Chr$(PinState) ' Send Pin Number & Pin State to BS Board
End Sub
Private Sub cmdOff_click()
'Turn LED OFF
PinNumber = 14 ' PIN # on Basic Stamp Board Where LED is connected.
PinState = 0 ' PIN State of Above PIN #.....( 0 = LOW (Off))
MSComm1.Output = Chr$(255) & Chr$(PinNumber) & Chr$(PinState) ' Send Pin Number & Pin State to BS Board
End Sub
Private Sub Form_Unload(Cancel As Integer)
MSComm1.PortOpen = False 'Close Port
End Sub
Private Sub MSComm1_OnComm() 'This section is not working!!!!
If MSComm1.CommEvent = comEvReceive Then 'Code to fire off if MSComm1 is receiving from the BS Board
Text1.Text = MSComm1.Input ' Put result from BS Board in Text Box 1
End If
End Sub
BASIC STAMP II Side of the project:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' {$STAMP BS2}
' {$PBASIC 2.5}
PinNumber VAR Byte
PinState VAR Byte
Main:
' Use the programming port to receive
' data at 2400 baud
' Wait for the synch byte (255) and then
' get the PinNumber and PinState
SERIN 16,16780,[noparse][[/noparse]WAIT(255),PinNumber,PinState]
' If PinState=0 Then go to GoLow
' otherwise go to GoHigh
BRANCH PinState,[noparse][[/noparse]GoLow,GoHigh]
GOTO Main
' Set The pin low
GoLow:
LOW PinNumber
PAUSE 500
SEROUT 16,16780,[noparse][[/noparse]"Off"] 'This is not working!!!
GOTO Main
' Set the pin high
GoHigh:
HIGH PinNumber
PAUSE 500
SEROUT 16,16780,[noparse][[/noparse]"On"] 'This is not working!!!!
GOTO Main
http://forums.parallax.com/showthread.php?p=671804
Sending and receiving strings is perhaps the easier if you have a way to do that
MSComm1.Output = Chr$(255) &·"14" & Chr$(13)·&·"0" & Chr$(13)·' Send Pin Number & Pin State to BS Board,
the carriage returns in the code above indicate and seperate·the end of each piece of data, to receive the data use the code below
SERIN 16,16780,[noparse][[/noparse]WAIT(255),DEC2 PinNumber,DEC1 PinState]
without too much alteration to your code PinNumber should now contain the value 14 and PinState 0
Jeff T.
' {$STAMP BS2}
' {$PBASIC 2.5}
PinNumber VAR Byte
PinState VAR Byte
Main:
' Use the programming port to receive
' data at 2400 baud
' Wait for the synch byte (255) and then
' get the PinNumber and PinState
SERIN 16,16780,[noparse][[/noparse]WAIT(255),PinNumber,PinState]
' If PinState=0 Then go to GoLow
' otherwise go to GoHigh
BRANCH PinState,[noparse][[/noparse]GoLow,GoHigh]
' Set The pin low
GoLow:
LOW PinNumber
SEROUT 16,16780,[noparse][[/noparse]"Off] 'This is not working!!!
GOTO Main
' Set the pin high
GoHigh:
HIGH PinNumber
SEROUT 16,16780,[noparse][[/noparse]"On"] 'This is not working!!!!
GOTO Main
when you use the programming port the sent characters are echoed from the Stamp back to the PC so when you send 255,14 and 0 to the stamp the stamp replies "255140Off" those characters are now in the read buffer and need to be parsed.
Jeff T.