LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Auto detect serial port settings using LabWindows

Solved!
Go to solution

Hi All, 

 

I have a program which interfaces with device via RS232. Right now I just set up the port number in my code and it needs to be changed every time we switch the computer. Is it doable that I could detect the port number first and then communicate with that device. 

 

Thank you very much!!

 

Tianchi

0 Kudos
Message 1 of 18
(8,665 Views)

yes Smiley Happy

 

You could use viFindRsrc, see here

 

This tells you all available ports. If you have more than one instrument, you can then loop through all ports to query for the identity of the attached devices.

 

Hth, Wolfgang

0 Kudos
Message 2 of 18
(8,666 Views)

Hi, 

 

Thanks, that function seemed to work. But we got an issue, it worked fine detecting the instrument on ports 0~8, but then failed on higher ports. We are using this function to find the device via RS232: viFindRsrc(defaultRM, "?*INSTR",&find_list, &retCnt, instrDesc); 

 

 

Thanks again. 

 

Andrew

0 Kudos
Message 3 of 18
(8,648 Views)

Hi,

 

I use it with 32 serial ports and it is working... below is the function call:

 

status = viFindRsrc ( resource_manager_handle, "ASRL[0-9]*::?*INSTR", &find_handle, &return_count, instrument_descriptor );

 

I am not sure why it doesn't work for you, maybe you want to try the expression "ASRL[0-9]*::?*INSTR" ?

 

Also, did you check MAX to see if all your ports are recognized?

0 Kudos
Message 4 of 18
(8,650 Views)

Hi Wolfgang, 

 

Actually, viFindRsrc(defaultRM, "ASRL[0-9]*::?*INSTR",&find_list, &retCnt, instrDesc); seemed to return the VISA name such as ASRL11, but what we want is the com number like COM11. Is there any way to do that? Thank you. 

 

Andrew

 

0 Kudos
Message 5 of 18
(8,644 Views)

Maybe with Windows SDK calls, but I am not sure; someone else might answer this question;

 

What I can tell is that the correlation ASRL - COM may change if you add or remove hardware...

0 Kudos
Message 6 of 18
(8,640 Views)

Hi, 

 

To help clarify. We need the actual COM port number so we could use it as an argument to use this function:  OpenComConfig (FPORT, COMPORT, BAUD, 0, 8, 1, 32, 32) FPORT should be the COM number. But viFindRsrc(defaultRM, "?*INSTR",&find_list, &retCnt, instrDesc); just return the ASRL number, which we cannot use in OpenComConfig() function.

Basically, we need this program to be able to recognize the COM port the device is on. That's why we can't simply tweak the port settings, since this program should work for other machines without relying on actually specifying the correct port number each time.

 

Any help would be appreciated. 

 

Andrew

0 Kudos
Message 7 of 18
(8,637 Views)

hm, may be I missed something, but why don't you use viOpen ()? You don't need the RS232 library if you are going to use VISA...

Message 8 of 18
(8,630 Views)

Hi Wolfgang, 

 

The problem is that we have existing (and working!)  code in which we use a lot functions from RS232 library which need the COM port to configure. So it would be really painful if we switch all of them to VISA functions.

 

Thanks!

0 Kudos
Message 9 of 18
(8,619 Views)

I see.

 

Unfortunately I ran out of suggestions... Some experts advice would be needed here.

 

Good luck!

Message 10 of 18
(8,615 Views)