日本語 English

finsdll
API Reference (OMRON PLC FINS Communication Library)

Related pages

For an explanation of FinsMes, see the FinsMes page

For an explanation of FINS communication, see FINS Message Communication

For an explanation of FINS commands, see the manuals for the CJ1W-ETN21:
Communications Commands Reference Manual and Ethernet Unit Operation Manual (Construction of Applications)

Osd.Omron.Fins class

Constructor
ConstructorDescription
Fins()Initializes a new instance of the Fins class
Properties
PropertiesDescription
MessageLogGets the communication log
ClientFinsAddressSets and gets the source FINS address
ServerFinsAddressSets and gets the destination FINS address
Methods
MethodsDescription
Connect(string, bool)Connects via UDP or TCP to the specified IP address
Close()Closes the connection
SendCommand(byte[])Sends a FINS command to the connected host
MemOffset(string, short)Converts a memory address notation to the FINS command memory specification
read(string, int)Memory area read (0101)
write(string, byte[])Memory area write (0102)
fill(string, int, byte[])Memory area fill (0103)
MultiRead(string)Multiple memory area read (0104)
run(byte)Change operating mode (0401)
stop()Stop operation (0402)
ReadUnitData()CPU unit data read (0501)
ReadUnitStatus()CPU unit status read (0601)
ReadCycleTime()Cycle time read (0620)
Clock()Clock read (0701)
SetClock()Clock write (0702)
ErrorClear(byte[])Error clear (2101)
ErrorLogRead(int, int)Error log read (2102)
ErrorLogClear()Error log clear (2103)
WordToBin(byte[])Converts a byte array to a string of binary 0s and 1s
toBitArray(byte[])Converts a byte array to BitArray
toBoolArray(byte[])Converts a byte array to a Bool array
toInt16(byte[])Converts a byte array to an Int16 array
toInt32(byte[])Converts a byte array to an Int32 array
toInt64(byte[])Converts a byte array to an Int64 array
toUInt16(byte[])Converts a byte array to a UInt16 array
toUInt32(byte[])Converts a byte array to a UInt32 array
toUInt64(byte[])Converts a byte array to a UInt64 array
toFloat(byte[])Converts a byte array to a Float array
toDouble(byte[])Converts a byte array to a Double array
toString(byte[])Converts a byte array to String

Constructor

Definition

Namespace: Osd.Omron
Assembly: fins.dll

Initializes a new instance of the Fins class


public Fins();
	

Example

Osd.Omron.Fins fins = new Osd.Omron.Fins();
	

Properties

Fins.MessageLog property

Definition

Gets the communication log


public string MessageLog{ get; };
	
Example

An example of getting the command and response when reading the value of DM0


public staic viod ReadMemory()
{
	Osd.Omron.Fins fins = new Osd.Omron.Fins();
	fins.ServerFinsAddress = new byte[3] {0, 1, 0};
	fins.ClientFinsAddress = new byte[3] {0, 10, 0}
	fins.Connect("192.168.0.20");
	byte[] res = fins.read("D0", 1);
	string text = fins.MessageLog;
	Console.WriteLine(text);
	//[UDP]-> 80-00-02-00-14-00-00-0A-00-01-01-01-82-00-00-00-00-01
	//[UDP]<- C0-00-02-00-0A-00-00-14-00-01-01-01-00-00-12-34
}
	

Fins.ClientFinsAddress property

Definition

Sets and gets the source FINS address


public byte[] ClientFinsAddress
	
Example

fins.ClientFinsAddress = new byte[3] {0, 10, 0}
	

Remarks

The FINS address byte[3] contains the following
ClientFinsAddress[0] : network address
ClientFinsAddress[1] : node address
ClientFinsAddress[2] : unit address


Fins.ServerFinsAddress property

Definition

Sets and gets the destination FINS address


public byte[] ServerFinsAddress
	
Example

fins.ServerFinsAddress = new byte[3] {0, 1, 0};
	

Remarks

The FINS address byte[3] contains the following
ClientFinsAddress[0] : network address
ClientFinsAddress[1] : node address
ClientFinsAddress[2] : unit address


Methods

Fins.Connect method

Definition

Connects to the specified IP address


public byte[] Connect(string TargetIP, bool TcpConnect = false);
	
Parameters
TargetIP
string
Destination IP address
TcpConnect
bool
true for TCP connection, false for UDP connection (UDP if omitted)
Return value
Return value
byte[]
A byte array containing the source and destination FINS node addresses
byte[0]: destination node number
byte[1]: source node number
Example

An example of connecting via TCP

public void FinsTcpConnect()
{
	Osd.Omron.Fins fins = new Osd.Omron.Fins();
	fins.ServerFinsAddress = new byte[3] {0, 1, 0};
	fins.ClientFinsAddress = new byte[3] {0, 10, 0}
	byte[] FinsNode = fins.Connect("192.168.0.1", true);
}
	

Remarks

For a UDP connection, an instance of UdpClient is created and the specified IPv4 address and port 9600 are set as the destination.
For a TCP connection, an instance of TcpClient is created and connects asynchronously to the specified IPv4 address on port 9600; the "FINS node address data send" command is sent to obtain the node address. Subsequent commands are built using the obtained node address


Fins.Close method

Definition

Closes the connection


public void Close();
	
Example

An example of closing a fins connection that is already connected


fins.Close();
	

Remarks

For a UDP connection, the UdpClient resources are released
For a TCP connection, the TcpClient is requested to close and the instance is marked as disposed


Fins.SendCommand method

Definition

Sends a FINS command and receives the response


public byte[] SendCommand(byte[] command)();
	
Return value
Return value
byte[]
A byte array containing the response
Example

An example of connecting via UDP to a PLC at IP address 192.168.0.20 and sending a FINS command

public void FinsSend()
{
	Osd.Omron.Fins fins = new Osd.Omron.Fins();
	fins.Connect("192.168.0.20", "0.20.0", "0.10.0");

	byte[] cmd = new byte[12];
	cmd[0] = 0x80;
	cmd[1] = 0x00;
	cmd[2] = 0x02;
	cmd[3] = 0;     // destination FINS address
	cmd[4] = 20;
	cmd[5] = 0;
	cmd[6] = 0;     // source FINS address
	cmd[7] = 10;
	cmd[8] = 0;
	cmd[9] = 1;     // SID
	cmd[10] = 0x05; // CPU unit data read 0501
	cmd[11] = 0x01;

	byte[] res = fins.SendCommand(cmd);
	Console.WriteLine(BitConverter.ToString(res));
}
		

Fins.MemOffset method

Definition

Converts a memory address notation to the FINS command memory specification


public byte[] MemOffset(string memstring, short offset);
	
Parameters
memstring
string
String representing the memory
Memory prefix
Memory typeExample
DMD100
EM0E0_100
WRW100
HRH100
CIO100
* Bits are not supported
offsetshortOffset
Return value
Return value
byte[]
A byte array following the I/O memory specification used in FINS commands
byte[0]: memory type
byte[1]: address (high)
byte[2]: address (low)
byte[3]: bit position (fixed 0x00)
Example

An example converting the address at offset +1 from DM100 (D101)


byte[] mem = fins.MemOffset("D100", 1);
Console.WriteLine(BitConverter.ToString(mem));
// mem = 82-00-65-00
		

Remarks

Only word (channel) addresses can be specified
The correspondence between addresses and I/O memory types is as follows

AddressI/O memory type
DM0x82
EM0-F0xA0-0xAF
EM10-180x60-0x68
WR0xB1
HR0xB2
CIO0xB0

Fins.read method

Definition

Memory area read (0101)


public byte[] read(string memadrstr, int readsize);
	
Parameters
memstring
string
String representing the memory
readsize
int
Number of words to read
Return value
Return value
byte[]
Read data
Example

An example reading 3 words from DM0


byte[] res = fins.read("D0", 3);
Console.WriteLine(BitConverter.ToString(res));
// res = 00-01-00-02-00-03
		

Remarks

Reads the 3 words from D0 to D2 and stores them in a byte array
To convert the byte array to numbers, use conversion methods such as toInt16()


Fins.write method

Definition

Memory area write (0102)


public void write(string memadrstr, byte[] data);
	
Parameters
memstring
string
String representing the memory
data
byte[]
Write data
Example

An example writing sequential numbers to D1000 through D1999


byte[] writedata = new byte[2000];
for (int cnt = 0; cnt < 1000; cnt++)
{
	byte[] data = BitConverter.GetBytes((short)cnt).Reverse().ToArray();
	Array.Copy(data, 0, writedata, cnt * 2, 2);
}
fins.write("D1000", writedata);
		

Fins.fill method

Definition

Memory area fill (0103)


public void fill(string memadrstr, int size, byte[] data);
	
Parameters
memstring
string
String representing the memory
data
byte[]
Write data
Example

An example writing the value 100 to DM2000 through DM2099


int data = 100;
byte[] filldata = BitConverter.GetBytes((short)data).Reverse().ToArray();
fins.fill("D2000", 100, filldata);
		

Fins.MultiRead method

Definition

Multiple memory area read (0104)


public byte[] MultiRead(string memaddresses);
	
Parameters
memaddresses
string
Strings representing memory (multiple, comma-separated)
Example

An example reading the values of DM0, DM10 and DM50


byte[] res = fins.MultiRead("D0,D10,D50");
	

Fins.run method

Definition

Change operating mode (0401)


public void run(byte Mode);
	
Parameters
Mode
byte
Mode
Example

An example changing to MONITOR mode


fins.run(0x02);
	

Remarks

Mode types
0x02 : MONITOR mode
0x04 : RUN mode


Fins.stop method

Definition

Stop operation (0402)


public void stop();
	
Example

An example changing to MONITOR mode


fins.stop();
	

Fins.ReadUnitData method

Definition

CPU unit data read (0501)


public byte[] ReadUnitData();
	
Example

An example changing to MONITOR mode


byte[] res = fins.ReadUnitData();
	

Remarks

Reads the following information
CPU unit model
CPU Bus Unit configuration
CPU unit internal system version
Remote I/O information
Area information
CPU unit information

Fins.ReadUnitStatus method

Definition

CPU unit status read (0601)


public byte[] ReadUnitStatus();
	
Example

byte[] res = fins.ReadUnitStatus();
	

Remarks

Reads the following information
Operating status
Operating mode
Fatal error information
Non-fatal error information
Message present
Error code
Error message

Fins.ReadCycleTime method

Definition

Cycle time read (0620)


public byte[] ReadCycleTime();
	
Example

byte[] res = fins.ReadCycleTime();
	

Remarks

Reads the following information
Average cycle time
Maximum cycle time
Minimum cycle time

Fins.Clock method

Definition

Clock read (0701)


public byte[] Clock();
	
Example

byte[] res = fins.Clock();
	

Fins.SetClock method

Definition

Clock write (0702)


public void SetClock();
	
Example

fins.SetClock();
	

Remarks

Writes the PC time to the PLC

Fins.ErrorClear method

Definition

Error clear (2101)


public void ErrorClear(byte[] code);
	
Parameters
code
byte[]
Error code
Example

An example clearing all errors


fins.ErrorClear(new byte[2] { 0xFF, 0xFF });
	

Remarks

code = FFFF: clears all current errors

Fins.ErrorLogRead method

Definition

Error log read (2102)


public byte[] ErrorLogRead(int startIndex, int count);
	
Parameters
startIndex
int
Start record No.
count
int
Number of records to read
Example

An example reading all errors


byte[] res = fins.ErrorLogRead(0, 20);
	

Remarks

code = FFFF: clears all current errors
Maximum number of records
Number of stored records
Number of records read
Error log data 1 to 20

Fins.ErrorLogClear method

Definition

Error log clear (2103)


public void ErrorLogClear();
	
Example

fins.ErrorLogClear();
	

Fins.WordToBin method

Definition

Converts a byte array to a string of binary 0s and 1s


		public string WordToBin(byte[] data);
	
Example

Reads 2 words from DM0 and stores them in a string


res = fins.read("D0", 2);
string WordToBin = fins.WordToBin(res);
Console.WriteLine(WordToBin);
//out 00010010001101000101011001111000
	

Fins.toBitArray method

Definition

Converts a byte array to BitArray


public BitArray toBitArray(byte[] data);
	
Example

Reads 2 words from DM0 and stores them in the BitArray variable bits


res = fins.read("D0", 2);
BitArray bits = fins.toBitArray(res);
StringBuilder sb = new StringBuilder();
for (int i = bits.Length; i > 0; i--)
{
	char c = bits[i - 1] ? '1' : '0';
	sb.Append(c);
}
Console.WriteLine(sb.ToString());
//out 00010010001101000101011001111000
	

Fins.toBoolArray method

Definition

Converts a byte array to a bool array


public bool[] toBoolArray(byte[] data);
	
Example

Reads 2 words from DM0 and stores them in a bool array


res = fins.read("D0", 2);
bool[] bools = fins.toBoolArray(res);
Console.WriteLine(String.Join(",", bools));
//out False,False,False,True,False,False,True,False, ...
	

Fins.toInt16 method

Definition

Converts a byte array to an Int16 array


public short[] toInt16(byte[] data);
	
Example

Reads 10 words from DM10 and stores them in a short array


res = fins.read("D10", 10);
short[] data16 = fins.toInt16(res);
Console.WriteLine(String.Join(",", data16));
//out 10,11,12,13,14,15,16,17,18,19
	

Fins.toInt32 method

Definition

Converts a byte array to an Int32 array


public int[] toInt32(byte[] data);
	
Example

Reads 10 words from DM20 and stores them in an int array


res = fins.read("D20", 10);
int[] data32 = fins.toInt32(res);
Console.WriteLine(String.Join(",", data32));
//out 1376276,1507350,1638424,1769498,1900572
	

Fins.toInt64 method

Definition

Converts a byte array to an Int64 array


public long[] toInt64(byte[] data);
	
Example

Reads 8 words from DM30 and stores them in a long array


res = fins.read("D30", 8);
long[] data64 = fins.toInt64(res);
Console.WriteLine(String.Join(",", data64));
//out 9288811672436766,10414728759410722
	

Fins.toUInt16 method

Definition

Converts a byte array to a UInt16 array


public ushort[] toUInt16(byte[] data);
	
Example

Reads 10 words from DM40 and stores them in a ushort array


res = fins.read("D40", 10);
ushort[] datau16 = fins.toUInt16(res);
Console.WriteLine(String.Join(",", datau16));
//out 40,41,42,43,44,45,46,47,48,49
	

Fins.toUInt32 method

Definition

Converts a byte array to a UInt32 array


public uint[] toUInt32(byte[] data);
	
Example

Reads 10 words from DM50 and stores them in a uint array


res = fins.read("D50", 10);
uint[] datau32 = fins.toUInt32(res);
Console.WriteLine(String.Join(",", datau32));
//out 3342386,3473460,3604534,3735608,3866682
	

Fins.toUInt64 method

Definition

Converts a byte array to a UInt64 array


public ulong[] toUInt64(byte[] data);
	
Example

Reads 8 words from DM60 and stores them in a ulong array


res = fins.read("D60", 8);
ulong[] datau64 = fins.toUInt64(res);
Console.WriteLine(String.Join(",", datau64));
//out 17733189824741436,18859106911715392
	

Fins.toFloat method

Definition

Converts a byte array to a float array


public float[] toFloat(byte[] data);
	
Example

Reads 10 words from DM70 and stores them in a float array


res = fins.read("D70", 10);
float[] dataf = fins.toFloat(res);
Console.WriteLine(String.Join(",", dataf));
//out 6.520418E-39,6.704092E-39,6.887766E-39,7.07144E-39,7.255113E-39
	

Fins.toDouble method

Definition

Converts a byte array to a Double array


public double[] toDouble(byte[] data);
	
Example

Reads 8 words from DM80 and stores them in a double array


res = fins.read("D80", 8);
double[] datad = fins.toDouble(res);
Console.WriteLine(String.Join(",", datad));
//out 4.22791874120785E-307,5.11796186559102E-307
	

Fins.toString method

Definition

Converts a byte array to a string (UTF-8)


public string toString(byte[] data);
	
Example

Reads 5 words from DM90 and stores them in a string


res = fins.read("D90", 5);
string datastr = fins.toString(res);
Console.WriteLine(datastr);
//out 1234567890
	

Download

By downloading, you are deemed to have agreed to the Terms of Use

Comments