You can use the comedi_dio_bitfield() or comedi_dio_bitfield2()
functions to set the output bits of a DO or DIO subdevice. If it is a
DIO subdevice you need to configure the bits as outputs using the
comedi_dio_config() function.
--
-=( Ian Abbott @ MEV Ltd. E-mail: <abb...@mev.co.uk> )=-
-=( Tel: +44 (0)161 477 1898 FAX: +44 (0)161 718 3587 )=-
To write 4 digital channels simultaneously you have to use the
comedi_dio_bitfield() or comedi_dio_bitfield2() functions. The
comedi_dio_write() function can only write a single channel.
--
-=( Ian Abbott @ MEV Ltd. E-mail: <abb...@mev.co.uk> )=-
It's easier to explain the simpler comedi_dio_bitfield() before
explaining comedi_dio_bitfield2():
int comedi_dio_bitfield(comedi_t * device, unsigned int subdevice,
unsigned int write_mask, unsigned int *bits);
This can optionally write any combination of the first 32 channels of
the digital subdevice and read the channels back. The 'bits' parameter
points to a variable holding the data to be written and will be set to
the data read back. The 'write_mask' variable is a bit vector
indicating which channels are to be written - set bit 0 to 1 to write
channel 0, set bit 1 to 1 to write channel 1, etc.
For example:
unsigned int data;
data = 0x4200;
comedi_dio_bitfield(device, subd, 0xFF00, &data);
will write 0x42 (binary 01000010) to channels 15 to 8 (determined by
write_mask = 0xFF00). So channel 15 gets set to 0, chan 14 = 1, chan 13
= 0, chan 12 = 0, chan 11 = 0, chan 10 = 0, chan 9 = 1, chan 8 = 0.
Then the first 32 channels are read back to '*bits' (data).
The comedi_dio_bitfield2() function is similar except that it starts at
the 'base_channel' instead of channel 0. Bit 0 of the write_mask
corresponds to the 'base_channel' channel, bit 1 of write_mask
corresponds to the 'base_channel+1' channel, etc. Logically, you can
think of it as 'write_mask' and '*bits' being shifted left by
'base_channel' ( << base_channel) before writing, and the data read back
is shifted right by 'base_channel' ( >> base_channel).
comedi_dio_bitfield() is equivalent to comedi_dio_bitfield2() with
base_channel = 0.
In practice, most drivers can't write individual bits to the hardware,
they can only write a byte or 16-or-32-bit word at a time, depending on
the hardware. They work around this limitation by remembering all the
previous data written to the subdevice's channels and combining it
(using the 'write_mask' value) with the new data before writing it to
the physical port addresses.
--
-=( Ian Abbott @ MEV Ltd. E-mail: <abb...@mev.co.uk> )=-
Assuming your digital output subdevice has 8 channels, it should set
channels 3 downto 0 as follows: chan[3]=0, chan[2]=0, chan[1]=0,
chan[0]=1, and leave channels 7 downto 4 set to their original values.
The value read back is binary 11100001, so chan[7]==1, chan[6]==1,
chan[5]==1, chan[4]==0, chan[3]==0, chan[2]==0, chan[1]==0, chan[0]==1.
Note that the channe write_mask only affects the channels that are
written, not the channels that are read back. It will always read back
'min(comedi_get_n_channels(dev,subd)-base_channel,32)' channels.
--
-=( Ian Abbott @ MEV Ltd. E-mail: <abb...@mev.co.uk> )=-
Have you configured the DIO channels as outputs using comedi_dio_config()?
--
-=( Ian Abbott @ MEV Ltd. E-mail: <abb...@mev.co.uk> )=-
Rather than trying to second-guess the problem, it would be easier if
you posted the relevant bits of your code.
--
-=( Ian Abbott @ MEV Ltd. E-mail: <abb...@mev.co.uk> )=-
Can you configure the DIO channels as outputs after opening the device,
but before the bitfield operations?
unsigned int n;
for (n = 0; n < 4; n++) {
ret = comedi_dio_config(device, 2, n, COMEDI_OUTPUT);
if (ret < 0) {
comedi_perror(options.filename);
exit(-1);
}
--
-=( Ian Abbott @ MEV Ltd. E-mail: <abb...@mev.co.uk> )=-