User data rate

I am trying to talk to a hardware device through a virtual COM port. The host computer is a Windows PC. The device operates at a speed of 921600 baud. This code works:

  DCB dcb;
 ...
 dcb.BaudRate = CBR_115200;
 SetCommState (hPort, & dcb);

As soon as I change the baud rate:

  dcb.BaudRate = 921600;

SetCommState error with last error 0x57 (parameter is 0x57 ). Does this mean that the Windows API prevents any data rate other than predefined values? Or maybe the virtual COM port can be configured to allow this speed?

The virtual COM port is part of the CameraLink connection. I speak with the seller of the CameraLink board. But I need to know if the Windows serial communication API supports custom baud rates.

+6
source share
1 answer

Iv'e just visited the MSDN docs for this, and here's what the BaudRate property in the DCB structure says.

BaudRate Baud rate at which the communication device is operating. This member may be the actual baud rate or one of the following indices. CBR_110. CBR_300, CBR_600, CBR_1200, CBR_2400, CBR_4800, CBR_9600, CBR_14400, CBR_19200, CBR_38400, CBR_57600, CBR_115200, CBR_128000, CBR_256000

So, in theory, at least you shouldn't have a problem setting the serial port speed to your request.

It also indicates that incorrect combinations exist (especially when programming a 8250 serial chip)

Notes When the DCB structure is used for the 8250 configuration, the following restrictions apply to the values โ€‹โ€‹specified for the ByteSize and StopBits members: The number of data bits must be between 5 and 8 bits. Using 5 data bits with two stop bits is an invalid combination, just like 6, 7 or 8 data bits with 1.5 stop bits.

This makes me wonder if you have a problem in that some combinations are what cause something, and not just set the data rate, for example.

Your speed may be limited, but by choosing this speed you can invalidate the number of stop bits or the parity length, which, when the transmission speed returns to the default setting, will become valid again.

I donโ€™t know the hardware you are encountering, so I canโ€™t say 100%, if so, I only know how to program the serial port as a whole, but, personally, my next step would be to set the baud rate I need to leave it as it is , try all the different combinations of other flags in the block.

The official MSDN page for the DCB framework can be found here:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa363214(v=vs.85).aspx

You can also find the BuildCommDCB function for some help:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa363143(v=vs.85).aspx

+6
source

Source: https://habr.com/ru/post/898977/


All Articles