|
@@ -12,23 +12,30 @@ namespace CyberX8_Simulator.Devices
|
|
|
public class WagoSocketSimulator : SocketDeviceSimulator
|
|
|
{
|
|
|
private const short WRITE_DO_STARTADDRESS = 0x0200;
|
|
|
- private const short WRITE_AO_STARTADDRESS = 0x0200;
|
|
|
-
|
|
|
-
|
|
|
+ private const short WRITE_AO_STARTADDRESS = 0x0200;
|
|
|
+
|
|
|
+ //键是名字,值是对应数据所在的位置 注意:要和WagoControlCfg里面的地址顺序对上
|
|
|
+ private Dictionary<string, int> DONameIndexDic = new Dictionary<string, int>
|
|
|
+ {{"DO0",0 },{"c_LoaderA_LS_Vacuum",1} };
|
|
|
+ private Dictionary<string, int> DINameIndexDic = new Dictionary<string, int>
|
|
|
+ {{"r_DRIP_TRAY_FLUID_DETECTION",19 },{"DI1",1} };
|
|
|
+ private Dictionary<string, int> AINameIndexDic = new Dictionary<string, int>
|
|
|
+ {{"r_LoaderA_LS_Vacuum_anlg",0 },{"AI1",1} };
|
|
|
+ private Dictionary<string, int> AONameIndexDic = new Dictionary<string, int>
|
|
|
+ {{"AO0",0 },{"AO1",1} };
|
|
|
+
|
|
|
private IByteTransform byteTransform = new BigEndianByteTransformBase();
|
|
|
|
|
|
private byte[] DOBytes = new byte[100];
|
|
|
- //键是名字,值是对应DoByte所在的位置
|
|
|
- private Dictionary<string,int> DONameIndexDic = new Dictionary<string, int>
|
|
|
- {{"DO0",0 },{"c_LoaderA_LS_Vacuum",1} };
|
|
|
- private Dictionary<string, int> DINameIndexDic = new Dictionary<string, int>
|
|
|
- {{"DI0",0 },{"DI1",1} };
|
|
|
|
|
|
private short[] AOShorts = new short[50];
|
|
|
|
|
|
private byte[] DIBytes = new byte[100];
|
|
|
|
|
|
private short[] AIShorts = new short[50];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 写DO锁
|
|
|
/// </summary>
|
|
@@ -48,8 +55,7 @@ namespace CyberX8_Simulator.Devices
|
|
|
/// </summary>
|
|
|
private void InitializeData()
|
|
|
{
|
|
|
- AIShorts[3] = 0x1388;
|
|
|
- DIBytes[2] = 0x01;
|
|
|
+ AIShorts[0] = 0x1388;
|
|
|
}
|
|
|
|
|
|
#region 公共方法
|
|
@@ -57,23 +63,59 @@ namespace CyberX8_Simulator.Devices
|
|
|
{
|
|
|
if (DONameIndexDic.ContainsKey(name))
|
|
|
{
|
|
|
- DOBytes[DONameIndexDic[name]] = value == 0 ? (byte)0 : (byte)1;
|
|
|
+ if (DONameIndexDic[name] < DOBytes.Length)
|
|
|
+ {
|
|
|
+ DOBytes[DONameIndexDic[name]] = value == 0 ? (byte)0 : (byte)1;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
public void UpdataDIBytes(string name, int value)
|
|
|
{
|
|
|
if (DINameIndexDic.ContainsKey(name))
|
|
|
{
|
|
|
- DIBytes[DONameIndexDic[name]] = value == 0 ? (byte)0 : (byte)1;
|
|
|
+ if (DINameIndexDic[name] < DIBytes.Length)
|
|
|
+ {
|
|
|
+ DIBytes[DINameIndexDic[name]] = value == 0 ? (byte)0 : (byte)1;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
public void UpdataAOShorts(string name, int value)
|
|
|
{
|
|
|
-
|
|
|
+ if (AONameIndexDic.ContainsKey(name))
|
|
|
+ {
|
|
|
+ string hexValue = value.ToString("X2");
|
|
|
+ try
|
|
|
+ {
|
|
|
+ short result = Convert.ToInt16(hexValue, 16);
|
|
|
+ if (AONameIndexDic[name] < AOShorts.Length)
|
|
|
+ {
|
|
|
+ AOShorts[AONameIndexDic[name]] = result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (FormatException)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
public void UpdataAIShorts(string name, int value)
|
|
|
{
|
|
|
-
|
|
|
+ if (AINameIndexDic.ContainsKey(name))
|
|
|
+ {
|
|
|
+ string hexValue = value.ToString("X2");
|
|
|
+ try
|
|
|
+ {
|
|
|
+ short result = Convert.ToInt16(hexValue, 16);
|
|
|
+ if(AINameIndexDic[name] < AIShorts.Length)
|
|
|
+ {
|
|
|
+ AIShorts[AINameIndexDic[name]] = result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (FormatException)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
#endregion
|
|
|
|