irserver patch

All LINUX related questions (Installation & usage)

Moderator: marcus

irserver patch

Postby johnadoe » Sun 13. Sep 2009, 17:55

Hi.

I had some problems with irtrans and other usb-serial devices (mainly 3g usb modem). Since the 3g modem isn't always attached i had problems to get right devicename on my startup scripts. Sometimes irtrans was /dev/ttyUSB0 and sometimes it was /dev/ttyUSB1.

I deceided to fix that problem with simple udev rules. I made a rule which made a symlink /dev/irtrans0 to point to right ttyUSB device. However i noticed that irserver wasn't working with /dev/irtrans0, so i took a peek at irserver souces and made a small patch.

The quick and dirty patch:
Code: Select all
diff -w -r -x '*.o' -x irserver -u irserver-vanilla/lowlevel.c irserver20090912/lowlevel.c
--- irserver-vanilla/lowlevel.c 2009-07-24 18:13:19.000000000 +0300
+++ irserver20090912/lowlevel.c 2009-09-12 20:48:57.000000000 +0300
@@ -2549,10 +2549,17 @@
 #endif
 #ifdef LINUX
                //LINUX Autofind USB devices
-               if ((!strncmp (st + q,"usb",3) || !strncmp (st + q,"USB",3)) && !autoflag) {
+               if( !strncmp( st, "/dev/irtrans", 12 ) && !autoflag ) {
+                  autoflag = 1;
+                  res = 0;
+                  get_detail_deviceinfo ("",st,IF_USB);
+               }
+      else if ((!strncmp (st + q,"usb",3) || !strncmp (st + q,"USB",3)) && !autoflag) {
                        autoflag = 1;
                        res = 0;
                        for (i=0;i < 16;i++) {
+                          sprintf (dst,"/dev/irtrans%d",i);
+                          if (get_detail_deviceinfo ("",dst,IF_USB)) {
                                sprintf (dst,"/dev/ttyUSB%d",i);
                                if (get_detail_deviceinfo ("",dst,IF_USB)) {
                                        sprintf (dst,"/dev/usb/ttyUSB%d",i);
@@ -2566,6 +2573,7 @@
                                }
                        }
                }
+               }
                else if ((!strncmp (st + q,"/dev/usb/tty",12) || !strncmp (st + q,"/dev/ttyUSB",11) || !strncmp (st + q,"/dev/usb/tts",12) ||
                                  !strncmp (st + q,"/dev/ttyusb",11) || !strncmp (st + q,"/dev/tts/USB",12)) && !autoflag) {
                        if (st[q + strlen (st+q) - 1] == ']') {



It would be nice to get similar feature to upstream code, since i'm 101% sure i will forget to patch irserver if i never update it :) And i think I'm not the only one who likes to give more descriptive devicenames for usb devices, so that might help others too.

Regards
John
johnadoe
 
Posts: 4
Joined: Sun 13. Sep 2009, 17:40

Re: irserver patch

Postby IRTrans » Sun 13. Sep 2009, 21:30

Hi,
thank you for the patch.

We already thought if it might be possible for the irserver to discover the correct USB devices (with a connected IRTrans device).

Is there any way to open USB devices with the device ID ?

IRTrans
IRTrans
Administrator
 
Posts: 2115
Joined: Mon 21. Apr 2008, 23:32

Re: irserver patch

Postby johnadoe » Wed 16. Sep 2009, 09:33

Hi,

Sure, with libusb it's possible to connect to usb device using device id. But there is one mandatory problem: As far as ai know there isn't any way to find out device node from libusb. That means complete rewrite of irserver's usb communication using libusb and not std serial communication like it does currently.

Another way to do intelligent usb connection is the use of libsysfs. With libsysfs it's possible to enumerate all connected irtrans devices without trying to open every possible ttyUSBn devices. It's also possible to find right irtrans device based on serial number if system has multiple usb irtrans devices connected. With libsysfs approach there isn't any restrictions with actual device node names, so renaming /dev/ttyUSBn to another name does'nt affect autodetection at all.

Of course also this approach has one drawback. kernels older than 2.5 doesn't have sysfs at all.

Regards,
John
johnadoe
 
Posts: 4
Joined: Sun 13. Sep 2009, 17:40

Re: irserver patch

Postby IRTrans » Wed 16. Sep 2009, 21:35

Hi John,
thank you for the info.

Currently we are very busy developing some other things but I think we should change that sooner or later.

Another way would be to use the FTDI USB Library - it is available for LINUX in the meantime, too. We are already using that API on the Windows platform.

We will see ...

IRTrans
IRTrans
Administrator
 
Posts: 2115
Joined: Mon 21. Apr 2008, 23:32

Re: irserver patch

Postby johnadoe » Thu 17. Sep 2009, 08:43

Hi,

FTDI USB Linux Library also has one drawback. It can't coexist with ftdi_sio kernel module. Since modern linux distributions have that compiled either in kernel or as module you must change irtrans vendor and/or product id to prevent ftdi_sio module to detect irtrans device.

Of course unloading ftdi_sio is also possible but that will break other devices using ftdio_sio. Since irtrans is popular in htpc computers, there is high possiblity to have a smartcard reader using ftdi_sio at the same computer.

So if you want irserver to work out of the box without hassling with kernel modules, current implementation of serial communication using virtual serial port is best option.

Regards
John
johnadoe
 
Posts: 4
Joined: Sun 13. Sep 2009, 17:40

Re: irserver patch

Postby OpenELEC.tv » Sun 25. Apr 2010, 18:13

Hi all

johnadoe wrote:I had some problems with irtrans and other usb-serial devices (mainly 3g usb modem). Since the 3g modem isn't always attached i had problems to get right devicename on my startup scripts. Sometimes irtrans was /dev/ttyUSB0 and sometimes it was /dev/ttyUSB1.


i have the same problem here, because there is an smartcard reader connected for an dvb card. i never know exactly if the device becomes /dev/ttyUSB0 or /dev/ttyUSB1. so i am looking at a simple and safe way for my init scripts to get the right devicenode. how is it possible?

johnadoe wrote:I deceided to fix that problem with simple udev rules. I made a rule which made a symlink /dev/irtrans0 to point to right ttyUSB device. However i noticed that irserver wasn't working with /dev/irtrans0, so i took a peek at irserver souces and made a small patch.


can i become your udev rules? how udev knows there is an lcd/ir device behind the usb/serial chip?

i like the solution with /dev/irtrans0, but then i need also an solution for the card reader.... or is there an way to start irserver without /dev/ttyUSB* and let detect irserver the right device?

greetings

Stephan
✩✩✩✩✩ http://www.OpenELEC.tv ✩✩✩✩✩
✩✩✩✩✩ try now the fast booting and smallest (50-70MB) embedded XBMC distribution with PVR function ✩✩✩✩✩
OpenELEC.tv
 
Posts: 4
Joined: Sun 25. Apr 2010, 17:47

Re: irserver patch

Postby johnadoe » Sun 17. Oct 2010, 16:12

Hi Sephan,
Probably you have already solved your problem, but incase someone else is struggling with udev rules here is my current rule:

in file /etc/udev/rules.d/z21_persistent-local.rules:
Code: Select all
KERNEL=="ttyUSB*", ATTRS{interface}=="IRTrans USB", NAME="irtrans0"
KERNEL=="ttyUSB*", ATTRS{product}=="USB Phoenix/Smartmouse", ATTRS{serial}=="XXXXXXXX", SYMLINK+="cardreader0"


Regards,
John
johnadoe
 
Posts: 4
Joined: Sun 13. Sep 2009, 17:40


Return to LINUX

Who is online

Users browsing this forum: No registered users and 10 guests

cron