Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class JNWSNProtocol(basic.LineReceiver):
- .
- .
- .
- def connectionMade(self):
- log.msg("Connected...")
- def connectionLost(self, reason):
- log.msg("Lost connection (%s)" % reason)
- log.msg("Reconnecting in 5 seconds...")
- self.retry = self.wrapper.reactor.callLater(5, self.reconnect)
- def reconnect(self):
- try:
- SerialPort(self, self.wrapper.port, self.wrapper.reactor)
- log.msg("RECONNECTED")
- except:
- log.msg("Error opening serial port %s (%s)" % (self.wrapper.port, sys.exc_info()[1]))
- log.msg("Reconnecting in 5 seconds...")
- self.retry = self.wrapper.reactor.callLater(5, self.reconnect)
- .
- .
- .
- class JNWSNWrapper():
- .
- .
- .
- def start(self):
- '''
- Function that starts the JeeNode WSN plug-in. It handles the creation
- of the plugin connection and connects to the specified serial port.
- '''
- try:
- self.myserial = SerialPort (self.protocol, self.port, reactor)
- self.myserial.setBaudRate(57600)
- self.reactor = reactor
- reactor.run(installSignalHandlers=0)
- log.msg("The main loop has terminated")
- return(True)
- except:
- log.msg("Error opening serial port %s (%s)" % (self.port, sys.exc_info()[1]))
- return(False)
- if __name__ == '__main__':
- jnwsn = JNWSNWrapper()
- jnwsn.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement