Yoannes
Posts: 1
Joined: Wed Oct 01, 2014 1:04 pm

USB Modem

Wed Oct 01, 2014 1:10 pm

Hi,
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 fine the device, so I need unplug than plug back again to work... is there someway to locate the usb inside the code?

At this point:

Code: Select all

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:

Code: Select all

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'

Thanks

sdjf
Posts: 1395
Joined: Fri Mar 16, 2012 5:20 am
Location: California
Contact: Website

Re: USB Modem

Wed Oct 01, 2014 8:49 pm

I don't know python, but do think what you need to do is build in a test for whether the normal device exists and, if it does not, then see what the device name is that has been assigned to your modem. I use a USB modem, but I don't recall it ever being assigned a different /dev address.

You probably should build in to your script some debugging output so you can see what is going on, and once it is working properly, you can comment out those debugging statements.

I would log the date and time for each time the script is run, and include the output of an ls command, something like the following:

ls /dev/serial/by-id/usb*

The output of that command in a log could help you debug better, and give you clues how to make python find the actual device address.

You could have python examine the output of dmesg, looking for the device address, and might want to consider putting some of the output of dmesg into your log. For sure, after a failed attempt, I would at least examine the output of the dmesg command carefully, to see if you can figure out what lines tell you the address for the device.

Chances are that the 0 at the end of the device address has become a 1 or 2, but without some debugging output, or examining dmesg while debugging this, you cannot be sure.
FORUM TIP: To view someone's posting history, sign in, click on their user name, then on "Search User's Posts." || Running ArchLinuxArm on Model 2B and 512MB Model B

Return to “Beginners”