本文介绍了来自初学者的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我是关于phyton编程的新手。 在我的带有嵌入式Phyton 1.5.2+版本的GPRS调制解调器上,我必须从串口接收 a字符串发送一封在 电子邮件中的内容。 如果在代码中直接生成字符串,则一切正常。但是,如果我在''while''循环中等待这个,那么它不会起作用。这是简单的 代码: 全局字符串ZVEI 而stringZVEI =='''': MOD.sleep(10) a = SER.send('sono nel而stringZVEI == st vuota'') stringZVEI = SER .readbyte() a = SER.send(''stringZVEI ='') a = SER.send(stringZVEI) MOD和SER是由第三部分组成的嵌入式类。 时间尽管如此,stringZVEI仍然是空的。线路 a = SER.send(''stringZVEI ='') 正常工作但 a = SER.send( stringZVEI) 不工作 有什么建议吗? 谢谢 Dario。 解决方案 如果没有要读取的数据,.readbyte()会怎么做?由于你的循环是基于一个完全空的字符串,如果.readbyte返回/ anything / (甚至是一个null字节 - 0x00)你的循环将退出;一个空字节可能 在发送中不可见... - ============== ==================================== ============< wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG< wu******@dm.net | Bestiaria支持人员< ========================================= ========= ============< 主页:< http://www.dm.net/~wulfraed/> < 溢出页面:< http://wlfraed.home.netcom.com/> < 首先 - 发布真正的代码文件会有所帮助 - 下面前两个语句的缩进是错误的。 global stringZVEI 这在顶层没有任何作用 - 如果只是在INSIDE a def中有意义的话。阻止,它具有说这个变量不是函数本地的的效果> 导入时间有问题 time.sleep(< seconds>)? ??? #for debug print"%2X" %stringZVEI 时间只有stringZVEI仍然是空的。线路 a = SER.send(''stringZVEI ='')正常工作但是 a = SER.send(stringZVEI) 如果没有要读取的数据,.readbyte()会怎么做?由于你的循环基于一个完全空的字符串,如果.readbyte返回/ anything / (甚至是一个null字节 - 0x00),你的循环将退出;并且在发送时可能无法看到空字节... - Hi, Im new on phyton programming.On my GPRS modem with embedded Phyton 1.5.2+ version, I have to receivea string from serial port and after send this one enclosed in ane-mail.All OK if the string is directly generated in the code. But it doesn''tworks if I wait for this inside a ''while'' loop. This is the simplecode: global stringZVEI while stringZVEI=='''':MOD.sleep(10)a=SER.send('' sono nel while stringZVEI==st vuota'')stringZVEI = SER.readbyte()a=SER.send('' stringZVEI='')a=SER.send(stringZVEI) MOD and SER are embedded class maked by third part. time only nevertheless stringZVEI is still empty. The linea=SER.send('' stringZVEI='')work correctly but a=SER.send(stringZVEI) doesn''t work Any suggestion? ThanksDario. 解决方案 What does .readbyte() do if there is no data to be read? Since yourloop is based on a totally empty string, if .readbyte returns /anything/(even a "null" byte -- 0x00) your loop will exit; and a null byte maynot be visible on the send... -- ================================================== ============ < wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG < wu******@dm.net | Bestiaria Support Staff < ================================================== ============ < Home Page: <http://www.dm.net/~wulfraed/> < Overflow Page: <http://wlfraed.home.netcom.com/> < First -- post the real code file would help -- the indentation of the first two statements below is wrong. This does nothing at the top level -- if only makes sense INSIDE a "def" block, where it has the effect of saying "this variable is not local to the function" There is something wrong with import time time.sleep(<seconds>) ???? #for debug print "%2X " % stringZVEI time only nevertheless stringZVEI is still empty. The line a=SER.send('' stringZVEI='') work correctly but a=SER.send(stringZVEI) What does .readbyte() do if there is no data to be read? Since your loop is based on a totally empty string, if .readbyte returns /anything/ (even a "null" byte -- 0x00) your loop will exit; and a null byte may not be visible on the send... -- 这篇关于来自初学者的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-16 01:20