lib: don't change read or write subdevice unnecessarily
Change comedi_set_read_subdevice() and comedi_set_write_subdevice() to do nothing if the requested subdevice is already set as the current read or write subdevice, respectively. The functions now return success even if the Comedi drivers do not support changes to the read or write subdevice as long as the specified subdevice is the default one.
This commit is contained in:
parent
aff4937e03
commit
8c31fb88c1
2 changed files with 21 additions and 4 deletions
|
@ -403,8 +403,12 @@ Param: unsigned int subdevice
|
|||
Status: Works for Linux "in-tree" Comedi since kernel version 3.19.
|
||||
Description:
|
||||
The function <function>comedi_set_read_subdevice</function> sets
|
||||
<parameter class="function">subdevice</parameter> as the current streaming
|
||||
input subdevice if the subdevice supports streaming input commands.
|
||||
<parameter class="function">subdevice</parameter> as the current
|
||||
<quote>read</quote> subdevice if the subdevice supports streaming
|
||||
input commands.
|
||||
|
||||
No action is performed if <parameter class="function">subdevice</parameter>
|
||||
is already the current <quote>read</quote> subdevice.
|
||||
|
||||
Changes are local to the <emphasis>open file description</emphasis> for this
|
||||
<parameter class="function">device</parameter> and have no effect on other
|
||||
|
@ -420,8 +424,12 @@ Param: unsigned int subdevice
|
|||
Status: Works for Linux "in-tree" Comedi since kernel version 3.19.
|
||||
Description:
|
||||
The function <function>comedi_set_write_subdevice</function> sets
|
||||
<parameter class="function">subdevice</parameter> as the current streaming
|
||||
output subdevice if the subdevice supports streaming output commands.
|
||||
<parameter class="function">subdevice</parameter> as the current
|
||||
<quote>write</quote> subdevice if the subdevice supports streaming
|
||||
output commands.
|
||||
|
||||
No action is performed if <parameter class="function">subdevice</parameter>
|
||||
is already the current <quote>write</quote> subdevice.
|
||||
|
||||
Changes are local to the <emphasis>open file description</emphasis> for this
|
||||
<parameter class="function">device</parameter> and have no effect on other
|
||||
|
|
|
@ -237,6 +237,11 @@ int _comedi_set_read_subdevice(comedi_t *it,unsigned int subdevice)
|
|||
int ret;
|
||||
|
||||
if(!valid_dev(it)) return -1;
|
||||
if(it->devinfo.read_subdevice >= 0 &&
|
||||
it->devinfo.read_subdevice == subdevice){
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = comedi_ioctl(it->fd, COMEDI_SETRSUBD, (void*)(unsigned long)subdevice);
|
||||
if(ret == 0){
|
||||
it->devinfo.read_subdevice = subdevice;
|
||||
|
@ -250,6 +255,10 @@ int _comedi_set_write_subdevice(comedi_t *it,unsigned int subdevice)
|
|||
int ret;
|
||||
|
||||
if(!valid_dev(it)) return -1;
|
||||
if(it->devinfo.write_subdevice >= 0 &&
|
||||
it->devinfo.write_subdevice == subdevice){
|
||||
return 0;
|
||||
}
|
||||
ret = comedi_ioctl(it->fd, COMEDI_SETWSUBD, (void*)(unsigned long)subdevice);
|
||||
if(ret == 0){
|
||||
it->devinfo.write_subdevice = subdevice;
|
||||
|
|
Loading…
Add table
Reference in a new issue