LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

virtual comport auto detect

Solved!
Go to solution

As mentioned earlier I think it would be easier to assist you if you would provide some more details:

 

why don't you provide

 

- a screenshot of MAX showing your serial configuration; this would tell, for example, if all your serial ports are identical, or 9 is different from 10...

- your sample code where you address your different ports

- the return value of the function call for 10 ('not working')

 

0 Kudos
Message 21 of 39
(2,690 Views)

HI,

 

thank you for reply .

 

My conport  numner is "19". In max its showing "19" only .  

IN labwinodw  code status = +viFindRsrc (defaultRM, "ASRL[00-99]*::?*INSTR", &find_list, &retCnt, instrDesc);  its  showing "ASRL10::INSTR", please  see the attched  both images .

 

Please let me knoew if  i  diid wroong in reading port via visa,.  

 

 

max.JPGport_detection .JPG

0 Kudos
Message 22 of 39
(2,690 Views)

First of all, it seems you changed VISA search string: your "[00-99]" won't find all devices! As discussed earlier in this thread, the expression in brackets is not a list but a regular expression instead. You are actually searching for a port that includes "0", "characters from 0 to 9", "9", additive!

 

Next, if I correclty understand your code, you are only scanning the first instrument found by the function; to scan for additional resources you must loop on viFindNext (see here). Try this code in the Interactive Execution Window:

 

#include <visa.h>
static ViSession rm;
static ViFindList find_list;
static ViUInt32 cnt;
static char desc[256];
static ViStatus sts;
#include <utility.h>
#include <formatio.h>
static int		portNo;

viOpenDefaultRM (&rm);
sts = viFindRsrc (rm, "ASRL[0-9]*::?*INSTR", &find_list, &cnt, desc);
while (sts != VI_ERROR_RSRC_NFOUND) {
	Scan (desc, "%s[dt#]%d[x]", &portNo);
	DebugPrintf ("Instrument description: %s (port %d)\n", desc, portNo);
	sts = viFindNext (find_list, desc);
}

In debug output window you should find the list of all ports found and the associated com port retrieved from the instrument descriptor. Note that I used Scan function from the Formatting and I/O Library to extract the com port number in a single pass. You can see in the function help page how to interpret the format codes I used.

 

On my system the above code returns the following list:

Instrument description: ASRL1::INSTR (port 1)
Instrument description: ASRL2::INSTR (port 2)
Instrument description: ASRL4::INSTR (port 4)
Instrument description: ASRL10::INSTR (port 10)

which actually includes all the ports I have.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 23 of 39
(2,684 Views)

As you can see in MAX, there is a port called COM10, and because 10 is smaller than 19, it is the first one reported by your function call.

 

So I see the following issues:

 

1) MAX reports a non-existing LPT port - this is a bug in VISA and has been solved in VISA 15, see here

 

2) You need to search for your port - viFindRsrc returns all ports that match your search string; for this you can query a specific attribute of your port, (by opening the port with viOpen and then using viGetAttribute) and if it is not the one you are looking for, analyse the next, this can be done using the command

viFindNext ( find_handle, instrument_descriptor );

 

3) I don't understand the purpose of your plus sign in calling viFindRsrc; what you should do is something like this:

 

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

if ( status != VI_SUCCESS )
{
    ErrorMessage ( status, resource_manager_handle );
    return ( FALSE );
}
serial_ports_available = ( int ) return_count;

if ( serial_ports_available == 0 )
{
    ErrorMessage ( "Warning", "No serial ports detected!" );
    return ( FALSE );
}

0 Kudos
Message 24 of 39
(2,684 Views)

 

hi

 

 

But  i am uing only one port not multiple port . it should show only one  right .

 

if  i connect only one port its detectig 2  comport  then how i can decide which one is correct one. (in my appliction only one port uisng  but that comport no is not constant  its change according  to baord )

 

0 Kudos
Message 25 of 39
(2,673 Views)

As mentioned before, detecting a non-existing LPT port (your port 10) is a bug in some VISA versions and all you can do is upgrade to VISA15 or later.

 

Your mainboard may have an internal serial port, that's why it may show two. In this case you can disable it in MAX, see my previous link.

0 Kudos
Message 26 of 39
(2,678 Views)

But  i am uing only one port not multiple port . it should show only one  right . 


This is an assumption that you must never make! Smiley Wink

 

As mentioned by Wolfgang, you may have additional serial ports on the motherboard or a parallel port or even non-existing ports!

To discriminate which port to use and exclude parallel ports you can open a session to the port, get the instrument name and search for "COM" text in it.

 

Inside the loop in my code above you can add these lines:

	viOpen (rm, desc, VI_NO_LOCK, 1, &instr);
	viGetAttribute (instr, VI_ATTR_INTF_INST_NAME, desc);
	DebugPrintf (" Instrument name: %s\n", desc);
	viClose (instr);

This will modify the output this way:

Instrument description: ASRL1::INSTR (port 1) Instrument name: ASRL1  (COM1 - Communications Port)


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 27 of 39
(2,677 Views)

... or you can use the dll from msaxon which lists all and only serial ports, see my previous posts.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 28 of 39
(2,669 Views)

hi 

 

Once agian thanks  for your reply .

 

sorry to keep bug you more .

 

Again i ma confuse . my aplliction is  read which comport is connected  and  config that  comport  and  do communictaion  thats it . 

as per your suggetion i thing its read all port . In this  case  i ma able to conform which port  is connected .  if  my port is below  line  as per ur code  its showing comport "10". becouse  if below 9  its detected 1st time only   and in nextfind  its  detec 10 ..  and if above 9   , 1st time it dectec 10 nad then  in find next  its detect acutual  port  but in this  case  labwinodw showing  "RS232 error -5",   

 

so still  not abe to conclude my issue ..

 

Thank you 🙂

0 Kudos
Message 29 of 39
(2,666 Views)

Sorry but I don't understand what you are saying: can you rephrase your message please?

 

And some questions to answer:

- Are you using VISA to communicate also or only to detect the ports in the system?

- Which function is returning that -1 error?

- Did you make a try with msaxon code?

- Which ports are returned on the first pne and which one on the second? Do they actually exist in your system?



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 30 of 39
(2,661 Views)