1. <tfoot id='y1n2U'></tfoot>

    • <bdo id='y1n2U'></bdo><ul id='y1n2U'></ul>

    <i id='y1n2U'><tr id='y1n2U'><dt id='y1n2U'><q id='y1n2U'><span id='y1n2U'><b id='y1n2U'><form id='y1n2U'><ins id='y1n2U'></ins><ul id='y1n2U'></ul><sub id='y1n2U'></sub></form><legend id='y1n2U'></legend><bdo id='y1n2U'><pre id='y1n2U'><center id='y1n2U'></center></pre></bdo></b><th id='y1n2U'></th></span></q></dt></tr></i><div id='y1n2U'><tfoot id='y1n2U'></tfoot><dl id='y1n2U'><fieldset id='y1n2U'></fieldset></dl></div>
    <legend id='y1n2U'><style id='y1n2U'><dir id='y1n2U'><q id='y1n2U'></q></dir></style></legend>

      <small id='y1n2U'></small><noframes id='y1n2U'>

      一段时间后,使用 PySerial 从 Arduino 到 Raspberry Pi 的串行接收停止

      时间:2023-07-23
      • <i id='6TtLm'><tr id='6TtLm'><dt id='6TtLm'><q id='6TtLm'><span id='6TtLm'><b id='6TtLm'><form id='6TtLm'><ins id='6TtLm'></ins><ul id='6TtLm'></ul><sub id='6TtLm'></sub></form><legend id='6TtLm'></legend><bdo id='6TtLm'><pre id='6TtLm'><center id='6TtLm'></center></pre></bdo></b><th id='6TtLm'></th></span></q></dt></tr></i><div id='6TtLm'><tfoot id='6TtLm'></tfoot><dl id='6TtLm'><fieldset id='6TtLm'></fieldset></dl></div>
          <tbody id='6TtLm'></tbody>
            <bdo id='6TtLm'></bdo><ul id='6TtLm'></ul>

              <legend id='6TtLm'><style id='6TtLm'><dir id='6TtLm'><q id='6TtLm'></q></dir></style></legend>
            1. <tfoot id='6TtLm'></tfoot>

              <small id='6TtLm'></small><noframes id='6TtLm'>

              1. 本文介绍了一段时间后,使用 PySerial 从 Arduino 到 Raspberry Pi 的串行接收停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在进行一个项目,我必须一次接收大约 25 个字符的数据才能在 Raspberry Pi 中处理它.这是生成我想从 Arduino 接收的一些数据的示例代码:

                I'm working on a project in which I have to receive some 25 character data at a time in order to process it in Raspberry Pi. Here is the example code that generates some data I want to receive from Arduino:

                char i =0;
                char  a =0;
                char b=0;
                
                
                void setup(){
                
                 Serial.begin(9600);
                 for(i=0;i<25;i++){
                
                    Serial.print('l');}
                    Serial.print('
                ');
                    delay(2000);
                }
                
                
                void loop(){
                
                 for(i=0;i<25;i++){
                     for(a=0;a<i;a++){
                      if((a==9)||(a==19)||(a==24))
                          Serial.print('l');
                      else
                          Serial.print('d');   
                     }
                     for(b=0;b<25-i;b++){
                          Serial.print('l');
                     }
                
                
                     delay(2000);
                  }
                }
                

                它会发送这样的一行 'lllldddddllldddd...' 这行是 25 个字符的长度.现在,我想用 Raspberry Pi 接收这个.这是我正在尝试工作的代码:

                It sends a line like this 'llllddddllldddd...' This line is 25 characters length. Now, I want to receive this with Raspberry Pi. Here is the code I'm trying to work:

                ser = serial.Serial('/dev/AMA0',9600,timeout=1)
                ser.open()
                
                try:
                   serial_data = ser.readline()
                   print serial_data
                except serial.serialutil.SerialException:
                   pass
                

                这段代码非常正确地接收数据大约 5 秒钟,然后突然停止接收.

                This code receives data very correctly for like 5 seconds, and then suddenly stops receiving.

                此外,当我尝试以下操作时,我没有得到任何输出或输入/输出错误.

                Moreover, when I try the following, I get no output, or Input/output errors.

                serial_data = ser.readline()
                print serial_data
                

                好的,我现在评论了异常.它给出了以下错误:

                Okay, I commented the exception now. It gives the following error:

                 raise SerialException('device reporst rediness to read but returned no data (device disconnected?)')
                serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected?)
                

                通过 PySerial 将 25 个字符的数据从 arduino 接收到 raspberry 的正确方法是什么?任何帮助将不胜感激.

                What is the correct way to receive a 25 character data from arduino into raspberry via PySerial? Any help will be greately appreciated.

                推荐答案

                我也遇到了同样的问题,头疼了好久,试试这个

                I had the same problem and was breaking my head for a good time, try this

                运行

                ps -ef | grep tty
                

                如果输出看起来像任何东西

                If the output looks anything like

                root      2522     1  0 06:08 ?        00:00:00 /sbin/getty -L ttyAMA0 115200 vt100
                

                那么你需要禁止 getty 尝试向该端口发送数据

                Then you need to disable getty from trying to send data to that port

                为了使用树莓派的串口,我们需要通过在文件/etc/inittab中找到这一行来禁用getty(显示登录屏幕的程序)

                In order to use the Raspberry Pi’s serial port, we need to disable getty (the program that displays login screen) by find this line in file /etc/inittab

                T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
                

                并在前面加#注释掉

                #T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100)
                

                要防止树莓派在启动时向串口发送数据,请转到文件/boot/cmdline.txt 并找到该行并将其删除

                To prevents the Raspberry Pi from sending out data to the serial ports when it boots, go to file /boot/cmdline.txt and find the line and remove it

                console=ttyAMA0,115200 kgdboc=ttyAMA0,115200
                

                重启树莓派

                信用到期:http://blog.oscarliang.net/raspberry-pi-and-arduino-connected-serial-gpio/ 帮助我弄清楚如何禁用 getty

                Credit where credit is due: http://blog.oscarliang.net/raspberry-pi-and-arduino-connected-serial-gpio/ helped me figure out how to diable getty

                这篇关于一段时间后,使用 PySerial 从 Arduino 到 Raspberry Pi 的串行接收停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何确保 Python while 循环需要特定的时间才能运行? 下一篇:Python 将字符串转换为字节

                相关文章

                  <bdo id='dbyEQ'></bdo><ul id='dbyEQ'></ul>

                  <tfoot id='dbyEQ'></tfoot>
                1. <legend id='dbyEQ'><style id='dbyEQ'><dir id='dbyEQ'><q id='dbyEQ'></q></dir></style></legend>

                  1. <small id='dbyEQ'></small><noframes id='dbyEQ'>

                  2. <i id='dbyEQ'><tr id='dbyEQ'><dt id='dbyEQ'><q id='dbyEQ'><span id='dbyEQ'><b id='dbyEQ'><form id='dbyEQ'><ins id='dbyEQ'></ins><ul id='dbyEQ'></ul><sub id='dbyEQ'></sub></form><legend id='dbyEQ'></legend><bdo id='dbyEQ'><pre id='dbyEQ'><center id='dbyEQ'></center></pre></bdo></b><th id='dbyEQ'></th></span></q></dt></tr></i><div id='dbyEQ'><tfoot id='dbyEQ'></tfoot><dl id='dbyEQ'><fieldset id='dbyEQ'></fieldset></dl></div>