- From: Ian Abbott <abbotti_at_mev.co.uk>
- Date: Fri, 18 Feb 2005 14:10:34 +0000
On 18/02/05 12:55, Carl Ljungmark wrote:
> Hello!
> I'm writing a program to control a few digital pins on a IO-card using
> comedi.
> To configure the pins (set them to output, and put them low), I do this:
>
> for (ch=0; ch<24; ch++){
> printf("ch%d: (%s, %s).\t", ch+1, comedi_dio_config(device, 0,
> ch, COMEDI_OUTPUT)==1? "output": "error", comedi_dio_write(device, 0,
> ch, 0)==1? "low" : "error");
>
> To check if this works, I put them high instead - but nothing happened
> on the pins. Is this an invalid use of the comedi functions?
No, but the order in which the arguments of a function call are
evaluated is undefined in C. You want to make sure that
comedi_dio_config is called before comedi_dio_write. This should work:
for (ch=0; ch<24; ch++){
int ret_config=comedi_dio_config(device, 0, ch, COMEDI_OUTPUT);
printf("ch%d: (%s, %s).\t", ch+1, ret_config==1? "output":
"error", comedi_dio_write(device, 0, ch, 0)==1? "low" : "error");
--
-=( Ian Abbott _at_ MEV Ltd. E-mail: <abbotti_at_mev.co.uk> )=-
-=( Tel: +44 (0)161 477 1898 FAX: +44 (0)161 718 3587 )=-
Received on 2005-02-18Z14:10:34