Visual Basic 8, usb comm with stamp.
twhaley
Posts: 4
Hello all,
I'm trying to write a VB app that communicates with a basic stamp2e via my usb port. It's a simple app, i'm just trying to have my program poll a usb port looking for simply a change in state to trigger an event, i can go from there.
Has anyone here done this? i can figure out the programming for the stamp but not the vb part. I'm using VB 2008 express.
The VB help and MS website have not helped, TMI. I used to use MScomm for serial ports but i cant find it in vb2008. I also used inpout.dll to access my parallel port. Any ideas or info would be greatly appreciated. Thanks.
Todd Whaley
I'm trying to write a VB app that communicates with a basic stamp2e via my usb port. It's a simple app, i'm just trying to have my program poll a usb port looking for simply a change in state to trigger an event, i can go from there.
Has anyone here done this? i can figure out the programming for the stamp but not the vb part. I'm using VB 2008 express.
The VB help and MS website have not helped, TMI. I used to use MScomm for serial ports but i cant find it in vb2008. I also used inpout.dll to access my parallel port. Any ideas or info would be greatly appreciated. Thanks.
Todd Whaley
Comments
Cheers,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
·
As Tom says feel free to PM me if you need help on specifics and I will help the best that I can.
Jeff T.
Is it possible that all i need to do is use the SerialPort controll and·make the port name whatever my USB port is called? and the treat it as a standard serial port? I never tried·poking·at·a usb port from vb before. Thanks again.
Todd
Does anyone know if VB 2008 treats a usb port the same as a com port? by that i mean can i use the SerialPort control to communicate through my USB port? if so, what would i use for PortName etc? I think it's so simple that i cant see the forest through the trees.
TIA
My names todd and I'm a noob.
And typically you refer to it as "com3:", or "com4:", or whatever it "appears" as when you plug it in.
i have done this
here is the code that will connect your basic stamp to your vb code
'CODE
'this is the vb code
Public Class Connect
Dim switch1, switch2, switch3, switch4 As Boolean
Private Sub Connect_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If RadioButton1.Checked Then
WSNParent.SerialPort1.BaudRate = 4800
End If
If RadioButton2.Checked Then
WSNParent.SerialPort1.BaudRate = 9600
End If
If RadioButton3.Checked Then
WSNParent.SerialPort1.BaudRate = 19200
End If
Me.Visible = False
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Not WSNParent.SerialPort1.IsOpen Then
Dim port As String
port = ListBox1.SelectedItem
If Not port = Nothing Then
WSNParent.SerialPort1.PortName = port
Dim Title As String = "Port"
Try ' Set up structured error handling.
CheckForIllegalCrossThreadCalls = False
WSNParent.SerialPort1.Open()
'Form1.Timer1.Enabled = True
Catch ex As Exception When Not WSNParent.SerialPort1.IsOpen
MsgBox("Com Port already in use by another application", MsgBoxStyle.Critical, "Error")
Finally
'Beep() ' This line is executed no matter what.
End Try
Else
MsgBox("Select a port", MsgBoxStyle.DefaultButton1, "Error")
End If
End If
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim instance As IO.Ports.SerialPort = WSNParent.SerialPort1
For Each portName As String In My.Computer.Ports.SerialPortNames
ListBox1.Items.Add(portName)
Next
RadioButton2.Checked = True
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If WSNParent.SerialPort1.IsOpen Then
WSNParent.SerialPort1.Close()
End If
End Sub
End Class
'
'end of line
your form will need to look like the screen cap bellow