I have serios problem setting baud rate on serial port.
I’m calling the serial.sys driver from within my driver through
IoBuildDeviceIoControlRequest/IoCallDriver functions to set the baud
rate I’m using IOCTL_SERIAL_SET_BAUD_RATE this way:
NTSTATUS SerialSetBaudRate(DEVICE_INFO *uDeviceInfo,ULONG uBaudRate)
{
PIRP irp;
KEVENT event;
NTSTATUS status;
IO_STATUS_BLOCK ioStatus;
SERIAL_BAUD_RATE baudRate;
baudRate.BaudRate=uBaudRate;
KeInitializeEvent(&event,NotificationEvent,FALSE);
irp=IoBuildDeviceIoControlRequest(
IOCTL_SERIAL_SET_BAUD_RATE,
uDeviceInfo->serialObject,
&baudRate,sizeof(baudRate),
NULL,0,
FALSE,&event,&ioStatus);
if(!irp) return STATUS_INSUFFICIENT_RESOURCES;
status=IoCallDriver(uDeviceInfo->serialObject,irp);
if(!NT_SUCCESS(status)) return status;
status=KeWaitForSingleObject(&event,Executive,KernelMode,FALSE,NULL);
return STATUS_SUCCESS;
}
The function works fine, but only for speeds under 57600. When I use
SERIAL_BAUD_57600 or SERIAL_BAUD_115200 speeds the IoCallDriver returns
starus STATUS_INVALID_PARAMETER. But from the user-mode program I can
set these speeds, is there any problem with setting higher speeds in
kernel-mode? If I ask the driver for properties - it tells me, that it
should be possible to set all regular speeds (the driver does not
support only 128kbit as I think) - in the structure SERIAL_COMMPROP that
returns IOCTL_SERIAL_GET_PROPERTIES there is a number that are ORed all
speeds that the serial port should support and it is 0x6FFFF (exactly I
think that it is 0x1006FFFF) - the SERIAL_BAUD_57600 is 0x40000 and
SERIAL_BAUD_115200 is 0x20000 so they should work, but they don’t…
Thanks in advance
Martin