Hauptmenü

Devio.pm

Begonnen von andrejs, 13 September 2014, 11:43:09

Vorheriges Thema - Nächstes Thema

andrejs

I used in FHEM script DevIo module to connect RFID reader to USB port on FHEM server. The RFID reader was connected without any errors. The problems started when I read the RFID card/key over the reader because time to time a very strange output came out. I found out where is the problem:
In DevIo script sub DevIo_DoSimpleRead is the following code:
my ($hash) = @_;
  my ($buf, $res);

  if($hash->{USBDev}) {
    $buf = $hash->{USBDev}->input();

  } elsif($hash->{DIODev}) {
    $res = sysread($hash->{DIODev}, $buf, 256);
    $buf = undef if(!defined($res));

  } elsif($hash->{TCPDev}) {
    $res = sysread($hash->{TCPDev}, $buf, 256);
    $buf = "" if(!defined($res));

  }
  return $buf;

If I change   "$buf = $hash->{USBDev}->input();" to   "$buf = $hash->{USBDev}->read(1);" all errors disappeared. My question is it is possible somehow to change DevIo script to have also possibility to use instead of input() read(1)?

Andrej




     

rudolfkoenig

Most certainly not, as this routine is used by a lot of modules, and I cannot tell the side effects.
Additionally it would be a lot less efficient, as your proposal only reads one byte at a time.

Can you check, if your problem is caused by the fact, that you are trying to read more than one byte?
Since the routine is neither very long, nor very sophisticated, it may be a workaround just to copy and modify it.

andrejs

Rudolf I agree it is easier just to copy the code of SimpleRead in my script.

Thanks

Andrej