Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from twisted.application import internet, service
- from twisted.internet import defer, protocol, reactor, serialport, task, threads
- from twisted.protocols import basic
- from twisted.python import log
- from collections import deque
- ## SerialModemProtocol ##
- class SerialModemProtocol(basic.LineOnlyReceiver):
- initSequence = [
- 'ATE0', # command echo disabled
- 'AT',
- 'AT#BND=0', # 900/1800
- 'AT#AUTOBND=2', # quad-band
- 'AT+CMGF=1', # text mode
- 'AT+CMEE=2', # verbose debug
- ]
- def __init__(self):
- self.outgoingQueue = deque(self.initSequence)
- def connectionMade(self):
- print 'conn made'
- self.init_modem()
- def connectionLost(self, reason):
- print 'conn lost: %s' % (reason,)
- def lineReceived(self, line):
- if 'OK' in line:
- self._sendNext()
- def send_command(self, cmd):
- pass
- # self.transport.write or self.sendLine, I think
- def _sendNext(self):
- if self.outgoingQueue:
- self.send_command(self.outgoingQueue.popleft())
- def init_modem(self):
- self._sendNext()
- ## SerialModemProtocol ##
- serialport.SerialPort(SerialModemProtocol(), '/dev/ttyUSB1', reactor,
- baudrate=115200, timeout=2)
- reactor.callLater(10, reactor.stop)
- reactor.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement