02-04-2011 09:45 AM
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
Solved! Go to Solution.
02-04-2011 09:55 AM
yes
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
02-04-2011 11:46 AM
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
02-04-2011 12:14 PM
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?
02-04-2011 01:09 PM
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
02-04-2011 01:18 PM
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...
02-04-2011 01:31 PM
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
02-04-2011 02:12 PM
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...
02-04-2011 02:29 PM
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!
02-04-2011 02:36 PM
I see.
Unfortunately I ran out of suggestions... Some experts advice would be needed here.
Good luck!