当前位置: 首页>>代码示例>>Python>>正文


Python Arduino.isconnected方法代码示例

本文整理汇总了Python中arduino.Arduino.isconnected方法的典型用法代码示例。如果您正苦于以下问题:Python Arduino.isconnected方法的具体用法?Python Arduino.isconnected怎么用?Python Arduino.isconnected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在arduino.Arduino的用法示例。


在下文中一共展示了Arduino.isconnected方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: CloudSensor

# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import isconnected [as 别名]

#.........这里部分代码省略.........
            self.mutebutton.config(text='Unmute')
        else:
            self.mute = False
            self.mutebutton.config(text='Mute')

    def updatetmp(self):
        ''' Update the temperatures and gui.
            Also check if we need to raise alarm.
        '''
        if self.stop:
            self.frame.after(polldelay, self.updatetmp)
            return
        if 'Client' in self.csmode.get():
            try:
                if self.socket is not None:
                    self.socket.close()
                    self.socket = None
                self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                self.socket.connect((socket.gethostname(), 8001))
                mesg = self.socket.recv(32).strip('\0')
                self.socket.close()
            except Exception as msg:
                log.error("client exception: " + str(msg))
            if mesg is None:
                log.warning("Didn't get a response from the server...")
                self.frame.after(polldelay, self.updatetmp)
                return
            else:
                [a, b, c] = mesg.split(';')
                self.timearray.append(datetime.datetime.strptime(a.split('.')[0], '%Y-%m-%d %H:%M:%S'))
                self.skytmphist.append(int(b))
                self.ambtmphist.append(int(c))
        else:
            log.debug("Arduino is connected? " + str(self.uno.isconnected()))
            if self.uno.isconnected() == True:
                # Add workaround for 1037.55
                newtmp, anewtmp = self.uno.get_temperatures()
                if newtmp == '1037.55':
                    try:
                        self.skytmphist.append(self.skytmphist[-1])
                    except IndexError:
                        self.skytmphist.append('0')
                else:
                    self.skytmphist.append(newtmp)
                if anewtmp == '1037.55':
                    try:
                        self.ambtmphist.append(self.ambtmphist[-1])
                    except IndexError:
                        self.ambtmphist.append('0')
                else:
                    self.ambtmphist.append(anewtmp)
                templog.debug("sky=" + str(newtmp) + ":ambient=" + str(anewtmp))

            else:
                newtmp = randint(0, 100)
                anewtmp = randint(0, 100)
                templog.debug("sky=" + str(newtmp) + ":ambient=" + str(anewtmp))
                self.skytmphist.append(newtmp)
                self.ambtmphist.append(anewtmp)
            tnow = datetime.datetime.now()
            self.timearray.append(tnow)
        self.skytemp.config(text=str(self.skytmphist[-1]))
        self.ambtemp.config(text=str(self.ambtmphist[-1]))
        self.__updateplot()
        if (float(self.skytmphist[-1]) > float((self.threshold.get()))) and not self.mute:
            log.debug("BEEEEEEEPPPPPP")
开发者ID:albertw,项目名称:AutoSkyX,代码行数:70,代码来源:cloudsensor.py


注:本文中的arduino.Arduino.isconnected方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。