ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

Roaming among the Dinosaurs

(1/2) > >>

parkint:
I am having trouble and hope one of my new-found friends (here on DC) can help.
In unmanaged C++ code, inside a simple DLL (for use with a proprietary interface), I need to access a COM port and read the data stream.
I can handle all the 'interpolation' of the data, but am having a real struggle getting access to the COM port; which, by the way is actually 'virtual' from a Bluetooth device.
Is there anyone out there with experience in this realm who is willing to help me?
I have scoured the Web for samples but none work as expected.

Inside this construct, I need to connect and read from a COM port:


BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD
               fdwReason,LPVOID
               lpvReserved){
                  switch (fdwReason)
                  {
                  case DLL_PROCESS_ATTACH:
                     /* Init Code here */
                     /* If there is something you need to do before the functions in this
                     * Library can be used, perform it here and return a true (or false if it fails) */
                     MessageBox ( NULL, L"Process Attach", L"DXExternal DLL", MB_OK);
                     break;
                  case DLL_THREAD_ATTACH:
                     /* Thread-specific init code here */
                     MessageBox ( NULL, L"Thread Attach", L"DXExternal DLL", MB_OK);
                     break;
                  case DLL_THREAD_DETACH:
                     /* Thread-specific cleanup code here.
                     */
                     MessageBox ( NULL, L"Thread Detach", L"DXExternal DLL", MB_OK);
                     break;
                  case DLL_PROCESS_DETACH:
                     /* Cleanup code here */
                     /* This is called as the DLL is being unloaded (most likely when your
                     * application is shutting down. */
                     MessageBox ( NULL, L"Process Detach", L"DXExternal DLL", MB_OK);
                     return false;
                     break;
                  }
                  /* The return value is used for successful DLL_PROCESS_ATTACH */
                  return true;
}

Thanks, in advance.

Stoic Joker:
I'm probably missing something here, but... COM Ports are accessed via OpenFile in Win2k and up (no direct hardware access).

f0dder:
Eh, you want to read from the COM port in DllMain? Doesn't seem very smart to me, COM ports are slow and when control won't return back to the application loading the DLL before DllMain returns. So you'll probably either want to export some functions for dealing with the device interaction, or do CreateThread and handle the device in a background thread (and it'd still be smarter to export a StartLoggingDevice() rather than setting up the thread directly in DllMain).

At any rate, Stoic Joke is (almost :)) correct: you open the virtual COM ports with CreateFile, specying a name of \\.\COMx (for ports less than 10 you can use COM1, .. COM9 directly, but you might as well make the code generic).

You might want to check out what CodeProject has regarding serial comms :)

Stoic Joker:
Oops! *Shrug* Hay, it's been awhile... ;)

ElenRey:
The easiest way to access remote serial port is to use additional soft like Network Serial Port KIt or Serial to Ethernet Connector (as I prefer more). Here is a comparative article  http://www.eltima.com/network-serial-port-kit-alternative.html

To log and analyze COM port data try Serial port Monitor - http://www.virtual-serial-port.org/products/serialmonitor/

Navigation

[0] Message Index

[#] Next page

Go to full version