I'm working on an embedded device that communicates using Modbus RTU. A single slave device may be configured with different baud rates, parities, data bits and stop bit.
When I connect a slave device to my computer, I have to know the exact configuration of the device in order to communicate with it. In C# for example, you would open a connection in the following way:
SerialPort port = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
Is there a standard way of "scanning" the virtual COM-ports for a device and figuring out the communication parameters? It would be really great to just plug my device into a USB-port and and connect to it with a single click.
Is there a standard way of "scanning" the virtual COM-ports for a device and figuring out the communication parameters?
No.
Unless the device specifically supports it, there's no standard way to auto-negotiate the baud rate. If a device does support it, it requires that a known sequence of characters be transmitted to the device, so it can detect the proper baud rate.
Given that Modbus doesn't have any support for auto baud rate, this would have to be implemented in a device-specific manner as it would fall outside of the Modbus specification. So you always have to set up your serial settings every time.