Ejemplo n.º 1
0
import logging

logging.basicConfig(level=logging.WARNING)
f = logging.Formatter('%(name)s[%(levelno)s]: %(message)s')
h = logging.StreamHandler()
h.setLevel(logging.INFO)
h.formatter = f
pycommando.commando.logger.addHandler(h)
pycommando.commando.logger.setLevel(logging.INFO)

port = '/dev/ttyACM1'
if len(sys.argv) > 1:
    port = sys.argv[1]

conn = serial.Serial(port, 9600)
com = pycommando.Commando(conn)
cmd = pycommando.protocols.CommandProtocol()

com.register_protocol(0, cmd)


def got_ping(cmd):
    counts = []
    while cmd.has_arg():
        counts.append(cmd.get_arg(ctypes.c_byte).value)
    print("Got ping: %s[%s]" % (counts[0], len(counts)))


def set_led(v):
    cmd.start_command(0)
    cmd.add_arg(ctypes.c_byte(v))
Ejemplo n.º 2
0
#!/usr/bin/env python

import time

import serial

import pycommando

com = pycommando.Commando(serial.Serial('/dev/ttyACM0', 9600))
text = pycommando.protocols.TextProtocol(com)

com.register_protocol(0, text)


def show(text):
    print(text)


text.register_callback(show)

while True:
    com.handle_stream()
    time.sleep(0.01)
Ejemplo n.º 3
0
import pycommando
import serial

if sys.version_info >= (3, 0):
    raw_input = input

if len(sys.argv) < 2:
    raise Exception("A serial port must be supplied: commands.py <port>")
port = sys.argv[1]

# open the serial port
serial_port = serial.Serial(port, 9600)

# create commando, the stream handler
com = pycommando.Commando(serial_port)
# create a few protocols to receive text and send/receive commands
text = pycommando.protocols.TextProtocol(com)
cmd = pycommando.protocols.CommandProtocol(com)

# register the created protocols, the protocol ids (first argument)
# should match on both the arduino and in python
com.register_protocol(0, text)
com.register_protocol(1, cmd)


# define a callback to be used for the text protocol
def print_message(msg):
    # just print out the message with a header
    print("from arduino->%s" % msg)
Ejemplo n.º 4
0
<<<<<<< HEAD
pycommando.protocols.command.test_type_conversion()
=======
if sys.version_info >= (3, 0):
    xrange = range

pycomando.protocols.command.test_type_conversion()
>>>>>>> b5a30c92b56bc8296ab6e49589a776f7a40872ff

port = serial.Serial('/dev/ttyACM0', 9600)
# time.sleep(1)  # wait for arduino
# port.setDTR(level=0)
# time.sleep(1)

com = pycommando.Commando(port)
text = pycommando.protocols.TextProtocol(com)
cmd = pycommando.protocols.CommandProtocol(com)

com.register_protocol(0, text)
com.register_protocol(1, cmd)

cmds = [
    (0, None, ()),
    # (1, ctypes.c_bool, (True, False)),
    (1, bool, (True, False)),
    (2, ctypes.c_char, (b'\r', b'\n', b'a', b'Z', b'\x00')),
    # (3, ctypes.c_int32, (0, 1, -1, 1000000, -1000000)),
    (3, int, (0, 1, -1, 1000000, -1000000)),
    # (4, ctypes.c_float, (0.0, 1.0, -1.0, 1.23, -123.0)),
    (4, float, (0.0, 1.0, -1.0, 1.23, -123.0)),