09-17-2009 04:14 PM
I have a CP2103 USB-UART bridge. I have no problem accessing the serial functions on the bridge. What I am trying to do is access the GPIO function. I have built vi's from the provided DLL to control the GPIO, however they need a handle reference number to know which comport to use. To date, the only way I have been able to get the handle reference number is to put the write function inside a loop and use the loop indicator as the handle number and run until the function return message is success (it is Unable to find resource) prior to that. Below is the API definition:
8.1. CP210xRT_ReadLatch
Description: Gets the current port latch value from the device.
Supported Devices: CP2103
Location: CP210x Runtime DLL
Prototype: CP210x_STATUS CP210xRT_ReadLatch(HANDLE Handle, LPBYTE Latch)
Parameters: 1. Handle—Handle to the Com port returned by CreateFile().
2. Latch—Pointer for 1-byte return GPIO latch value [Logic High = 1, Logic Low = 0].
Return Value: CP210x_STATUS = CP210x_SUCCESS,CP210x_INVALID_HANDLE,
CP210x_DEVICE_IO_FAILED
CP210x_FUNCTION_NOT_SUPPORTED
8.2. CP210xRT_WriteLatch
Description: Sets the current port latch value for the device.
Supported Devices: CP2103
Location: CP210x Runtime DLL
Prototype: CP210x_STATUS CP210xRT_WriteLatch(HANDLE Handle, BYTE Mask, BYTE Latch)
Parameters: 1. Handle—Handle to the Com port returned by CreateFile().
2. Mask—Determines which pins to change [Change = 1, Leave = 0].
3. Latch—1-byte value to write to GPIO latch [Logic High = 1, Logic Low = 0]
Return Value: CP210x_STATUS = CP210x_SUCCESS,CP210x_INVALID_HANDLE,
CP210x_DEVICE_IO_FAILED
CP210x_FUNCTION_NOT_SUPPORTED
I can not figure out how to determine the Handle variable which is based off the C++ function of CreateFile(). Any assistance would be greatly appreciated.
09-18-2009 09:04 AM
goofylogic98 wrote:To date, the only way I have been able to get the handle reference number is to put the write function inside a loop and use the loop indicator as the handle number and run until the function return message is success (it is Unable to find resource) prior to that.
That's a very bad way to do it.
There must be some sort of "Open" function or something within the library that opens the port. You mentioned something called "CreateFile" - what does that do? The library you are using is specific to some third-party hardware, so there's only a small chance that someone here will have actually used it. Possible, but low probability.
09-18-2009 02:10 PM
I guess the real question:
In C++, to access a Com Port you use the createfile() API which returns a unsigned 32bit interger reference value. In LabView we get a Resource Name, but in the workings of the computer that comport that is opened is assigned a value each time it is opened. How to I get to the reference number. I have run numerous test, and the "Handle" value is not constant. I believe that this value is a reference to the memory location where the Com Port Buffer is being held. Is there a way to identify this value in Labview.
09-18-2009 02:44 PM
09-18-2009 03:07 PM - edited 09-18-2009 03:10 PM
09-18-2009 03:11 PM
Let's try this again:
Does this help?
getting session ID from resource name
Bill