DIO / PFI configuration

121 views
Skip to first unread message

GS

unread,
Jan 22, 2012, 4:47:04 AM1/22/12
to Comedi: Linux Control and Measurement Device Interface
Hi,

I am trying to read and write to PFI channels on NI PCI 6221.

1. Do I need to issue a comedi_dio_config() once for 16 PFI channels
or do I need to do it for all the 16 channels?
2. comedi_dio_config(): I am expecting either -1/+1 as a return value,
but I am getting a 0 both for input and output.
3. Regardless, I am able to read the input values without any issue,
but I cannot output any values.

Any suggestions?

Thanks.



Ian Abbott

unread,
Jan 23, 2012, 6:24:17 AM1/23/12
to comed...@googlegroups.com
On 2012-01-22 09:47, GS wrote:
> Hi,
>
> I am trying to read and write to PFI channels on NI PCI 6221.
>
> 1. Do I need to issue a comedi_dio_config() once for 16 PFI channels
> or do I need to do it for all the 16 channels?

Once per channel. Both comedi_dio_config() and comedi_dio_get_config()
are channel-specific[1]. The directions of the PFI channels are
individually configurable.

[1] However, on hardware where the DIO channel directions are not
individually configurable, but grouped into partitions of several
channels, configuring the direction of one channel will affect all the
channels in the same partition.

> 2. comedi_dio_config(): I am expecting either -1/+1 as a return value,
> but I am getting a 0 both for input and output.

comedi_dio_config() returns 0 if successful, or -1 if an error occurred.

comedi_dio_get_config() returns 0 if successful, or -1 if an error
occurred. If successful, the direction is passed back via the final
pointer parameter.

> 3. Regardless, I am able to read the input values without any issue,
> but I cannot output any values.
>
> Any suggestions?
>
> Thanks.

I'm not sure where the PFI outputs go by default. You may need to
reroute each output channel with comedi_set_routing(), using the
constant NI_PFI_OUTPUT_PFI_DO for the last parameter.

--
-=( Ian Abbott @ MEV Ltd. E-mail: <abb...@mev.co.uk> )=-
-=( Tel: +44 (0)161 477 1898 FAX: +44 (0)161 718 3587 )=-

GS

unread,
Jan 29, 2012, 11:43:50 PM1/29/12
to comed...@googlegroups.com
Ian: Thanks for the response.
Regarding my Q#2, the source of my confusion is this : http://www.comedi.org/doc/r5849.html

Also regarding my Q#3: I couldn't find comedi_set_routing() in the documentation.

Is there a newer version of this documentation?

Thanks.


--
You received this message because you are subscribed to the Google Groups "Comedi: Linux Control and Measurement Device Interface" group.
To post to this group, send email to comed...@googlegroups.com.
To unsubscribe from this group, send email to comedi_list+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/comedi_list?hl=en.


GS

unread,
Feb 1, 2012, 5:34:29 PM2/1/12
to comed...@googlegroups.com
Hi,

Hi, I am  trying to do DIO read and write and I am trying to read all the 48 channels of NI PCI 6221.

Please correct me if I am wrong on this:

For read, below are the steps:
comedi_dio_config(device, subDevice[i], channel[i], COMEDI_INPUT);
comedi_dio_read(device, subDevice[i], channel[i], &data);

For write, below are the steps:
comedi_dio_config(device, subDevice[i], channel[i], COMEDI_OUTPUT);
if(subDevice[ii] ==7} {  comedi_set_routing( device, subDevice[i], channel[i], NI_PFI_OUTPUT_PFI_DO);  }
comedi_dio_write(device, subDevice[i], channel[i], bit);


Any suggestions?

Thanks.

Sebas Inc

unread,
Feb 1, 2012, 6:08:22 PM2/1/12
to Comedi: Linux Control and Measurement Device Interface
Hi,
i have the same problem. I only can write the subdevice 2 of my NI_DAQ
6220.

Exist the comedi_set_routing function? my comedi version isn't CVS.

Thanks

Ian Abbott

unread,
Feb 2, 2012, 4:52:18 AM2/2/12
to comed...@googlegroups.com

You could copy the comedi_set_routing function from git and rename it
for your program. It's just a wrapper function around comedi_do_insn.

int my_comedi_set_routing(comedi_t *device, unsigned subdevice,
unsigned channel, unsigned routing)
{
comedi_insn insn;
lsampl_t data[2];

memset(&insn, 0, sizeof(comedi_insn));
insn.insn = INSN_CONFIG;
insn.subdev = subdevice;
insn.chanspec = channel;
insn.data = data;
insn.n = sizeof(data) / sizeof(data[0]);
data[0] = INSN_CONFIG_SET_ROUTING;
data[1] = routing;

if(comedi_do_insn(device, &insn) >= 0) return 0;
else return -1;

Sebas Inc

unread,
Feb 2, 2012, 4:13:23 PM2/2/12
to Comedi: Linux Control and Measurement Device Interface
Thanks Ian. Now works correctly.

and should be added #include <cstring> if works with C++ or #include
<string,h> in C.
> -=( Ian Abbott @ MEV Ltd.    E-mail: <abbo...@mev.co.uk>             )=-

Ian Abbott

unread,
Feb 3, 2012, 6:07:06 AM2/3/12
to GS, Comedi: Linux Control and Measurement Device Interface
[Cc'ing the list for general interest.]

Hi GS,

Configuring the PFI subdevice (subdevice 7) channels as inputs or
outputs sets the direction of the physical PFI pins to input or output,
but as the PFI signals can be routed to different functions inside the
card, a PFI pin might not be routed to the "static DO" function.

If you look at Figure 8-1 in the "DAQ M Series User Manual"
<http://www.ni.com/pdf/manuals/371022k.pdf> then for subdevice 7:

* comedi_dio_config() controls the "Direction Control" signals.
* comedi_set_routing() controls the input/output source selectors (the
unlabelled trapezoid-shaped blocks on the diagram).
* comedi_set_filter() controls the "PFI Filters" block.
* comedi_dio_bitfield()/comedi_dio_bitfield2() may modify the "Static DO
Buffer" bits and reads back the "Static DI" signals.
* comedi_dio_read() reads a "Static DI" signal.
* comedi_dio_write() modifies a "Static DO Buffer" bit.

Note that a "Static DO Buffer" bit (channel) does not appear on the
corresponding PFI pin (channel) unless that PFI pin (channel) is
configured as an output (COMEDI_OUTPUT) and is routed to the "Static DO
Buffer" (NI_PFI_OUTPUT_PFI_DO).

Best regards,
Ian.

On 2012-02-03 00:46, GS wrote:
> Ian,
>
> Thanks. I am able to do DIO, however, I am getting it to work without
> comedi_set_routing.
>
> I am trying to understand this. Why does one need to use the
> "comedi_set_routing" function. What is it doing exactly? Won't
> comedi_dio_config() suffice?
>
> Thanks.


>
> On Feb 2, 4:52 am, Ian Abbott<abbo...@mev.co.uk> wrote:
>> On 2012/02/01 11:08 PM, Sebas Inc wrote:
>>
>>> Hi,
>>> i have the same problem. I only can write the subdevice 2 of my NI_DAQ
>>> 6220.
>>
>>> Exist the comedi_set_routing function? my comedi version isn't CVS.
>>
>> You could copy the comedi_set_routing function from git and rename it
>> for your program. It's just a wrapper function around comedi_do_insn.
>>
>> int my_comedi_set_routing(comedi_t *device, unsigned subdevice,
>> unsigned channel, unsigned routing)
>> {
>> comedi_insn insn;
>> lsampl_t data[2];
>>
>> memset(&insn, 0, sizeof(comedi_insn));
>> insn.insn = INSN_CONFIG;
>> insn.subdev = subdevice;
>> insn.chanspec = channel;
>> insn.data = data;
>> insn.n = sizeof(data) / sizeof(data[0]);
>> data[0] = INSN_CONFIG_SET_ROUTING;
>> data[1] = routing;
>>

>> if(comedi_do_insn(device,&insn)>= 0) return 0;
>> else return -1;
>>
>> }
>>
>> --
>> -=( Ian Abbott @ MEV Ltd. E-mail:<abbo...@mev.co.uk> )=-

Reply all
Reply to author
Forward
0 new messages