Exemplo n.º 1
0
def main():
    """Connect to Notcard and run a transaction test."""
    print("Opening port...")
    try:
        if use_uart:
            port = UART(2, 9600)
            port.init(9600, bits=8, parity=None, stop=1)
        else:
            port = I2C()
    except Exception as exception:
        raise Exception("error opening port: "
                        + NotecardExceptionInfo(exception))

    print("Opening Notecard...")
    try:
        if use_uart:
            card = notecard.OpenSerial(port)
        else:
            card = notecard.OpenI2C(port, 0, 0)
    except Exception as exception:
        raise Exception("error opening notecard: "
                        + NotecardExceptionInfo(exception))

    # If success, do a transaction loop
    print("Performing Transactions...")
    while True:
        time.sleep(2)
        transactionTest(card)
Exemplo n.º 2
0
def main():
    """Connect to Notcard and run a transaction test."""
    print("Opening port...")
    try:
        if use_uart:
            port = busio.UART(board.TX, board.RX, baudrate=9600)
        else:
            port = busio.I2C(board.SCL, board.SDA)
    except Exception as exception:
        raise Exception("error opening port: " +
                        NotecardExceptionInfo(exception))

    print("Opening Notecard...")
    try:
        if use_uart:
            card = notecard.OpenSerial(port)
        else:
            card = notecard.OpenI2C(port, 0, 0)
    except Exception as exception:
        raise Exception("error opening notecard: " +
                        NotecardExceptionInfo(exception))

    # If success, do a transaction loop
    print("Performing Transactions...")
    while True:
        time.sleep(2)
        transactionTest(card)
Exemplo n.º 3
0
    def connect_notecard(appConfig):
        """Connect to Notcard and run a transaction test."""
        print("Opening port...")
        use_uart = appConfig.PortType == config.PortType.UART or appConfig.PortType == config.PortType.USB
        try:
            if use_uart:
                uartMethodTimeoutMS = 10000
                port = UART(appConfig.PortID,
                            appConfig.PortBaudRate,
                            parity=None,
                            stop=1,
                            bits=8,
                            rx=Pin(17),
                            tx=Pin(16),
                            timeout=uartMethodTimeoutMS)

            else:
                port = I2C()
        except Exception as exception:
            raise Exception("error opening port: " +
                            NotecardExceptionInfo(exception))

        print("Opening Notecard...")
        try:
            if use_uart:
                card = notecard.OpenSerial(port, debug=appConfig.Debug)
            else:
                card = notecard.OpenI2C(port, 0, 0, debug=appConfig.Debug)
        except Exception as exception:
            raise Exception("error opening notecard: " +
                            NotecardExceptionInfo(exception))

        return card
Exemplo n.º 4
0
def main():

    # Initialize
    print("opening port")
    try:
        if sys.implementation.name == 'circuitpython':
            if use_uart:
                # https://circuitpython.readthedocs.io/en/2.x/shared-bindings/busio/UART.html
                port = busio.UART(board.TX, board.RX, baudrate=9600)
            else:
                # https://circuitpython.readthedocs.io/en/2.x/shared-bindings/busio/I2C.html
                port = busio.I2C(board.SCL, board.SDA)
        elif sys.implementation.name == 'micropython':
            if use_uart:
                # https://docs.micropython.org/en/latest/library/machine.UART.html
                # ESP32 IO2 RX:16 TX:17
                port = UART(2, 9600)
                port.init(9600, bits=8, parity=None, stop=1)
            else:
                # https://docs.micropython.org/en/latest/library/machine.I2C.html
                port = I2C()
        elif sys.implementation.name == 'cpython':
            if use_uart:
                # https://github.com/vsergeev/python-periphery#serial
                if sys.platform == "linux" or sys.platform == "linux2":
                    if use_periphery:
                        port = Serial("/dev/serial0", 9600)
                    else:
                        port = serial.Serial(port="/dev/serial0",
                                             baudrate=9600)
                elif sys.platform == "darwin":
                    port = serial.Serial(port="/dev/tty.usbmodemNOTE1",
                                         baudrate=9600)
                elif sys.platform == "win32":
                    port = serial.Serial(port="COM21",
                                         baudrate=9600)
            else:
                # https://github.com/vsergeev/python-periphery#i2c
                if use_periphery:
                    port = I2C("/dev/i2c-1")
                else:
                    raise Exception("I2C not supported on platform: "
                                    + sys.platform)
    except Exception as exception:
        raise Exception("error opening port: " + ExceptionInfo(exception))

    print("opening notecard")
    try:
        if use_uart:
            card = notecard.OpenSerial(port)
        else:
            card = notecard.OpenI2C(port, 0, 0)
    except Exception as exception:
        raise Exception("error opening notecard: " + ExceptionInfo(exception))

    # If success, do a transaction loop
    print("transaction loop")
    while True:
        time.sleep(2)
        transactionTest(card)
Exemplo n.º 5
0
def main():
    """Connect to Notcard and run a transaction test."""
    print("Opening port...")
    try:
        if sys.platform == "linux" or sys.platform == "linux2":
            if use_periphery:
                port = Serial("/dev/serial0", 9600)
            else:
                port = serial.Serial(port="/dev/serial0", baudrate=9600)
        elif sys.platform == "darwin":
            port = serial.Serial(port="/dev/tty.usbmodemNOTE1", baudrate=9600)
        elif sys.platform == "win32":
            port = serial.Serial(port="COM21", baudrate=9600)
    except Exception as exception:
        raise Exception("error opening port: " +
                        NotecardExceptionInfo(exception))

    print("Opening Notecard...")
    try:
        card = notecard.OpenSerial(port)
    except Exception as exception:
        raise Exception("error opening notecard: " +
                        NotecardExceptionInfo(exception))

    # If success, do a transaction loop
    print("Performing Transactions...")
    while True:
        time.sleep(2)
        transactionTest(card)
Exemplo n.º 6
0
def test_debug_mode_on_serial():
    serial = Mock()  # noqa: F811
    port = serial.Serial("/dev/tty.foo", 9600)
    port.read.side_effect = [b'\r', b'\n', None]

    nCard = notecard.OpenSerial(port, debug=True)

    assert nCard._debug
Exemplo n.º 7
0
def get_serial_and_port():
    serial = Mock()  # noqa: F811
    port = serial.Serial("/dev/tty.foo", 9600)
    port.read.side_effect = [b'\r', b'\n', None]

    nCard = notecard.OpenSerial(port)

    return (nCard, port)
Exemplo n.º 8
0
def connectNotecard(config):
    if config.PortType == 'i2c':
        port = I2C(config.PortName)
        card = notecard.OpenI2C(port, 0, 0, debug=config.EnableDebug)
    else:
        port = serial.Serial(port=config.PortName, baudrate=config.BaudRate)
        card = notecard.OpenSerial(port, debug=config.EnableDebug)

    return card
Exemplo n.º 9
0
def createNotecardAndPort():
    serial = Mock()  # noqa: F811
    port = serial.Serial("/dev/tty.foo", 9600)
    port.read.side_effect = [b'\r', b'\n', None]
    port.readline.return_value = "\r\n"
    port.write()

    nCard = notecard.OpenSerial(port)

    return (nCard, port)
Exemplo n.º 10
0
def connectToNotecard(debugFlag=defaultDebugFlag,
                      useSerial=defaultUseSerialFlag,
                      portName=defaultPortName,
                      baudRate=9600):
    if useSerial:
        port = serial.Serial(port=portName, baudrate=baudRate)
        card = notecard.OpenSerial(port, debug=debugFlag)
    else:
        port = I2C(portName)
        card = notecard.OpenI2C(port, 0, 0, debug=debugFlag)

    return card
Exemplo n.º 11
0
    def connect_notecard(appConfig):
        """Connect to Notcard and run a transaction test."""
        print("Opening port...")
        use_uart = appConfig.PortType == config.PortType.UART or appConfig.PortType == config.PortType.USB

        if not use_uart:
            raise Exception("only supports UART in CPython implementations")

        try:
            port = serial.Serial(port=appConfig.PortID,
                                 baudrate=appConfig.PortBaudRate)
        except Exception as exception:
            raise Exception("error opening port: " +
                            NotecardExceptionInfo(exception))

        print("Opening Notecard...")
        try:
            card = notecard.OpenSerial(port, debug=appConfig.Debug)
        except Exception as exception:
            raise Exception("error opening notecard: " +
                            NotecardExceptionInfo(exception))

        return card
import sys
import argparse
import time

from periphery import Serial
import notecard

port = Serial("/dev/serial0", 9600)
card = notecard.OpenSerial(port)

if card.uart is not None:
    print("Notecard connected...")


def send_request(req):
    try:
        rsp = card.Transaction(req)

        return rsp
    except Exception as exception:
        print("transaction error: " + ExceptionInfo(exception))


def ExceptionInfo(exception):
    s1 = '{}'.format(sys.exc_info()[-1].tb_lineno)
    s2 = exception.__class__.__name__
    return "line " + s1 + ": " + s2 + ": " + ' '.join(map(str, exception.args))


def main():
    print("Configuring card...")
Exemplo n.º 13
0
import board
import busio
import time
import json
import adafruit_bme680
import notecard

productUID = "com.your-company.your-project"

# Configure the serial connection to the Notecard
serial = busio.UART(board.TX, board.RX, baudrate=9600)
card = notecard.OpenSerial(serial)

req = {"req": "hub.set"}
req["product"] = productUID
req["mode"] = "continuous"
rsp = card.Transaction(req)

print(rsp)

# Configure the Adafruit BME680
i2c = busio.I2C(board.SCL, board.SDA)
bmeSensor = adafruit_bme680.Adafruit_BME680_I2C(i2c)

while True:
    temp = bmeSensor.temperature
    humidity = bmeSensor.humidity
    print("\nTemperature: %0.1f C" % temp)
    print("Humidity: %0.1f %%" % humidity)

    req = {"req": "note.add"}