Giter Site home page Giter Site logo

demo-smart-factory-concordia-university / mtcadapterrelay Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 42 KB

MTConnect Adapter acting as a relay for a device sending SHDR data on serial port

License: BSD 3-Clause "New" or "Revised" License

C++ 34.41% Python 65.59%
mtconnect mtconnect-adapter serial-communication arduino

mtcadapterrelay's Introduction

MTCAdapterRelay

MTConnect Adapter acting as a relay for a physical device (e.g. a sensor) sending SHDR data on the serial port.

The MTCAdapterReay allows to hock up a device capable of sending SHDR data on the serial port but not capable of sending TCP/IP data to an MTConnect Agent.

The MTCAdapterRelay is a small Python library desinged to work together with the MTConnect cpp agent.

Usage

Two classes need to be defined: an MTCAdapterRelayHandler and a MTCAdapterRelay class.

MTCAdapterRelayHandler

The MTCAdapterRelayHandler is responsible to define the proper parameters for communicating with the device over the serial port.

At minimum the 'serial_port' attribute must be defined. It is the name of the Linux device file to access the serial port (e.g. /dev/ttyUSB1).

Further the following attributes may have to be redfined to match the configuration of the used serial port:

baudrate = 115200
parity = serial.PARITY_NONE
bytesize = serial.EIGHTBITS
stopbits = serial.STOPBITS_ONE

MTCAdapterRelay

The MTCAdapterRelay class is a specialized TCP/IP server which implements the PING/PONG hearthbeat convention of the MTConnect cpp agent.

The attribute adapter_port (default value 7878) holds the port number on which the adapter relay will run.

The attribute deviceHandler_class must contain the MTCAdapterRelayHandler class defining the correct serial port paramters to communicate with the device.

Example

A typical example looks like this (this is an example for a temperature sensor connected via an Arduino type device. The Arduino sketch is availble here):

from mtcadapterrelay import MTCAdapterRelay, MTCAdapterRelayHandler
import sys


class DS18B20_MTCAdapterRelayHandler(MTCAdapterRelayHandler):
    
    serial_port = '/dev/ttyUSB1'
    baudrate = 115200
    parity = serial.PARITY_NONE
    bytesize = serial.EIGHTBITS
    stopbits = serial.STOPBITS_ONE


class DS18B20_MTCAdapterRelay(MTCAdapterRelay):
    
    adapter_port = 8881
    deviceHandler_class = DS18B20_MTCAdapterRelayHandler

    
myAdapter = DS18B20_MTCAdapterRelay()
try:
    myAdapter.serve_forever()
except KeyboardInterrupt:
    sys.exit(0)

mtcadapterrelay's People

Contributors

rwuthric avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.