How to validate USB Serial port name

4

I'm doing the rationalization of a scale in C #, I can communicate with code all right, but when I connect, I need to specify the port name, I have other devices connected and the port name varies from machine machine.

Can anyone help me validate the port where the balance is connected?

For the time being I left the static name as COM15, but the port name may change.

I'm opening a connection so it works, but the name can not be static.

//Definindo a porta
 SerialPort port = new SerialPort("COM15", 2400, Parity.None, 8,StopBits.One);
//Abrindo a porta
 port.Open();

I tried to get the names of all the connected ports, but I can not tell which port is the balance.

//Pegando o nomes das portas conectadas
 string[] Portas = SerialPort.GetPortNames();

Is there any way to tell if the connected port is scales?

Note: I use a serial to USB converter cable.

    
asked by anonymous 10.08.2018 / 19:25

1 answer

1

Normally the scales have bidirectional communication, you send a command and it responds to you, it can be a weight request, a ping, something like that, so you should check all active COM ports, that way you can identify , but the ideal is to do this every time you open the system and not just the installation, because the serial port can change COM if the user changes the USB port, after some update of windows or the like.

    
10.08.2018 / 23:14