GithubHelp home page GithubHelp logo

fisothemes / fisothemes-common-library-for-twincat Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 2.23 MB

A library for providing a set of common utilities and definitions that streamline and standardise the development of PLC applications. The library offers a set of reusable components that simplify everyday tasks and ensure consistency across projects.

License: MIT License

beckhoff common framework iec-st library plc twincat twincat3 codesys plc-programming

fisothemes-common-library-for-twincat's Introduction

FisoThemes' Common Library for TwinCAT

Overview

A library for providing a set of common utilities and definitions that streamline and standardise the development of PLC applications. The library offers a set of reusable components that simplify everyday tasks and ensure consistency across projects.

Features

  • Memory Management Utilities: Functions for dynamic and static memory management, ensuring efficient memory usage and safety.
  • Hashing Functions: Efficient hashing functions for data integrity and change detection.
  • Type Aliases: Predefined type aliases for common data types to simplify code readability and maintenance.
  • Type Limits: Constants defining the limits of various data types, helping to enforce value constraints and prevent errors.
  • Task Information Interfaces: Interfaces and function blocks for retrieving and managing PLC task information, including detecting PLC cycle changes.
  • Processor Architecture Information: Easy access to processor architecture details.
  • Value Change Detection: Function blocks for detecting changes in variable values, enabling responsive and adaptive control logic.
  • Flag Resetting: Functions for resetting boolean values, useful for state management in PLC programs.
  • Cycle Time Monitoring: Tools for monitoring and responding to PLC cycle times, ensuring timely execution of control logic.
  • Random Number Generation: A fast and memory-efficient function block for generating random integers and real numbers, including ranged random numbers.
  • Decimal Places Setting: Rounding of real values to a specified number of decimal places.

Usage

Example: Memory Management

VAR
    pDynamicMemory : POINTER TO BYTE;
END_VAR

// Allocate memory
pDynamicMemory := F_AllocateMemory(100);

// Checks if the memory is in stack or heap and then deallocates memory
IF pDynamicMemory <> 0 THEN
    F_DeallocateMemory(pDynamicMemory);
    END_IF

Example: Value Change Detection

VAR
    fbValueChangeDetector   : FB_ValueChangeDetector;
    bValueChanged           : BOOL;
    nValue                  : INT;
END_VAR

// Value to watch for change
fbValueChangeDetector(Value := nValue);

// Check if the value has changed
IF fbValueChangeDetector.HasChanged THEN
    // Handle the value change
    END_IF

Example: PLC Task Information

VAR
    nCycleCount     : UDINT;
    tCycleTime,
    tLastExecTime   : LTIME;
END_VAR


// Get the cycle count of the current task
nCycleCount     := F_GetCurrentPlcTaskInformation().CycleCount;

// Get the task cycle time
tCycleTime      := F_GetCurrentPlcTaskInformation().CycleTime

// Get the execution time of the last cycle
tLastExecTime   := F_GetCurrentPlcTaskInformation().LastCycleExecutionTime;

Example: Random Number Generation

VAR
    fbGenRand       : FB_RandomNumberGenerator(0); // FB_RandomNumberGenerator(<seed>)
    nRand1, nRand2  : LINT;
    fRand1, fRand2  : LREAL;
END_VAR

// Generate random integers and real numbers
nRand1 := fbGenRand.NextInt();
nRand2 := fbGenRand.NextRangedInt(-10, 100);
fRand1 := fbGenRand.NextReal();
fRand2 := fbGenRand.NextRangedReal(5.8, 8.92);

Comparison with LabVIEW's Random Number Generator

Example: PLC Task Cycle Change Detection

METHOD DoSomething : BOOL
VAR_INST
    fbTaskCycleChanged : FB_PlcTaskCycleChangeDetector(1); // FB_PlcTaskCycleChangeDetector(<Task Index>)
END_VAR

// Check if the task cycle has changed
IF fbTaskCycleChanged.HasChanged THEN
    // Handle the task cycle change
    END_IF
...
END_METHOD

Example: Setting Decimal Places

VAR
    fOriginalValue  : LREAL := 123.456789;
    fRoundedValue   : LREAL;
    nDecimalPlaces  : USINT := 2;
END_VAR

fRoundedValue := F_SetDecimalPlaces(fOriginalValue, nDecimalPlaces);
// fRoundedValue will be 123.46

Developer Notes

This project is still in development. There's a lot of work and testing ahead. Changes to functionality may occur in the future.

This is designed to be part of a larger framework that is still under development.

fisothemes-common-library-for-twincat's People

Contributors

fisothemes avatar

Watchers

 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.