Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Get comm num from handle?

Options
  • 07-06-2011 1:55pm
    #1
    Registered Users Posts: 307 ✭✭


    Hi again folks.

    Is there a way in C (win32, windows.h) of getting the comm port number if I have a handle of said comm port?

    Obviously I already know the comm number (thats how I got the handle in the first place) but I am using multiple ports and dont want to have to go passing the different numbers around along with the handles, especially when its essentially only going to lead to a more concise error messaging.

    Thanks


Comments

  • Registered Users Posts: 981 ✭✭✭fasty


    I had a quick look at all the comm related Win32 functions here and didn't see anything suitable.

    A solution would be to create a struct that acts as a context for all communications and store the comm number and other info in there along with the handle.

    You said you were using C, so something like this... But a C++ class or struct would be the same
    typedef struct _CommContext
    {
    	HANDLE commPort;
    	DWORD portNumber;
    	// Other connection related stuff
    } CommContext;
    

    This makes more sense than hitting up windows with an OS call each time you need to query info, and it makes for something a bit easier to maintain down the road.


  • Registered Users Posts: 307 ✭✭wolf99


    Ha I was just stepping through them myself! (am still working on a SerialRx())
    Thanks thats a good idea, effectively creating an object to hold the data for each port.
    Cheers fasty


  • Registered Users Posts: 1,216 ✭✭✭carveone


    It might be possible to use the GetFileInformationByHandle function to return something. It would return something like: "\\\\.\\COM1" if it worked at all!

    Worth a go?!


  • Registered Users Posts: 307 ✭✭wolf99


    thanks carveone, I'll try that tomorrow, first glance looks promising though :)


Advertisement