C# 클래스 ENDA.PLCNetLib.PLC

Represents a PLC device.

Please note that all of the functions except the ones beginning with Begin* and End* are blocking and calling these functions will block until a response is received from the PLC device. If there's a communication problem your application will block (freeze) until a timeout occur.

You can either use blocking methods in a separate thread or use advanced asynchronous methods for a non blocking usage.

파일 보기 프로젝트 열기: engina/PLCNetLib 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
IP ENDA.PLCNetLib.Accessors.BoolArrayAccessor
MB ENDA.PLCNetLib.Accessors.BoolArrayAccessor
MF ENDA.PLCNetLib.Accessors.FloatArrayAccessor
MI ENDA.PLCNetLib.Accessors.Int32ArrayAccessor
MW ENDA.PLCNetLib.Accessors.UInt16ArrayAccessor
QP ENDA.PLCNetLib.Accessors.BoolArrayAccessor

Private Properties

프로퍼티 타입 설명
IP2Int int
Int2IP System.Net.IPAddress
ReadUntil Response
ReadUntil Response
ReadUntil Response

공개 메소드들

메소드 설명
BeginCmd ( byte buf, AsyncCallback cb, object state ) : IAsyncResult

Sends buf byte array command to the PLC asynchronously.

This method returns immediately. When the response is received cb will be invoked.

BeginConnect ( AsyncCallback cb, object state ) : IAsyncResult
BeginRead ( int offset, int len, AsyncCallback cb, object state ) : IAsyncResult

Starts an async reading.

BeginReadMulti ( ushort offsets, AsyncCallback cb, object state ) : IAsyncResult

Begins an asynchronous multiple read.

BeginWriteRaw ( int offset, byte data, AsyncCallback cb, object state ) : IAsyncResult

Writes raw data to PLC memory in the given offset asynchronously.

When the write operation is complete cb will be invoked (from another thread).

Cmd ( byte buf ) : Response

Sends a byte stream as a telnet command.

Cmd ( string cmd ) : Response

Sends a string as a telnet command.

ConfigureNetwork ( IPAddress ip, IPAddress nm, IPAddress gw, IPAddress dns ) : void

Configures the networking configuration of the PLC. If either ip or dns is 0.0.0.0 or 255.255.255.255 the device puts itself in DHCP mode and tries to acquire IP automatically. If your configuration changed any of ip, nm or gw all connections to the device will be closed. After sending this command, this object will update its IP configuration regardless of any response and will try to reconnect during next data send. Note that reconnections will block. Also, note that, if a not working DNS configuration is provided, WMI feature of the PLC won't be usable.

Connect ( ) : void

Attempts to connect to the PLC. This method will be automatically called if a data send attempt is made prior to connecting, partly because of your convenience and partly for making the library handle disconnections better.

It is a good practice to initally call this method first to check if the password is correct.

Disconnect ( ) : void
EndCmd ( IAsyncResult ar ) : Response

Ends a BeginCmd asynchronous call.

EndConnect ( IAsyncResult ar ) : void
EndRead ( IAsyncResult ar ) : BinaryReader
EndReadMulti ( IAsyncResult ar ) : BinaryReader
EndWrite ( IAsyncResult ar ) : void

Ends a asynchronous BeginWriteRaw call.

PLC ( IPAddress ip, string password ) : System

Connects to said PLC with given IP and password on default port 23.

PLC ( IPEndPoint ip, string password ) : System

Initiates a PLC object. Does not automatically connect until said. Finder can be used to find IP addresses of PLC devices from PLC serial numbers (MAC addresses).

Read ( int offset, int len ) : BinaryReader

Reads len bytes of data from offset sequentially.

ReadMulti ( ushort offsets ) : BinaryReader

Reads 4-byte values from PLC memory at arbitrary offsets given as offsets. Usefull for reading non sequential data from PLC memory. Unlike alternatives, it does all the reading in a single network packet roundtrip, hence it is higher performance, yet harder to use.

Reboot ( ) : void

Sends a reboot command to the PLC. Your connection will be lost.

Rewrite ( ) : void

Rewrites last command

Run ( ) : bool

Sends run command to the PLC.

Send ( byte data ) : void
Send ( string str ) : void
Stop ( ) : bool

Sends stop command to the PLC.

ToString ( ) : string
UpdateFirmware ( string path ) : void

Updates the firmware.

UpdateNetwork ( ) : void
Write ( int offset, byte data ) : void

Writes whole data to PLC memory at offset, sequentially.

Write ( int offset, float value ) : void

Writes a floating point value to the given offset.

Write ( int offset, int value ) : void

Writes an Int32 value to the given offset.

Write ( int offset, ushort value ) : void

Writes a UInt16 value to the given offset.

비공개 메소드들

메소드 설명
IP2Int ( IPAddress addr ) : int
Int2IP ( int addr ) : IPAddress
ReadUntil ( ) : Response

Reads until command prompt.

ReadUntil ( String untils ) : Response

Waits until any of the strings in the untils array matched.

ReadUntil ( string str ) : Response

Reads until a str matched

메소드 상세

BeginCmd() 공개 메소드

Sends buf byte array command to the PLC asynchronously.

This method returns immediately. When the response is received cb will be invoked.

public BeginCmd ( byte buf, AsyncCallback cb, object state ) : IAsyncResult
buf byte ///
cb AsyncCallback Callback to be called when the operation is complete.
state object Any state to be passed to when invoked, it's a good idea to use the PLC instance as state.
리턴 IAsyncResult

BeginConnect() 공개 메소드

public BeginConnect ( AsyncCallback cb, object state ) : IAsyncResult
cb AsyncCallback
state object
리턴 IAsyncResult

BeginRead() 공개 메소드

Starts an async reading.
public BeginRead ( int offset, int len, AsyncCallback cb, object state ) : IAsyncResult
offset int
len int
cb AsyncCallback
state object
리턴 IAsyncResult

BeginReadMulti() 공개 메소드

Begins an asynchronous multiple read.
public BeginReadMulti ( ushort offsets, AsyncCallback cb, object state ) : IAsyncResult
offsets ushort
cb AsyncCallback
state object
리턴 IAsyncResult

BeginWriteRaw() 공개 메소드

Writes raw data to PLC memory in the given offset asynchronously.

When the write operation is complete cb will be invoked (from another thread).

public BeginWriteRaw ( int offset, byte data, AsyncCallback cb, object state ) : IAsyncResult
offset int Offset of the memory location in the whole PLC memory in bytes.
data byte Byte array of the data you want to write. This can contain sequential 4-byte integers, floats or 2-byte unsigned hosrts or 1-byte data.
cb AsyncCallback Callback to be called when the operation is complete.
state object Any state to be passed to when invoked, it's a good idea to use the PLC instance as state.
리턴 IAsyncResult

Cmd() 공개 메소드

Sends a byte stream as a telnet command.
public Cmd ( byte buf ) : Response
buf byte telnet command as byte array
리턴 Response

Cmd() 공개 메소드

Sends a string as a telnet command.
public Cmd ( string cmd ) : Response
cmd string
리턴 Response

ConfigureNetwork() 공개 메소드

Configures the networking configuration of the PLC. If either ip or dns is 0.0.0.0 or 255.255.255.255 the device puts itself in DHCP mode and tries to acquire IP automatically. If your configuration changed any of ip, nm or gw all connections to the device will be closed. After sending this command, this object will update its IP configuration regardless of any response and will try to reconnect during next data send. Note that reconnections will block. Also, note that, if a not working DNS configuration is provided, WMI feature of the PLC won't be usable.
public ConfigureNetwork ( IPAddress ip, IPAddress nm, IPAddress gw, IPAddress dns ) : void
ip System.Net.IPAddress IP Address of the PLC
nm System.Net.IPAddress Netmask
gw System.Net.IPAddress Gateway IP
dns System.Net.IPAddress DNS IP
리턴 void

Connect() 공개 메소드

Attempts to connect to the PLC. This method will be automatically called if a data send attempt is made prior to connecting, partly because of your convenience and partly for making the library handle disconnections better.

It is a good practice to initally call this method first to check if the password is correct.

Thrown if the password is wrong.
public Connect ( ) : void
리턴 void

Disconnect() 공개 메소드

public Disconnect ( ) : void
리턴 void

EndCmd() 공개 메소드

Ends a BeginCmd asynchronous call.
public EndCmd ( IAsyncResult ar ) : Response
ar IAsyncResult
리턴 Response

EndConnect() 공개 메소드

public EndConnect ( IAsyncResult ar ) : void
ar IAsyncResult
리턴 void

EndRead() 공개 메소드

public EndRead ( IAsyncResult ar ) : BinaryReader
ar IAsyncResult
리턴 System.IO.BinaryReader

EndReadMulti() 공개 메소드

public EndReadMulti ( IAsyncResult ar ) : BinaryReader
ar IAsyncResult
리턴 System.IO.BinaryReader

EndWrite() 공개 메소드

Ends a asynchronous BeginWriteRaw call.
public EndWrite ( IAsyncResult ar ) : void
ar IAsyncResult
리턴 void

PLC() 공개 메소드

Connects to said PLC with given IP and password on default port 23.
public PLC ( IPAddress ip, string password ) : System
ip System.Net.IPAddress
password string
리턴 System

PLC() 공개 메소드

Initiates a PLC object. Does not automatically connect until said. Finder can be used to find IP addresses of PLC devices from PLC serial numbers (MAC addresses).

public PLC ( IPEndPoint ip, string password ) : System
ip System.Net.IPEndPoint IP of the PLC
password string Password of the PLC
리턴 System

Read() 공개 메소드

Reads len bytes of data from offset sequentially.
Thrown when offset and/or length is out of PLC memory boundaries.
public Read ( int offset, int len ) : BinaryReader
offset int Offset in bytes.
len int Length in bytes.
리턴 System.IO.BinaryReader

ReadMulti() 공개 메소드

Reads 4-byte values from PLC memory at arbitrary offsets given as offsets. Usefull for reading non sequential data from PLC memory. Unlike alternatives, it does all the reading in a single network packet roundtrip, hence it is higher performance, yet harder to use.
public ReadMulti ( ushort offsets ) : BinaryReader
offsets ushort List of offsets in bytes.
리턴 System.IO.BinaryReader

Reboot() 공개 메소드

Sends a reboot command to the PLC. Your connection will be lost.
public Reboot ( ) : void
리턴 void

Rewrite() 공개 메소드

Rewrites last command
public Rewrite ( ) : void
리턴 void

Run() 공개 메소드

Sends run command to the PLC.
public Run ( ) : bool
리턴 bool

Send() 공개 메소드

public Send ( byte data ) : void
data byte
리턴 void

Send() 공개 메소드

public Send ( string str ) : void
str string
리턴 void

Stop() 공개 메소드

Sends stop command to the PLC.
public Stop ( ) : bool
리턴 bool

ToString() 공개 메소드

public ToString ( ) : string
리턴 string

UpdateFirmware() 공개 메소드

Updates the firmware.
public UpdateFirmware ( string path ) : void
path string The path.
리턴 void

UpdateNetwork() 공개 메소드

public UpdateNetwork ( ) : void
리턴 void

Write() 공개 메소드

Writes whole data to PLC memory at offset, sequentially.
public Write ( int offset, byte data ) : void
offset int Offset in bytes.
data byte Data to be written
리턴 void

Write() 공개 메소드

Writes a floating point value to the given offset.
public Write ( int offset, float value ) : void
offset int Offset in bytes
value float Float value
리턴 void

Write() 공개 메소드

Writes an Int32 value to the given offset.
public Write ( int offset, int value ) : void
offset int Offset in bytes
value int Int32 value
리턴 void

Write() 공개 메소드

Writes a UInt16 value to the given offset.
public Write ( int offset, ushort value ) : void
offset int Offset in bytes
value ushort UInt16 value
리턴 void

프로퍼티 상세

IP 공개적으로 프로퍼티

MI registers of PLC. These are general purpose integer registers. Consists of 1024 4-byte integers. Each read and write attempt will result in a network transmission. plc.MI[5] = 10; Console.Out.WriteLine(plc.MI[5]);
Thrown when offset and/or length is out of PLC memory boundaries.
public BoolArrayAccessor,ENDA.PLCNetLib.Accessors IP
리턴 ENDA.PLCNetLib.Accessors.BoolArrayAccessor

MB 공개적으로 프로퍼티

MI registers of PLC. These are general purpose integer registers. Consists of 1024 4-byte integers. Each read and write attempt will result in a network transmission. plc.MI[5] = 10; Console.Out.WriteLine(plc.MI[5]);
Thrown when offset and/or length is out of PLC memory boundaries.
public BoolArrayAccessor,ENDA.PLCNetLib.Accessors MB
리턴 ENDA.PLCNetLib.Accessors.BoolArrayAccessor

MF 공개적으로 프로퍼티

MI registers of PLC. These are general purpose integer registers. Consists of 1024 4-byte integers. Each read and write attempt will result in a network transmission. plc.MI[5] = 10; Console.Out.WriteLine(plc.MI[5]);
Thrown when offset and/or length is out of PLC memory boundaries.
public FloatArrayAccessor,ENDA.PLCNetLib.Accessors MF
리턴 ENDA.PLCNetLib.Accessors.FloatArrayAccessor

MI 공개적으로 프로퍼티

MI registers of PLC, consists of 1024 4-byte integers. Each read and write attempt will result in a network transmission. plc.MI[5] = 10; Console.Out.WriteLine(plc.MI[5]);
Thrown when offset and/or length is out of PLC memory boundaries.
public Int32ArrayAccessor,ENDA.PLCNetLib.Accessors MI
리턴 ENDA.PLCNetLib.Accessors.Int32ArrayAccessor

MW 공개적으로 프로퍼티

MI registers of PLC. These are general purpose integer registers. Consists of 1024 4-byte integers. Each read and write attempt will result in a network transmission. plc.MI[5] = 10; Console.Out.WriteLine(plc.MI[5]);
Thrown when offset and/or length is out of PLC memory boundaries.
public UInt16ArrayAccessor,ENDA.PLCNetLib.Accessors MW
리턴 ENDA.PLCNetLib.Accessors.UInt16ArrayAccessor

QP 공개적으로 프로퍼티

MI registers of PLC. These are general purpose integer registers. Consists of 1024 4-byte integers. Each read and write attempt will result in a network transmission. plc.MI[5] = 10; Console.Out.WriteLine(plc.MI[5]);
Thrown when offset and/or length is out of PLC memory boundaries.
public BoolArrayAccessor,ENDA.PLCNetLib.Accessors QP
리턴 ENDA.PLCNetLib.Accessors.BoolArrayAccessor