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

        <tfoot id='zGoOI'></tfoot>
      1. <legend id='zGoOI'><style id='zGoOI'><dir id='zGoOI'><q id='zGoOI'></q></dir></style></legend>
          <bdo id='zGoOI'></bdo><ul id='zGoOI'></ul>
      2. <small id='zGoOI'></small><noframes id='zGoOI'>

        使用 Python ctypes 调用 rs232.c 时如何解决分段错误

        时间:2023-08-06

          <bdo id='0dvYP'></bdo><ul id='0dvYP'></ul>

          <small id='0dvYP'></small><noframes id='0dvYP'>

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

                  <tbody id='0dvYP'></tbody>

                • 本文介绍了使用 Python ctypes 调用 rs232.c 时如何解决分段错误问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我将 rs232.c 构建为共享库并尝试使用 python3 调用它.但是我得到了分段错误";尝试获取 com 端口 tcgetattr() 的属性时出错.有谁知道这是什么问题?我的操作系统是树莓派 p3.

                  I build the rs232.c as a shared library and try to use python3 to call it. But I got the "Segmentation fault" error when try to get the attributes of com port, tcgetattr(). Anyone know what's this problem? my os system is raspberry pi p3.

                  testcom.py

                  from ctypes import *
                  comdll = cdll.LoadLibrary("rs232.so")
                  comdll.RS232_OpenComport(c_int(22),c_int(115200),c_char_p(b'8N1'))
                  

                  rs232.c

                  #include <termios.h>
                  #include <unistd.h>
                  #define RS232_PORTNR  39
                  int Cport[RS232_PORTNR],error;
                  struct termios old_port_settings[RS232_PORTNR];
                  
                  int RS232_OpenComport(int comport_number, int baudrate, const char *mode)
                  {
                      error = tcgetattr(Cport[comport_number], old_port_settings + comport_number); //segmentation fault at this line
                      return error;
                  }
                  

                  推荐答案

                  问题是您将变量命名为 error 并使其成为全局变量.作为 GNU 扩展,glibc 添加了一个名为error,你的库最终混淆了两者,并试图将 tcgetattr 的返回值写入名为 error 的函数上.要修复它,请将 error 重命名为其他名称,将其声明为 static,或将其声明移至 RS232_OpenCompport.

                  The problem is that you named your variable error and made it global. As a GNU extension, glibc adds a function named error, and your library ends up confusing the two and trying to write the return value of tcgetattr over the function called error. To fix it, either rename error to something else, declare it static, or move its declaration inside RS232_OpenComport.

                  这篇关于使用 Python ctypes 调用 rs232.c 时如何解决分段错误问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 Raspberry 上的 python 中,opencv 的分段错误 下一篇:Tkinter 导致 SIGSEGV 和系统崩溃 - 如何修复?

                  相关文章

                  最新文章

                  1. <legend id='PghjO'><style id='PghjO'><dir id='PghjO'><q id='PghjO'></q></dir></style></legend>
                        <bdo id='PghjO'></bdo><ul id='PghjO'></ul>
                      <tfoot id='PghjO'></tfoot>

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

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