尝试将AT命令与Huawei E3531一起使用 [英] Trying to use the AT command with an Huawei E3531

查看:187
本文介绍了尝试将AT命令与Huawei E3531一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想阅读我的华为E3531的RSSI.因此,我找到了一些文档,这些文档显示了使用AT命令获取这些信息的简便方法.问题是我什至无法连接到华为E3531.我的意思是,它可以很好地用作调制解调器.我的关系很好.但是,当我在dev中寻找设备时,我只发现2个设备("sdb"和"sgm")似乎是2个光盘,但与串行端口无关.

I want to read the RSSI of my Huawei E3531. So I found some documentations that show an easy way to get those informations using the AT command. The problem is that I can't even connect to my Huawei E3531. I mean, it works really well as a modem. I have a good connection. But when I am looking for the device in dev, I just find 2 devices ("sdb" and "sgm") which seem to be 2 disc, but nothing to do with serial port.

因此,我尝试了一些发现的事情: -插入华为插头后,我发现Idvendor和Idproduct做一个lsusb. -他们我做一个sudo modprobe usbserial供应商= 0X"Idvendor"产品= 0X"Idproduct" -然后当我执行dmesg时,我可以阅读:

So I tried somethin I found: -After I plugged the Huawei, I find the Idvendor and Idproduct doing an lsusb. -They I do a sudo modprobe usbserial vendor=0X"Idvendor" product=0X"Idproduct" -And then when I do dmesg I can read:

[ 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

通常我应该有类似的东西:

Normally I should have something like:

usb 1-1: generic converter now attached to ttyUSB0

我想我不得不说,甚至无法从Mac上看到sdb和sgm,所以我是从Ubuntu上完成的.如果启用了wifi,调制解调器将无法连接(因此我看不到sdb和sgm)

I think I have to say that it was not even possible to see the sdb and sgm from my mac, so I am doing this from my Ubuntu. And if I enable my wifi, the modem cannot connect ( so I do not see the sdb and sgm)

如果有人需要,这是dmesg的第一部分:

If someone need it here is the first part of the 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

再次感谢您,如果您能给我一个小主意,我也会接受! 待会见

Thank you again, if you can give me even a small idea, I will take it! see you soon

编辑9/04/2015 所以我发现了一些东西.轻描淡写地将您的设备显示为:

EDIT 9/04/2015 So I found something. Do an lsusb you will see your device as:

Bus 003 Device 020:ID 12d1:1f01华为技术有限公司

Bus 003 Device 020: ID 12d1:1f01 Huawei Technologies Co., Ltd.

1f01是Idproduct,但它可能会更改,因为调制解调器会自行进入不同的模式.如果是1F01,请执行以下操作:

1f01 is the Idproduct, but it can change sometime, because the modem goes to different mode on its own. If it is 1F01, do:

sudo usb_modeswitch -v 12d1 -p 1F01 -M '55534243123456780000000000000011062000000100000000000000000000' 

这将强制您的设备更改设备的模式.现在,您的设备将具有等于1001的Idproduct.请通过lsusb进行查看:

This will force your device your device to change mode. Now your device will have an Idproduct iqual to 1001. Do an lsusb to see it:

Bus 003 Device 023:ID 12d1:1001华为技术有限公司 E169/E620/E800 HSDPA调制解调器

Bus 003 Device 023: ID 12d1:1001 Huawei Technologies Co., Ltd. E169/E620/E800 HSDPA Modem

您将拥有4个新的USB开发人员:USB0,USB1,USB2和USB3. 现在,我将尝试使用minicom发送AT命令.

And you have 4 new usb dev: USB0, USB1, USB2 and USB3. Now I am going to try minicom to send the AT command.

推荐答案

所以基本上,我的问题是我看不到调制解调器是串行的.我解释了如何执行此操作,您必须使用以下命令强制调制解调器:

so basically, my problem was that I could not see my modem as a serial. I explained how to do that, you have to force your modem with this command:

sudo usb_modeswitch -v 12d1 -p 1F01 -M '55534243123456780000000000000011062000000100000000000000000000'

sudo usb_modeswitch -v 12d1 -p 1F01 -M '55534243123456780000000000000011062000000100000000000000000000'

然后我尝试了Minicom,它非常好,您只需要使用正确的参数(例如波特率和端口)就可以很好地进行连接.因此,寻找它并进行一些测试.要查看您在minicom中写的内容,只需启用本地回显(按ctrl + a组合键,然后按z组合键即可). 这样您就可以发送所有想要的信息.

Then I tried Minicom, which is really nice, you just have to connect well using the right parameters like baud rate and port. So look for it and do some test. To see what you are writing in minicom, just enable local echo (ctrl+a then z to the option). So you can send all the information you want.

但是我想将其集成到python脚本中,所以这是我的代码:

But I wanted to integrate it in a python script so here is my code:

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)

所以这对我有用,希望对您有所帮助! 干杯

So this worked for me, I hope it will help you! Cheers

这篇关于尝试将AT命令与Huawei E3531一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆