Code Monkey home page Code Monkey logo

fxplc's Introduction

FXPLC

Python connector for low-level Mitsubishi MELSEC FX series (FX-232AW) serial protocol.

Protocol specification - Link

Note it is not the same as Non-Protocol Communication (or D8120) as described in FX Series Programmable Controllers manuals.

Overview

Python library and CLI utility allow to read and write PLC registers like X0, Y0, S0, T0, M0 and D0.

Example usage

Library

import asyncio
from contextlib import closing
from fxplc.client.FXPLCClient import FXPLCClient
from fxplc.transports.TransportSerial import TransportSerial
from fxplc.transports.TransportTCP import TransportTCP


async def main():
    transport = TransportSerial("/dev/ttyUSB0")
    # or, for TCP transport
    # transport = TransportTCP("192.168.1.100", 8888)
    # await transport.connect()

    with closing(FXPLCClient(transport)) as fx:
        s0_state = await fx.read_bit("S0")
        t0_state = await fx.read_bit("T0")
        t0_value = await fx.read_int("T0")

        await fx.write_bit("S1", True)


asyncio.run(main())

CLI

fxplc -p /dev/ttyUSB0 read_bit S0
fxplc -p /dev/ttyUSB0 read_bit T0
fxplc -p /dev/ttyUSB0 read_int T0
fxplc -p tcp:192.168.1.100:8888 read_int T0

fxplc -p /dev/ttyUSB0 write_bit S1 on

fxplc -p /dev/ttyUSB0 read S0 T0
# S0 = off
# T0 = on, counter: 30

HTTP server

The project also includes HTTP webserver subproject which exposes REST API for external clients. It also serves a simple UI that allows variables viewing and modifying.

Usage

python --variables vars.yaml --path /dev/ttyUSB0
python --variables vars.yaml --path tcp:10.5.12.10:8887

Example variables file

vars.yaml

variables:
  - name: PUMP
    register: M10
  - name: MIXER_OPEN
    register: D0
  - name: MIXER_CLOSE
    register: D1
  - name: OUT_PUMP
    register: Y000
  - name: OUT_MIXER_OPEN
    register: Y000
  - name: OUT_MIXER_CLOSE
    register: Y001
  - name: FLOW_COUNTER_1
    register: D50

.github/rest.png

.github/ui_example.png

Compatibility

Tested on:

  • FX1N-06MR (chinese clone)
  • FX1N-20MR (chinese clone)
  • FX3U-24MR (chinese clone)
  • FX3U-48MR (chinese clone)

fxplc's People

Contributors

krystiand avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

jerry-zww szf2020

fxplc's Issues

Unable to connect with the PLC of FX series

Hi,

Thanks for the library, for FX series PLC's.

I am trying to connect with the PLC, but i am unable to connect. My PLC is FX3U and FX5U. I am using python script similar to provided by you in the document, but it throws me error as,
image

I can see the error is thrown at transport.connect itself. Here, in the snippet, i have tried read method of transport too, in order to verify the connection, even if we remove that and keep the code same as given in the document , the error is same. However, the plc is available at the pointed ip-address and port, i have verified this.

It will be helpful if you can guide, what mistake i am making!!

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.