LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reference Number to Open Comport

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.

0 Kudos
Message 1 of 6
(3,306 Views)

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. 

0 Kudos
Message 2 of 6
(3,285 Views)

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.

0 Kudos
Message 3 of 6
(3,269 Views)
Curious.  Are you closing the port after each run?  I think you are creating a new handle each time you run it.
Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 6
(3,260 Views)
Message Edited by billko on 09-18-2009 03:10 PM
Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 5 of 6
(3,251 Views)

Let's try this again:

 

Does this help?

 

getting session ID from resource name

 

Bill

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 6
(3,246 Views)