Skip to main content

based pydevmgr object for serial communication

Project description

An pydevmgr_core extension for serial communication

Sources are here

Doc to comme

Install

> pip install pydevmgr_serial 

Basic Usage

Bellow is an exemple of implementation of a node that check a value from a Tesla Sensor. An extra configuration argument is added and the fget method is implemented.

from pydevmgr_serial import BaseSerialNode
import time

    
class TesaNode(BaseSerialNode):
    class Config:
        delay: float = 0.1
        
    def fget(self):
        self.serial.write(b'?\r')
        time.sleep(self.config.delay)
        sval = self.serial.read(20)
        val = float(sval)
        return val

you can simply use the node with a Serial object :

from serial import Serial 

# build a standalone node 
com = Serial(port='COM1', baudrate=9600)
tesa = TesaNode(com=com)

print( "Position is ", tesa.get() )
com.close()

One can include the node in a serial device which will hold the communcation

Note: One creating a SerialDevice the port is not directly opened one needs to use the connect method or within a with statement.

from pydevmgr_serial import SerialDevice
from pydevmgr_core import nodealias



class Tesa(SerialDevice):    
    raw_pos = TesaNode.Config()
    
    @nodealias('raw_pos')
    def position(self, raw_pos):
        return 10 + 1.3 * raw_pos    
tesa = Tesa('tesa',  port ='COM1', baudrate=9600)

with tesa:
    tesa.position.get()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydevmgr_serial-0.6a0.tar.gz (3.6 kB view hashes)

Uploaded Source

Built Distribution

pydevmgr_serial-0.6a0-py3-none-any.whl (4.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page