我正在尝试通过串行方式与我的mac(10.7.5)上的斯坦福研究系统SR760频谱分析仪通话,使用串行到USB适配器连接到我的笔记本电脑。我正在使用多产的USB串行驱动程序。不知道是哪个,但我最近安装的。可能是PL2303型的。在
下面是一些使用Python的示例代码
import time
import serial
# configure the serial connections (the parameters differs on the device you
# are connecting to)
ser = serial.Serial(
port='/dev/cu.PL2303-0000201A',
baudrate=19200,
parity=serial.PARITY_NONE,
bytesize=serial.EIGHTBITS,
stopbits=serial.STOPBITS_ONE,
rtscts=0,
dsrdtr=0,
timeout=2,
)
if ser.isOpen():
ser.flushInput()
ser.flushOutput()
print """Enter your commands below.\r\nInsert "exit" to leave the
application."""
while 1:
# get keyboard input
input = raw_input(">> ")
if input == 'exit':
ser.close()
exit()
else:
ser.write(input + '\r')
out = ''
# let's wait one second before reading output (let's give device
# time to answer)
lines = 0
while 1:
time.sleep(1)
out = out + ser.readline()
lines = lines + 1
if lines > 5:
break
print "read data: " + out
使用SR760的手册,我发送它:*IDN?,一个基本的“识别”命令。我希望我的终端机里突然出现什么东西,什么也做不了。只是超时了。但是,如果我查看SR760上的发送队列,它将显示标识字符串,并且实际上响应一系列不同的命令。我只是没有在我的电脑上得到任何东西,这就是问题所在。我知道它应该是这样工作的,因为我的同事在他的电脑(一台windows笔记本电脑)上写了这样的代码。在
我怎么开始调试这个呢?我调整了超时时间,并确认了sr760的参数与我预期的相同。在
目前没有回答
相关问题 更多 >
编程相关推荐