Virtual serial port is occupied, software available Serial Port Limited COM1-COM4, how to release and delete the occupied serial port
A: You can delete a numeric entry in the Registry to clear these configurations: Enter Regedit in the "run" dialog box to enter the registry; then go to HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ com name arbiter. Then we can find this value: comdb. Its value indicates the serial port number currently in use. For example, for 1d, the binary value is 0001 1101, And the number from right to left indicates ports, and 5 are occupied. In this way, we only need to delete the comdb data item and disable the Registry (without restarting the computer.
How to connect with symbols?
Modify the Registry: HKEY_LOCAL_MACHINE \ hardware \ devicemap \ serialcomm, create a project, name mywdmdevice, type REG_SZ, content COM7. Open the serial port monitoring, you can see.
/*************************************** *********************************
* Function name: hellowdmadddevice
* Function Description: Add a new device.
* Parameter list:
Driverobject: The driver object that comes in from the I/O manager.
Physicaldeviceobject: The physical device object that comes in from the I/O manager.
* Return value: the status of the added device is returned.
**************************************** *********************************/
# Pragma pagedcode
Ntstatus hellowdmadddevice (in pdriver_object driverobject,
In pdevice_object physicaldeviceobject)
{
Paged_code ();
Kdprint ("Enter hellowdmadddevice \ n "));
Ntstatus status;
Pdevice_object fdo;
Unicode_string devname;
Rtlinitunicodestring (& devname, l "\ device \ mywdmdevice ");
Status = iocreatedevice (
Driverobject,
Sizeof (device_extension ),
& (Unicode_string) devname,
File_device_unknown,
0,
False,
& Fdo );
If (! Nt_success (Status ))
Return status;
Pdevice_extension PDX = (pdevice_extension) fdo-> deviceextension;
PDX-> fdo = fdo;
PDX-> nextstackdevice = ioattachdevicetodevicestack (fdo, physicaldeviceobject );
Unicode_string symlinkname;
Rtlinitunicodestring (& symlinkname, l "\ dosdevices \ COM7 ");
PDX-> ustrdevicename = devname;
PDX-> ustrsymlinkname = symlinkname;
Status = iocreatesymboliclink (& (unicode_string) symlinkname, & (unicode_string) devname );
If (! Nt_success (Status ))
{
Iodeletesymboliclink (& PDX-> ustrsymlinkname );
Status = iocreatesymboliclink (& symlinkname, & devname );
If (! Nt_success (Status ))
{
Return status;
}
}
Fdo-> flags | = do_buffered_io | do_power_pagable;
Fdo-> flags & = ~ Do_device_initializing;
Kdprint ("Leave hellowdmadddevice \ n "));
Return STATUS_SUCCESS;
}
Serial Port I/O control code
# Include <ntddser. h>
# Define ioctl_serial_set_baud_rate ctl_code (file_device_serial_port, 1, method_buffered, file_any_access)
# Define ioctl_serial_set_queue_size ctl_code (file_device_serial_port, 2, method_buffered, file_any_access)
How to Implement Virtual serial port driver? I used DriverStudio to automatically generate a driver without any changes.
I put
Change class and classguid
Class = ports
Classguid = {4d36e978-e325-11ce-bfc1-08002be10318}
Then you can see my driver in the Device Manager, and there is com4 in the brackets.
You only need to use pdevice-> CreateLink (\ "com4 \") in adddevice.
The Super Terminal and serial port debugging assistant of Windows adopt two different mechanisms.
The Super Terminal uses the query method. The serial port debugging assistant and other serial port applications using the MSComm class use the event notification method.
Super Terminal Mode:
Keep trying to read 1 byte.
Event method: not actively read
Call ioctl_serial_set_wait_mask to set some flag
This is equivalent to setting the hardware interrupt enabling and interrupt blocking.
Call ioctl_serial_wait_on_mask to send an IRP request, which is sent to you for processing. The real serial port is that when the specified mask event occurs, the interrupt handler completes this IRP.
When the IO manager finds that this IRP is returned, it first checks ioctl_get_wait_mask for the flag it has just set. If the serial_ev_rxchar flag in the completed IRP
When it is set, the IO manager will ioctl_get_commstatus
Virtual serial port-Note