4
People, I am doing the approval of a scale in c#, I can make the communication via code all right, however when making the connection, I need to specify the name of the port, I have other connected devices and the name of the port varies from machine to machine.
Can someone help me validate the door where the scale is connected?
For now I left the static name as COM15, but the door name may change.
I’m opening a connection like this, it works, but the name can’t be statistical.
//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’t tell which door is the scale.
//Pegando o nomes das portas conectadas
string[] Portas = SerialPort.GetPortNames();
Is there any way to know if the connected port is from the scale?
Obs: I use a serial to USB converter cable.
It would not be the case to list the ports and try to verify which device is connected in the same?
– Leandro Angelo
I think there is not much to do in this case, in general should stay as configuration for the user, unless you try to connect port by port and test send some command to see if it is the correct device
– Leandro Godoy Rosa
And if instead of mapping the ports, use the VID and PID identifications of the USB device?
– Leonardo
Hey, guys, thanks for your help. I managed to solve the problem as follows: I created a parameter in the system configuration, that is every time I install the system it defines the correct port name
– Carolina
I did this using a combobox, so the user only needs to select the port once
– Carolina