本文整理汇总了Python中arduino.Arduino.poll方法的典型用法代码示例。如果您正苦于以下问题:Python Arduino.poll方法的具体用法?Python Arduino.poll怎么用?Python Arduino.poll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arduino.Arduino
的用法示例。
在下文中一共展示了Arduino.poll方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MainWindow
# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import poll [as 别名]
class MainWindow(wx.Frame):
""" Main frame of the application
"""
title = 'Data Acquisition'
def __init__(self):
wx.Frame.__init__(self, None, title=self.title, size=(650,570))
if platform.system() == 'Windows':
arduino_port = 'COM4'
else:
arduino_port = '/dev/ttyACM0'
# Try Arduino
try:
self.arduino = Arduino(arduino_port, 115200)
except:
msg = wx.MessageDialog(self, 'Unable to connect to arduino. Check port or connection.', 'Error', wx.OK | wx.ICON_ERROR)
msg.ShowModal() == wx.ID_YES
msg.Destroy()
self.create_main_panel()
self.recording = False
self.output_file = ''
time.sleep(1)
# Timer
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.on_timer, self.timer)
self.rate = 500
self.timer.Start(self.rate)
def create_main_panel(self):
# Panels
self.plots_panel = wx.Panel(self)
self.record_panel = wx.Panel(self)
# Init Plots
self.init_plots()
self.PlotsCanvas = FigCanvas(self.plots_panel, wx.ID_ANY, self.fig)
# Recording
self.btn_record = wx.Button(self.record_panel, wx.ID_ANY, label="Record", pos=(500,20), size=(100,30))
self.Bind(wx.EVT_BUTTON, self.on_btn_record, self.btn_record)
self.Bind(wx.EVT_UPDATE_UI, self.on_update_btn_record, self.btn_record)
self.txt_output_file = wx.TextCtrl(self.record_panel, wx.ID_ANY, pos=(20,20), size=(440,30))
# Sizers
vertical = wx.BoxSizer(wx.VERTICAL)
vertical.Add(self.plots_panel, 0 , wx.ALL, 5)
vertical.Add(self.record_panel, 0 , wx.ALL, 5)
# Layout
self.SetAutoLayout(True)
self.SetSizer(vertical)
self.Layout()
def init_plots(self):
self.plotMem = 50 # how much data to keep on the plot
self.plotData = [[0] * (6)] * self.plotMem # mem storage for plot
self.fig = Figure((8,6))
self.fig.subplots_adjust(hspace=.5) # sub plot spacing
self.axes = [] # subplot list
for i in range(1,7):
self.axes.append(self.fig.add_subplot(3,2,i, xticks=[], yticks=[0, 500, 1000]))
def poll(self):
self.dataRow = self.arduino.poll()
# self.dataRow = (np.random.rand(6)*1000).tolist()
# print self.dataRow
def save(self):
file = open(self.output_file, 'a')
for i in range(0,5):
file.write(str(self.dataRow[i]) + ',')
file.write(str(self.dataRow[5]) + '\n')
file.close()
def draw(self):
self.plotData.append(self.dataRow) # adds to the end of the list
self.plotData.pop(0) # remove the first item in the list, ie the oldest
# Plot
x = np.asarray(self.plotData)
for (i, ax) in enumerate(self.axes):
ax.plot(range(0,self.plotMem), x[:,i],'k')
ax.set_title('CH A'+str(i))
#.........这里部分代码省略.........
示例2: float
# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import poll [as 别名]
t = float(sys.argv[2])
#fname = "%s/data/%s_%s_%s.txt" % (prefix, date.today(), datetime.time(datetime.now()), sys.argv[2])
#fname = "%s/5sek_2h_herbergi.txt" % prefix
for x in infrange(n, inf=pollEndlessly):
# Sleep every 15 000 reading, for increasing amount of time (first 10 sec, then 20.. etc)
#if x%15000:
# print "Thats it, sleeping for", x/15000*10, "seconds".
# sleep(x/15000)
try:
# By first applying the int-function to the numbers we
# throw exceptions when the arduino sends a malformed
# string. This happens in about 0.2% of the time. I
# should perhaps look into this?
r = ard.poll()
l.append(int(r))
if "-v" in sys.argv:
print r
sleep(t)
except KeyboardInterrupt:
print
break
except OSError:
sleep(1)
except Exception as E:
if printErrors:
sys.stdout.write(str(E) + "\n")
if fname: