Obtaining a HANDLE from IO.Ports.SerialPort
-
Hi Everyone, Thanks for taking the time to read my question! I have an old unmanaged DLL that will handle all of the low level bootloader communications to a device on the serial port, however most of the functions in the DLL require a handle to the serial port. I also want to communicate with the device on the serial port using another protocol first (to put the device into bootloader mode) and this would be easiest done using some command classes that have already been written for another project using the System.IO.Ports.SerialPort class. Does anybody know of any fancy footwork that will allow me to begin using the serial port with the SerialPort class and then obtain a corresponding handle and pass that into the DLL calls? I'm definately not an expert in this area - it's been enough just looking into marshalling to use the unmanaged DLL, but I'm really stuck on this problem. Any help is greatly appreciated! Chris Chambers.
-
Hi Everyone, Thanks for taking the time to read my question! I have an old unmanaged DLL that will handle all of the low level bootloader communications to a device on the serial port, however most of the functions in the DLL require a handle to the serial port. I also want to communicate with the device on the serial port using another protocol first (to put the device into bootloader mode) and this would be easiest done using some command classes that have already been written for another project using the System.IO.Ports.SerialPort class. Does anybody know of any fancy footwork that will allow me to begin using the serial port with the SerialPort class and then obtain a corresponding handle and pass that into the DLL calls? I'm definately not an expert in this area - it's been enough just looking into marshalling to use the unmanaged DLL, but I'm really stuck on this problem. Any help is greatly appreciated! Chris Chambers.
-
If I am remembering right the handle you are looking for is ".SafeHandle". Just look down the intellisense list.
Phil
Hi Phil, As far as I can see it's not possible to obtain a SafeHandle object from the SerialPort object. I might be missing something but I don't think it's obvious though. Thanks anyway, Chris.
-
Hi Everyone, Thanks for taking the time to read my question! I have an old unmanaged DLL that will handle all of the low level bootloader communications to a device on the serial port, however most of the functions in the DLL require a handle to the serial port. I also want to communicate with the device on the serial port using another protocol first (to put the device into bootloader mode) and this would be easiest done using some command classes that have already been written for another project using the System.IO.Ports.SerialPort class. Does anybody know of any fancy footwork that will allow me to begin using the serial port with the SerialPort class and then obtain a corresponding handle and pass that into the DLL calls? I'm definately not an expert in this area - it's been enough just looking into marshalling to use the unmanaged DLL, but I'm really stuck on this problem. Any help is greatly appreciated! Chris Chambers.