Commit 54afefd5 authored by Gallacchi Mattia's avatar Gallacchi Mattia
Browse files

Add python serial

parent 0b6e6098
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
build/
.vscode/
__pycache__/
 No newline at end of file

poetry.lock

0 → 100644
+21 −0
Original line number Diff line number Diff line
[[package]]
name = "pyserial"
version = "3.5"
description = "Python Serial Port Extension"
category = "main"
optional = false
python-versions = "*"

[package.extras]
cp2110 = ["hidapi"]

[metadata]
lock-version = "1.1"
python-versions = "^3.10"
content-hash = "83470a6e1edc12e69f3d4c948150ce8c3f64d700d606daa8c7ca2dd0019c0d6c"

[metadata.files]
pyserial = [
    {file = "pyserial-3.5-py2.py3-none-any.whl", hash = "sha256:c4451db6ba391ca6ca299fb3ec7bae67a5c55dde170964c7a14ceefec02f2cf0"},
    {file = "pyserial-3.5.tar.gz", hash = "sha256:3c77e014170dfffbd816e6ffc205e9842efb10be9f58ec16d3e8675b4925cddb"},
]

pymcp2221a/__init__.py

0 → 100644
+0 −0

Empty file added.

pymcp2221a/mcp2221a.py

0 → 100644
+35 −0
Original line number Diff line number Diff line
import serial

class MCP2221ASerial:

    def __init__(self, port : str = "/dev/ttyACM0", baud: int = 115200):
        self.ser = None
        self.ser = serial.Serial(port, baud, timeout=1)

    def __del__(self):
        if self.ser is not None:
            self.ser.close()

    def write(self, data: bytearray):

        bytes = self.ser.write(data)
        if bytes < len(data):
            print("Failed to send")

    def read(self, size : int = 1) -> bytearray:

        data = self.ser.read(size)
        if len(data) < size:
            print("Failed to read")
        
        return data


if "__main__" == __name__:

    ser = MCP2221ASerial()

    data = b"Hello World!"
    ser.write(data)
    recv = ser.read(len(data))
    print(recv.decode())
 No newline at end of file

pyproject.toml

0 → 100644
+15 −0
Original line number Diff line number Diff line
[tool.poetry]
name = "pymcp2221a"
version = "0.1.0"
description = "Python module to interact with the MCP2221 IC"
authors = ["mattia.gallacchi <mattia.gallacchi@he-arc.ch>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.10"
pyserial = "^3.5"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"