12-20-2011 05:24 AM
Hi,
I have two NI PXI 8431 serial boards installed in my PXI system. I can change the transceiver mode of one of the ports by using NI MAX (Attachment1).
But I cannot change it by using CVI. My sample code is below.
Before running the code, I change the transceiver mode of ASRL12 to "two wire auto" by using NI MAX. I save the configuration and close the NI MAX. And then, I run my sample code below. Status returns 0 all the time. But when I check in NI MAX, the transceiver mode is still "two wire auto".
The software installed and versions are attached (Attachment2). My serial hardware can be seen on Attachment3.
If you have any idea please let me know.
Regards,
Gökhan
************
#include <ansi_c.h>
#include <visa.h>
static ViStatus status;
static ViSession rschandle;
static ViSession inshandle;
status = viOpenDefaultRM (&rschandle);
status = viOpen(rschandle, "ASRL12::INSTR", VI_NULL, VI_NULL,&inshandle);
status = viSetAttribute(inshandle, VI_ATTR_ASRL_WIRE_MODE, VI_ASRL_WIRE_485_4);
status = viClose(inshandle);
***********
12-20-2011 05:42 AM
Hi,
I have two minor comments:
- I am not sure about your two arguments VI_NULL - at least the help doesn't mention this value and I always used VI_EXCLUSIVE_LOCK; the same for the timeout value: what is the maximum time if you provide VI_NULL? Here I provide a time (in ms)...
- Also I am not sure if the attribute set by CVI is reflected in MAX - did you check using viGetAttribute after setting the attribute with viSetAttribute?
Wolfgang
12-20-2011 07:30 AM
Wolfgang,
Thanks for the reply. I used the sample code from http://digital.ni.com/public.nsf/allkb/94899E7A1D9BA56586256ED700641615.
But I changed it like below to try your suggestions.
I set port 12 to VI_ASRL_WIRE_485_2_DTR_ECHO by using MAX.
I run my sample code and saw that:
wiremode_before = 1 as expected
wiremode_after = 0 as expected. That is what I expected.
The problem is, when I re-run the code, I see that "wiremode_before = 1" and "wiremode_after = 0".
I expect "wiremode_before = 0" because wiremode is already setted to "0" after the first run of the sample code.
So, when i close the session with ViClose, wiremode gets the previous value written in MAX.
Any ideas?
******
#include <visa.h>
static ViSession managerhandle;
static ViStatus status;
static ViInt16 wiremode_before, wiremode_after;
static ViSession ins_handle;
status = viOpenDefaultRM (&managerhandle);
status = viOpen (managerhandle, "ASRL12::INSTR", VI_LOAD_CONFIG, VI_NULL, &ins_handle);
status = viGetAttribute (ins_handle, VI_ATTR_ASRL_WIRE_MODE, &wiremode_before);
status = viSetAttribute (ins_handle, VI_ATTR_ASRL_WIRE_MODE, VI_ASRL_WIRE_485_4);
status = viGetAttribute (ins_handle, VI_ATTR_ASRL_WIRE_MODE, &wiremode_after);
status = viClose(ins_handle);
******
12-20-2011 07:47 AM
Hi,
as I understand your reply, your code is working as expected - fine! But you are wondering why the setting of your program is not permanent - could it be because you are loading the very same configuration at the beginning of your code using VI_LOAD_CONFIG every time? I never used this setting myself so I am only guessing but I would assume that VI_LOAD_CONFIG configures the attributes to values specified by some external configuration utility, in your case MAX... And because the values in MAX are not changed your code reads the same initial data...
12-21-2011 01:06 AM
I want to use Visa Test panel to explain my problem. I write down what i did step by step.
1. Open NI MAX and select one of the serial port (1.jpg)
2. Click on "Open VISA Test Panel" (2.jpg)
3. Select attribute "VI_ATTR_ASRL_WIRE_MODE" and note that current value is 0. (3.jpg)
4. Enter 3 as new value and click on "Execute". Note that the current value is now 3.
5. Close the VISA test panel by using the cross at the top right corner.
6. Open a new VISA test panel and select the attribute "VI_ATTR_ASRL_WIRE_MODE" again. And note that the current value is still 0, not 3. (5.jpg)
So, I expect to see that current value as 3 at the last step. If I do something wrong please let me know. Any help will be appreciated.
Gokhan
12-21-2011 01:07 AM
4.jpg and 5.jpg attached
12-21-2011 01:35 AM
Maybe I still misunderstand your problem - but your figure 5 shows the viSetAttribute panel... I am not sure that a freshly opened panel really displays the current setting... In order to check that your setting '3' is still valid I would suggest calling viGetAttribute... So replace your last step by selecting the viGetAttribute tab, select the attribute name, and push the execute button.
12-21-2011 02:16 AM
Thanks for the reply. But when you open the visa panel and select the attribute, the program reads the current value of that attribute to the field "Current Value".
In order to be sure that the attribute value, I use viGetAttribute as you suggested(6.jpg). And the setting is still 0.