1

I have a python program that sends text message using a USB modem, it works fine.. But sometimes when I reboot my device the program cant find the device, so I need unplug than plug back again to work... is there someway for me to locate the usb inside the code without unpluging the device?

At this point:

dongle = serial.Serial(port="/dev/serial/by-id/usb-HUAWEI_HUAWEI_Mobile-if02-port0",baudrate=9600,timeout=0,rtscts=0,xonxoff=0)

I get this error:

Traceback (most recent call last):
  File "lsms.py", line 5, in <module>
    dongle = serial.Serial(port="/dev/serial/by-id/usb-HUAWEI_HUAWEI_Mobile-if02-port0",baudrate=9600,timeout=0,rtscts=0,xonxoff=0)
  File "/usr/lib/python2.7/dist-packages/serial/serialutil.py", line 260, in __init__
    self.open()
  File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 276, in open
    raise SerialException("could not open port %s: %s" % (self._port, msg))
serial.serialutil.SerialException: could not open port /dev/serial/by-id/usb-HUAWEI_HUAWEI_Mobile-if02-port0: [Errno 2] No such file or directory: '/dev/serial/by-id/usb-HUAWEI_HUAWEI_Mobile-if02-port0'
  • Hello and welcome to RPI.SE. Just for clarification by "reboot my device the program cant find the device" you mean reboot the RPi and cannot find the USB device? I am using a USB-serial converter on the Pi and it failed just once to be recognized by the usb core (never found the cause). Could you check your logs during boot-up (journalctl if on Arch) for anything suspicious with respect to "usb" and "usbcore"? On a side note, now that the error is known it would be could practise to catch the exception in your script (although it wouldn't resolve the error). – Ghanima Oct 1 '14 at 14:31
  • Hi, thanks for your answer.. My USB modem works fine, but everytime I reboot the RPi it doesn't work anymore, I have to unplug than plug back again to work... – Yoannes Geissler Oct 1 '14 at 15:37
  • So I'd like to recommend to check the syslog from start up and then again after re-plugging the modem. Does the modem have any indicators whether it is powered or not (like a LED or what)? There is the remote possibility that the power supply of the Pi is insufficient. Could this be ruled out? – Ghanima Oct 1 '14 at 15:53
  • It has a LED and it blinks normal.. when I plug in I can keep using for days, but reboot and no more, need to unplug – Yoannes Geissler Oct 1 '14 at 16:43
  • Any news on the logfiles? What is your operation system anyways? – Ghanima Oct 1 '14 at 18:35
1

Check the output of dmesg and lsusb after booting the RPi (with the USB modem not being recognized) as well es after un-/replugging the modem.

Also check out the following Q&A's on the reset and forced re-enumeration of USB devices https://superuser.com/questions/141908/how-do-i-reset-an-usb-device-without-unplugging-it-in-linux and https://askubuntu.com/questions/645/how-do-you-reset-a-usb-device-from-the-command-line

1

here is my solution:

First install usb-modeswitch

sudo apt-get install usb-modeswitch

Connect the 3g dongle to usb port then give the command lsusb in terminal, it will give something like

Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 002: ID 046d:c05a Logitech, Inc. 
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 005: ID 12d1:1506 Huawei Technologies Co., Ltd. 
Bus 001 Device 003: ID 0bda:0111 Realtek Semiconductor Corp. Card Reader
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

here we can see 12d1 as vendor id and 1506 as device id

After that you need to add a configuration to /etc/usb_modeswitch.conf:

Type sudo nano /etc/usb_modeswitch.conf

DefaultVendor = 0x12d1
DefaultProduct = 0x1506
MessageEndPoint = "0x01"
MessageContent = "55534243000000000000000000000011060000000000000000000000000000"

and save. Create a custom udev rule to override the devices initial attempts to be removable storage.

sudo nano /etc/udev/rules.d/10-Huawei-Datacard.rules

Paste the following:

SUBSYSTEM=="usb", SYSFS{idProduct}=="1506", SYSFS{idVendor}=="12d1",
RUN+="/usr/sbin/usb_modeswitch --vendor 0x12d1 --product 0x1506 --type option-zerocd"

save and reboot

It worked for me, hope it can help.. I use a Huawei E303C usb 3G modem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.