Many Windows CE devices contain multiple peripherals. Some peripherals will be accessed through windows CE native drivers and the remaining peripherals will be accessed through stream drivers. A typical example of native driver is display driver and a typical example of stream driver is serial port. Stream driver is a simple, also powerful architecture and it is extremely flexible to develop a driver for any kind of devices. Serial port driver, bus drivers and custom device drivers are the typical examples for the stream driver.
We can take a serial port driver as an example to explain this blog. Devices like POS terminals need several serial ports to connect the peripherals like GPS, GSM Modem, IR devices, Magnetic card readers etc. In some cases, we need virtual serial port to access devices. We assume a POS terminal contains more than ten serial ports. This blogs explains you – how to access the serial port with the Index number greater than 10.
Opening a serial port device with an index number less than 10
Normally a combination of three letter prefix with the index number alone used to open the serial port driver. For example “COM3” is the name space used to open the serial port with the index 3. Following code snippet explains you to open the serial port with the index 3.
HANDLE hPort;
hPort = CreateFile(TEXT("COM3:"), GENERIC_READ GENERIC_WRITE, 0,NULL, OPEN_EXISTING, 0, NULL);
This method supports to open a serial port with the index less than 10. Index1-9 represents the first nine serial ports and index 0 represents the 10th serial port. This method is called as legacy naming convention.
Opening a serial port device with an index number greater than 10
We need to add a device string in front of the above mentioned notation to open a serial port with the index greater than 10. Following code snippet explains you to open the serial port with the index 20.
HANDLE hport;
hPort = CreateFile(TEXT("\$device\COM20"), GENERIC_READ GENERIC_WRITE, 0,NULL, OPEN_EXISTING, 0, NULL);
This method supports to open a serial port with any index from 0. This means, we can also open the index 3 with this method.
We can take a serial port driver as an example to explain this blog. Devices like POS terminals need several serial ports to connect the peripherals like GPS, GSM Modem, IR devices, Magnetic card readers etc. In some cases, we need virtual serial port to access devices. We assume a POS terminal contains more than ten serial ports. This blogs explains you – how to access the serial port with the Index number greater than 10.
Opening a serial port device with an index number less than 10
Normally a combination of three letter prefix with the index number alone used to open the serial port driver. For example “COM3” is the name space used to open the serial port with the index 3. Following code snippet explains you to open the serial port with the index 3.
HANDLE hPort;
hPort = CreateFile(TEXT("COM3:"), GENERIC_READ GENERIC_WRITE, 0,NULL, OPEN_EXISTING, 0, NULL);
This method supports to open a serial port with the index less than 10. Index1-9 represents the first nine serial ports and index 0 represents the 10th serial port. This method is called as legacy naming convention.
Opening a serial port device with an index number greater than 10
We need to add a device string in front of the above mentioned notation to open a serial port with the index greater than 10. Following code snippet explains you to open the serial port with the index 20.
HANDLE hport;
hPort = CreateFile(TEXT("\$device\COM20"), GENERIC_READ GENERIC_WRITE, 0,NULL, OPEN_EXISTING, 0, NULL);
This method supports to open a serial port with any index from 0. This means, we can also open the index 3 with this method.