Esempio n. 1
0
def increment(message):
    console.log(message)
    if message == "This is message number 0":
        # console.log("Message correct")
        pass
    else:
        console.log("Message incorrect")
Esempio n. 2
0
 def _processInput(self, message):
     index = message.find('\r\n')
     while not index == -1:
         line = message[:index]
         console.log(line)
         if not self.cb == None:
             self.cb(line)
         message = message[index + 2:]
         index = message.find('\r\n')
     return message
Esempio n. 3
0
    def _startListenLoop(self):
        with serial.Serial(self.port, self.baud, timeout=0) as ser:
            console.log('Connected to %s (%s)' % (ser.name, ser.baudrate))
            incoming = ''
            while not self.stopped:
                # Send all outgoing messages
                while len(self.outgoing_buffer):
                    message = self.outgoing_buffer.pop(0) + '\n'
                    ser.write(bytes(message, 'ascii'))

                # Read all incoming messages
                incoming += ser.read(ser.in_waiting).decode('ascii')
                incoming = self._processInput(incoming)
Esempio n. 4
0
    def _start_listen_loop(self):
        with serial.Serial(self.port, self.baud, timeout=0) as ser:
            console.log('Connected to %s (%s)' % (ser.name, ser.baudrate))
            incoming = ''
            while not self.stopped:
                # Send all outgoing messages
                while len(self.outgoing_buffer):
                    message = self.outgoing_buffer.pop(0)
                    # console.log('Sending %s' % (message,))
                    ser.write(bytes(message + '\n', 'ascii'))

                # Read all incoming messages
                incoming += ser.read(ser.in_waiting).decode('ascii')
                incoming = self._process_input(incoming)

                if self.should_flush:
                    ser.flush()
Esempio n. 5
0
from SerialInterface import SerialInterface
import time
from Logger import console


def increment(message):
    console.log(message)
    if message == "This is message number 0":
        # console.log("Message correct")
        pass
    else:
        console.log("Message incorrect")


interface = SerialInterface('/dev/tty.usbmodem1421', 115200)
interface.Listen()
interface.OnInput(increment)
message_count = 0

last_time = time.time()
while True:
    cur_time = time.time()
    if cur_time - last_time > 1:
        # print('Recieved %s messages' % (message_count,))
        last_time = cur_time
        interface.Write('This is message number %s' % (message_count, ))
        console.log('Sending message')
Esempio n. 6
0
from SerialInterface import SerialInterface
import time
import math
from Logger import console

# interface = SerialInterface('/dev/tty.usbmodem1421', baud=9600)
# interface = SerialInterface('/dev/tty.usbmodem1421', baud=38400)
# interface = SerialInterface('/dev/tty.usbmodem1421', baud=57600)
interface = SerialInterface('/dev/tty.usbmodem1421', baud=115200)
interface.listen()
time.sleep(1)

console.log('Starting test')
for i in range(0, 500):
    interface.write('Number %d' % (i, ))

interface.flush()

input('Waiting for completion...')
interface.stop()