尝试使用华为 E3531 的 AT 命令
Trying to use the AT command with an Huawei E3531
我想看看我的华为E3531的RSSI。所以我找到了一些文档,这些文档显示了使用 AT 命令获取这些信息的简单方法。问题是我什至无法连接到我的华为 E3531。我的意思是,它作为调制解调器真的很好用。我有很好的联系。但是当我在dev中寻找设备时,我只找到2个设备("sdb"和"sgm"),它们似乎是2个光盘,但与串口无关。
所以我尝试了一些我发现的东西:
- 插入华为后,我发现 Idvendor 和 Idproduct 正在执行 lsusb。
-他们我做了一个 sudo modprobe usbserial vendor=0X"Idvendor" product=0X"Idproduct"
- 然后当我执行 dmesg 时,我可以阅读:
[ 1038.498282] usbcore: registered new interface driver usbserial
[ 1038.498299] usbcore: registered new interface driver usbserial_generic
[ 1038.498312] usbserial: USB Serial support registered for generic
通常我应该有这样的东西:
usb 1-1: generic converter now attached to ttyUSB0
我想我不得不说,甚至不可能从我的 mac 中看到 sdb 和 sgm,所以我在我的 Ubuntu 中这样做。如果我启用 wifi,调制解调器无法连接(所以我看不到 sdb 和 sgm)
如果有人需要,这里是 dmesg 的第一部分:
[ 742.756888] usb 3-1: USB disconnect, device number 6
[ 743.123706] usb 3-1: new high-speed USB device number 7 using xhci_hcd
[ 743.252854] usb 3-1: New USB device found, idVendor=12d1, idProduct=14dc
[ 743.252861] usb 3-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 743.252865] usb 3-1: Product: HUAWEI Mobile
[ 743.252868] usb 3-1: Manufacturer: HUAWEI
[ 743.482312] cdc_ether 3-1:1.0 usb0: register 'cdc_ether' at usb-0000:00:14.0-1, CDC Ethernet Device, 9a:c2:9b:ee:4c:d9
[ 743.482859] usb-storage 3-1:1.2: USB Mass Storage device detected
[ 743.483249] scsi11 : usb-storage 3-1:1.2
[ 743.520839] audit: type=1400 audit(1427889713.269:79): apparmor="DENIED" operation="file_inherit" profile="/usr/lib/NetworkManager/nm-dhcp-client.action" pid=3414 comm="nm-dhcp-client." lport=29180 family="inet" sock_type="dgram" protocol=17
[ 743.520857] audit: type=1400 audit(1427889713.269:80): apparmor="DENIED" operation="file_inherit" profile="/usr/lib/NetworkManager/nm-dhcp-client.action" pid=3414 comm="nm-dhcp-client." lport=47709 family="inet6" sock_type="dgram" protocol=17
[ 744.481267] scsi 11:0:0:0: Direct-Access HUAWEI TF CARD Storage 2.31 PQ: 0 ANSI: 2
[ 744.481722] sd 11:0:0:0: Attached scsi generic sg2 type 0
[ 744.482933] sd 11:0:0:0: [sdb] Attached SCSI removable disk
[ 753.752310] audit: type=1400 audit(1427889723.496:81): apparmor="DENIED" operation="file_inherit" profile="/usr/lib/NetworkManager/nm-dhcp-client.action" pid=3423 comm="nm-dhcp-client." lport=29180 family="inet" sock_type="dgram" protocol=17
[ 753.752328] audit: type=1400 audit(1427889723.496:82): apparmor="DENIED" operation="file_inherit" profile="/usr/lib/NetworkManager/nm-dhcp-client.action" pid=3423 comm="nm-dhcp-client." lport=47709 family="inet6" sock_type="dgram" protocol=17
[ 1038.498282] usbcore: registered new interface driver usbserial
[ 1038.498299] usbcore: registered new interface driver usbserial_generic
[ 1038.498312] usbserial: USB Serial support registered for generic
再次感谢你,如果你能给我一个小小的想法,我会采纳!
待会儿见
编辑 2015 年 9 月 4 日
所以我发现了一些东西。执行 lsusb 你会看到你的设备为:
Bus 003 Device 020: ID 12d1:1f01 Huawei Technologies Co., Ltd.
1f01 是 Idproduct,但它有时会发生变化,因为调制解调器会自行进入不同的模式。如果是1F01,则:
sudo usb_modeswitch -v 12d1 -p 1F01 -M '55534243123456780000000000000011062000000100000000000000000000'
这将强制您的设备更改模式。现在您的设备将有一个等于 1001 的 Idproduct。执行 lsusb 以查看它:
Bus 003 Device 023: ID 12d1:1001 Huawei Technologies Co., Ltd.
E169/E620/E800 HSDPA Modem
并且您有 4 个新的 USB 设备:USB0、USB1、USB2 和 USB3。
现在我要试试minicom发送AT指令
所以基本上,我的问题是我无法将我的调制解调器视为串行。我解释了如何做到这一点,你必须用这个命令强制你的调制解调器:
sudo usb_modeswitch -v 12d1 -p 1F01 -M
'55534243123456780000000000000011062000000100000000000000000000'
然后我尝试了 Minicom,这真的很不错,您只需使用正确的参数(如波特率和端口)连接好即可。所以寻找它并做一些测试。要查看您在 minicom 中写的内容,只需启用本地回显(ctrl+a 然后 z 到该选项)。
所以你可以发送所有你想要的信息。
但我想将它集成到 python 脚本中,所以这是我的代码:
def terminalComAndRead(a,b) :
found = False
proc = subprocess.Popen([a], stdout=subprocess.PIPE, shell=True)#send the command
(out, err) = proc.communicate()
string=str(out)
#print(string)
foundstring=string.find(b, 0, len(string))#look for the string b in the serial answer of my device
if foundstring != -1 :
found= True #send back true if it found it
return found
def send(data,ser):
try:
ser.write(data)#write the command my serail port
except Exception as e:
print "Couldn't send data to serial port: %s" % str(e)
else:
try:
sleep(1)
data = ser.read(1)#read the serial
except Exception as e:
print "Couldn't read data from serial port: %s" % str(e)
else:
if data: # If data = None, timeout occurr
n = ser.inWaiting()
if n > 0: data += ser.read(n)
return data
def searchModem():
foundmob= False
foundusb= False
sudoPassword='Figaro5558_'#my sudo password
command="usb_modeswitch -v 12d1 -p 1f01 -M '55534243123456780000000000000011062000000100000000000000000000'" # the command that for ce the modem to be on serial mode
while foundusb!= True : # this allows me to look for the modem as an usb and then force it
foundmob=terminalComAndRead("lsusb",'12d1:1f01')#doing a ls usb and then looking for the id of my device
changemob=terminalComAndRead("lsusb",'12d1:1001')#this is the id of my device when it is already in serial mode
if foundmob == True :
sleep(1)
os.system('echo %s|sudo -S %s' % (sudoPassword, command))# this is the line who execute the command on sudo
foundusb=terminalComAndRead("ls /dev/ttyUSB*",'ttyUSB1')
if changemob == True :
foundusb=terminalComAndRead("ls /dev/ttyUSB*",'ttyUSB1')
if foundusb == True :
print('Modem ready for connection')
ttyusb0=terminalComAndRead('dmesg | tail -50','now attached to ttyUSB0') #look int he dmesg if there is my new usb port
if ttyusb0 == True :
usbPort='/dev/ttyUSB0'#give the path
return usbPort
ser = serial.Serial(usbPort, 9600, bytesize=8, parity='N', stopbits=1, timeout=1, rtscts=False, dsrdtr=False) #connect to your serial
cmd="AT^HCSQ?\r\n"#the AT command
msg=str(send(cmd,ser))#use the send function to send the AT command
print(msg)
所以这对我有用,希望对您有所帮助!
干杯
我想看看我的华为E3531的RSSI。所以我找到了一些文档,这些文档显示了使用 AT 命令获取这些信息的简单方法。问题是我什至无法连接到我的华为 E3531。我的意思是,它作为调制解调器真的很好用。我有很好的联系。但是当我在dev中寻找设备时,我只找到2个设备("sdb"和"sgm"),它们似乎是2个光盘,但与串口无关。
所以我尝试了一些我发现的东西: - 插入华为后,我发现 Idvendor 和 Idproduct 正在执行 lsusb。 -他们我做了一个 sudo modprobe usbserial vendor=0X"Idvendor" product=0X"Idproduct" - 然后当我执行 dmesg 时,我可以阅读:
[ 1038.498282] usbcore: registered new interface driver usbserial
[ 1038.498299] usbcore: registered new interface driver usbserial_generic
[ 1038.498312] usbserial: USB Serial support registered for generic
通常我应该有这样的东西:
usb 1-1: generic converter now attached to ttyUSB0
我想我不得不说,甚至不可能从我的 mac 中看到 sdb 和 sgm,所以我在我的 Ubuntu 中这样做。如果我启用 wifi,调制解调器无法连接(所以我看不到 sdb 和 sgm)
如果有人需要,这里是 dmesg 的第一部分:
[ 742.756888] usb 3-1: USB disconnect, device number 6
[ 743.123706] usb 3-1: new high-speed USB device number 7 using xhci_hcd
[ 743.252854] usb 3-1: New USB device found, idVendor=12d1, idProduct=14dc
[ 743.252861] usb 3-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 743.252865] usb 3-1: Product: HUAWEI Mobile
[ 743.252868] usb 3-1: Manufacturer: HUAWEI
[ 743.482312] cdc_ether 3-1:1.0 usb0: register 'cdc_ether' at usb-0000:00:14.0-1, CDC Ethernet Device, 9a:c2:9b:ee:4c:d9
[ 743.482859] usb-storage 3-1:1.2: USB Mass Storage device detected
[ 743.483249] scsi11 : usb-storage 3-1:1.2
[ 743.520839] audit: type=1400 audit(1427889713.269:79): apparmor="DENIED" operation="file_inherit" profile="/usr/lib/NetworkManager/nm-dhcp-client.action" pid=3414 comm="nm-dhcp-client." lport=29180 family="inet" sock_type="dgram" protocol=17
[ 743.520857] audit: type=1400 audit(1427889713.269:80): apparmor="DENIED" operation="file_inherit" profile="/usr/lib/NetworkManager/nm-dhcp-client.action" pid=3414 comm="nm-dhcp-client." lport=47709 family="inet6" sock_type="dgram" protocol=17
[ 744.481267] scsi 11:0:0:0: Direct-Access HUAWEI TF CARD Storage 2.31 PQ: 0 ANSI: 2
[ 744.481722] sd 11:0:0:0: Attached scsi generic sg2 type 0
[ 744.482933] sd 11:0:0:0: [sdb] Attached SCSI removable disk
[ 753.752310] audit: type=1400 audit(1427889723.496:81): apparmor="DENIED" operation="file_inherit" profile="/usr/lib/NetworkManager/nm-dhcp-client.action" pid=3423 comm="nm-dhcp-client." lport=29180 family="inet" sock_type="dgram" protocol=17
[ 753.752328] audit: type=1400 audit(1427889723.496:82): apparmor="DENIED" operation="file_inherit" profile="/usr/lib/NetworkManager/nm-dhcp-client.action" pid=3423 comm="nm-dhcp-client." lport=47709 family="inet6" sock_type="dgram" protocol=17
[ 1038.498282] usbcore: registered new interface driver usbserial
[ 1038.498299] usbcore: registered new interface driver usbserial_generic
[ 1038.498312] usbserial: USB Serial support registered for generic
再次感谢你,如果你能给我一个小小的想法,我会采纳! 待会儿见
编辑 2015 年 9 月 4 日 所以我发现了一些东西。执行 lsusb 你会看到你的设备为:
Bus 003 Device 020: ID 12d1:1f01 Huawei Technologies Co., Ltd.
1f01 是 Idproduct,但它有时会发生变化,因为调制解调器会自行进入不同的模式。如果是1F01,则:
sudo usb_modeswitch -v 12d1 -p 1F01 -M '55534243123456780000000000000011062000000100000000000000000000'
这将强制您的设备更改模式。现在您的设备将有一个等于 1001 的 Idproduct。执行 lsusb 以查看它:
Bus 003 Device 023: ID 12d1:1001 Huawei Technologies Co., Ltd. E169/E620/E800 HSDPA Modem
并且您有 4 个新的 USB 设备:USB0、USB1、USB2 和 USB3。 现在我要试试minicom发送AT指令
所以基本上,我的问题是我无法将我的调制解调器视为串行。我解释了如何做到这一点,你必须用这个命令强制你的调制解调器:
sudo usb_modeswitch -v 12d1 -p 1F01 -M '55534243123456780000000000000011062000000100000000000000000000'
然后我尝试了 Minicom,这真的很不错,您只需使用正确的参数(如波特率和端口)连接好即可。所以寻找它并做一些测试。要查看您在 minicom 中写的内容,只需启用本地回显(ctrl+a 然后 z 到该选项)。 所以你可以发送所有你想要的信息。
但我想将它集成到 python 脚本中,所以这是我的代码:
def terminalComAndRead(a,b) :
found = False
proc = subprocess.Popen([a], stdout=subprocess.PIPE, shell=True)#send the command
(out, err) = proc.communicate()
string=str(out)
#print(string)
foundstring=string.find(b, 0, len(string))#look for the string b in the serial answer of my device
if foundstring != -1 :
found= True #send back true if it found it
return found
def send(data,ser):
try:
ser.write(data)#write the command my serail port
except Exception as e:
print "Couldn't send data to serial port: %s" % str(e)
else:
try:
sleep(1)
data = ser.read(1)#read the serial
except Exception as e:
print "Couldn't read data from serial port: %s" % str(e)
else:
if data: # If data = None, timeout occurr
n = ser.inWaiting()
if n > 0: data += ser.read(n)
return data
def searchModem():
foundmob= False
foundusb= False
sudoPassword='Figaro5558_'#my sudo password
command="usb_modeswitch -v 12d1 -p 1f01 -M '55534243123456780000000000000011062000000100000000000000000000'" # the command that for ce the modem to be on serial mode
while foundusb!= True : # this allows me to look for the modem as an usb and then force it
foundmob=terminalComAndRead("lsusb",'12d1:1f01')#doing a ls usb and then looking for the id of my device
changemob=terminalComAndRead("lsusb",'12d1:1001')#this is the id of my device when it is already in serial mode
if foundmob == True :
sleep(1)
os.system('echo %s|sudo -S %s' % (sudoPassword, command))# this is the line who execute the command on sudo
foundusb=terminalComAndRead("ls /dev/ttyUSB*",'ttyUSB1')
if changemob == True :
foundusb=terminalComAndRead("ls /dev/ttyUSB*",'ttyUSB1')
if foundusb == True :
print('Modem ready for connection')
ttyusb0=terminalComAndRead('dmesg | tail -50','now attached to ttyUSB0') #look int he dmesg if there is my new usb port
if ttyusb0 == True :
usbPort='/dev/ttyUSB0'#give the path
return usbPort
ser = serial.Serial(usbPort, 9600, bytesize=8, parity='N', stopbits=1, timeout=1, rtscts=False, dsrdtr=False) #connect to your serial
cmd="AT^HCSQ?\r\n"#the AT command
msg=str(send(cmd,ser))#use the send function to send the AT command
print(msg)
所以这对我有用,希望对您有所帮助! 干杯