Commit 590a69a1 LN

IO类型=99时使用模拟IO

1 个父辈 cf1beefc
...@@ -99,6 +99,7 @@ ...@@ -99,6 +99,7 @@
<Compile Include="csvLoad\CSVBomManager.cs" /> <Compile Include="csvLoad\CSVBomManager.cs" />
<Compile Include="db.cs" /> <Compile Include="db.cs" />
<Compile Include="deviceLibrary\halcon\UsbCameraHDevelop.cs" /> <Compile Include="deviceLibrary\halcon\UsbCameraHDevelop.cs" />
<Compile Include="deviceLibrary\IO\EmulationIO.cs" />
<Compile Include="deviceLibrary\IO\IOManager.cs" /> <Compile Include="deviceLibrary\IO\IOManager.cs" />
<Compile Include="deviceLibrary\IO\kangnaide\KNDManager.cs" /> <Compile Include="deviceLibrary\IO\kangnaide\KNDManager.cs" />
<Compile Include="deviceLibrary\IO\kangnaide\MasterTcpClient.cs" /> <Compile Include="deviceLibrary\IO\kangnaide\MasterTcpClient.cs" />
......

using System.Collections.Generic;
namespace TSA_V.DeviceLibrary
{
internal class EmulationIO : IOBase
{
/// <summary>
/// 所有DI状态
/// </summary>
public bool[] DIstate = new bool[128];
/// <summary>
/// 所有DO状态
/// </summary>
public bool[] DOstate = new bool[128];
public override void CloseAllConnection()
{
}
public override void CloseAllDO()
{
}
public override void ConnectionIP(string kNDIP, ushort kNDPort)
{
for(int i = 0; i < DIstate.Length; i++)
{
DIstate[i] = false ;
}
for (int i = 0; i < DOstate.Length; i++)
{
DOstate[i] = false;
}
}
public override void ConnectionKND(List<string> dIODeviceNameList)
{
}
private bool WriteDO(int index,bool v)
{
if(DOstate.Length>index)
{
DOstate[index] = v;
return true;
}
return false;
}
public override void WriteSingleDO(string deviceName, byte slaveId, ushort index, IO_VALUE value, int time)
{
WriteDO(index, value == IO_VALUE.HIGH);
}
public override bool IsConnection(string kNDIP)
{
return true ;
}
public override void WriteSingleDO(string deviceName, byte slaveId, ushort index, IO_VALUE value)
{
WriteDO(index, value == IO_VALUE.HIGH);
}
public override IO_VALUE GetDIValue(string deviceName, byte slaveID, ushort v)
{
if (v < DIstate.Length)
return DIstate[v] ? IO_VALUE.HIGH : IO_VALUE.LOW;
else
return IO_VALUE.LOW;
}
public override IO_VALUE GetDOValue(string deviceName, byte slaveID, ushort v)
{
if (v < DOstate.Length)
return DOstate[v] ? IO_VALUE.HIGH : IO_VALUE.LOW;
else
return IO_VALUE.LOW;
}
public override IO_VALUE GetIOValue(ConfigIO configIO)
{
if (configIO.ProType.Equals(ConfigItemType.DI))
{
if (configIO.IOIndex < DIstate.Length)
return DIstate[configIO.IOIndex] ? IO_VALUE.HIGH : IO_VALUE.LOW;
else
return IO_VALUE.LOW;
}
else
{
if (configIO.IOIndex < DOstate.Length)
return DOstate[configIO.IOIndex] ? IO_VALUE.HIGH : IO_VALUE.LOW;
else
return IO_VALUE.LOW;
}
}
public override void ReadAllDI(string deviceName, byte slaveId)
{
}
public override void ReadAllDO(string deviceName, byte slaveId)
{
}
public override void WriteSingleDI(string deviceName, byte slaveId, ushort index, IO_VALUE value)
{
if (DIstate.Length > index)
{
DIstate[index] = value.Equals(IO_VALUE.HIGH);
}
}
}
}
...@@ -22,28 +22,40 @@ namespace TSA_V.DeviceLibrary ...@@ -22,28 +22,40 @@ namespace TSA_V.DeviceLibrary
/// </summary> /// </summary>
public static bool NoLine = false; public static bool NoLine = false;
public static int IOType = Setting_NInit.Work_IOType;
public static void Init() public static void Init()
{ {
//int isAIOBox = ConfigAppSettings.GetIntValue(Setting_Init.UseAIOBOX); //int isAIOBox = ConfigAppSettings.GetIntValue(Setting_Init.UseAIOBOX);
int isAIOBox = Setting_NInit.Work_IOType; IOType = Setting_NInit.Work_IOType;
if (isAIOBox==1) if (IOType == 1)
{ {
instance = new AIOBOXManager(); instance = new AIOBOXManager();
} }
else if (isAIOBox == 2) else if (IOType == 2)
{ {
instance = new NanjingSDotIO(); instance = new NanjingSDotIO();
} }
else if (isAIOBox == 3) else if (IOType == 3)
{ {
instance = new NiRenIO(); instance = new NiRenIO();
NoLine = true; NoLine = true;
}else if (IOType == 99)
{
instance = new EmulationIO();
NoLine = true;
LogUtil.info("使用模拟IO");
} }
else else
{ {
instance = new KNDManager(); instance = new KNDManager();
} }
} }
public static bool UseEmulationIO
{
get { return IOType == 99; }
set { }
}
public abstract void ReadAllDI(string deviceName, byte slaveId); public abstract void ReadAllDI(string deviceName, byte slaveId);
public abstract void ReadAllDO(string deviceName, byte slaveId); public abstract void ReadAllDO(string deviceName, byte slaveId);
...@@ -66,5 +78,8 @@ namespace TSA_V.DeviceLibrary ...@@ -66,5 +78,8 @@ namespace TSA_V.DeviceLibrary
public abstract void CloseAllConnection(); public abstract void CloseAllConnection();
public virtual void WriteSingleDI(string deviceName, byte slaveId, ushort index, IO_VALUE value)
{
}
} }
} }
...@@ -33,7 +33,7 @@ namespace TSA_V.DeviceLibrary ...@@ -33,7 +33,7 @@ namespace TSA_V.DeviceLibrary
} }
private static StringBuilder builder = new StringBuilder("\r\n"); private static StringBuilder builder = new StringBuilder("\r\n");
public static void InitData() public static void InitData()
{ {
KNDIP = Setting_NInit.Device_IO_IP; KNDIP = Setting_NInit.Device_IO_IP;
KNDPort = (ushort)Setting_NInit.Device_IO_Port; KNDPort = (ushort)Setting_NInit.Device_IO_Port;
...@@ -41,9 +41,19 @@ namespace TSA_V.DeviceLibrary ...@@ -41,9 +41,19 @@ namespace TSA_V.DeviceLibrary
IOBase.Init(); IOBase.Init();
builder = new StringBuilder("\r\n"); builder = new StringBuilder("\r\n");
if (IOBase.NoLine) if (IOBase.NoLine)
{
IOBase.instance.DIStartAddress = 0; IOBase.instance.DIStartAddress = 0;
AddDI(new ConfigIO(ConfigItemType.DI, KNDIP, slaveId, IOBase.instance.DIStartAddress, "SuddenStop", "X01_急停")); }
AddDI(new ConfigIO(ConfigItemType.DI, KNDIP, slaveId, IOBase.instance.DIStartAddress, "SuddenStop", "X01_急停"));
AddDI(new ConfigIO(ConfigItemType.DI, KNDIP, slaveId, (ushort)(IOBase.instance.DIStartAddress + 1), "Footrest_Single", "X02_启动")); AddDI(new ConfigIO(ConfigItemType.DI, KNDIP, slaveId, (ushort)(IOBase.instance.DIStartAddress + 1), "Footrest_Single", "X02_启动"));
if (IOBase.UseEmulationIO)
{
DIMove(SuddenStop, IO_VALUE.HIGH);
DIMove(Footrest_Single, IO_VALUE.LOW);
IO_VALUE value = IOValue(SuddenStop);
}
if (!IOBase.NoLine) if (!IOBase.NoLine)
{ {
AddDI(new ConfigIO(ConfigItemType.DI, KNDIP, slaveId, (ushort)(IOBase.instance.DIStartAddress + 2), "AirCheck_Single", "X03_气压检测")); AddDI(new ConfigIO(ConfigItemType.DI, KNDIP, slaveId, (ushort)(IOBase.instance.DIStartAddress + 2), "AirCheck_Single", "X03_气压检测"));
...@@ -55,12 +65,12 @@ namespace TSA_V.DeviceLibrary ...@@ -55,12 +65,12 @@ namespace TSA_V.DeviceLibrary
AddDI(new ConfigIO(ConfigItemType.DI, KNDIP, slaveId, (ushort)(IOBase.instance.DIStartAddress + 8), "StopCylinder_Up", "X09_挡停气缸上升端")); AddDI(new ConfigIO(ConfigItemType.DI, KNDIP, slaveId, (ushort)(IOBase.instance.DIStartAddress + 8), "StopCylinder_Up", "X09_挡停气缸上升端"));
AddDI(new ConfigIO(ConfigItemType.DI, KNDIP, slaveId, (ushort)(IOBase.instance.DIStartAddress + 9), "StopCylinder_Down", "X10_挡停气缸下降端")); AddDI(new ConfigIO(ConfigItemType.DI, KNDIP, slaveId, (ushort)(IOBase.instance.DIStartAddress + 9), "StopCylinder_Down", "X10_挡停气缸下降端"));
if (!TSAVBean.DisableSideCylinder) if (!TSAVBean.DisableSideCylinder)
{ {
AddDI(new ConfigIO(ConfigItemType.DI, KNDIP, slaveId, (ushort)(IOBase.instance.DIStartAddress + 10), "SideCylinder_Forward", "X11_侧挡气缸前进端")); AddDI(new ConfigIO(ConfigItemType.DI, KNDIP, slaveId, (ushort)(IOBase.instance.DIStartAddress + 10), "SideCylinder_Forward", "X11_侧挡气缸前进端"));
AddDI(new ConfigIO(ConfigItemType.DI, KNDIP, slaveId, (ushort)(IOBase.instance.DIStartAddress + 11), "SideCylinder_Back", "X12_侧挡气缸后退端")); AddDI(new ConfigIO(ConfigItemType.DI, KNDIP, slaveId, (ushort)(IOBase.instance.DIStartAddress + 11), "SideCylinder_Back", "X12_侧挡气缸后退端"));
} }
if (!TSAVBean.DisableBottomCylinder) if (!TSAVBean.DisableBottomCylinder)
{ {
AddDI(new ConfigIO(ConfigItemType.DI, KNDIP, slaveId, (ushort)(IOBase.instance.DIStartAddress + 12), "BottomCylinder_Down1", "X13_底部定位气缸1下降端")); AddDI(new ConfigIO(ConfigItemType.DI, KNDIP, slaveId, (ushort)(IOBase.instance.DIStartAddress + 12), "BottomCylinder_Down1", "X13_底部定位气缸1下降端"));
AddDI(new ConfigIO(ConfigItemType.DI, KNDIP, slaveId, (ushort)(IOBase.instance.DIStartAddress + 13), "BottomCylinder_Down2", "X14_底部定位气缸2下降端")); AddDI(new ConfigIO(ConfigItemType.DI, KNDIP, slaveId, (ushort)(IOBase.instance.DIStartAddress + 13), "BottomCylinder_Down2", "X14_底部定位气缸2下降端"));
} }
...@@ -76,7 +86,7 @@ namespace TSA_V.DeviceLibrary ...@@ -76,7 +86,7 @@ namespace TSA_V.DeviceLibrary
AddDO(new ConfigIO(ConfigItemType.DO, KNDIP, slaveId, (ushort)(IOBase.instance.DoStartAddress + 7), "SideCylinder_Back", "Y08_侧挡气缸后退SOL")); AddDO(new ConfigIO(ConfigItemType.DO, KNDIP, slaveId, (ushort)(IOBase.instance.DoStartAddress + 7), "SideCylinder_Back", "Y08_侧挡气缸后退SOL"));
} }
if (!TSAVBean.DisableBottomCylinder) if (!TSAVBean.DisableBottomCylinder)
{ {
AddDO(new ConfigIO(ConfigItemType.DO, KNDIP, slaveId, (ushort)(IOBase.instance.DoStartAddress + 8), "BottomCylinder_Up", "Y09_底部定位气缸上升SOL")); AddDO(new ConfigIO(ConfigItemType.DO, KNDIP, slaveId, (ushort)(IOBase.instance.DoStartAddress + 8), "BottomCylinder_Up", "Y09_底部定位气缸上升SOL"));
AddDO(new ConfigIO(ConfigItemType.DO, KNDIP, slaveId, (ushort)(IOBase.instance.DoStartAddress + 9), "BottomCylinder_Down", "Y10_底部定位气缸下降SOL")); AddDO(new ConfigIO(ConfigItemType.DO, KNDIP, slaveId, (ushort)(IOBase.instance.DoStartAddress + 9), "BottomCylinder_Down", "Y10_底部定位气缸下降SOL"));
} }
...@@ -88,7 +98,7 @@ namespace TSA_V.DeviceLibrary ...@@ -88,7 +98,7 @@ namespace TSA_V.DeviceLibrary
} }
if (String.IsNullOrEmpty(builder.ToString()).Equals(false) && builder.ToString().Equals("\r\n").Equals(false)) if (String.IsNullOrEmpty(builder.ToString()).Equals(false) && builder.ToString().Equals("\r\n").Equals(false))
{ {
// LogUtil.info(builder.ToString()); // LogUtil.info(builder.ToString());
} }
} }
private static void AddDI(ConfigIO io) private static void AddDI(ConfigIO io)
...@@ -196,6 +206,21 @@ namespace TSA_V.DeviceLibrary ...@@ -196,6 +206,21 @@ namespace TSA_V.DeviceLibrary
IOMove(ioType, ioValue); IOMove(ioType, ioValue);
} }
} }
public static void DIMove(string ioType, IO_VALUE ioValue)
{
try
{
if (DIList.ContainsKey(ioType))
{
ConfigIO io = DIList[ioType];
IOBase.instance.WriteSingleDI(io.DeviceName, io.SlaveID, io.IOIndex, ioValue);
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "DOMove 错误ioType=" + ioType + ",value=" + ioValue + ",错误信息:" + ex.ToString());
}
}
public static void IOMove(string ioType, IO_VALUE ioValue) public static void IOMove(string ioType, IO_VALUE ioValue)
{ {
try try
...@@ -207,15 +232,17 @@ namespace TSA_V.DeviceLibrary ...@@ -207,15 +232,17 @@ namespace TSA_V.DeviceLibrary
Thread.Sleep(60); Thread.Sleep(60);
} }
else else
{ {
if (IOBase.NoLine) if (IOBase.NoLine)
{
return; return;
}
LogUtil.error(LOGGER, "没有DO=" + ioType); LogUtil.error(LOGGER, "没有DO=" + ioType);
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.error(LOGGER, "KNDIOMove错误ioType=" + ioType + ",value=" + ioValue + ",错误信息:" + ex.ToString()); LogUtil.error(LOGGER, "IOMove 错误ioType=" + ioType + ",value=" + ioValue + ",错误信息:" + ex.ToString());
} }
} }
......
...@@ -746,7 +746,7 @@ ...@@ -746,7 +746,7 @@
this.btnStartWorking.BackColor = System.Drawing.SystemColors.Control; this.btnStartWorking.BackColor = System.Drawing.SystemColors.Control;
this.btnStartWorking.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.btnStartWorking.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnStartWorking.Font = new System.Drawing.Font("微软雅黑", 10.5F); this.btnStartWorking.Font = new System.Drawing.Font("微软雅黑", 10.5F);
this.btnStartWorking.Location = new System.Drawing.Point(866, 583); this.btnStartWorking.Location = new System.Drawing.Point(744, 583);
this.btnStartWorking.Name = "btnStartWorking"; this.btnStartWorking.Name = "btnStartWorking";
this.btnStartWorking.Size = new System.Drawing.Size(120, 60); this.btnStartWorking.Size = new System.Drawing.Size(120, 60);
this.btnStartWorking.TabIndex = 263; this.btnStartWorking.TabIndex = 263;
...@@ -956,11 +956,11 @@ ...@@ -956,11 +956,11 @@
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1479, 652); this.ClientSize = new System.Drawing.Size(1479, 652);
this.Controls.Add(this.lblShortageInfo); this.Controls.Add(this.lblShortageInfo);
this.Controls.Add(this.btnWorkInfo);
this.Controls.Add(this.btnResetAOI); this.Controls.Add(this.btnResetAOI);
this.Controls.Add(this.lblHandInfo); this.Controls.Add(this.lblHandInfo);
this.Controls.Add(this.linkLabel1); this.Controls.Add(this.linkLabel1);
this.Controls.Add(this.groupBoard); this.Controls.Add(this.groupBoard);
this.Controls.Add(this.btnWorkInfo);
this.Controls.Add(this.btnStartWorking); this.Controls.Add(this.btnStartWorking);
this.Controls.Add(this.groupHand); this.Controls.Add(this.groupHand);
this.Controls.Add(this.btnCodeTest); this.Controls.Add(this.btnCodeTest);
......
...@@ -135,7 +135,11 @@ namespace TSA_V ...@@ -135,7 +135,11 @@ namespace TSA_V
btnPrePoint.Visible = Visible; btnPrePoint.Visible = Visible;
btnNextPoint.Visible = Visible; btnNextPoint.Visible = Visible;
btnGoHome.Visible = Visible; btnGoHome.Visible = Visible;
} }
if (IOBase.UseEmulationIO)
{
btnStartWorking.Visible = true;
}
HandRecordManager.Reset(); HandRecordManager.Reset();
isInitOk = true; isInitOk = true;
// string ip = ConfigAppSettings.GetValue(Setting_Init.StatusServerIp); // string ip = ConfigAppSettings.GetValue(Setting_Init.StatusServerIp);
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!