Метод | Описание | |
---|---|---|
ClearLastError ( ) : void |
Sets the LastErrorCode to NoError and LastErrorString to String.Empty
|
|
Close ( ) : void |
Disonnects from the plc and close the socket
|
|
Dispose ( ) : void |
Releases all resources, disonnects from the plc and closes the socket
|
|
Open ( ) : ErrorCode |
Open a socket and connects to the plc, sending all the corrected package and returning if the connection was successful (ErroreCode.NoError) of it was wrong.
|
|
Plc ( CpuType cpu, string ip, |
Creates a PLC object with all the parameters needed for connections. For S7-1200 and S7-1500, the default is rack = 0 and slot = 0. You need slot > 0 if you are connecting to external ethernet card (CP). For S7-300 and S7-400 the default is rack = 0 and slot = 2.
|
|
Read ( DataType dataType, int db, int startByteAdr, VarType varType, int varCount ) : object |
Read and decode a certain number of bytes of the "VarType" provided. This can be used to read multiple consecutive variables of the same type (Word, DWord, Int, etc). If the read was not successful, check LastErrorCode or LastErrorString.
|
|
Read ( string variable ) : object |
Reads a single variable from the plc, takes in input strings like "DB1.DBX0.0", "DB20.DBD200", "MB20", "T45", etc. If the read was not successful, check LastErrorCode or LastErrorString.
|
|
ReadBytes ( DataType dataType, int db, int startByteAdr, int count ) : byte[] |
Reads a number of bytes from a DB starting from a specified index. This handles more than 200 bytes with multiple requests. If the read was not successful, check LastErrorCode or LastErrorString.
|
|
ReadClass ( object sourceClass, int db, int startByteAdr ) : void |
Reads all the bytes needed to fill a class in C#, starting from a certain address, and set all the properties values to the value that are read from the plc. This reads ony properties, it doesn't read private variable or public variable without {get;set;} specified.
|
|
ReadMultipleVars ( List |
Reads multiple vars in a single request. You have to create and pass a list of DataItems and you obtain in response the same list with the values. Values are stored in the property "Value" of the dataItem and are already converted. If you don't want the conversion, just create a dataItem of bytes. DataItems must not be more than 20 (protocol restriction) and bytes must not be more than 200 + 22 of header (protocol restriction).
|
|
ReadStruct ( |
Reads all the bytes needed to fill a struct in C#, starting from a certain address, and return an object that can be casted to the struct.
|
|
Write ( DataType dataType, int db, int startByteAdr, object value ) : ErrorCode |
Takes in input an object and tries to parse it to an array of values. This can be used to write many data, all of the same type. You must specify the memory area type, memory are address, byte start address and bytes count. If the read was not successful, check LastErrorCode or LastErrorString.
|
|
Write ( string variable, object value ) : ErrorCode |
Writes a single variable from the plc, takes in input strings like "DB1.DBX0.0", "DB20.DBD200", "MB20", "T45", etc. If the write was not successful, check LastErrorCode or LastErrorString.
|
|
WriteBytes ( DataType dataType, int db, int startByteAdr, byte value ) : ErrorCode |
Write a number of bytes from a DB starting from a specified index. This handles more than 200 bytes with multiple requests. If the write was not successful, check LastErrorCode or LastErrorString.
|
|
WriteClass ( object classValue, int db, int startByteAdr ) : ErrorCode |
Writes a C# class to a DB in the plc
|
|
WriteStruct ( object structValue, int db, int startByteAdr ) : ErrorCode |
Writes a C# struct to a DB in the plc
|
Метод | Описание | |
---|---|---|
CreateReadDataRequestPackage ( DataType dataType, int db, int startByteAdr, int count = 1 ) : |
Create the bytes-package to request data from the plc. You have to specify the memory type (dataType), the address of the memory, the address of the byte and the bytes count.
|
|
ParseBytes ( VarType varType, byte bytes, int varCount ) : object |
Given a S7 variable type (Bool, Word, DWord, etc.), it converts the bytes in the appropriate C# format.
|
|
ReadBytesWithASingleRequest ( DataType dataType, int db, int startByteAdr, int count ) : byte[] | ||
ReadHeaderPackage ( int amount = 1 ) : |
Creates the header to read bytes from the plc
|
|
VarTypeToByteLength ( VarType varType, int varCount = 1 ) : int |
Given a S7 variable type (Bool, Word, DWord, etc.), it returns how many bytes to read.
|
|
WriteBytesWithASingleRequest ( DataType dataType, int db, int startByteAdr, byte value ) : ErrorCode |
Writes up to 200 bytes to the plc and returns NoError if successful. You must specify the memory area type, memory are address, byte start address and bytes count. If the write was not successful, check LastErrorCode or LastErrorString.
|
public Plc ( CpuType cpu, string ip, |
||
cpu | CpuType | CpuType of the plc (select from the enum) |
ip | string | Ip address of the plc |
rack | rack of the plc, usually it's 0, but check in the hardware configuration of Step7 or TIA portal | |
slot | slot of the CPU of the plc, usually it's 2 for S7300-S7400, 0 for S7-1200 and S7-1500. /// If you use an external ethernet card, this must be set accordingly. | |
Результат | System |
public Read ( DataType dataType, int db, int startByteAdr, VarType varType, int varCount ) : object | ||
dataType | DataType | Data type of the memory area, can be DB, Timer, Counter, Merker(Memory), Input, Output. |
db | int | Address of the memory area (if you want to read DB1, this is set to 1). This must be set also for other memory area types: counters, timers,etc. |
startByteAdr | int | Start byte address. If you want to read DB1.DBW200, this is 200. |
varType | VarType | Type of the variable/s that you are reading |
varCount | int | |
Результат | object |
public Read ( string variable ) : object | ||
variable | string | Input strings like "DB1.DBX0.0", "DB20.DBD200", "MB20", "T45", etc. |
Результат | object |
public ReadBytes ( DataType dataType, int db, int startByteAdr, int count ) : byte[] | ||
dataType | DataType | Data type of the memory area, can be DB, Timer, Counter, Merker(Memory), Input, Output. |
db | int | Address of the memory area (if you want to read DB1, this is set to 1). This must be set also for other memory area types: counters, timers,etc. |
startByteAdr | int | Start byte address. If you want to read DB1.DBW200, this is 200. |
count | int | Byte count, if you want to read 120 bytes, set this to 120. |
Результат | byte[] |
public ReadClass ( object sourceClass, int db, int startByteAdr ) : void | ||
sourceClass | object | Instance of the class that will store the values |
db | int | Index of the DB; es.: 1 is for DB1 |
startByteAdr | int | Start byte address. If you want to read DB1.DBW200, this is 200. |
Результат | void |
public ReadMultipleVars ( List |
||
dataItems | List |
List of dataitems that contains the list of variables that must be read. Maximum 20 dataitems are accepted. |
Результат | void |
public ReadStruct ( |
||
structType | Type of the struct to be readed (es.: TypeOf(MyStruct)). | |
db | int | Address of the DB. |
startByteAdr | int | Start byte address. If you want to read DB1.DBW200, this is 200. |
Результат | object |
public Write ( DataType dataType, int db, int startByteAdr, object value ) : ErrorCode | ||
dataType | DataType | Data type of the memory area, can be DB, Timer, Counter, Merker(Memory), Input, Output. |
db | int | Address of the memory area (if you want to read DB1, this is set to 1). This must be set also for other memory area types: counters, timers,etc. |
startByteAdr | int | Start byte address. If you want to read DB1.DBW200, this is 200. |
value | object | Bytes to write. The lenght of this parameter can't be higher than 200. If you need more, use recursion. |
Результат | ErrorCode |
public Write ( string variable, object value ) : ErrorCode | ||
variable | string | Input strings like "DB1.DBX0.0", "DB20.DBD200", "MB20", "T45", etc. |
value | object | Value to be written to the plc |
Результат | ErrorCode |
public WriteBytes ( DataType dataType, int db, int startByteAdr, byte value ) : ErrorCode | ||
dataType | DataType | Data type of the memory area, can be DB, Timer, Counter, Merker(Memory), Input, Output. |
db | int | Address of the memory area (if you want to read DB1, this is set to 1). This must be set also for other memory area types: counters, timers,etc. |
startByteAdr | int | Start byte address. If you want to write DB1.DBW200, this is 200. |
value | byte | Bytes to write. If more than 200, multiple requests will be made. |
Результат | ErrorCode |
public WriteClass ( object classValue, int db, int startByteAdr ) : ErrorCode | ||
classValue | object | The class to be written |
db | int | Db address |
startByteAdr | int | Start bytes on the plc |
Результат | ErrorCode |
public WriteStruct ( object structValue, int db, int startByteAdr ) : ErrorCode | ||
structValue | object | The struct to be written |
db | int | Db address |
startByteAdr | int | Start bytes on the plc |
Результат | ErrorCode |