From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

COMport problem

Hello all,

 

Here is another newbie problem on RS232, because I have a USB to Com (FTDI) interface, and PC is registering it as the last COM available, say I have previous Com1 and COm2, then when I plug the USB to COm interface it has Com22 assigned by XP.

 

What  want my program in CVI is to enumerate all available COMport and select the last Com automatically. How can I do this  in CVI? Hopefully someone can provide me a sample code for this. Thank you in advance.

0 Kudos
Message 1 of 20
(6,271 Views)

See this thread, which contains a download of a DLL I wrote some time ago to enumerate the COM ports and find ones with specific names. It uses the Windows Setup API.

 

I wrote it as a DLL because, at the time, CVI had problems compiling the Setup API header files. That is no longer the case, so you could probably quite easily modify the source code to compile within CVI directly.

Message Edited by msaxon on 08-11-2009 11:53 AM
--
Martin
Certified CVI Developer
Message 2 of 20
(6,264 Views)

Hi Martin,

Thanks for posting that DLL, that's pretty awesome! You should consider posting it to the community as an example so that it's more accessible to people that search on ni.com!

Jervin Justin
NI TestStand Product Manager
0 Kudos
Message 3 of 20
(6,240 Views)
thank you Martin for the help. Really appreciate it.
0 Kudos
Message 4 of 20
(6,225 Views)

msaxon wrote: 

I wrote it as a DLL because, at the time, CVI had problems compiling the Setup API header files. That is no longer the case, so you could probably quite easily modify the source code to compile within CVI directly.


 

Because I am old and decrepit, I had completely forgotten that I have already translated the source code to compile in CVI. A sample CVI 9 project containing the source code and a simple application to use it is attached.

--
Martin
Certified CVI Developer
Message 5 of 20
(6,200 Views)

Hello Martin,

 

Sorry for bringing this back again, the sample do the job fine as expected to be, though i run out on problem the given sample because of the redeclaration upon compiling.

 

But my followup question would be, how can I select the last COMport scanned, so that the last COM will be the one to be used on either OpenComConfig or OpenCom under comport parameter.

 

So I can use err= OpenCom(theLastCom,"")

 

James

0 Kudos
Message 6 of 20
(6,068 Views)

For follow-up, same scenario for the provided sample of CVI usng VISA on FindRsrc.c , I want to use the resource or COM last scanned.

So if it found 3 say

 

3 instruments, serial ports, and other resources found:

ASRL1::INSTR
ASRL10::INSTR
ASRL22::INSTR

How can select the last resource scanned the ASRL22::INSTR, so I can place that on

status = viOpen (defaultRM, "ASRL22::INSTR", VI_NULL, VI_NULL, &instr);  dynamically


 

 

0 Kudos
Message 7 of 20
(6,073 Views)

Hi ,

 

Take a look at the viFindNext operation on line 87 of the FindRsrc.c example (which installs with the NI-VISA driver). You can just loop through them until the final element, and you can know how many devices you have to go through to find the last one by using the numInstrs value that the viFindRsrc sets.

 

According to the Help for the viFindRsrc(), "The Find Handle, can be used in subsequent calls to the viFindNext operation to retrieve descriptor strings for the remaining instruments that were found."  The Find Handle is the parameter findList in the example. 

Message 8 of 20
(6,032 Views)

Hello Mark,

 

thank you for the help, I know this is spoon feeding (sorry for being a new ), is it possible if I can ask some code snippet on how can I accomplish this?

 

Regards,

James

0 Kudos
Message 9 of 20
(5,969 Views)

I tried by inserting lines on the FindRsrc.c and it display the last scanned resource on the textbox but I dont know if this is the right thing to do.

 

The next question would be, how could I automatically send the Enter key without physically press the Enter key on the keyboard?

 

Just to give an idea on what I am trying to achieve, 

1. Open the Last scanned port.

2. Send Enter key to interrupt the booting of the DUT

3. Send reset command to the DUT

4. Read the response of the DUT.

 

Thank you very much for the help.

 

0 Kudos
Message 10 of 20
(5,959 Views)