1194 lines
26 KiB
C#
1194 lines
26 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Globalization;
|
|
using System.Net;
|
|
using System.Net.Sockets;
|
|
using System.Text;
|
|
using System.Threading;
|
|
|
|
namespace AGVSystem.Cls
|
|
{
|
|
// Token: 0x0200002A RID: 42
|
|
public class OmronFINS
|
|
{
|
|
// Token: 0x14000008 RID: 8
|
|
// (add) Token: 0x0600024C RID: 588 RVA: 0x00050808 File Offset: 0x0004EA08
|
|
// (remove) Token: 0x0600024D RID: 589 RVA: 0x00050840 File Offset: 0x0004EA40
|
|
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
|
public event OmronFINS.ReceiveMsgHandler OnMsgReceived;
|
|
|
|
// Token: 0x14000009 RID: 9
|
|
// (add) Token: 0x0600024E RID: 590 RVA: 0x00050878 File Offset: 0x0004EA78
|
|
// (remove) Token: 0x0600024F RID: 591 RVA: 0x000508B0 File Offset: 0x0004EAB0
|
|
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
|
public event OmronFINS.StartListenHandler StartListenThread;
|
|
|
|
// Token: 0x1400000A RID: 10
|
|
// (add) Token: 0x06000250 RID: 592 RVA: 0x000508E8 File Offset: 0x0004EAE8
|
|
// (remove) Token: 0x06000251 RID: 593 RVA: 0x00050920 File Offset: 0x0004EB20
|
|
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
|
public event OmronFINS.SendCompleted OnSended;
|
|
|
|
// Token: 0x06000252 RID: 594 RVA: 0x00050958 File Offset: 0x0004EB58
|
|
public OmronFINS(string hostName, int port, int PLCStaion)
|
|
{
|
|
this.Plcport = PLCStaion;
|
|
IPAddress[] hostAddresses = Dns.GetHostAddresses(hostName);
|
|
this.hostEndPoint = new IPEndPoint(hostAddresses[hostAddresses.Length - 1], port);
|
|
this.clientSocket = new Socket(this.hostEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
|
}
|
|
|
|
// Token: 0x06000253 RID: 595 RVA: 0x000509B4 File Offset: 0x0004EBB4
|
|
private bool Connect()
|
|
{
|
|
bool result;
|
|
using (SocketAsyncEventArgs socketAsyncEventArgs = new SocketAsyncEventArgs())
|
|
{
|
|
socketAsyncEventArgs.UserToken = this.clientSocket;
|
|
socketAsyncEventArgs.RemoteEndPoint = this.hostEndPoint;
|
|
socketAsyncEventArgs.Completed += this.OnConnect;
|
|
this.clientSocket.ConnectAsync(socketAsyncEventArgs);
|
|
bool flag = OmronFINS.autoConnectEvent.WaitOne(1000);
|
|
bool flag2 = flag;
|
|
if (flag2)
|
|
{
|
|
this.listenerSocketAsyncEventArgs = new SocketAsyncEventArgs();
|
|
byte[] array = new byte[255];
|
|
this.listenerSocketAsyncEventArgs.UserToken = this.clientSocket;
|
|
this.listenerSocketAsyncEventArgs.SetBuffer(array, 0, array.Length);
|
|
this.listenerSocketAsyncEventArgs.Completed += this.OnReceive;
|
|
this.StartListenThread();
|
|
this.clientSocket.SetKeepAlive(3000UL, 1000UL);
|
|
result = true;
|
|
}
|
|
else
|
|
{
|
|
result = false;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
// Token: 0x06000254 RID: 596 RVA: 0x00050AB8 File Offset: 0x0004ECB8
|
|
private void Listen()
|
|
{
|
|
(this.listenerSocketAsyncEventArgs.UserToken as Socket).ReceiveAsync(this.listenerSocketAsyncEventArgs);
|
|
}
|
|
|
|
// Token: 0x06000255 RID: 597 RVA: 0x00050AD8 File Offset: 0x0004ECD8
|
|
private void Send(byte[] message)
|
|
{
|
|
bool flag = this.connected;
|
|
if (flag)
|
|
{
|
|
SocketAsyncEventArgs senderSocketAsyncEventArgs = null;
|
|
List<SocketAsyncEventArgs> obj = OmronFINS.s_lst;
|
|
lock (obj)
|
|
{
|
|
bool flag3 = OmronFINS.s_lst.Count > 0;
|
|
if (flag3)
|
|
{
|
|
senderSocketAsyncEventArgs = OmronFINS.s_lst[OmronFINS.s_lst.Count - 1];
|
|
OmronFINS.s_lst.RemoveAt(OmronFINS.s_lst.Count - 1);
|
|
}
|
|
}
|
|
bool flag4 = senderSocketAsyncEventArgs == null;
|
|
if (flag4)
|
|
{
|
|
senderSocketAsyncEventArgs = new SocketAsyncEventArgs();
|
|
senderSocketAsyncEventArgs.UserToken = this.clientSocket;
|
|
senderSocketAsyncEventArgs.RemoteEndPoint = this.hostEndPoint;
|
|
senderSocketAsyncEventArgs.Completed += delegate(object sender, SocketAsyncEventArgs _e)
|
|
{
|
|
List<SocketAsyncEventArgs> obj2 = OmronFINS.s_lst;
|
|
lock (obj2)
|
|
{
|
|
OmronFINS.s_lst.Add(senderSocketAsyncEventArgs);
|
|
}
|
|
};
|
|
}
|
|
senderSocketAsyncEventArgs.SetBuffer(message, 0, message.Length);
|
|
this.clientSocket.SendAsync(senderSocketAsyncEventArgs);
|
|
}
|
|
else
|
|
{
|
|
this.connected = false;
|
|
}
|
|
this.SendMess = message;
|
|
}
|
|
|
|
// Token: 0x06000256 RID: 598 RVA: 0x00050C0C File Offset: 0x0004EE0C
|
|
private bool Disconnect()
|
|
{
|
|
bool result = true;
|
|
try
|
|
{
|
|
this.clientSocket.Shutdown(SocketShutdown.Both);
|
|
this.clientSocket.Close();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
result = false;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
// Token: 0x06000257 RID: 599 RVA: 0x00050C58 File Offset: 0x0004EE58
|
|
private void OnConnect(object sender, SocketAsyncEventArgs e)
|
|
{
|
|
OmronFINS.autoConnectEvent.Set();
|
|
this.connected = (e.SocketError == 0);
|
|
}
|
|
|
|
// Token: 0x06000258 RID: 600 RVA: 0x00050C78 File Offset: 0x0004EE78
|
|
private void OnReceive(object sender, SocketAsyncEventArgs e)
|
|
{
|
|
bool flag = e.BytesTransferred == 0;
|
|
if (flag)
|
|
{
|
|
bool flag2 = this.clientSocket.Connected;
|
|
if (flag2)
|
|
{
|
|
try
|
|
{
|
|
this.clientSocket.Shutdown(SocketShutdown.Both);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
finally
|
|
{
|
|
bool flag3 = this.clientSocket.Connected;
|
|
if (flag3)
|
|
{
|
|
this.clientSocket.Close();
|
|
}
|
|
}
|
|
}
|
|
byte[] info = new byte[]
|
|
{
|
|
0
|
|
};
|
|
this.OnMsgReceived(info);
|
|
this.connected = false;
|
|
}
|
|
else
|
|
{
|
|
byte[] buffer = e.Buffer;
|
|
this.OnMsgReceived(buffer);
|
|
this.Listen();
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000259 RID: 601 RVA: 0x00050D3C File Offset: 0x0004EF3C
|
|
private void OnSend(object sender, SocketAsyncEventArgs e)
|
|
{
|
|
bool flag = e.SocketError == 0;
|
|
if (flag)
|
|
{
|
|
this.OnSended(true);
|
|
}
|
|
else
|
|
{
|
|
this.OnSended(false);
|
|
this.ProcessError(e);
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600025A RID: 602 RVA: 0x00050D80 File Offset: 0x0004EF80
|
|
private void ProcessError(SocketAsyncEventArgs e)
|
|
{
|
|
Socket socket = e.UserToken as Socket;
|
|
bool flag = socket.Connected;
|
|
if (flag)
|
|
{
|
|
try
|
|
{
|
|
socket.Shutdown(SocketShutdown.Both);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
finally
|
|
{
|
|
bool flag2 = socket.Connected;
|
|
if (flag2)
|
|
{
|
|
socket.Close();
|
|
}
|
|
}
|
|
this.connected = false;
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600025B RID: 603 RVA: 0x00050DF4 File Offset: 0x0004EFF4
|
|
public void Dispose()
|
|
{
|
|
OmronFINS.autoConnectEvent.Close();
|
|
bool flag = this.clientSocket.Connected;
|
|
if (flag)
|
|
{
|
|
this.clientSocket.Close();
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600025C RID: 604 RVA: 0x00050E2C File Offset: 0x0004F02C
|
|
private void OmronFINS_OnSended(bool successorfalse)
|
|
{
|
|
bool flag = !successorfalse;
|
|
if (flag)
|
|
{
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600025D RID: 605 RVA: 0x00050E48 File Offset: 0x0004F048
|
|
private void OmronFINS_OnMsgReceived(byte[] info)
|
|
{
|
|
bool sendmessHas = this.SendmessHas;
|
|
if (sendmessHas)
|
|
{
|
|
bool flag = info[0] > 0;
|
|
if (flag)
|
|
{
|
|
bool flag2 = info.Length > 24;
|
|
if (flag2)
|
|
{
|
|
string str = "";
|
|
for (int i = 0; i < 24; i++)
|
|
{
|
|
str += info[i].ToString("X").PadLeft(2, '0');
|
|
}
|
|
bool flag3 = int.Parse(info[23].ToString("X").Trim(), NumberStyles.HexNumber) == this.Plcport;
|
|
if (flag3)
|
|
{
|
|
this.PCS = info[19];
|
|
this.PLCS = info[23];
|
|
this.SendmessHas = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
bool flag4 = info[0] > 0;
|
|
if (flag4)
|
|
{
|
|
bool flag5 = this.SendOrRev2 == 1;
|
|
if (flag5)
|
|
{
|
|
this.SendBack = info;
|
|
this.SendOrRev2 = 0;
|
|
}
|
|
else
|
|
{
|
|
bool flag6 = this.SendOrRev == 2;
|
|
if (flag6)
|
|
{
|
|
this.RecvBack = info;
|
|
this.SendOrRev = 0;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
bool flag7 = this.SendOrRev2 == 1;
|
|
if (flag7)
|
|
{
|
|
this.SendBack = new byte[1];
|
|
this.SendBack[0] = 0;
|
|
this.SendOrRev2 = 0;
|
|
}
|
|
else
|
|
{
|
|
bool flag8 = this.SendOrRev == 2;
|
|
if (flag8)
|
|
{
|
|
this.RecvBack = new byte[1];
|
|
this.RecvBack[0] = 0;
|
|
this.SendOrRev = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600025E RID: 606 RVA: 0x00050FC5 File Offset: 0x0004F1C5
|
|
private void OmronFINS_StartListenThread()
|
|
{
|
|
this.Listen();
|
|
}
|
|
|
|
// Token: 0x0600025F RID: 607 RVA: 0x00050FD0 File Offset: 0x0004F1D0
|
|
public bool OpenLinkPLC()
|
|
{
|
|
this.StartListenThread += this.OmronFINS_StartListenThread;
|
|
this.OnMsgReceived += this.OmronFINS_OnMsgReceived;
|
|
this.OnSended += this.OmronFINS_OnSended;
|
|
bool flag = this.Connect();
|
|
bool flag2 = flag;
|
|
if (flag2)
|
|
{
|
|
this.SendmessHas = true;
|
|
this.Send(this.GetPCAdress());
|
|
int num = 0;
|
|
while (this.SendmessHas && num < 1000)
|
|
{
|
|
Thread.Sleep(1);
|
|
num++;
|
|
}
|
|
bool flag3 = num < 1000;
|
|
flag = flag3;
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
// Token: 0x06000260 RID: 608 RVA: 0x00051084 File Offset: 0x0004F284
|
|
public bool CloseLinkPLC()
|
|
{
|
|
return this.Disconnect();
|
|
}
|
|
|
|
// Token: 0x06000261 RID: 609 RVA: 0x0005109C File Offset: 0x0004F29C
|
|
public bool WritePlcData(string TypeInt, int NumData, ref int[] IntValue)
|
|
{
|
|
bool result = false;
|
|
bool flag = NumData > 0;
|
|
if (flag)
|
|
{
|
|
byte[] bytes = BitConverter.GetBytes(NumData);
|
|
byte[] array = new byte[34 + NumData * 2];
|
|
bool flag2 = this.GetType(TypeInt, 0) != 0 && this.Address != null && this.Address.Length > 1;
|
|
if (flag2)
|
|
{
|
|
byte[] array2 = this.SetPLCvalue(this.PLCS, this.PCS, this.GetType(TypeInt, 0), this.Address[1], this.Address[0], 0, bytes[1], bytes[0], NumData);
|
|
for (int i = 0; i < 34 + NumData * 2; i++)
|
|
{
|
|
bool flag3 = i < 34;
|
|
if (flag3)
|
|
{
|
|
array[i] = array2[i];
|
|
}
|
|
else
|
|
{
|
|
bool flag4 = (i - 33) % 2 != 0;
|
|
if (flag4)
|
|
{
|
|
byte[] bytes2 = BitConverter.GetBytes(IntValue[(i - 33) / 2]);
|
|
array[i] = bytes2[1];
|
|
}
|
|
else
|
|
{
|
|
byte[] bytes3 = BitConverter.GetBytes(IntValue[(i - 33) / 2 - 1]);
|
|
array[i] = bytes3[0];
|
|
}
|
|
}
|
|
}
|
|
this.SendOrRev2 = 1;
|
|
this.Send(array);
|
|
int num = 0;
|
|
while (this.SendOrRev2 != 0 & this.connected & num < 1000)
|
|
{
|
|
Thread.Sleep(1);
|
|
num++;
|
|
}
|
|
bool flag5 = num < 1000;
|
|
if (flag5)
|
|
{
|
|
try
|
|
{
|
|
bool flag6 = this.SendBack.Length > 1 && this.SendBack[26] == 1 && this.SendBack[27] == 2 && this.SendBack[28] == 0;
|
|
result = flag6;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.SendOrRev2 = 0;
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
// Token: 0x06000262 RID: 610 RVA: 0x00051270 File Offset: 0x0004F470
|
|
public bool ReadPlcData(string TypeInt, int NumData, out int[] IntValue)
|
|
{
|
|
bool result = false;
|
|
IntValue = new int[1];
|
|
bool flag = NumData > 0;
|
|
if (flag)
|
|
{
|
|
IntValue = new int[NumData];
|
|
byte[] bytes = BitConverter.GetBytes(NumData);
|
|
byte[] array = new byte[34];
|
|
bool flag2 = this.GetType(TypeInt, 0) != 0 && this.Address != null && this.Address.Length > 1;
|
|
if (flag2)
|
|
{
|
|
byte[] plcvalue = this.GetPLCvalue(this.PLCS, this.PCS, this.GetType(TypeInt, 0), this.Address[1], this.Address[0], 0, bytes[1], bytes[0]);
|
|
string str = "";
|
|
for (int i = 0; i < 34; i++)
|
|
{
|
|
str += plcvalue[i].ToString("X").PadLeft(2, '0');
|
|
}
|
|
string @string = Encoding.ASCII.GetString(plcvalue);
|
|
this.Send(plcvalue);
|
|
this.SendOrRev = 2;
|
|
int num = 0;
|
|
while (this.SendOrRev != 0 & this.connected & num < 1000)
|
|
{
|
|
Thread.Sleep(1);
|
|
num++;
|
|
}
|
|
bool flag3 = num < 1000;
|
|
if (flag3)
|
|
{
|
|
bool flag4 = this.RecvBack.Length > 1 && this.RecvBack[26] == 1 && this.RecvBack[27] == 1 && this.RecvBack[28] == 0;
|
|
if (flag4)
|
|
{
|
|
result = true;
|
|
for (int j = 0; j < NumData; j++)
|
|
{
|
|
IntValue[j] = int.Parse(this.RecvBack[30 + j * 2].ToString("X").PadLeft(2, '0') + this.RecvBack[30 + j * 2 + 1].ToString("X").PadLeft(2, '0'), NumberStyles.HexNumber);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
result = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.SendOrRev = 0;
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
// Token: 0x06000263 RID: 611 RVA: 0x00051480 File Offset: 0x0004F680
|
|
public bool ReadPlcBitData(string TypeInt, out int IntValue)
|
|
{
|
|
bool result = false;
|
|
IntValue = 0;
|
|
byte[] array = new byte[34];
|
|
bool flag = this.GetType(TypeInt, 1) != 0 && this.Address != null && this.Address.Length > 1;
|
|
if (flag)
|
|
{
|
|
byte[] plcvalue = this.GetPLCvalue(this.PLCS, this.PCS, this.GetType(TypeInt, 1), this.Address[1], this.Address[0], this.AddressBit[0]);
|
|
this.Send(plcvalue);
|
|
this.SendOrRev = 2;
|
|
int num = 0;
|
|
while (this.SendOrRev != 0 & num < 1000)
|
|
{
|
|
Thread.Sleep(1);
|
|
num++;
|
|
}
|
|
bool flag2 = num < 1000;
|
|
if (flag2)
|
|
{
|
|
bool flag3 = this.RecvBack.Length > 1 && this.RecvBack[26] == 1 && this.RecvBack[27] == 1 && this.RecvBack[28] == 0 && this.RecvBack[29] == 0;
|
|
if (flag3)
|
|
{
|
|
result = true;
|
|
IntValue = int.Parse(this.RecvBack[30].ToString("X").PadLeft(2, '0'), NumberStyles.HexNumber);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.SendOrRev = 0;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
// Token: 0x06000264 RID: 612 RVA: 0x000515C8 File Offset: 0x0004F7C8
|
|
public bool WriteBitPlcData(string TypeInt, int ItemValue)
|
|
{
|
|
bool result = false;
|
|
byte[] array = new byte[35];
|
|
bool flag = this.GetType(TypeInt, 1) != 0 && this.Address != null && this.Address.Length > 1;
|
|
if (flag)
|
|
{
|
|
byte[] array2 = this.WritePLCBitvalue(this.PLCS, this.PCS, this.GetType(TypeInt, 1), this.Address[1], this.Address[0], this.AddressBit[0]);
|
|
for (int i = 0; i < 35; i++)
|
|
{
|
|
bool flag2 = i < 32;
|
|
if (flag2)
|
|
{
|
|
array[i] = array2[i];
|
|
}
|
|
else
|
|
{
|
|
bool flag3 = i == 32;
|
|
if (flag3)
|
|
{
|
|
array[i] = 0;
|
|
}
|
|
else
|
|
{
|
|
bool flag4 = i == 33;
|
|
if (flag4)
|
|
{
|
|
array[i] = 1;
|
|
}
|
|
else
|
|
{
|
|
bool flag5 = ItemValue == 1;
|
|
if (flag5)
|
|
{
|
|
array[i] = 1;
|
|
}
|
|
else
|
|
{
|
|
array[i] = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
this.Send(array);
|
|
this.SendOrRev2 = 1;
|
|
int num = 0;
|
|
while (this.SendOrRev2 != 0 & num < 1000)
|
|
{
|
|
Thread.Sleep(1);
|
|
num++;
|
|
}
|
|
bool flag6 = num < 1000;
|
|
if (flag6)
|
|
{
|
|
bool flag7 = this.SendBack.Length > 1 && this.SendBack[26] == 1 && this.SendBack[27] == 2 && this.SendBack[28] == 0 && this.SendBack[29] == 0;
|
|
if (flag7)
|
|
{
|
|
result = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.SendOrRev2 = 0;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
// Token: 0x06000265 RID: 613 RVA: 0x00051758 File Offset: 0x0004F958
|
|
public bool SetPlcData(string TypeInt)
|
|
{
|
|
bool result = false;
|
|
byte[] array = new byte[35];
|
|
bool flag = this.GetType(TypeInt, 1) != 0 && this.Address != null && this.Address.Length > 1;
|
|
if (flag)
|
|
{
|
|
byte[] array2 = this.SetPLCBitvalue(this.PLCS, this.PCS, this.GetType(TypeInt, 1), this.Address[1], this.Address[0], this.AddressBit[0]);
|
|
for (int i = 0; i < 35; i++)
|
|
{
|
|
bool flag2 = i < 34;
|
|
if (flag2)
|
|
{
|
|
array[i] = array2[i];
|
|
}
|
|
else
|
|
{
|
|
array[i] = 0;
|
|
}
|
|
}
|
|
this.Send(array);
|
|
this.SendOrRev2 = 1;
|
|
int num = 0;
|
|
while (this.SendOrRev2 != 0 & num < 1000)
|
|
{
|
|
Thread.Sleep(1);
|
|
num++;
|
|
}
|
|
bool flag3 = num < 1000;
|
|
if (flag3)
|
|
{
|
|
bool flag4 = this.SendBack.Length > 1 && this.SendBack[26] == 1 && this.SendBack[27] == 2 && this.SendBack[28] == 0 && this.SendBack[29] == 0;
|
|
if (flag4)
|
|
{
|
|
result = true;
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
// Token: 0x06000266 RID: 614 RVA: 0x000518A0 File Offset: 0x0004FAA0
|
|
public bool RestPlcData(string TypeInt)
|
|
{
|
|
bool result = false;
|
|
byte[] array = new byte[35];
|
|
bool flag = this.GetType(TypeInt, 1) != 0 && this.Address != null && this.Address.Length > 1;
|
|
if (flag)
|
|
{
|
|
byte[] array2 = this.RstPLCBitvalue(this.PLCS, this.PCS, this.GetType(TypeInt, 1), this.Address[1], this.Address[0], this.AddressBit[0]);
|
|
for (int i = 0; i < 35; i++)
|
|
{
|
|
bool flag2 = i < 34;
|
|
if (flag2)
|
|
{
|
|
array[i] = array2[i];
|
|
}
|
|
else
|
|
{
|
|
array[i] = 0;
|
|
}
|
|
}
|
|
this.Send(array);
|
|
this.SendOrRev2 = 1;
|
|
int num = 0;
|
|
while (this.SendOrRev2 != 0 & num < 1000)
|
|
{
|
|
Thread.Sleep(1);
|
|
num++;
|
|
}
|
|
bool flag3 = num < 1000;
|
|
if (flag3)
|
|
{
|
|
bool flag4 = this.SendBack.Length > 1 && this.SendBack[26] == 1 && this.SendBack[27] == 2 && this.SendBack[28] == 0 && this.SendBack[29] == 0;
|
|
if (flag4)
|
|
{
|
|
result = true;
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
// Token: 0x06000267 RID: 615 RVA: 0x000519E8 File Offset: 0x0004FBE8
|
|
private byte GetType(string TypeInt, int SizeofInt)
|
|
{
|
|
byte result = 0;
|
|
bool flag = TypeInt.IndexOf("D") == 0 | TypeInt.IndexOf("d") == 0;
|
|
if (flag)
|
|
{
|
|
bool flag2 = SizeofInt == 0;
|
|
if (flag2)
|
|
{
|
|
result = 130;
|
|
bool flag3 = TypeInt.IndexOf(".") == -1;
|
|
if (flag3)
|
|
{
|
|
this.Address = BitConverter.GetBytes(int.Parse(TypeInt.Substring(1, TypeInt.Length - 1)));
|
|
}
|
|
else
|
|
{
|
|
this.Address = new byte[1];
|
|
this.AddressBit = new byte[1];
|
|
}
|
|
}
|
|
else
|
|
{
|
|
result = 2;
|
|
bool flag4 = TypeInt.IndexOf(".") > 1;
|
|
if (flag4)
|
|
{
|
|
this.Address = BitConverter.GetBytes(int.Parse(TypeInt.Substring(1, TypeInt.IndexOf(".") - 1)));
|
|
this.AddressBit = BitConverter.GetBytes(int.Parse(TypeInt.Substring(TypeInt.IndexOf(".") + 1, TypeInt.Length - TypeInt.IndexOf(".") - 1)));
|
|
}
|
|
else
|
|
{
|
|
this.Address = new byte[1];
|
|
this.AddressBit = new byte[1];
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
bool flag5 = TypeInt.IndexOf("CIO") == 0 | TypeInt.IndexOf("cio") == 0;
|
|
if (flag5)
|
|
{
|
|
bool flag6 = SizeofInt == 0;
|
|
if (flag6)
|
|
{
|
|
result = 176;
|
|
bool flag7 = TypeInt.IndexOf(".") == -1;
|
|
if (flag7)
|
|
{
|
|
this.Address = BitConverter.GetBytes(int.Parse(TypeInt.Substring(3, TypeInt.Length - 3)));
|
|
}
|
|
else
|
|
{
|
|
this.Address = new byte[1];
|
|
this.AddressBit = new byte[1];
|
|
}
|
|
}
|
|
else
|
|
{
|
|
result = 48;
|
|
bool flag8 = TypeInt.IndexOf(".") > 3;
|
|
if (flag8)
|
|
{
|
|
this.Address = BitConverter.GetBytes(int.Parse(TypeInt.Substring(3, TypeInt.IndexOf(".") - 3)));
|
|
this.AddressBit = BitConverter.GetBytes(int.Parse(TypeInt.Substring(TypeInt.IndexOf(".") + 1, TypeInt.Length - TypeInt.IndexOf(".") - 1)));
|
|
}
|
|
else
|
|
{
|
|
this.Address = new byte[1];
|
|
this.AddressBit = new byte[1];
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
bool flag9 = TypeInt.IndexOf("W") == 0 | TypeInt.IndexOf("w") == 0;
|
|
if (flag9)
|
|
{
|
|
bool flag10 = SizeofInt == 0;
|
|
if (flag10)
|
|
{
|
|
result = 177;
|
|
bool flag11 = TypeInt.IndexOf(".") == -1;
|
|
if (flag11)
|
|
{
|
|
this.Address = BitConverter.GetBytes(int.Parse(TypeInt.Substring(1, TypeInt.Length - 1)));
|
|
}
|
|
else
|
|
{
|
|
this.Address = new byte[1];
|
|
this.AddressBit = new byte[1];
|
|
}
|
|
}
|
|
else
|
|
{
|
|
result = 49;
|
|
bool flag12 = TypeInt.IndexOf(".") > 1;
|
|
if (flag12)
|
|
{
|
|
this.Address = BitConverter.GetBytes(int.Parse(TypeInt.Substring(1, TypeInt.IndexOf(".") - 1)));
|
|
this.AddressBit = BitConverter.GetBytes(int.Parse(TypeInt.Substring(TypeInt.IndexOf(".") + 1, TypeInt.Length - TypeInt.IndexOf(".") - 1)));
|
|
}
|
|
else
|
|
{
|
|
this.Address = new byte[1];
|
|
this.AddressBit = new byte[1];
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
bool flag13 = TypeInt.IndexOf("H") == 0 | TypeInt.IndexOf("h") == 0;
|
|
if (flag13)
|
|
{
|
|
bool flag14 = SizeofInt == 0;
|
|
if (flag14)
|
|
{
|
|
result = 178;
|
|
bool flag15 = TypeInt.IndexOf(".") == -1;
|
|
if (flag15)
|
|
{
|
|
this.Address = BitConverter.GetBytes(int.Parse(TypeInt.Substring(1, TypeInt.Length - 1)));
|
|
}
|
|
else
|
|
{
|
|
this.Address = new byte[1];
|
|
this.AddressBit = new byte[1];
|
|
}
|
|
}
|
|
else
|
|
{
|
|
result = 50;
|
|
bool flag16 = TypeInt.IndexOf(".") > 1;
|
|
if (flag16)
|
|
{
|
|
this.Address = BitConverter.GetBytes(int.Parse(TypeInt.Substring(1, TypeInt.IndexOf(".") - 1)));
|
|
this.AddressBit = BitConverter.GetBytes(int.Parse(TypeInt.Substring(TypeInt.IndexOf(".") + 1, TypeInt.Length - TypeInt.IndexOf(".") - 1)));
|
|
}
|
|
else
|
|
{
|
|
this.Address = new byte[1];
|
|
this.AddressBit = new byte[1];
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
bool flag17 = TypeInt.IndexOf("A") == 0 | TypeInt.IndexOf("a") == 0;
|
|
if (flag17)
|
|
{
|
|
bool flag18 = SizeofInt == 0;
|
|
if (flag18)
|
|
{
|
|
result = 179;
|
|
bool flag19 = TypeInt.IndexOf(".") == -1;
|
|
if (flag19)
|
|
{
|
|
this.Address = BitConverter.GetBytes(int.Parse(TypeInt.Substring(1, TypeInt.Length - 1)));
|
|
}
|
|
else
|
|
{
|
|
this.Address = new byte[1];
|
|
this.AddressBit = new byte[1];
|
|
}
|
|
}
|
|
else
|
|
{
|
|
result = 51;
|
|
bool flag20 = TypeInt.IndexOf(".") > 1;
|
|
if (flag20)
|
|
{
|
|
this.Address = BitConverter.GetBytes(int.Parse(TypeInt.Substring(1, TypeInt.IndexOf(".") - 1)));
|
|
this.AddressBit = BitConverter.GetBytes(int.Parse(TypeInt.Substring(TypeInt.IndexOf(".") + 1, TypeInt.Length - TypeInt.IndexOf(".") - 1)));
|
|
}
|
|
else
|
|
{
|
|
this.Address = new byte[1];
|
|
this.AddressBit = new byte[1];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
// Token: 0x06000268 RID: 616 RVA: 0x00051FAC File Offset: 0x000501AC
|
|
private byte[] GetPCAdress()
|
|
{
|
|
return new byte[]
|
|
{
|
|
70,
|
|
73,
|
|
78,
|
|
83,
|
|
0,
|
|
0,
|
|
0,
|
|
12,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0
|
|
};
|
|
}
|
|
|
|
// Token: 0x06000269 RID: 617 RVA: 0x00052028 File Offset: 0x00050228
|
|
private byte[] GetPLCvalue(byte DA1, byte SA1, byte DataValue, byte Address1, byte Address2, byte Address3, byte DataNum1, byte DataNum2)
|
|
{
|
|
return new byte[]
|
|
{
|
|
70,
|
|
73,
|
|
78,
|
|
83,
|
|
0,
|
|
0,
|
|
0,
|
|
26,
|
|
0,
|
|
0,
|
|
0,
|
|
2,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
128,
|
|
0,
|
|
2,
|
|
0,
|
|
DA1,
|
|
0,
|
|
0,
|
|
SA1,
|
|
0,
|
|
1,
|
|
1,
|
|
1,
|
|
DataValue,
|
|
Address1,
|
|
Address2,
|
|
Address3,
|
|
DataNum1,
|
|
DataNum2
|
|
};
|
|
}
|
|
|
|
// Token: 0x0600026A RID: 618 RVA: 0x000520F4 File Offset: 0x000502F4
|
|
private byte[] SetPLCvalue(byte DA1, byte SA1, byte DataValue, byte Address1, byte Address2, byte Address3, byte DataNum1, byte DataNum2, int num)
|
|
{
|
|
return new byte[]
|
|
{
|
|
70,
|
|
73,
|
|
78,
|
|
83,
|
|
0,
|
|
0,
|
|
0,
|
|
(byte)(26 + 2 * num),
|
|
0,
|
|
0,
|
|
0,
|
|
2,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
128,
|
|
0,
|
|
2,
|
|
0,
|
|
DA1,
|
|
0,
|
|
0,
|
|
SA1,
|
|
0,
|
|
1,
|
|
1,
|
|
2,
|
|
DataValue,
|
|
Address1,
|
|
Address2,
|
|
Address3,
|
|
DataNum1,
|
|
DataNum2
|
|
};
|
|
}
|
|
|
|
// Token: 0x0600026B RID: 619 RVA: 0x000521C4 File Offset: 0x000503C4
|
|
private byte[] GetPLCvalue(byte DA1, byte SA1, byte DataValue, byte Address1, byte Address2, byte Address3)
|
|
{
|
|
return new byte[]
|
|
{
|
|
70,
|
|
73,
|
|
78,
|
|
83,
|
|
0,
|
|
0,
|
|
0,
|
|
26,
|
|
0,
|
|
0,
|
|
0,
|
|
2,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
128,
|
|
0,
|
|
2,
|
|
0,
|
|
DA1,
|
|
0,
|
|
0,
|
|
SA1,
|
|
0,
|
|
1,
|
|
1,
|
|
1,
|
|
DataValue,
|
|
Address1,
|
|
Address2,
|
|
Address3,
|
|
0,
|
|
1
|
|
};
|
|
}
|
|
|
|
// Token: 0x0600026C RID: 620 RVA: 0x0005228C File Offset: 0x0005048C
|
|
private byte[] WritePLCBitvalue(byte DA1, byte SA1, byte DataValue, byte Address1, byte Address2, byte Address3)
|
|
{
|
|
return new byte[]
|
|
{
|
|
70,
|
|
73,
|
|
78,
|
|
83,
|
|
0,
|
|
0,
|
|
0,
|
|
27,
|
|
0,
|
|
0,
|
|
0,
|
|
2,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
128,
|
|
0,
|
|
2,
|
|
0,
|
|
DA1,
|
|
0,
|
|
0,
|
|
SA1,
|
|
0,
|
|
1,
|
|
1,
|
|
2,
|
|
DataValue,
|
|
Address1,
|
|
Address2,
|
|
Address3
|
|
};
|
|
}
|
|
|
|
// Token: 0x0600026D RID: 621 RVA: 0x0005234C File Offset: 0x0005054C
|
|
private byte[] SetPLCBitvalue(byte DA1, byte SA1, byte DataValue, byte Address1, byte Address2, byte Address3)
|
|
{
|
|
return new byte[]
|
|
{
|
|
70,
|
|
73,
|
|
78,
|
|
83,
|
|
0,
|
|
0,
|
|
0,
|
|
27,
|
|
0,
|
|
0,
|
|
0,
|
|
2,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
128,
|
|
0,
|
|
2,
|
|
0,
|
|
DA1,
|
|
0,
|
|
0,
|
|
SA1,
|
|
0,
|
|
1,
|
|
35,
|
|
1,
|
|
1,
|
|
0,
|
|
1,
|
|
DataValue,
|
|
Address1,
|
|
Address2,
|
|
Address3
|
|
};
|
|
}
|
|
|
|
// Token: 0x0600026E RID: 622 RVA: 0x0005241C File Offset: 0x0005061C
|
|
private byte[] RstPLCBitvalue(byte DA1, byte SA1, byte DataValue, byte Address1, byte Address2, byte Address3)
|
|
{
|
|
return new byte[]
|
|
{
|
|
70,
|
|
73,
|
|
78,
|
|
83,
|
|
0,
|
|
0,
|
|
0,
|
|
27,
|
|
0,
|
|
0,
|
|
0,
|
|
2,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
128,
|
|
0,
|
|
2,
|
|
0,
|
|
DA1,
|
|
0,
|
|
0,
|
|
SA1,
|
|
0,
|
|
1,
|
|
35,
|
|
1,
|
|
1,
|
|
0,
|
|
0,
|
|
DataValue,
|
|
Address1,
|
|
Address2,
|
|
Address3
|
|
};
|
|
}
|
|
|
|
// Token: 0x0400060B RID: 1547
|
|
private Socket clientSocket;
|
|
|
|
// Token: 0x0400060C RID: 1548
|
|
public bool connected = false;
|
|
|
|
// Token: 0x0400060D RID: 1549
|
|
private byte[] SendMess;
|
|
|
|
// Token: 0x0400060E RID: 1550
|
|
private IPEndPoint hostEndPoint;
|
|
|
|
// Token: 0x0400060F RID: 1551
|
|
private static AutoResetEvent autoConnectEvent = new AutoResetEvent(false);
|
|
|
|
// Token: 0x04000613 RID: 1555
|
|
private SocketAsyncEventArgs listenerSocketAsyncEventArgs;
|
|
|
|
// Token: 0x04000614 RID: 1556
|
|
private int Plcport;
|
|
|
|
// Token: 0x04000615 RID: 1557
|
|
public static List<SocketAsyncEventArgs> s_lst = new List<SocketAsyncEventArgs>();
|
|
|
|
// Token: 0x04000616 RID: 1558
|
|
private byte PCS;
|
|
|
|
// Token: 0x04000617 RID: 1559
|
|
private byte PLCS;
|
|
|
|
// Token: 0x04000618 RID: 1560
|
|
private int SendOrRev;
|
|
|
|
// Token: 0x04000619 RID: 1561
|
|
private int SendOrRev2;
|
|
|
|
// Token: 0x0400061A RID: 1562
|
|
private byte[] SendBack;
|
|
|
|
// Token: 0x0400061B RID: 1563
|
|
private byte[] RecvBack;
|
|
|
|
// Token: 0x0400061C RID: 1564
|
|
private bool SendmessHas = false;
|
|
|
|
// Token: 0x0400061D RID: 1565
|
|
private byte[] Address;
|
|
|
|
// Token: 0x0400061E RID: 1566
|
|
private byte[] AddressBit;
|
|
|
|
// Token: 0x02000046 RID: 70
|
|
// (Invoke) Token: 0x060002FB RID: 763
|
|
public delegate void ReceiveMsgHandler(byte[] info);
|
|
|
|
// Token: 0x02000047 RID: 71
|
|
// (Invoke) Token: 0x060002FF RID: 767
|
|
public delegate void StartListenHandler();
|
|
|
|
// Token: 0x02000048 RID: 72
|
|
// (Invoke) Token: 0x06000303 RID: 771
|
|
public delegate void SendCompleted(bool successorfalse);
|
|
}
|
|
}
|