|
@@ -1,23 +1,23 @@
|
|
|
-using Aitex.Common.Util;
|
|
|
-using Aitex.Core.RT.Device;
|
|
|
-using Aitex.Core.RT.Log;
|
|
|
-using Aitex.Core.UI.Control;
|
|
|
-using Aitex.Core.Util;
|
|
|
-using MECF.Framework.Common.Device.Festo;
|
|
|
-using MECF.Framework.Common.Device.Wago;
|
|
|
-using MECF.Framework.Common.Net;
|
|
|
-using MECF.Framework.Common.Simulator;
|
|
|
-using MECF.Framework.Simulator.Core.Driver;
|
|
|
-using System;
|
|
|
-using System.Collections.Generic;
|
|
|
-using System.IO;
|
|
|
-using static MECF.Framework.Common.Simulator.MotorSimulator;
|
|
|
-
|
|
|
-namespace CyberX8_Simulator.Devices
|
|
|
-{
|
|
|
- public class WagoSocketSimulator : SocketDeviceSimulator
|
|
|
- {
|
|
|
- private const short WRITE_DO_STARTADDRESS = 0x0200;
|
|
|
+using Aitex.Common.Util;
|
|
|
+using Aitex.Core.RT.Device;
|
|
|
+using Aitex.Core.RT.Log;
|
|
|
+using Aitex.Core.UI.Control;
|
|
|
+using Aitex.Core.Util;
|
|
|
+using MECF.Framework.Common.Device.Festo;
|
|
|
+using MECF.Framework.Common.Device.Wago;
|
|
|
+using MECF.Framework.Common.Net;
|
|
|
+using MECF.Framework.Common.Simulator;
|
|
|
+using MECF.Framework.Simulator.Core.Driver;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.IO;
|
|
|
+using static MECF.Framework.Common.Simulator.MotorSimulator;
|
|
|
+
|
|
|
+namespace CyberX8_Simulator.Devices
|
|
|
+{
|
|
|
+ public class WagoSocketSimulator : SocketDeviceSimulator
|
|
|
+ {
|
|
|
+ private const short WRITE_DO_STARTADDRESS = 0x0200;
|
|
|
private const short WRITE_AO_STARTADDRESS = 0x0200;
|
|
|
|
|
|
|
|
@@ -27,41 +27,41 @@ namespace CyberX8_Simulator.Devices
|
|
|
|
|
|
public Dictionary<string, int> AINameIndexDic;
|
|
|
|
|
|
- public Dictionary<string, int> AONameIndexDic;
|
|
|
-
|
|
|
- private IByteTransform byteTransform = new BigEndianByteTransformBase();
|
|
|
-
|
|
|
- public byte[] DOBytes = new byte[200];
|
|
|
-
|
|
|
- public short[] AOShorts = new short[200];
|
|
|
-
|
|
|
- public byte[] DIBytes = new byte[200];
|
|
|
-
|
|
|
- public short[] AIShorts = new short[200];
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private object _writeDOLocker = new object();
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private object _writeAOLocker = new object();
|
|
|
+ public Dictionary<string, int> AONameIndexDic;
|
|
|
+
|
|
|
+ private IByteTransform byteTransform = new BigEndianByteTransformBase();
|
|
|
+
|
|
|
+ public byte[] DOBytes = new byte[200];
|
|
|
+
|
|
|
+ public short[] AOShorts = new short[200];
|
|
|
+
|
|
|
+ public byte[] DIBytes = new byte[200];
|
|
|
+
|
|
|
+ public short[] AIShorts = new short[200];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private object _writeDOLocker = new object();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private object _writeAOLocker = new object();
|
|
|
|
|
|
|
|
|
-
|
|
|
- private Dictionary<string, bool> _festoDataBuffer = new Dictionary<string, bool>();
|
|
|
+
|
|
|
+ private Dictionary<string, bool> _festoDataBuffer = new Dictionary<string, bool>();
|
|
|
|
|
|
|
|
|
-
|
|
|
- private Dictionary<string, WagoDO> _doNameWagoDODic = new Dictionary<string, WagoDO>();
|
|
|
+
|
|
|
+ private Dictionary<string, WagoDO> _doNameWagoDODic = new Dictionary<string, WagoDO>();
|
|
|
|
|
|
|
|
|
-
|
|
|
- private Dictionary<string, WagoDI> _diNameWagoDIDic = new Dictionary<string, WagoDI>();
|
|
|
+
|
|
|
+ private Dictionary<string, WagoDI> _diNameWagoDIDic = new Dictionary<string, WagoDI>();
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
private PeriodicJob _LoaderPeriodicJob;
|
|
|
private PeriodicJob _Wago2PeriodicJob;
|
|
|
private PeriodicJob _Wago4PeriodicJob;
|
|
@@ -92,14 +92,14 @@ namespace CyberX8_Simulator.Devices
|
|
|
public event VariableValueChanged OnAIVariableValueChanged;
|
|
|
public event VariableValueChanged OnDOVariableValueChanged;
|
|
|
public event VariableValueChanged OnAOVariableValueChanged;
|
|
|
- #endregion
|
|
|
-
|
|
|
- public WagoSocketSimulator(int port):base(port)
|
|
|
- {
|
|
|
- SimulatorCommManager.Instance.OnUpdateVariableValueChanged += UpdataDataCausedByOtherModule;
|
|
|
- MotorSimulator.Instance.OnUpdateWagoDatasChanged += UpdataDataCausedByOtherModule;
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ public WagoSocketSimulator(int port):base(port)
|
|
|
+ {
|
|
|
+ SimulatorCommManager.Instance.OnUpdateVariableValueChanged += UpdataDataCausedByOtherModule;
|
|
|
+ MotorSimulator.Instance.OnUpdateWagoDatasChanged += UpdataDataCausedByOtherModule;
|
|
|
InitializeData(port);
|
|
|
- _port = port;
|
|
|
+ _port = port;
|
|
|
}
|
|
|
private void UpdataDataCausedByOtherModule(string sourceName,string name, bool value, bool invert)
|
|
|
{
|
|
@@ -298,11 +298,11 @@ namespace CyberX8_Simulator.Devices
|
|
|
UpdataDIBytes("r_METAL4_PUMP_ON", value ? 1 : 0);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private void InitializeData(int port)
|
|
|
- {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void InitializeData(int port)
|
|
|
+ {
|
|
|
|
|
|
try
|
|
|
{
|
|
@@ -459,7 +459,7 @@ namespace CyberX8_Simulator.Devices
|
|
|
if (AINameIndexDic.ContainsKey("r_MBS2_FLOW")) AIShorts[AINameIndexDic["r_MBS2_FLOW"]] = 16000;
|
|
|
|
|
|
}
|
|
|
- #region 公共方法
|
|
|
+ #region 公共方法
|
|
|
public void UpdataDOBytes(string name,int value)
|
|
|
{
|
|
|
if (OnDOVariableValueChanged != null)
|
|
@@ -535,237 +535,237 @@ namespace CyberX8_Simulator.Devices
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- #endregion
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 功能方法
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public byte ConvertByteArrayToHex(byte[] byteArray)
|
|
|
+ {
|
|
|
+ byte result = 0;
|
|
|
+
|
|
|
+ int binaryValue = 0;
|
|
|
+ for (int i = 0; i < 8; i++)
|
|
|
+ {
|
|
|
+ binaryValue |= (byteArray[i] << (7 - i));
|
|
|
+ }
|
|
|
|
|
|
- #region 功能方法
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- public byte ConvertByteArrayToHex(byte[] byteArray)
|
|
|
- {
|
|
|
- byte result = 0;
|
|
|
-
|
|
|
- int binaryValue = 0;
|
|
|
- for (int i = 0; i < 8; i++)
|
|
|
- {
|
|
|
- binaryValue |= (byteArray[i] << (7 - i));
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- int reversedValue = 0;
|
|
|
- for (int i = 0; i < 8; i++)
|
|
|
- {
|
|
|
- reversedValue |= ((binaryValue >> i) & 1) << (7 - i);
|
|
|
- }
|
|
|
-
|
|
|
- if (byte.TryParse(reversedValue.ToString("X2"), System.Globalization.NumberStyles.HexNumber, null, out result))
|
|
|
- {
|
|
|
- return result;
|
|
|
- }
|
|
|
- return 0;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private byte[] ConvertShortArrayToByteArray(short[] shortArray)
|
|
|
- {
|
|
|
- byte[] byteArray = new byte[shortArray.Length * 2];
|
|
|
- for (int i = 0; i < shortArray.Length; i++)
|
|
|
- {
|
|
|
- byte[] tempBytes = BitConverter.GetBytes(shortArray[i]);
|
|
|
- Array.Reverse(tempBytes);
|
|
|
- Array.Copy(tempBytes, 0, byteArray, i * 2, 2);
|
|
|
- }
|
|
|
- return byteArray;
|
|
|
- }
|
|
|
- #endregion
|
|
|
-
|
|
|
- protected override void ProcessUnsplitMessage(byte[] data)
|
|
|
- {
|
|
|
- byte command = data[7];
|
|
|
- if (command == 0x01)
|
|
|
- {
|
|
|
- short flag = byteTransform.TransInt16(data, 0);
|
|
|
- byte channel = data[6];
|
|
|
- short startAddress = byteTransform.TransInt16(data, 8);
|
|
|
- short bitCount = byteTransform.TransInt16(data, 10);
|
|
|
- byte byteCount = (byte)(bitCount / 8 + 1);
|
|
|
- byte[] bytes = new byte[byteCount];
|
|
|
- for(int i = 0; i < byteCount;i++)
|
|
|
- {
|
|
|
- byte[] tempbytes = new byte[8];
|
|
|
- Array.Copy(DOBytes,8 * i, tempbytes, 0, 8);
|
|
|
- bytes[i] = ConvertByteArrayToHex(tempbytes);
|
|
|
- }
|
|
|
- OnWriteMessage(CreateReadDigitalResponse(flag, channel, command, byteCount, bytes));
|
|
|
- return;
|
|
|
- }
|
|
|
- else if(command == 0x03)
|
|
|
- {
|
|
|
- short flag = byteTransform.TransInt16(data, 0);
|
|
|
- byte channel = data[6];
|
|
|
- short startAddress = byteTransform.TransInt16(data, 8);
|
|
|
- short registerCount = byteTransform.TransInt16(data, 10);
|
|
|
- short[] shorts = new short[registerCount];
|
|
|
- Array.Copy(AOShorts, 0, shorts, 0, registerCount);
|
|
|
- byte[] bytes = new byte[registerCount * 2];
|
|
|
- bytes = ConvertShortArrayToByteArray(shorts);
|
|
|
- OnWriteMessage(CreateReadAnalogyResponse(flag, channel, command, (byte)registerCount, bytes));
|
|
|
- return;
|
|
|
- }
|
|
|
- else if (command == 0x02)
|
|
|
- {
|
|
|
- short flag = byteTransform.TransInt16(data, 0);
|
|
|
- byte channel = data[6];
|
|
|
- short startAddress = byteTransform.TransInt16(data, 8);
|
|
|
- short bitCount = byteTransform.TransInt16(data, 10);
|
|
|
- byte byteCount = (byte)(bitCount / 8 + 1);
|
|
|
- byte[] bytes = new byte[byteCount];
|
|
|
- for (int i = 0; i < byteCount; i++)
|
|
|
- {
|
|
|
- byte[] tempbytes = new byte[8];
|
|
|
- Array.Copy(DIBytes, 8 * i, tempbytes, 0, 8);
|
|
|
- bytes[i] = ConvertByteArrayToHex(tempbytes);
|
|
|
- }
|
|
|
- OnWriteMessage(CreateReadDigitalResponse(flag, channel, command, byteCount, bytes));
|
|
|
- return;
|
|
|
- }
|
|
|
- else if (command == 0x04)
|
|
|
- {
|
|
|
- short flag = byteTransform.TransInt16(data, 0);
|
|
|
- byte channel = data[6];
|
|
|
- short startAddress = byteTransform.TransInt16(data, 8);
|
|
|
- short registerCount = byteTransform.TransInt16(data, 10);
|
|
|
- short[] shorts = new short[registerCount];
|
|
|
- Array.Copy(AIShorts, 0, shorts, 0, registerCount);
|
|
|
- byte[] bytes = new byte[registerCount * 2];
|
|
|
- bytes = ConvertShortArrayToByteArray(shorts);
|
|
|
- OnWriteMessage(CreateReadAnalogyResponse(flag, channel, command, (byte)registerCount, bytes));
|
|
|
- return;
|
|
|
- }
|
|
|
- else if (command == 0x05)
|
|
|
- {
|
|
|
- short startAddress = byteTransform.TransInt16(data, 8);
|
|
|
- if (startAddress > 0x03FF || startAddress < WRITE_DO_STARTADDRESS)
|
|
|
- {
|
|
|
- short flag = byteTransform.TransInt16(data, 0);
|
|
|
- byte channel = data[6];
|
|
|
- OnWriteMessage(CreateError(flag, channel, command, 0x02));
|
|
|
- return;
|
|
|
- }
|
|
|
- int position = startAddress - WRITE_DO_STARTADDRESS;
|
|
|
- bool status = data[10] == 0xFF ? true : false;
|
|
|
- lock (_writeDOLocker)
|
|
|
- {
|
|
|
- DOBytes[position] = status ? (byte)1 : (byte)0;
|
|
|
- }
|
|
|
- OnWriteMessage(data);
|
|
|
-
|
|
|
+
|
|
|
+ int reversedValue = 0;
|
|
|
+ for (int i = 0; i < 8; i++)
|
|
|
+ {
|
|
|
+ reversedValue |= ((binaryValue >> i) & 1) << (7 - i);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (byte.TryParse(reversedValue.ToString("X2"), System.Globalization.NumberStyles.HexNumber, null, out result))
|
|
|
+ {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private byte[] ConvertShortArrayToByteArray(short[] shortArray)
|
|
|
+ {
|
|
|
+ byte[] byteArray = new byte[shortArray.Length * 2];
|
|
|
+ for (int i = 0; i < shortArray.Length; i++)
|
|
|
+ {
|
|
|
+ byte[] tempBytes = BitConverter.GetBytes(shortArray[i]);
|
|
|
+ Array.Reverse(tempBytes);
|
|
|
+ Array.Copy(tempBytes, 0, byteArray, i * 2, 2);
|
|
|
+ }
|
|
|
+ return byteArray;
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ protected override void ProcessUnsplitMessage(byte[] data)
|
|
|
+ {
|
|
|
+ byte command = data[7];
|
|
|
+ if (command == 0x01)
|
|
|
+ {
|
|
|
+ short flag = byteTransform.TransInt16(data, 0);
|
|
|
+ byte channel = data[6];
|
|
|
+ short startAddress = byteTransform.TransInt16(data, 8);
|
|
|
+ short bitCount = byteTransform.TransInt16(data, 10);
|
|
|
+ byte byteCount = (byte)(bitCount / 8 + 1);
|
|
|
+ byte[] bytes = new byte[byteCount];
|
|
|
+ for(int i = 0; i < byteCount;i++)
|
|
|
+ {
|
|
|
+ byte[] tempbytes = new byte[8];
|
|
|
+ Array.Copy(DOBytes,8 * i, tempbytes, 0, 8);
|
|
|
+ bytes[i] = ConvertByteArrayToHex(tempbytes);
|
|
|
+ }
|
|
|
+ OnWriteMessage(CreateReadDigitalResponse(flag, channel, command, byteCount, bytes));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else if(command == 0x03)
|
|
|
+ {
|
|
|
+ short flag = byteTransform.TransInt16(data, 0);
|
|
|
+ byte channel = data[6];
|
|
|
+ short startAddress = byteTransform.TransInt16(data, 8);
|
|
|
+ short registerCount = byteTransform.TransInt16(data, 10);
|
|
|
+ short[] shorts = new short[registerCount];
|
|
|
+ Array.Copy(AOShorts, 0, shorts, 0, registerCount);
|
|
|
+ byte[] bytes = new byte[registerCount * 2];
|
|
|
+ bytes = ConvertShortArrayToByteArray(shorts);
|
|
|
+ OnWriteMessage(CreateReadAnalogyResponse(flag, channel, command, (byte)registerCount, bytes));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else if (command == 0x02)
|
|
|
+ {
|
|
|
+ short flag = byteTransform.TransInt16(data, 0);
|
|
|
+ byte channel = data[6];
|
|
|
+ short startAddress = byteTransform.TransInt16(data, 8);
|
|
|
+ short bitCount = byteTransform.TransInt16(data, 10);
|
|
|
+ byte byteCount = (byte)(bitCount / 8 + 1);
|
|
|
+ byte[] bytes = new byte[byteCount];
|
|
|
+ for (int i = 0; i < byteCount; i++)
|
|
|
+ {
|
|
|
+ byte[] tempbytes = new byte[8];
|
|
|
+ Array.Copy(DIBytes, 8 * i, tempbytes, 0, 8);
|
|
|
+ bytes[i] = ConvertByteArrayToHex(tempbytes);
|
|
|
+ }
|
|
|
+ OnWriteMessage(CreateReadDigitalResponse(flag, channel, command, byteCount, bytes));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else if (command == 0x04)
|
|
|
+ {
|
|
|
+ short flag = byteTransform.TransInt16(data, 0);
|
|
|
+ byte channel = data[6];
|
|
|
+ short startAddress = byteTransform.TransInt16(data, 8);
|
|
|
+ short registerCount = byteTransform.TransInt16(data, 10);
|
|
|
+ short[] shorts = new short[registerCount];
|
|
|
+ Array.Copy(AIShorts, 0, shorts, 0, registerCount);
|
|
|
+ byte[] bytes = new byte[registerCount * 2];
|
|
|
+ bytes = ConvertShortArrayToByteArray(shorts);
|
|
|
+ OnWriteMessage(CreateReadAnalogyResponse(flag, channel, command, (byte)registerCount, bytes));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else if (command == 0x05)
|
|
|
+ {
|
|
|
+ short startAddress = byteTransform.TransInt16(data, 8);
|
|
|
+ if (startAddress > 0x03FF || startAddress < WRITE_DO_STARTADDRESS)
|
|
|
+ {
|
|
|
+ short flag = byteTransform.TransInt16(data, 0);
|
|
|
+ byte channel = data[6];
|
|
|
+ OnWriteMessage(CreateError(flag, channel, command, 0x02));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ int position = startAddress - WRITE_DO_STARTADDRESS;
|
|
|
+ bool status = data[10] == 0xFF ? true : false;
|
|
|
+ lock (_writeDOLocker)
|
|
|
+ {
|
|
|
+ DOBytes[position] = status ? (byte)1 : (byte)0;
|
|
|
+ }
|
|
|
+ OnWriteMessage(data);
|
|
|
+
|
|
|
UpdateDataCausedByWago(position, status);
|
|
|
- return;
|
|
|
- }
|
|
|
- else if (command == 0x06)
|
|
|
- {
|
|
|
- short startAddress = byteTransform.TransInt16(data, 8);
|
|
|
- if(startAddress > 0x02FF || startAddress < WRITE_AO_STARTADDRESS)
|
|
|
- {
|
|
|
- short flag = byteTransform.TransInt16(data, 0);
|
|
|
- byte channel = data[6];
|
|
|
- OnWriteMessage(CreateError(flag, channel, command, 0x02));
|
|
|
- return;
|
|
|
- }
|
|
|
- int position = startAddress - WRITE_AO_STARTADDRESS;
|
|
|
- short value = byteTransform.TransInt16(data, 10);
|
|
|
- lock (_writeAOLocker)
|
|
|
- {
|
|
|
- AOShorts[position] = value;
|
|
|
- }
|
|
|
- OnWriteMessage(data);
|
|
|
- return;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- short flag = byteTransform.TransInt16(data, 0);
|
|
|
- byte channel = data[6];
|
|
|
- OnWriteMessage(CreateError(flag, channel, command, 0x01));
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private byte[] CreateReadDigitalResponse(short flag, byte channel, byte command, byte byteCount, byte[] values)
|
|
|
- {
|
|
|
- byte[] bytes = new byte[7 + 2 + values.Length];
|
|
|
- Array.Copy(byteTransform.GetBytes(flag), 0, bytes, 0, 2);
|
|
|
- bytes[2] = 0x00;
|
|
|
- bytes[3] = 0x00;
|
|
|
- short dataLength = (short)(3 + values.Length);
|
|
|
- Array.Copy(byteTransform.GetBytes(dataLength), 0, bytes, 4, 2);
|
|
|
- bytes[6] = channel;
|
|
|
- bytes[7] = command;
|
|
|
- bytes[8] = byteCount;
|
|
|
- Array.Copy(values, 0, bytes, 9, values.Length);
|
|
|
- return bytes;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private byte[] CreateReadAnalogyResponse(short flag, byte channel, byte command, byte registerCount, byte[] values)
|
|
|
- {
|
|
|
- byte[] bytes = new byte[7 + 2 + 2 * registerCount];
|
|
|
- Array.Copy(byteTransform.GetBytes(flag), 0, bytes, 0, 2);
|
|
|
- bytes[2] = 0x00;
|
|
|
- bytes[3] = 0x00;
|
|
|
- short dataLength = (short)(3 + 2 * registerCount);
|
|
|
- Array.Copy(byteTransform.GetBytes(dataLength), 0, bytes, 4, 2);
|
|
|
- bytes[6] = channel;
|
|
|
- bytes[7] = command;
|
|
|
- bytes[8] = (byte)(2 * registerCount);
|
|
|
- Array.Copy(values, 0, bytes, 9, values.Length);
|
|
|
- return bytes;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private byte[] CreateError(short flag, byte channel, byte command, byte error)
|
|
|
- {
|
|
|
- byte[] bytes = new byte[9];
|
|
|
- Array.Copy(byteTransform.GetBytes(flag), 0, bytes, 0, 2);
|
|
|
- bytes[2] = 0x00;
|
|
|
- bytes[3] = 0x00;
|
|
|
- bytes[4] = 0x00;
|
|
|
- bytes[5] = 0x03;
|
|
|
- bytes[6] = channel;
|
|
|
- bytes[7] = (byte)(command | 0x80);
|
|
|
- bytes[8] = error;
|
|
|
- return bytes;
|
|
|
- }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else if (command == 0x06)
|
|
|
+ {
|
|
|
+ short startAddress = byteTransform.TransInt16(data, 8);
|
|
|
+ if(startAddress > 0x02FF || startAddress < WRITE_AO_STARTADDRESS)
|
|
|
+ {
|
|
|
+ short flag = byteTransform.TransInt16(data, 0);
|
|
|
+ byte channel = data[6];
|
|
|
+ OnWriteMessage(CreateError(flag, channel, command, 0x02));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ int position = startAddress - WRITE_AO_STARTADDRESS;
|
|
|
+ short value = byteTransform.TransInt16(data, 10);
|
|
|
+ lock (_writeAOLocker)
|
|
|
+ {
|
|
|
+ AOShorts[position] = value;
|
|
|
+ }
|
|
|
+ OnWriteMessage(data);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ short flag = byteTransform.TransInt16(data, 0);
|
|
|
+ byte channel = data[6];
|
|
|
+ OnWriteMessage(CreateError(flag, channel, command, 0x01));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private byte[] CreateReadDigitalResponse(short flag, byte channel, byte command, byte byteCount, byte[] values)
|
|
|
+ {
|
|
|
+ byte[] bytes = new byte[7 + 2 + values.Length];
|
|
|
+ Array.Copy(byteTransform.GetBytes(flag), 0, bytes, 0, 2);
|
|
|
+ bytes[2] = 0x00;
|
|
|
+ bytes[3] = 0x00;
|
|
|
+ short dataLength = (short)(3 + values.Length);
|
|
|
+ Array.Copy(byteTransform.GetBytes(dataLength), 0, bytes, 4, 2);
|
|
|
+ bytes[6] = channel;
|
|
|
+ bytes[7] = command;
|
|
|
+ bytes[8] = byteCount;
|
|
|
+ Array.Copy(values, 0, bytes, 9, values.Length);
|
|
|
+ return bytes;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private byte[] CreateReadAnalogyResponse(short flag, byte channel, byte command, byte registerCount, byte[] values)
|
|
|
+ {
|
|
|
+ byte[] bytes = new byte[7 + 2 + 2 * registerCount];
|
|
|
+ Array.Copy(byteTransform.GetBytes(flag), 0, bytes, 0, 2);
|
|
|
+ bytes[2] = 0x00;
|
|
|
+ bytes[3] = 0x00;
|
|
|
+ short dataLength = (short)(3 + 2 * registerCount);
|
|
|
+ Array.Copy(byteTransform.GetBytes(dataLength), 0, bytes, 4, 2);
|
|
|
+ bytes[6] = channel;
|
|
|
+ bytes[7] = command;
|
|
|
+ bytes[8] = (byte)(2 * registerCount);
|
|
|
+ Array.Copy(values, 0, bytes, 9, values.Length);
|
|
|
+ return bytes;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private byte[] CreateError(short flag, byte channel, byte command, byte error)
|
|
|
+ {
|
|
|
+ byte[] bytes = new byte[9];
|
|
|
+ Array.Copy(byteTransform.GetBytes(flag), 0, bytes, 0, 2);
|
|
|
+ bytes[2] = 0x00;
|
|
|
+ bytes[3] = 0x00;
|
|
|
+ bytes[4] = 0x00;
|
|
|
+ bytes[5] = 0x03;
|
|
|
+ bytes[6] = channel;
|
|
|
+ bytes[7] = (byte)(command | 0x80);
|
|
|
+ bytes[8] = error;
|
|
|
+ return bytes;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
private bool OnTimer()
|
|
|
{
|
|
|
LeakTestSimulator();
|
|
@@ -774,7 +774,7 @@ namespace CyberX8_Simulator.Devices
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
private bool OnTimer1()
|
|
|
{
|
|
|
RinseWaterLevelSimulator();
|
|
@@ -784,16 +784,16 @@ namespace CyberX8_Simulator.Devices
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
private bool OnTimer3()
|
|
|
{
|
|
|
Pump4FlowSimulator();
|
|
|
return true;
|
|
|
}
|
|
|
- #region 模拟方法
|
|
|
+ #region 模拟方法
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
private void LeakTestSimulator()
|
|
|
{
|
|
|
if (DOBytes[DONameIndexDic["c_VACUUM_TEST"]] == 1 && _festoDataBuffer["FlowTestClamp"] && AIShorts[AINameIndexDic["r_LOADER_GasFlowSensor_FLOW"]] == 0)
|
|
@@ -816,7 +816,7 @@ namespace CyberX8_Simulator.Devices
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
private void RinseWaterLevelSimulator()
|
|
|
{
|
|
|
|
|
@@ -881,7 +881,7 @@ namespace CyberX8_Simulator.Devices
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
private void PumpFlowSimulator()
|
|
|
{
|
|
|
if (DOBytes[DONameIndexDic["c_METAL3_PUMP_ON"]] == 1)
|
|
@@ -913,7 +913,7 @@ namespace CyberX8_Simulator.Devices
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
private void Pump4FlowSimulator()
|
|
|
{
|
|
|
if (DONameIndexDic.ContainsKey("c_METAL4_PUMP_ON") && DOBytes[DONameIndexDic["c_METAL4_PUMP_ON"]] == 1)
|
|
@@ -924,7 +924,7 @@ namespace CyberX8_Simulator.Devices
|
|
|
{
|
|
|
SimulatorCommManager.Instance.CheckDataChanged("c_METAL4_PUMP_ON", false, false);
|
|
|
}
|
|
|
- }
|
|
|
- #endregion
|
|
|
- }
|
|
|
-}
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+ }
|
|
|
+}
|