キャンセル
次の結果を表示 
次の代わりに検索 
もしかして: 

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 件の賞賛
メッセージ1/20
9,750件の閲覧回数

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
メッセージ2/20
9,743件の閲覧回数

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 件の賞賛
メッセージ3/20
9,719件の閲覧回数
thank you Martin for the help. Really appreciate it.
0 件の賞賛
メッセージ4/20
9,704件の閲覧回数

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
メッセージ5/20
9,679件の閲覧回数

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 件の賞賛
メッセージ6/20
9,547件の閲覧回数

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 件の賞賛
メッセージ7/20
9,552件の閲覧回数

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. 


Mark E.
National Instruments

メッセージ8/20
9,511件の閲覧回数

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 件の賞賛
メッセージ9/20
9,448件の閲覧回数

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 件の賞賛
メッセージ10/20
9,438件の閲覧回数