Open Snowlav opened 8 years ago
Which pyserial
have you installed?
Have you installed it with python3 setup.py install
?
New pyserial
lets you detect easily with list_ports.comports()
.
On OS X, I can detect multiple plugged in dongles like this (it might work on pi changing the pre
):
from serial import SerialException
from serial.tools import list_ports
from humod.siminfo import seq, show_imsi
from sms.models import Sim, gateway_sim
import humod
pre = '/dev/cu.HUAWEIMobile-'
# m = humod.Modem(pre+'Modem', pre+'Pcui')
# print(m.show_model())
def get_modems():
"""Return a list of modems plugged into the computer.
Switched to text mode."""
ports = list_ports.comports()
ports = [s.device for s in ports if s.device.startswith(pre)]
no1 = True if 'Modem' in ''.join(ports) else False
ports = [int(p.replace(pre, '')) for p in ports if p[-1].isdigit()]
ports = [(y, z) for x,y,z in seq(ports, 3)]
if no1: ports.append(('Modem', 'Pcui'))
modems, info = {}, []
for i, pair in enumerate(ports):
try:
modems[i] = humod.Modem(
pre+str(pair[0]),
pre+str(pair[1])
)
modems[i].enable_textmode(True)
except OSError as e:
info.append(('Power off.', str(e), i+1))
except SerialException as e:
info.append(('Not connected.', str(e), i+1))
except humod.errors.AtCommandError as e:
info.append(('', str(e), i+1))
del modems[i]
return modems, info
Hey thanks for the answer, I am on python 2.7 and I should be on the latest pyserial. My problem is not that I don't know what model / port I have, the problem is humod hangs on every function.
The return of show_model() was just an example of the issue.
However when I magically screwed up my paths and had every path scoop up by one (/dev/ttyUSB0 became /dev/ttyUSB1) and setting the Modem() manually to Modem('/dev/ttyUSB1') made humod function again. However after rebooting, my paths are back to normal again (/dev/ttyUSB1 is now /dev/ttyUSB0 again) and now humod seized to function just like before.
Install python 3.5 and pyserial 3.0 or later and let us know if issues persist. It is likely to be pyserial
related and not pyhumod
issue.
I cannot port my software over to 3.5, I tried the latest pyserial but unfortunately got the same result.
Actually I remember having similar issues. I usually unplugged the dongles, plugged them back in and waited a short time. Mounting and unmounting should do the same trick via terminal/python.
not working for me unfortunately, have also formatted and re-installed everything about 5 times now
The above tip works on OS X. I don't have a Raspberry Pi to test on. Also format/re-install will just prevent you from understanding the problem and would only help if your default state was working.
When I get my dongle connected through pyserial, how do I make an internet connection through it ?
On Thu, Mar 24, 2016 at 3:35 PM, F. Malina notifications@github.com wrote:
The above tip works on OS X. I don't have a Raspberry Pi to test on. Also format/re-install will just prevent you from understanding the problem and would only help if your default state was working.
— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/oozie/pyhumod/issues/15#issuecomment-200864977
Hey everyone,
So finally got that dongle in the mail and delivered. However whenever I try to print the model it just hangs, for ever untill I ctrl-z / keyboard interrupt.
However, I was toying with pyserial after, and I did something to trigger a change in the path of the dongle. /dev/ttyUSB0 - 3 now became /dev/ttyUSB1 - 4 .
With this weird change in mind, I went back to try humod, this time it gave me an error and told me it couldn't find /dev/ttyUSB0 . (not strange since the paths scooped up a position) So I ran the same script, only this time with: m = humod.Modem('/dev/ttyUSB1') and strangely enough the script printed the model number instantly.
However, after rebooting my pi, all paths are back to normal, and the issue is back.
Can someone shine some light on this? Thanks!