Python 如何管理error:TypeError:参数必须是int或具有fileno()方法
我想让太多的zigbee设备使用RaspberryPi一起说话。 我正在使用Xbee“扩展”和系列1终端设备。 他们目前正在传输数据,我想为图书馆提取一个特定的数据。我的代码很简单Python 如何管理error:TypeError:参数必须是int或具有fileno()方法,python,raspberry-pi,zigbee,Python,Raspberry Pi,Zigbee,我想让太多的zigbee设备使用RaspberryPi一起说话。 我正在使用Xbee“扩展”和系列1终端设备。 他们目前正在传输数据,我想为图书馆提取一个特定的数据。我的代码很简单 #coding: utf #!/usr/bin/python import serial # for serie 1 componants from xbee import XBee # for serie 2 componants #from xbee import ZigBee #############
#coding: utf
#!/usr/bin/python
import serial
# for serie 1 componants
from xbee import XBee
# for serie 2 componants
#from xbee import ZigBee
##############################################################
def CalcDCAmps(data):
mes = (data*20)/1024 # conversion 0-1023 en 0-20mA
if (mes <4) : #si la valeur reçues est inférieure à 4mA
return -1 # problème sur le capteur
else :
return (mes*50)/20 # conversion 4-20mA en 0-50A
##############################################################
# Open serial port
serial_port = serial.Serial('/dev/ttyAMA0', 9600)
# Create XBee Series 1 object
zb = XBee(serial_port)
#zb = ZigBee(serial_port)
while True:
j = 0;
data_int = "";
try:
data = zb.wait_read_frame() #Get data for later use
#print data # for debugging only
print data['samples']# print the data frame of the list
# frame type received[{'adc-0': 1023}]
sample = str(data['samples']) #transformation de l'élément de la bibliothèque en chaîne de caractères
#print "Equivalent String : %s" % sample
for i in range(len(sample)): # boucle pour isoler les chiffres de la chaîne de caractères
if ((sample[i]>='0') & (sample[i]<='9')) :
data_int += sample[i] # stockage des chiffres dans une nouvelle chaîne de caractères
data_int = int(data_int) # conversion de la chaîne de caractère en entier
print "Valeur extraite:", data_int
courant = CalcDCAmps(data_int)
print "Courant DC: ", courant, "A"
except KeyboardInterrupt:
break
serial_port.close()
#编码:utf
#!/usr/bin/python
导入序列号
#对于系列1成分
从xbee导入xbee
#对于系列2成分
#从xbee进口ZigBee
##############################################################
def钙电流(数据):
mes=(数据*20)/1024#转换0-1023 en 0-20mA
如果(mes您正在关闭循环内的串行端口,那么在第一次迭代后,它将无法再读取帧
[{'adc-0': 172}]
Valeur extraite: 172
Courant DC: -1 A
Traceback (most recent call last):
File "conversion_v3.py", line 36, in <module>
data = zb.wait_read_frame() #Get data for later use
File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 399, in wait_read_frame
frame = self._wait_for_frame()
File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 117, in _wait_for_frame
if self.serial.inWaiting() == 0:
File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 431, in inWaiting
s = fcntl.ioctl(self.fd, TIOCINQ, TIOCM_zero_str)
TypeError: argument must be an int, or have a fileno() method.