Results 1 to 2 of 2

Thread: Serial Port Hardware

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Location
    Milan
    Posts
    810

    Serial Port Hardware

    I've got a 9pin serial port plug and I'm wanting to use a button to play music, seems easy enough except from a hardware point of view, say my standard button has a output wire how do I connect that to my serial port? this video says PIN 1 and 4, but why?

    http://www.youtube.com/watch?v=2MlJCMdD8MU

  2. #2
    Fanatic Member
    Join Date
    Sep 2009
    Location
    Lakewood, Colorado
    Posts
    621

    Re: Serial Port Hardware

    Hi,

    You can use one of the serial port inputs to monitor a switch by connecting the switch between an output (I'd use DTR, which defaults to high = True) to an input, such as DCD. So, connect your switch between pins 1 and 4. Open the port (settings don't matter, just specify the PortName, then call Open()). The SerialPort_PinChanged will be generate an event when the switch is opened or closed. For example,

    Code:
        
    Private Sub SerialPort_PinChanged(ByVal e As System.IO.Ports.SerialPinChangedEventArgs)
            If System.IO.Ports.SerialPinChange.DsrChanged = SerialPinChange.CDChanged Then
                If SerialPort.CDHolding = True Then
                    'switch was closed
                ElseIf SerialPort.CDHolding = False Then
                    'switch was opened
                End If
            End If
    End Sub
    Dick
    Richard Grier, Consultant, Hard & Software
    Microsoft MVP (Visual Basic)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width