-
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
-
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