本系列文章介绍华为网关AR502H的开发方法。
本文介绍了如何解决badfile descriptor问题。
调试程序时,如果连接了传感器,则一切正常,如果未连接传感器,则报告badfile descriptor错误。
badfile descriptor错误是Linux上的常见错误,通常在调用write函数时如果未正确设置参数就会发生。
在编程时,可以使用perror函数了解错误的类型。
1、通过错误语句定位调试程序,进行错误定位。 源程序如下。
void CRS 485: setdirction (direction _ mode direction ) { char crtlvalue; if (direction==input (this-outputdebuginformation ) (|--将控制引脚切换到接收方向…n ) ); crtlvalue=1; intIdatalen=write(this-crlfd,crtlvalue,sizeof ) crtlvalue ); 数据0个人(if ) (RS485 ); exit(-1; } //this-