09-23-2017 01:01 PM
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
09-25-2017 05:30 PM
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!
09-25-2017 06:19 PM
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
10-03-2017 09:24 AM
Does anyone have any other suggestions?