Is there a way to, in c# write a serial port redirector? I have an app that is coded to use port 1 (com1:) however, my port on the handheld (Intermec CN50) is always 3. I do not have access to modify the mobile software, however I would like to redirect any data going out to 1 to copy it to 3 and any data coming in to copy it from 3 to 1, so the app doesnt know the difference.
I know this is a difficult issue, but I am sure one of you guys out there have an answer.
I sure dont.
Thanks
Chris
No, there isn’t. You have a couple alternatives, depending on the device and your exact needs.
The first, and simplest, is to redirect the driver. If your device doesn’t already have a COM1 device defined, you can modify the registry in
HKLM\drivers\builtinand change the Index for your specific port from3to1. That will cause device.exe to expose the port as COM1 and not COM3. In my experience this isn’t likely to work, though, as most serial ports are set to let the OS auto-assign the index, meaning COM1 and COM2 are already in use. You can, however, still work around this. You simply have to explicitly assign an Index to every instance at or below 3 for the device. Move index 1 to 3 and index 3 to 1 and you effectively swap the ports.Here are some examples – there are a few because it depends on how the OEM set up driver initialization. Here’s an example of a driver with no explicit port named (in this case I2C, but it works the same way):
Note there is a
Prefixand anIndex. This driver is going to enumerate as “I2C0:”. If you changes theIndexvalue to something else, say ‘2’, then it would enumerate as “I2C2:”.In some cases the driver can provide a specific port name, like this one:
Note here that the
Portvalue matchesPrefixplusIndex. No idea what would happen if you manually set them different, so don’t do that. If you wanted to move this one to COM3, you’d changeIndexto 3 andPortto COM3, but you have to make sure there’s nothing else in the registry already set to use those values. You don’t want two driver instances trying to enumerate at the same Index. If you do, I think the behavior is that the second one just gets incremented, but it’s best to explicitly set the values as unique so you know what’s happening.If that doesn’t meet your needs, you’d have to write an actual device driver to do the port move/aggregation. It would work a lot like the existing GPS Intermediate Driver (GPSID) under Windows Mobile and would allow you to redirect the serial data to any port you want. This, however, must be written in C because managed code (in the CF) cannot export native symbols so there’s no way to get device.exe to load a C# assembly.