From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

RS485 Transceiver Mode setting resets after closing VISA session

I have a PXIe-8431/8 that I am trying to use in 2-wire Auto mode on all ports.  I know I can change this setting from the default 4-wire in MAX when running as Administrator, as well as with Device Manager.  However, I would like to do this programatically (my serial communication is implemented using the .NET SerialPort class, but I can use C++ or TestStand to change this setting if needed).  I've tried using DeviceIoControl as well as viSetAttribute.  In both cases, if I read the setting back after writing it, it is correct (RS485_MODE_2W_AUTO (3)).  If I close the CreateFile() handle or the VISA session I used to change the setting and then open a new session or handle, reading the Transceiver Mode attribute returns the default of 0 (RS485_MODE_4WIRE).  I have tried running my code as Administrator with the same results.

Since the transceiver mode can be changed in MAX or Device Manager, I know this setting can be persisted across multiple sessions.  How do I save this setting across multiple sessions programatically?

 

Thanks,

 

Brandon

0 Kudos
Message 1 of 4
(2,890 Views)

Hi bdybala, 

You can change the transceiver wire mode on Ports for National Instruments Serial Boards programatically by following this article: 

 

http://digital.ni.com/public.nsf/allkb/1D516C10D7EDFAC6862571110073B8F4 

 

Is this what you were looking for? 

 

Thanks!

0 Kudos
Message 2 of 4
(2,760 Views)

Maura,

 

I have already implemented the calls to setViAttribute and getViAttribute as shown in the LabWindows/CVI example you linked to.  However, this only works for the duration of the current until the first call to viClose().  If I create a new instrument session (a second call to viOpen()), the result of a new call viGetAttribute() shows the original transceiver mode setting, not the value that I previously set.  I've modified your linked example below to illustrate the issue.  I have tried running my code as Administrator, but the problem remains.

 

#include <ansi_c.h>
#include <visa.h>
#include <cvirte.h>

static ViInt16 RetWireMode;
static ViSession RSCHANDLE;
static ViSession INSTHANDLE;

int main (int argc, char *argv[])
{
    if (InitCVIRTE (0, argv, 0) == 0)
        return -1;    /* out of memory */
    
    
    viOpenDefaultRM (&RSCHANDLE);
    
    viOpen (RSCHANDLE, "ASRL3::INSTR", VI_NULL, VI_NULL, &INSTHANDLE);
    
    viGetAttribute (INSTHANDLE, VI_ATTR_ASRL_WIRE_MODE, &RetWireMode);
    printf("Original Wire Mode %d\n",RetWireMode);
    
    // Default value is VI_ASRL_WIRE_485_4WIRE, so change a 2-wire auto.
    viSetAttribute (INSTHANDLE, VI_ATTR_ASRL_WIRE_MODE,
                    VI_ASRL_WIRE_485_2W_AUTO);
                                                    
    // RetWireMode is VI_ASRL_WIRE_485_2W_AUTO
    viGetAttribute (INSTHANDLE, VI_ATTR_ASRL_WIRE_MODE, &RetWireMode);
    printf("New Wire Mode %d\n",RetWireMode);
                                
    viClose (INSTHANDLE);
    
    // Open a second instrument session
    viOpen (RSCHANDLE, "ASRL3::INSTR", VI_NULL, VI_NULL, &INSTHANDLE);
    
    // RetWireMode SHOULD be VI_ASRL_WIRE_485_2W_AUTO, but INSTEAD is
    // the default VI_ASRL_WIRE_485_4WIRE (as if the call to viSetAttribute()
    // above had no effect).
    viGetAttribute (INSTHANDLE, VI_ATTR_ASRL_WIRE_MODE, &RetWireMode);
    printf("New Wire Mode %d\n",RetWireMode);
                                
    viClose (INSTHANDLE);
    
    getchar();
    
    return 0;
}

 

Thanks,

 

Brandon

 

0 Kudos
Message 3 of 4
(2,756 Views)

Does anyone have any other suggestions?

0 Kudos
Message 4 of 4
(2,732 Views)