Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA error when opening a serial port in CVI/LabWindows

This has been asked before by people using LabView, and apparently there is some sort of solution in LabView. I need a solution that works in CVI/LabWindows 2020.

 

I have a device (power supply, but that doesn't matter) that's connected to a computer's native COM3 connector. If I use the device identifier "ASRL3::INSTR" I can find it in NI/MAX and talk to the device. Consider the following C program:

 

    //setup resource manager
    status = viOpenDefaultRM(&g_ResHandle);
    if (status < 0)
    {
        //resource manager failed to open - handle failure
        return PS_RES_OPEN_FAILED;
    }
//open the connection using the visa library
    status = viOpen (g_ResHandle, hwAddr, VI_NULL, VI_NULL, &g_InstrHandle);
    if (status < 0)
    {
        //port failed to open - handle failure
        return PS_RES_OPEN_FAILED;
    }
 
// Let's mess with the buffer flush settings
status = viSetAttribute(g_InstrHandle,  VI_ATTR_RD_BUF_OPER_MODE, VI_FLUSH_ON_ACCESS);
status = viSetAttribute(g_InstrHandle,  VI_ATTR_WR_BUF_OPER_MODE, VI_FLUSH_ON_ACCESS);
// Set the baudrate to 19200,n,8,1, no flow control
status = viSetAttribute(g_InstrHandle,  VI_ATTR_ASRL_BAUD, 19200);
status = viSetAttribute(g_InstrHandle,  VI_ATTR_ASRL_DATA_BITS, 8);
status = viSetAttribute(g_InstrHandle,  VI_ATTR_ASRL_STOP_BITS, VI_ASRL_STOP_ONE);
status = viSetAttribute(g_InstrHandle,  VI_ATTR_ASRL_FLOW_CNTRL, VI_ASRL_FLOW_NONE);

//get the instrument identification
sprintf(instr_cmd,"*IDN?\r\n");

// Look for and interpret a reply...

 

---------

 

On the machine where I need this to work, I can make the first call and get the default RM.  On the second call, the viOpen() fails and returns a VI_ERROR_RSRC_BUSY error.  If plug in a USB serial port instead of the port built into the computer, it works fine.  In essence, it appears that the IVI serial drivers do something different for native ports (Microsoft drivers) than they do with a USB serial port (FTDI driver).  This happens any time I start the program on one particular computer. On another computer with similar hardware, it seems to run okay.  It always works with the USB serial port.

 

Is there any explanation for this and is there a workaround using LabWindows and C?

 

Thanks!

 

Howard

0 Kudos
Message 1 of 6
(1,416 Views)

Any chance some other software has grabbed that port already?

Rolf Kalbermatter
My Blog
0 Kudos
Message 2 of 6
(1,371 Views)

I'm pretty sure that's not it.  If I make a test case with "Hello World" where a program launches, establishes the VI session and then tries to open the port to send "Hello World", it will work fine on a USB serial port or on some desktop (actually rackmount) machine built-in ports.

 

My only guess is that it must have something to do with Windows managing the built-in ports using the Microsoft driver, but the USB ports use the FTDI driver.  If it were possible somehow to open up the session and ask it which instruments were in use, I could loop through them and maybe make sure they're released. I see a call like that in PyVisa but not in the C version.

0 Kudos
Message 3 of 6
(1,349 Views)

One thing I did notice is that the machine had VISA version 20.0 and there are updates. I applied the latest 23.5.0. CVI no longer reports VI_ERROR_RSRC_BUSY but it still fails with a bad status and says the resource cannot be accessed.

0 Kudos
Message 4 of 6
(1,337 Views)

And I think the culprit has been found. I reapplied the Windows driver settings and the problem went away. The port was in fact, in use but I couldn't tell how.

 

I'd still love a way of querying a session to see what devices have been identified and opened...

0 Kudos
Message 5 of 6
(1,330 Views)

@HowardE wrote:

 

I'd still love a way of querying a session to see what devices have been identified and opened...


That requires communicating with the Windows SetupAPI to find your device port and then from there depending on what type of device it is, to try to communicate with it accordingly. It's doable but the SetupAPI is a pita to work with.

Rolf Kalbermatter
My Blog
0 Kudos
Message 6 of 6
(1,291 Views)