Code Monkey home page Code Monkey logo

codesysnetvar's Introduction

CodesysNetVar

ru

What is it ?

This is a small project that allows communication between a Codesys-based PLC and a PC.

The project is based on transferring data from the PLC to the PC via Network Variables (Network Variable Lists / NVL). This is a basic Codesys functionality that allows you to transfer data to another PLC (or with this project to a PC) with minimal effort using the UDP protocol.

The project allows you to generate variable objects based on Codesys configuration files and receive data from the PLC. In addition, it is possible to automatically generate a table in a PostgreSQL or Sqlite3 database and populate it as you receive data.

structure

How to use it?

  1. In the Codeys PLC programming environment, add NVL sender;

Setup_1

  1. Set the IP address and port of the receiver. It is important to make sure that the handshake and delivery acknowledge bits are disabled. The PLC I had at hand did not change the sends because of these settings, but I admit that other vendors may change the sends or the behavior of the data transfer depending on these settings;

Setup_2

  1. Declare variables in the NVL for transmission;

Setup_3

  1. In the NVL settings choose to link to the file, this way the configuration file will be generated after confirmation. The file contains declaration of variables, communication settings.

Setup_4

configuration file

<GVL>
  <Declarations><![CDATA[VAR_GLOBAL
    sinus, cosine: REAL;
    some_word : WORD;
    integer : INT;
    my_time : TIME;
    my_date : DATE;
    my_string20 : STRING(20);
    my_array : ARRAY[0..4] OF INT;
END_VAR]]></Declarations>
  <NetvarSettings Protocol="UDP">
    <ListIdentifier>1</ListIdentifier>
    <Pack>True</Pack>
    <Checksum>False</Checksum>
    <Acknowledge>False</Acknowledge>
    <CyclicTransmission>True</CyclicTransmission>
    <TransmissionOnChange>False</TransmissionOnChange>
    <TransmissionOnEvent>False</TransmissionOnEvent>
    <Interval>T#500ms</Interval>
    <MinGap>T#20ms</MinGap>
    <EventVariable>
    </EventVariable>
    <ProtocolSettings>
      <ProtocolSetting Name="Broadcast Adr." Value="192.168.56.35" />
      <ProtocolSetting Name="Port" Value="1202" />
    </ProtocolSettings>
  </NetvarSettings>
</GVL>
  1. Copy this file to CodesysNetVar/external

  2. The project is configured through environment variables or an .env file. The .env file must be located in CodesysNetVar/settings. The database password must be in the form of file with no extension CNV_STORAGE___PASSWORD, inside there should be only the password, no spaces, indents, etc. file must be in the folder CodesysNetVar/settings/secrets.

.env

### Settings

## network
CNV_NETWORK___LOCAL_IP="192.168.56.35"
CNV_NETWORK___LOCAL_PORT="1202"

## storage
CNV_STORAGE___DB_TYPE="postgresql"  #or 'sqlite3'
CNV_STORAGE___IP_OR_PATH="127.0.0.1"  #or '/db.sqlite'
CNV_STORAGE___PORT="5432"
CNV_STORAGE___LOGIN="postgres"
CNV_STORAGE___DB_NAME="mydb"
CNV_STORAGE___TABLE_NAME_PREFIX="nvl"  #prefix for table in DB

##nvl_files
CNV_NVL___PATHS='["external/exp.gvl"]'

##logger
CNV_LOGGER___LEVEL_IN_STDOUT="INFO"  #or DEBUG, INFO, WARNING, ERROR or Comment this string for disable stdout
CNV_LOGGER___LEVEL_IN_FILE="INFO"  #or DEBUG, INFO, WARNING, ERROR or Comment this string for disable filelog
CNV_LOGGER___FILE_ROTATE="1 MB"  # see format in loguru
  1. Install and Run

install dependencies

poetry install

Run

poetry run python main.py

Result in DB

Information

  1. Codesys data type supported:
  • Bool, Byte, Word, DWord, LWord;
  • Int, DInt, LInt, UInt, UDInt, ULInt;
  • Real, LReal;
  • Time, Time of day, Date, Date and time;
  • String or Dimensional String(..);
  • Array of supported data types;
  1. Exchange with several PLCs at the same time is supported. This requires that the NVL IDs of the PLCs are unique. The generated NVL configuration files must be copied into CodesysNetVar/external and in .env the parameter CNV_NVL___PATHS='["external/exp1.gvl", "external/exp2.gvl"]' must list these files

Roadmap

  • Support Arrays data type in Unpack mode
  • Support more codesys data type
    • TIME_OF_DAY
    • DATE_AND_TIME
    • LTime
    • String without dimensional
    • Structure
  • Bulk write to DB
  • other

codesysnetvar's People

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.