- From: Ivan Raikov <raikov_at_cc.gatech.edu>
- Date: 22 Nov 2002 20:02:01 -0500
The following code works with Linux 2.4.19, NI 6052 board, and
RT-Linux 3.1 patched with the "unofficial" 2.4.19 patch. I'm probably
going to test it with RTL 3.2 sometime this weekend.
I haven't provided the board initialization code here, since
it's a little more hairy, but I can send you that too, if you like.
/*
Performs a read from an analog channel of the data acquisition
board. The value returned is the return status of the Comedi read
instruction (0 for success).
Arguments have the following meaning:
comedi_t *handle -- the device handle, as returned by comedi_open
int ai_subdev -- the index of a subdevice capable of reading
data; this index can be obtained through
comedi_find_subdevice_by_type
int channel -- channel that we are interested of acquiring
through (number of channels is obtainable
through comedi_get_n_channels)
*/
inline int do_in_insn (comedi_t *handle, int ai_subdev, int channel)
{
comedi_insn insn;
memset(&insn, 0, sizeof(insn));
insn.insn = INSN_READ;
// we want to obtain one sample
insn.n = 1;
// sets a pointer to the buffer where we'll be storing the
// acquired samples
insn.data = (lsampl_t *)data_in;
// set the subdevice to read from
insn.subdev = ai_subdev;
// sets the channels, the range, and the analog reference
insn.chanspec = CR_PACK(channel, comedi_ai_range, AREF_GROUND);
// performs the instruction
return comedi_do_insn (handle, &insn);
}
/*
Performs a write to an analog channel of the data acquisition
board. The value returned is the return status of the Comedi write
instruction (0 for success).
Arguments have the following meaning:
comedi_t *handle -- the device handle, as returned by comedi_open
int ao_subdev -- the index of a subdevice capable of writing
data; this index can be obtained through
comedi_find_subdevice_by_type
int channel -- channel that we are interested of writing to
(number of channels is obtainable through
comedi_get_n_channels)
*/
inline int do_out_insn (comedi_t *handle, int ao_subdev, int channel)
{
comedi_insn insn;
memset(&insn, 0, sizeof(insn));
insn.insn = INSN_WRITE;
// we want to write one sample
insn.n = 1;
// sets a pointer to the buffer containing the data to be written
insn.data = (lsampl_t *)data_out;
// sets the subdevice to write to
insn.subdev = ao_subdev;
// sets the channels, the range, the analog reference
insn.chanspec = CR_PACK(channel, comedi_ao_range, AREF_GROUND);
// performs the instruction
return comedi_do_insn (handle, &insn);
}
"Evan Carey" <ecarey_at_zyvex.com> writes:
> Does anyone have an example of using the comedi_command and
> comedi_command_test from a RTLinux real-time thread that they would mind
> sharing? I'm having no luck with it. When I attempt
> comedi_command_test from a rt thread my machine just locks up. Is this
> possible? A bad idea? Or what?
>
> I thought I saw someone ask this once before in this group but I never
> saw a reply to it.
>
> Thanks,
> Evan
>
--
Ivan Raikov
337466 Georgia Tech Station, Atlanta, GA 30332-1750
Received on 2002-11-23Z01:02:01