来自初学者的问题 [英] question from beginner
问题描述
我是关于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是由第三部分组成的嵌入式类。
从我很少的调试可能性看起来循环执行1
时间尽管如此,stringZVEI仍然是空的。线路
a = SER.send(''stringZVEI ='')
正常工作但
a = SER.send( stringZVEI)
不工作
有什么建议吗?
谢谢
Dario。
2005年9月7日07:14:37 -0700,dario <柯****** @ libero.it>在comp.lang.python中声明
跟随:
我是phyton编程的新手。
在我的带有嵌入式Phyton 1.5的GPRS调制解调器上.2+版本,我必须从串口收到一个字符串,然后发送一封用
电子邮件封好的字符串。
如果字符串直接在代码中生成,那么一切正常。但是如果我在''while''循环中等待这个,它就不会起作用。这是简单的代码:
首先 - 发布实际代码文件会有所帮助 -
缩进下面的前两个语句是错误的。
全球字符串ZVEI
这在顶层没有任何作用 - 如果只是有意义内在一个
" def"块,它的效果是说这个变量不是
函数的本地>
而stringZVEI =='''':
MOD .sleep(10)
有什么问题
导入时间
time.sleep(<秒>)
????
a = SER.send('sono nel while stringZVEI == st vuota'')
stringZVEI = SER.readbyte ()
#for debug
print"%2X" %stringZVEI
a = SER.send(''stringZVEI ='')
a = SER.send(stringZVEI)
MOD和SER是由嵌入式类生成的第三部分。
从我很小的调试可能性来看,循环只执行了一次,但是字符串ZVEI仍然是空的。线路
a = SER.send(''stringZVEI ='')
正常工作但是
a = SER.send(stringZVEI)
如果没有要读取的数据,.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/> <
谢谢Dennis。实际上,在
..read方法之后,字符串ZVEI不会保持为空,然后循环执行一次。
怎么可能是'' ''循环等待串口
端口没有空字符串?
达里奥。
丹尼斯Lee Bieber ha scritto:
2005年9月7日07:14:37 -0700,dario <柯****** @ libero.it>在comp.lang.python中声明了以下内容:
我是关于phyton编程的新手。
在我的GPRS调制解调器上嵌入了Phyton 1.5.2+版本,我必须从串口接收一个字符串,并在发送后用
电子邮件发送一个字符串。
如果字符串直接在代码中生成,那么一切正常。但是如果我在''while''循环中等待这个,它就不会起作用。这是简单的代码:
首先 - 发布真正的代码文件会有所帮助 - 下面前两个语句的缩进是错误的。
< blockquote class =post_quotes> global stringZVEI
这在顶层没有任何作用 - 如果只是在INSIDE a
def中有意义的话。阻止,它具有说这个变量不是函数本地的的效果>
而stringZVEI =='''':
MOD .sleep(10)
导入时间有问题
time.sleep(< seconds>)
? ???
a = SER.send('sono nel while stringZVEI == st vuota'')
stringZVEI = SER.readbyte()
#for debug
print"%2X" %stringZVEI
a = SER.send(''stringZVEI ='')
a = SER.send(stringZVEI)
MOD和SER是由第三部分组成的嵌入式类。
从我很少的调试可能性来看,循环执行1
时间只有stringZVEI仍然是空的。线路
a = SER.send(''stringZVEI ='')
正常工作但是
a = SER.send(stringZVEI)
如果没有要读取的数据,.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/> <
2005年9月8日09:14:15 -0700,dario <柯****** @ libero.it>在comp.lang.python中声明
跟随:
谢谢Dennis。实际上,在
.read方法之后,字符串ZVEI不会保持为空,然后循环执行一次。
怎么可能是''while''循环等待一个空的来自串口
端口的字符串?
。
我要问的第一个问题是:.readbyte()调用的
规范是什么。如果它不等待数据
字节,它会返回什么?如果它确实等待数据字节,则没有
方式来查找空字符串。
我要问的第二个问题是:.readbyte()似乎一次只能读取一个字节,这真的是你想要的 - 每个字节读取一个字节
?或者你想要一个字符串?最后以< return>
结束 - ================================ ================== ============<
wl ***** @ ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG<
wu******@dm.net | Bestiaria支持人员<
========================================= ========= ============<
主页:< http://www.dm.net/~wulfraed/> <
溢出页面:< http://wlfraed.home.netcom.com/> <
Hi, Im new on phyton programming.
On my GPRS modem with embedded Phyton 1.5.2+ version, I have to receive
a string from serial port and after send this one enclosed in an
e-mail.
All OK if the string is directly generated in the code. But it doesn''t
works if I wait for this inside a ''while'' loop. This is the simple
code:
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.
From my very little debug possibility it seem that loop is executed 1
time only nevertheless stringZVEI is still empty. The line
a=SER.send('' stringZVEI='')
work correctly but
a=SER.send(stringZVEI)
doesn''t work
Any suggestion?
Thanks
Dario.
On 7 Sep 2005 07:14:37 -0700, "dario" <ke******@libero.it> declaimed the
following in comp.lang.python:
Hi, Im new on phyton programming.
On my GPRS modem with embedded Phyton 1.5.2+ version, I have to receive
a string from serial port and after send this one enclosed in an
e-mail.
All OK if the string is directly generated in the code. But it doesn''t
works if I wait for this inside a ''while'' loop. This is the simple
code:
First -- post the real code file would help -- the indentation of
the first two statements below is wrong.
global stringZVEI
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"
while stringZVEI=='''':
MOD.sleep(10)
There is something wrong with
import time
time.sleep(<seconds>)
????
a=SER.send('' sono nel while stringZVEI==st vuota'')
stringZVEI = SER.readbyte()
#for debug
print "%2X " % stringZVEI
a=SER.send('' stringZVEI='')
a=SER.send(stringZVEI)
MOD and SER are embedded class maked by third part.From my very little debug possibility it seem that loop is executed 1 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...
-- ================================================== ============ <
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/> <
Thanks Dennis. In effect stringZVEI doesn''t remain empty after the
..read method, then the loop is executed 1 time.
How could be a ''while'' loop to wait a no empty string from the serial
port?
Dario.
Dennis Lee Bieber ha scritto:
On 7 Sep 2005 07:14:37 -0700, "dario" <ke******@libero.it> declaimed the
following in comp.lang.python:Hi, Im new on phyton programming.
On my GPRS modem with embedded Phyton 1.5.2+ version, I have to receive
a string from serial port and after send this one enclosed in an
e-mail.
All OK if the string is directly generated in the code. But it doesn''t
works if I wait for this inside a ''while'' loop. This is the simple
code:
First -- post the real code file would help -- the indentation of
the first two statements below is wrong.global stringZVEI
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"while stringZVEI=='''':
MOD.sleep(10)
There is something wrong with
import time
time.sleep(<seconds>)
????a=SER.send('' sono nel while stringZVEI==st vuota'')
stringZVEI = SER.readbyte()
#for debug
print "%2X " % stringZVEIa=SER.send('' stringZVEI='')
a=SER.send(stringZVEI)
MOD and SER are embedded class maked by third part.From my very little debug possibility it seem that loop is executed 1
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...
--> ================================================== ============ <
> 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/> <
On 8 Sep 2005 09:14:15 -0700, "dario" <ke******@libero.it> declaimed the
following in comp.lang.python:
Thanks Dennis. In effect stringZVEI doesn''t remain empty after the
.read method, then the loop is executed 1 time.
How could be a ''while'' loop to wait a no empty string from the serial
port?
My apologies, I am having some difficulty making sense of some of
your phrases.
The first question I would have to ask is: what are the
specifications of that .readbyte() call. If it doesn''t wait for a data
byte, what does it return? If it does wait for a data byte, there is NO
way to look for an "empty string".
The second question I have to ask is: .readbyte() would seem to read
only one byte at a time, is that really what you want -- one byte per
read? or do you want a "string" that ends with a <return>
-- ================================================== ============ <
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/> <
这篇关于来自初学者的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!