Skip to content

jc211/JPLC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JPLC

This is code that augments Snap7 functionality so that you don't have to deal with bytes and can transfer information from a Siemens PLC directly to C# in a seamless manner. It allows you to describe UDTs and datablocks in C# using attributes.

Use

Lets say we had a datablock in a Siemens PLC called MyDatablock with various types of properties inside it.

To define it in JPLC, we make a class which inherits from JPLC_BASE.

using JPLC;
public class MyUDT : JPLC_BASE
{
    [Order(1)]
    public JPLCProperty<int> MyInteger { get; set; }
    
    public MyUDT(int address = 0) : base(address) { }
}
    
public class MyDatablock : JPLC_BASE
{
    [Order(1)]
    public JPLCProperty<int> MyInteger { get; set; }
    [Order(2)]
    public JPLCProperty<bool> MyBool { get; set; }
    [Order(3)]
    public JPLCProperty<MyUDT> MyCustomUDT { get; set; }
    [Order(4)]
    public JPLCProperty<DateTime> MyDateTime { get; set; }
    [Order(5)]
    public JPLCProperty<short> MyShort { get; set; }
    [Order(6)]
    public JPLCProperty<byte> MyByte { get; set; }
    [Order(7)]
    [ArraySize(10)]
    public JPLCProperty<int>[] SimpleArray { get; set; }
    [Order(8)]
    [ArraySize(10)]
    public JPLCProperty<MyUDT>[] UDTArray { get; set; }
    [Order(9)]
    [PLCString(150)]
    public JPLCProperty<string> MyString { get; set; }
    [Order(10)]
    public JPLCProperty<float> MyReal { get; set; }
    [Order(11)]
    [DoubleArraySize(10, 10)]
    public JPLCProperty<int>[,] DoubleArray { get; set; }
    [Order(12)]
    [DoubleArraySize(10, 10)]
    public JPLCProperty<MyUDT>[,] ComplexDoubleArray { get; set; }
    
    public MyDatablock(int address = 0) : base(address) { }
}

Connecting to the PLC

JPLCConnection is a wrapper around the S7Client.

var connection = JPLCConnection("192.168.0.1", 0 ,2)
connection.Connect(); 

var myDatablock = new MyDatablock();
myDatablock.ReadFromDB(connection, 24); // 24: Datablock Number

// To Write
myDatablock.MyBool.Value = false;
myDatablock.MyInteger.Value = 3;
myDatablock.WriteToDB(connection, 24); // 24: Datablock Number

Restrictions

Must be non-optimized datablock.

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages