I have a program that I have written using VB .NET 2008 that reads data from a barcode scanner through the serial port. This program works fine in a regular windows environment. I would like to deploy this program on a thin client in our shop. When I attempt to run this program on the thin client, I get an exception with the following message: "The given port name is invalid. It may be a valid port, but not a serial port."
I checked the serial port redirection and it looks fine. I used HyperTerminal and configured it to use COM1. It was able to read the data from the bar code scanner with no issue. This tells me that the hardware is fine so it must be my program and the serial port coding implementation.
I added some code to my program to query the ports. The result showed two COM1 ports, COM2, COM3, COM4 and COM5. I have no idea where all of these extra COM ports are coming from (except that one COM1 port is on the server and the other is from my thin client).
How do I identify the correct serial port to use in a thin client scenario?
-----------------------------------------------------
Here is a simple summary of my code.
Imports SystemImports System.IO.PortsPublicWithEvents serialPort AsNew SerialPort()PrivateSub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.LoadDim sResult AsString = ""Dim ports AsString() = serialPort.GetPortNames() sResult = "The following serial ports were found:" + vbCrLfDim port AsStringForEach port In ports sResult = sResult + port + vbCrLfNext port MsgBox(sResult)With serialPort .PortName = "COM1" .BaudRate = 9600 .DataBits = 8 .Parity = Parity.None .StopBits = 1 .NewLine = Chr(10)EndWith serialPort.Open()EndSub
The code is failing either when I go to set the serial port to COM1 or when I go to open the port.
John