6

I am trying to talk with hardware device through virtual COM port. Host computer is PC Windows OS PC. Device is working with 921600 baud rate. This code works:

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

Once I change baud rate:

dcb.BaudRate =  921600;

SetCommState fails with last error 0x57 (parameter is incorrect). Does this mean that Windows API prevents any baud rate except predefined values? Or maybe, virtual COM port may be configured to allow this baud rate?

Virtual COM port is part of CameraLink connection. I am talking with CameraLink board vendor. But I need to know whether Windows serial communications API support custom baud rates.

Mike
  • 47,263
  • 29
  • 113
  • 177
Alex F
  • 42,307
  • 41
  • 144
  • 212
  • 2
    If this is a virtual COM port, typically the configured baud rate doesn't matter. If you lower the rate down to 9600 or 4800 or so, do you see it slow down? I suspect it won't. – Brad Oct 10 '11 at 14:16
  • 1
    from my experience with CameraLink: the COM port is only provided for configuring the camera and should work with a standard low data rate (typically 9600baud). the CameraLink itself is much faster but does not pass through the COM port. other implementations are non-standard. (see [the CameraLink specification](http://www.lord-ing.com/web/IMG/pdf/Camera_Link-2.pdf)) – Adrien Plisson Oct 10 '11 at 14:23
  • @Adrien Plisson: According to Cameralink specification, cameras and frame grabbers should support at least 9600 baud. Actually, frame grabbers I am working with support 115200. It looks like frame grabber stops me, and not Windows. – Alex F Oct 10 '11 at 14:40
  • do you get any meaningfull data if you try the lower speeds? – shawty Oct 10 '11 at 17:30
  • @shawty: When baud rate doesn't match device requirements, communication doesn't work. Setting incorrect baud rate causes junk input. – Alex F Oct 10 '11 at 19:18

1 Answers1

6

Iv'e just had a quick trip to the MSDN documents for this, and here's what is said about the BaudRate property in the DCB struct.

BaudRate The baud rate at which the communications device operates. This member can be an actual baud rate value, or one of the following indexes. 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 should have no problem setting the serial port speed your requesting.

It also states further down that there are some combinations that are invalid (Specifically when programming the 8250 serial chip)

Remarks When a DCB structure is used to configure the 8250, the following restrictions apply to the values specified for the ByteSize and StopBits members: The number of data bits must be 5 to 8 bits. The use of 5 data bits with 2 stop bits is an invalid combination, as is 6, 7, or 8 data bits with 1.5 stop bits.

This makes me wonder if the issue you have is that certain combinations are what's causing things, rather than just setting the baud-rate for example.

Maybe your baudrate is fine, but by selecting that baudrate your invalidating the number of stop bits, or the parity length, which when the baudrate is set back to a standard setting then become valid again.

I don't know the hardware your dealing with so I can't say 100% if this is the case, I only know serial port programming in general, but personally, my next step would be to set the baudrate to what I need then leaving that as is, try all the different combinations of other flags in the block.

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

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

You may also find the BuildCommDCB function of some help too:

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

shawty
  • 5,729
  • 2
  • 37
  • 71
  • My port settings are pretty standard: byte size 8, parity None, flow control None, stop bits 1. Meanwhile, I got information from Cameralink board vendor, that this baud rate is not supported. Thanks for BuildCommDCB link :) – Alex F Oct 11 '11 at 13:36