0

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.

Q-bertsuit
  • 3,223
  • 6
  • 30
  • 55
  • https://stackoverflow.com/questions/3293889/how-to-auto-detect-arduino-com-port – aybe Mar 07 '18 at 20:02
  • @Aybe Thanks for the link, this shows how to get a list of all connected devices, but not how to find the communication parameters. – Q-bertsuit Mar 08 '18 at 07:57
  • What you should do then, like many programs, have known devices whose settings are known but also the ability to add a custom one. I mean there's no magic in the end, either a device can auto negotiate but in your case it's not PnP else you know safe or optimal settings. Hope that makes sense. – aybe Mar 08 '18 at 08:07
  • 1
    Serial ports are stone-age technology. Finding out how to configure a serial port is something you do the old-fashioned way, you ask. Or you take advantage of modern technology with email or a telephone. Somebody always knows, at a minimum the guy on the other end of the wire. If you are not going to be on-site when this is commissioned then do make sure you make these settings part of your program configuration. – Hans Passant Mar 08 '18 at 13:45

1 Answers1

2

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.

rm5248
  • 2,590
  • 3
  • 17
  • 16