Shop OBEX P1 Docs P2 Docs Learn Events
Visual Basic 8, usb comm with stamp. — Parallax Forums

Visual Basic 8, usb comm with stamp.

twhaleytwhaley Posts: 4
edited 2009-10-14 15:46 in BASIC Stamp
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

Comments

  • stamptrolstamptrol Posts: 1,731
    edited 2009-10-13 13:53
    Forum member Unsoundcode has helped me several times on VB communication topics. If he sees this post he'll likely provide some guidance or you could private message him.

    Cheers,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-10-13 14:51
    Hi Todd , check this link for the basics http://forums.parallax.com/showthread.php?p=671804

    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.
  • twhaleytwhaley Posts: 4
    edited 2009-10-13 16:58
    Thanks for the feedback!

    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
  • twhaleytwhaley Posts: 4
    edited 2009-10-14 13:22
    Great info, but i'm still fumbling around trying to make this work through my usb port, my laptop doesn't have a D style serial port.
    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.
  • allanlane5allanlane5 Posts: 3,815
    edited 2009-10-14 14:12
    Yes, when you install a USB to serial adapter (like the one on the BOE board) it acts exactly like a serial port.

    And typically you refer to it as "com3:", or "com4:", or whatever it "appears" as when you plug it in.
  • twhaleytwhaley Posts: 4
    edited 2009-10-14 14:29
    Sweet, thanks! I'll try that tonight.
  • chris joneschris jones Posts: 391
    edited 2009-10-14 15:33
    Hello

    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

    1024 x 736 - 109K
    Comm.jpg 108.7K
  • chris joneschris jones Posts: 391
    edited 2009-10-14 15:46
    here is the zip if you have any issues on how this will work it is not done i just started it and setup the communication
Sign In or Register to comment.