I have a program that reads data from a scanner via the serial port. This program works fine on Windows XP. We have a terminal server set up running Windows Server 2008. I run HyperTerminal on our test terminal, it connects and reads the scanner data fine through COM1. I run my app on that same test terminal and get nothing when I scan.
My app connects to COM1 without errors and disconnects without errors. BUT, the DataRecieved event is NEVER getting fired. Neither is the ErrorReceived event. I have played with the Handshaking, with the RecievedBytesThreshhold and pretty much every setup setting I found. Set it up exactly like the settings on Hyperterminal. I have even tried starting a timer on a different thread to call ReadByte every second to try to KICK this thing into doing SOMETHING. Nothing has worked.
I have been trying to fix this for an entire day now. Added events to my class trying to see EVERYTHING that is going on. All I know is, it connects to the port and it disconnects from the port correctly but nothing happens in between. No data when I scan. No event fired at all between connecting to and disconnecting from the port. I'm tired of google. :-)
HELP!! Please???
PS I have also downloaded other's simple serial communications applications. Nothing in .NET works. Period. :-(
Port SetUp code (mvarSerialPort is COM1):
If ComPort Is Nothing Then
ComPort = New SerialPort(mvarSerialPort)
ComPort.BaudRate = 9600
ComPort.Parity = Parity.None
ComPort.StopBits = StopBits.One
ComPort.DataBits = 8
ComPort.ReadTimeout = 2000
ComPort.Encoding = System.Text.Encoding.ASCII
ComPort.Handshake = Handshake.None
ComPort.ReceivedBytesThreshold = 1
End If
If Not ComPort.IsOpen Then ComPort.Open()
ComPort.DtrEnable = True
DataReceived event (which is never fired on that darn terminal):
Private Sub Scan(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) Handles ComPort.DataReceived
Dim sDataStatus As String = ""
Select Case e.EventType
Case SerialData.Chars
sDataStatus = "Data Received Event - Chars "
Case SerialData.Eof
sDataStatus = "Data Received Event - Eof"
End Select
RaiseEvent ClassStatus(sDataStatus)
Dim delInvoke As ScanResults
delInvoke = New ScanResults(AddressOf RaiseScanEvent)
delInvoke.Invoke()
End Sub
RaiseScanEvent (This works great on my computer and my coworker's computer running XP)
Private Sub RaiseScanEvent()
Dim sScanned As String = ComPort.ReadLine.TrimEnd
RaiseEvent ClassStatus("RaiseScanEvent data: " & sScanned)
RaiseEvent ComDataReceived(sScanned)
End Sub