Commit dc200d8b LN

RC1246流水线单台料仓修改:压紧轴修改,IO修改,去掉扫码和测高。

1 个父辈 fb45b826
正在显示 33 个修改的文件 包含 4912 行增加2511 行删除

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2024
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ACServoDriveTest", "source\ACServoDriveTest\ACServoDriveTest.csproj", "{7FA84E1E-BCDE-49F6-BE42-0BC397AF65B8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ACSingleStore", "source\ACSingleStore\ACSingleStore.csproj", "{0D2542F5-DD62-4352-82D0-383D9A045E74}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common", "source\Common\Common.csproj", "{43CDD09E-FCF3-4960-A01D-3BBFE9933122}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeviceLibrary", "source\DeviceLibrary\DeviceLibrary.csproj", "{513BC1C9-800D-43A6-9499-3700BAEC3554}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserFromControl", "source\UserFromControl\UserFromControl.csproj", "{F018462A-D9BC-4365-97F2-F6D71751641E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LoadCSVLibrary", "source\LoadCVSLibrary\LoadCSVLibrary.csproj", "{064BEBF5-8FAA-4EA2-A5F3-A06E6E7D9251}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7FA84E1E-BCDE-49F6-BE42-0BC397AF65B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7FA84E1E-BCDE-49F6-BE42-0BC397AF65B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7FA84E1E-BCDE-49F6-BE42-0BC397AF65B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7FA84E1E-BCDE-49F6-BE42-0BC397AF65B8}.Release|Any CPU.Build.0 = Release|Any CPU
{0D2542F5-DD62-4352-82D0-383D9A045E74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0D2542F5-DD62-4352-82D0-383D9A045E74}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0D2542F5-DD62-4352-82D0-383D9A045E74}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0D2542F5-DD62-4352-82D0-383D9A045E74}.Release|Any CPU.Build.0 = Release|Any CPU
{43CDD09E-FCF3-4960-A01D-3BBFE9933122}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{43CDD09E-FCF3-4960-A01D-3BBFE9933122}.Debug|Any CPU.Build.0 = Debug|Any CPU
{43CDD09E-FCF3-4960-A01D-3BBFE9933122}.Release|Any CPU.ActiveCfg = Release|Any CPU
{43CDD09E-FCF3-4960-A01D-3BBFE9933122}.Release|Any CPU.Build.0 = Release|Any CPU
{513BC1C9-800D-43A6-9499-3700BAEC3554}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{513BC1C9-800D-43A6-9499-3700BAEC3554}.Debug|Any CPU.Build.0 = Debug|Any CPU
{513BC1C9-800D-43A6-9499-3700BAEC3554}.Release|Any CPU.ActiveCfg = Release|Any CPU
{513BC1C9-800D-43A6-9499-3700BAEC3554}.Release|Any CPU.Build.0 = Release|Any CPU
{F018462A-D9BC-4365-97F2-F6D71751641E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F018462A-D9BC-4365-97F2-F6D71751641E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F018462A-D9BC-4365-97F2-F6D71751641E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F018462A-D9BC-4365-97F2-F6D71751641E}.Release|Any CPU.Build.0 = Release|Any CPU
{064BEBF5-8FAA-4EA2-A5F3-A06E6E7D9251}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{064BEBF5-8FAA-4EA2-A5F3-A06E6E7D9251}.Debug|Any CPU.Build.0 = Debug|Any CPU
{064BEBF5-8FAA-4EA2-A5F3-A06E6E7D9251}.Release|Any CPU.ActiveCfg = Release|Any CPU
{064BEBF5-8FAA-4EA2-A5F3-A06E6E7D9251}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5459501E-8250-488F-B563-3C6777AEFCBA}
EndGlobalSection
EndGlobal
......@@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>OnlineStore.ACSingleStore</RootNamespace>
<AssemblyName>ACSingleStore</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
......
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
</configSections>
<appSettings>
<!--是否开机自动启动料仓-->
<add key="App_AutoRun" value="1" />
<add key="App_Title" value="AC_SA_料仓_1" />
<add key="scanner_start_command" value="S" />
<add key="App_AutoRun" value="1"/>
<add key="App_Title" value="AC_SA_料仓_1"/>
<add key="scanner_start_command" value="S"/>
<!-- 开始吹气的判断值(配置值=服务器发送的湿度值-开始吹气值)-->
<add key="StartBlowValue" value="4" />
<add key="StartBlowValue" value="4"/>
<!-- 停止吹气的判断值(配置值=服务器发送的湿度值-停止吹气值)-->
<add key="StopBlowValue" value="4" />
<add key="StopBlowValue" value="4"/>
<!--Server address-->
<!--<add key="http.server" value="http://localhost:80/"/>-->
<!--storeType-->
<add key="store_count" value="1" />
<add key="store_count" value="1"/>
<!--start one store config-->
<add key="Store_Position_Config" value="\StoreConfig\AC\linePositions.csv" />
<add key="Store_ConfigPath" value="\StoreConfig\AC\StoreConfig.csv" />
<add key="Store_Type" value="RC_AC_SA" />
<add key="Store_CID" value="rc29ac-1" />
<add key="Store_Position_Config" value="\StoreConfig\AC\linePositions.csv"/>
<add key="Store_ConfigPath" value="\StoreConfig\AC\StoreConfig.csv"/>
<add key="Store_Type" value="RC_AC_SA"/>
<add key="Store_CID" value="rc29ac-1"/>
<!--end one store config-->
<!--摄像机名称列表配置,用#分割-->
<add key="CameraName" value="GigE:MV-CE100-30GC (00C69898483)" />
<add key="CameraName" value="GigE:MV-CE100-30GC (00C69898483)"/>
<!--二维码类型列表配置,用#分割,一维码=Barcode-->
<add key="CodeType" value="QR Code#Data Matrix ECC 200#Micro QR Code" />
<add key="CodeType" value="QR Code#Data Matrix ECC 200#Micro QR Code"/>
<!--<add key="CodeType" value="Data Matrix ECC 200"/>-->
<!--二维码参数文件所在路径,文件名与二维码类型名一样-->
<add key="CodeParamPath" value="\CodeParam\" />
<add key ="AI_ConvertPosition" value ="55"/>
<add key ="InOutDefaultPosition" value ="8000"/>
<add key ="Config_Pwd" value ="123456"/>
<add key="CodeParamPath" value="\CodeParam\"/>
<add key="AI_ConvertPosition" value="55"/>
<add key="InOutDefaultPosition" value="8000"/>
<add key="Config_Pwd" value="123456"/>
<!--出库等待料盘拿走的时间,秒-->
<add key ="OutStoreWaitSeconds" value ="10"/>
<add key="OutStoreWaitSeconds" value="10"/>
<!--压紧轴对应1mm的脉冲-->
<add key="ComAxisChangeValue" value="2400" />
<add key="ComAxisChangeValue" value="2400"/>
<!--温控器类型,0=壁挂王字壳温湿度变送器,1=妙昕温湿度记录仪-->
<add key ="HumitureControllerType" value ="1"/>
<add key="HumitureControllerType" value="1"/>
<add key="UseAIOBOX" value="1"/>
</appSettings>
<log4net>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="logs/ACStore-RC29-1.log" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyy-MM-dd" />
<file value="logs/ACStore-RC29-1.log"/>
<appendToFile value="true"/>
<rollingStyle value="Date"/>
<datePattern value="yyyy-MM-dd"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="[%date][%t]%-5p %m%n" />
<conversionPattern value="[%date][%t]%-5p %m%n"/>
</layout>
</appender>
<root>
<level value="Info" />
<appender-ref ref="RollingLogFileAppender" />
<level value="Info"/>
<appender-ref ref="RollingLogFileAppender"/>
</root>
</log4net>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
</startup>
<!-- 部署服务库项目时,必须将配置文件的内容添加到
主机的 app.config 文件中。System.Configuration 不支持库的配置文件。 -->
......@@ -65,14 +66,14 @@
<service name="AcStoreWCF.CWSMDBox">
<endpoint address="" binding="basicHttpBinding" contract="AcStoreWCF.ICWSMDBox">
<identity>
<dns value="localhost" />
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/Design_Time_Addresses/AcStoreWCF/CWSMDBox/" />
<add baseAddress="http://localhost:8733/Design_Time_Addresses/AcStoreWCF/CWSMDBox/"/>
</baseAddresses>
</host>
</service>
......@@ -82,13 +83,13 @@
<behavior>
<!-- 为避免泄漏元数据信息,
请在部署前将以下值设置为 false -->
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
<!-- 要接收故障异常详细信息以进行调试,
请将以下值设置为 true。在部署前设置为 false
以避免泄漏异常信息 -->
<serviceDebug includeExceptionDetailInFaults="False" />
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
\ No newline at end of file
</configuration>
......@@ -23,17 +23,19 @@ namespace OnlineStore.ACSingleStore
private ConfigMoveAxis updown = null;
//private ConfigMoveAxis compress = null;
private ConfigMoveAxis inout = null;
private int compress_Slv = 0;
private ConfigMoveAxis comp = null;
//private int compress_Slv = 0;
public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public FrmAxisDebug(AC_SA_BoxBean boxBean)
{
middle = boxBean.Config.Middle_Axis;
updown = boxBean.Config.UpDown_Axis;
compress_Slv = boxBean.Config.CompressAxis_Slv;
//compress_Slv = boxBean.Config.CompressAxis_Slv;
comp = boxBean.Config.Comp_Axis;
inout = boxBean.Config.InOut_Axis;
InitializeComponent();
txtComSpeed.Text = boxBean.Config.CompressAxis_EndSpeed.ToString();
this.Text = boxBean.StoreName + "_轴点动调试";
}
......@@ -48,7 +50,7 @@ namespace OnlineStore.ACSingleStore
txtMiddleSpeed.Text = (middle.TargetSpeed / 5).ToString();
txtInOutSpeed.Text = (inout.TargetSpeed / 5).ToString();
txtUpDownSpeed.Text = (updown.TargetSpeed / 5).ToString();
txtComSpeed.Text = (StoreManager.Config.CompressAxis_EndSpeed).ToString();
txtComSpeed.Text = (comp.TargetSpeed/5).ToString();
timer1.Start();
}
/// <summary>
......@@ -255,10 +257,10 @@ namespace OnlineStore.ACSingleStore
return;
}
this.btnComMove.BackColor = Color.Green;
ShuoKeControls.SetSpeed(compress_Slv, ShuoKeCMD.SetEndSpeed, speed);
ShuoKeControls.SetSpeed(compress_Slv, ShuoKeCMD.SetMaxSpeed, speed);
ShuoKeControls.VolMove(compress_Slv, speed);
AxisMove(comp, speed);
//ShuoKeControls.SetSpeed(compress_Slv, ShuoKeCMD.SetEndSpeed, speed);
//ShuoKeControls.SetSpeed(compress_Slv, ShuoKeCMD.SetMaxSpeed, speed);
//ShuoKeControls.VolMove(compress_Slv, speed);
}
}
......@@ -267,8 +269,11 @@ namespace OnlineStore.ACSingleStore
if (this.btnComMove.BackColor == Color.Green)
{
btnComMove.BackColor = System.Drawing.SystemColors.Control;
ShuoKeControls.SuddownStop(compress_Slv);
ShuoKeControls.GetABSPosition(compress_Slv);
//ShuoKeControls.SuddownStop(compress_Slv);
//ShuoKeControls.GetABSPosition(compress_Slv);
ACServerManager.SuddenStop(comp);
UpdateCompPosition();
}
}
private void btnComMovej_MouseDown(object sender, MouseEventArgs e)
......@@ -279,10 +284,11 @@ namespace OnlineStore.ACSingleStore
MessageBox.Show("提示", "请先输入正确的速度");
return;
}
this.btnComMovej.BackColor = Color.Green;
ShuoKeControls.SetSpeed(compress_Slv, ShuoKeCMD.SetEndSpeed, speed);
ShuoKeControls.SetSpeed(compress_Slv, ShuoKeCMD.SetMaxSpeed, speed);
ShuoKeControls.VolMove(compress_Slv,-speed);
this.btnComMovej.BackColor = Color.Green;
//ShuoKeControls.SetSpeed(compress_Slv, ShuoKeCMD.SetEndSpeed, speed);
//ShuoKeControls.SetSpeed(compress_Slv, ShuoKeCMD.SetMaxSpeed, speed);
//ShuoKeControls.VolMove(compress_Slv,-speed);
AxisMove(comp, -speed);
}
private void btnComMovej_MouseUp(object sender, MouseEventArgs e)
......@@ -290,8 +296,11 @@ namespace OnlineStore.ACSingleStore
if (btnComMovej.BackColor.Equals(Color.Green))
{
btnComMovej.BackColor = System.Drawing.SystemColors.Control;
ShuoKeControls.SuddownStop(compress_Slv);
txtComPosition.Text = ShuoKeControls.GetABSPosition(compress_Slv).ToString();
//ShuoKeControls.SuddownStop(compress_Slv);
//txtComPosition.Text = ShuoKeControls.GetABSPosition(compress_Slv).ToString();
ACServerManager.SuddenStop(comp);
UpdateCompPosition();
}
}
......@@ -313,10 +322,18 @@ namespace OnlineStore.ACSingleStore
UpdateMiddlePosition();
UpdateInOutPosition();
UpdateUpdownPosition();
UpdateCompPosition();
// txtComPosition.Text = ShuoKeControls.GetLastPosition(compress_Slv).ToString();
}
}
private void UpdateCompPosition()
{
int compPosition = ACServerManager.GetTargetPosition(comp.DeviceName, comp.GetAxisValue());
if (!txtComPosition.Text.Equals(compPosition.ToString()))
{
txtComPosition.Text = compPosition.ToString();
}
}
private void UpdateUpdownPosition()
{
int updownPosition = ACServerManager.GetTargetPosition(updown.DeviceName, updown.GetAxisValue());
......
......@@ -18,10 +18,8 @@
this.components = new System.ComponentModel.Container();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.btnCloseLed = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label();
this.txtSlaveId = new System.Windows.Forms.TextBox();
this.btnOpenLed = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.txtDOIndex = new System.Windows.Forms.TextBox();
this.txtDoName = new System.Windows.Forms.TextBox();
......@@ -48,28 +46,9 @@
this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.txtAIResult4 = new System.Windows.Forms.TextBox();
this.txtAI4 = new System.Windows.Forms.TextBox();
this.label11 = new System.Windows.Forms.Label();
this.txtSize = new System.Windows.Forms.TextBox();
this.label10 = new System.Windows.Forms.Label();
this.txtHeight = new System.Windows.Forms.TextBox();
this.label9 = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.txtAIResult3 = new System.Windows.Forms.TextBox();
this.txtAIResult2 = new System.Windows.Forms.TextBox();
this.txtAIResult1 = new System.Windows.Forms.TextBox();
this.txtAI3 = new System.Windows.Forms.TextBox();
this.label7 = new System.Windows.Forms.Label();
this.txtAI2 = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.txtAI1 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
this.groupBox4.SuspendLayout();
this.groupBox3.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
// timer1
......@@ -81,10 +60,8 @@
//
this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.groupBox1.Controls.Add(this.btnCloseLed);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.txtSlaveId);
this.groupBox1.Controls.Add(this.btnOpenLed);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.txtDOIndex);
this.groupBox1.Controls.Add(this.txtDoName);
......@@ -106,24 +83,13 @@
this.groupBox1.Controls.Add(this.btnCloseDoor);
this.groupBox1.Controls.Add(this.btnOpenDoor);
this.groupBox1.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.groupBox1.Location = new System.Drawing.Point(482, 197);
this.groupBox1.Location = new System.Drawing.Point(485, 12);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(332, 357);
this.groupBox1.Size = new System.Drawing.Size(332, 352);
this.groupBox1.TabIndex = 105;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "DO写入";
//
// btnCloseLed
//
this.btnCloseLed.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnCloseLed.Location = new System.Drawing.Point(173, 317);
this.btnCloseLed.Name = "btnCloseLed";
this.btnCloseLed.Size = new System.Drawing.Size(102, 34);
this.btnCloseLed.TabIndex = 256;
this.btnCloseLed.Text = "关闭照明";
this.btnCloseLed.UseVisualStyleBackColor = true;
this.btnCloseLed.Click += new System.EventHandler(this.btnCloseLed_Click);
//
// label3
//
this.label3.AutoSize = true;
......@@ -146,17 +112,6 @@
this.txtSlaveId.TabIndex = 246;
this.txtSlaveId.Text = "0";
//
// btnOpenLed
//
this.btnOpenLed.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnOpenLed.Location = new System.Drawing.Point(56, 317);
this.btnOpenLed.Name = "btnOpenLed";
this.btnOpenLed.Size = new System.Drawing.Size(102, 34);
this.btnOpenLed.TabIndex = 255;
this.btnOpenLed.Text = "打开照明";
this.btnOpenLed.UseVisualStyleBackColor = true;
this.btnOpenLed.Click += new System.EventHandler(this.btnOpenLed_Click);
//
// label2
//
this.label2.AutoSize = true;
......@@ -390,7 +345,7 @@
// button1
//
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.button1.Location = new System.Drawing.Point(683, 563);
this.button1.Location = new System.Drawing.Point(691, 411);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(126, 37);
this.button1.TabIndex = 254;
......@@ -405,7 +360,7 @@
this.chbAutoRead.Checked = true;
this.chbAutoRead.CheckState = System.Windows.Forms.CheckState.Checked;
this.chbAutoRead.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.chbAutoRead.Location = new System.Drawing.Point(499, 568);
this.chbAutoRead.Location = new System.Drawing.Point(507, 416);
this.chbAutoRead.Name = "chbAutoRead";
this.chbAutoRead.Size = new System.Drawing.Size(75, 21);
this.chbAutoRead.TabIndex = 244;
......@@ -419,7 +374,7 @@
this.groupBox4.Controls.Add(this.tableLayoutPanel2);
this.groupBox4.Location = new System.Drawing.Point(247, 8);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(229, 594);
this.groupBox4.Size = new System.Drawing.Size(229, 446);
this.groupBox4.TabIndex = 104;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "DO列表";
......@@ -436,7 +391,7 @@
this.tableLayoutPanel2.RowCount = 2;
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 17F));
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 17F));
this.tableLayoutPanel2.Size = new System.Drawing.Size(218, 574);
this.tableLayoutPanel2.Size = new System.Drawing.Size(218, 426);
this.tableLayoutPanel2.TabIndex = 103;
//
// groupBox3
......@@ -446,7 +401,7 @@
this.groupBox3.Controls.Add(this.tableLayoutPanel1);
this.groupBox3.Location = new System.Drawing.Point(12, 8);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(229, 594);
this.groupBox3.Size = new System.Drawing.Size(229, 446);
this.groupBox3.TabIndex = 103;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "DI列表";
......@@ -463,236 +418,15 @@
this.tableLayoutPanel1.RowCount = 2;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 17F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 17F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(218, 574);
this.tableLayoutPanel1.Size = new System.Drawing.Size(218, 426);
this.tableLayoutPanel1.TabIndex = 102;
//
// groupBox2
//
this.groupBox2.Controls.Add(this.txtAIResult4);
this.groupBox2.Controls.Add(this.txtAI4);
this.groupBox2.Controls.Add(this.label11);
this.groupBox2.Controls.Add(this.txtSize);
this.groupBox2.Controls.Add(this.label10);
this.groupBox2.Controls.Add(this.txtHeight);
this.groupBox2.Controls.Add(this.label9);
this.groupBox2.Controls.Add(this.label8);
this.groupBox2.Controls.Add(this.txtAIResult3);
this.groupBox2.Controls.Add(this.txtAIResult2);
this.groupBox2.Controls.Add(this.txtAIResult1);
this.groupBox2.Controls.Add(this.txtAI3);
this.groupBox2.Controls.Add(this.label7);
this.groupBox2.Controls.Add(this.txtAI2);
this.groupBox2.Controls.Add(this.label4);
this.groupBox2.Controls.Add(this.txtAI1);
this.groupBox2.Controls.Add(this.label1);
this.groupBox2.Location = new System.Drawing.Point(482, 8);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(332, 189);
this.groupBox2.TabIndex = 245;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "高度传感器";
//
// txtAIResult4
//
this.txtAIResult4.Enabled = false;
this.txtAIResult4.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.txtAIResult4.Location = new System.Drawing.Point(203, 112);
this.txtAIResult4.MaxLength = 10;
this.txtAIResult4.Name = "txtAIResult4";
this.txtAIResult4.Size = new System.Drawing.Size(121, 23);
this.txtAIResult4.TabIndex = 259;
this.txtAIResult4.Text = "0";
//
// txtAI4
//
this.txtAI4.Enabled = false;
this.txtAI4.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.txtAI4.Location = new System.Drawing.Point(39, 112);
this.txtAI4.MaxLength = 10;
this.txtAI4.Name = "txtAI4";
this.txtAI4.Size = new System.Drawing.Size(121, 23);
this.txtAI4.TabIndex = 258;
this.txtAI4.Text = "0";
//
// label11
//
this.label11.AutoSize = true;
this.label11.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label11.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.label11.Location = new System.Drawing.Point(15, 115);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(27, 17);
this.label11.TabIndex = 257;
this.label11.Text = "4:";
this.label11.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// txtSize
//
this.txtSize.Enabled = false;
this.txtSize.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.txtSize.Location = new System.Drawing.Point(253, 156);
this.txtSize.MaxLength = 10;
this.txtSize.Name = "txtSize";
this.txtSize.Size = new System.Drawing.Size(71, 23);
this.txtSize.TabIndex = 256;
this.txtSize.Text = "0";
//
// label10
//
this.label10.AutoSize = true;
this.label10.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label10.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.label10.Location = new System.Drawing.Point(179, 159);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(68, 17);
this.label10.TabIndex = 255;
this.label10.Text = "料盘尺寸:";
this.label10.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// txtHeight
//
this.txtHeight.Enabled = false;
this.txtHeight.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.txtHeight.Location = new System.Drawing.Point(89, 156);
this.txtHeight.MaxLength = 10;
this.txtHeight.Name = "txtHeight";
this.txtHeight.Size = new System.Drawing.Size(71, 23);
this.txtHeight.TabIndex = 254;
this.txtHeight.Text = "0";
//
// label9
//
this.label9.AutoSize = true;
this.label9.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label9.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.label9.Location = new System.Drawing.Point(15, 159);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(68, 17);
this.label9.TabIndex = 253;
this.label9.Text = "料盘高度:";
this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label8
//
this.label8.AutoSize = true;
this.label8.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label8.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.label8.Location = new System.Drawing.Point(170, 56);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(22, 17);
this.label8.TabIndex = 252;
this.label8.Text = "->";
this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// txtAIResult3
//
this.txtAIResult3.Enabled = false;
this.txtAIResult3.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.txtAIResult3.Location = new System.Drawing.Point(203, 82);
this.txtAIResult3.MaxLength = 10;
this.txtAIResult3.Name = "txtAIResult3";
this.txtAIResult3.Size = new System.Drawing.Size(121, 23);
this.txtAIResult3.TabIndex = 251;
this.txtAIResult3.Text = "0";
//
// txtAIResult2
//
this.txtAIResult2.Enabled = false;
this.txtAIResult2.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.txtAIResult2.Location = new System.Drawing.Point(203, 53);
this.txtAIResult2.MaxLength = 10;
this.txtAIResult2.Name = "txtAIResult2";
this.txtAIResult2.Size = new System.Drawing.Size(121, 23);
this.txtAIResult2.TabIndex = 250;
this.txtAIResult2.Text = "0";
//
// txtAIResult1
//
this.txtAIResult1.Enabled = false;
this.txtAIResult1.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.txtAIResult1.Location = new System.Drawing.Point(203, 24);
this.txtAIResult1.MaxLength = 10;
this.txtAIResult1.Name = "txtAIResult1";
this.txtAIResult1.Size = new System.Drawing.Size(121, 23);
this.txtAIResult1.TabIndex = 249;
this.txtAIResult1.Text = "0";
//
// txtAI3
//
this.txtAI3.Enabled = false;
this.txtAI3.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.txtAI3.Location = new System.Drawing.Point(39, 82);
this.txtAI3.MaxLength = 10;
this.txtAI3.Name = "txtAI3";
this.txtAI3.Size = new System.Drawing.Size(121, 23);
this.txtAI3.TabIndex = 248;
this.txtAI3.Text = "0";
//
// label7
//
this.label7.AutoSize = true;
this.label7.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label7.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.label7.Location = new System.Drawing.Point(15, 85);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(27, 17);
this.label7.TabIndex = 247;
this.label7.Text = "3:";
this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// txtAI2
//
this.txtAI2.Enabled = false;
this.txtAI2.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.txtAI2.Location = new System.Drawing.Point(39, 53);
this.txtAI2.MaxLength = 10;
this.txtAI2.Name = "txtAI2";
this.txtAI2.Size = new System.Drawing.Size(121, 23);
this.txtAI2.TabIndex = 246;
this.txtAI2.Text = "0";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label4.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.label4.Location = new System.Drawing.Point(15, 56);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(27, 17);
this.label4.TabIndex = 245;
this.label4.Text = "2:";
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// txtAI1
//
this.txtAI1.Enabled = false;
this.txtAI1.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.txtAI1.Location = new System.Drawing.Point(39, 24);
this.txtAI1.MaxLength = 10;
this.txtAI1.Name = "txtAI1";
this.txtAI1.Size = new System.Drawing.Size(121, 23);
this.txtAI1.TabIndex = 244;
this.txtAI1.Text = "0";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label1.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.label1.Location = new System.Drawing.Point(15, 27);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(27, 17);
this.label1.TabIndex = 243;
this.label1.Text = "1:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// FrmIOStatus
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(829, 612);
this.ClientSize = new System.Drawing.Size(829, 464);
this.Controls.Add(this.button1);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.groupBox4);
this.Controls.Add(this.groupBox3);
......@@ -708,8 +442,6 @@
this.groupBox1.PerformLayout();
this.groupBox4.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
......@@ -747,26 +479,6 @@
private System.Windows.Forms.Button btnCloseAxisBreak;
private System.Windows.Forms.Button btnOpenAxisBreak;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button btnCloseLed;
private System.Windows.Forms.Button btnOpenLed;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.TextBox txtAI3;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.TextBox txtAI2;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox txtAI1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtAIResult2;
private System.Windows.Forms.TextBox txtAIResult1;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.TextBox txtHeight;
private System.Windows.Forms.TextBox txtSize;
private System.Windows.Forms.Label label10;
private System.Windows.Forms.TextBox txtAIResult4;
private System.Windows.Forms.TextBox txtAI4;
private System.Windows.Forms.Label label11;
private System.Windows.Forms.TextBox txtAIResult3;
}
}
......@@ -121,11 +121,11 @@ namespace OnlineStore.ACSingleStore
int slaveId = FormUtil.GetIntValue(txtSlaveId);
if (time > 0)
{
KNDManager.WriteSingleDO(deviceName, (byte)slaveId, (ushort)index, (IO_VALUE)value, time);
IOManager.instance.WriteSingleDO(deviceName, (byte)slaveId, (ushort)index, (IO_VALUE)value, time);
}
else
{
KNDManager.WriteSingleDO(deviceName, (byte)slaveId, (ushort)index, (IO_VALUE)value);
IOManager.instance.WriteSingleDO(deviceName, (byte)slaveId, (ushort)index, (IO_VALUE)value);
}
}
......@@ -201,7 +201,7 @@ namespace OnlineStore.ACSingleStore
foreach (string key in DIControlList.Keys)
{
IOTextControl control = DIControlList[key];
int iov = (int)KNDManager.GetIOValue(boxBean.Config.StoreDIList[key]);
int iov = (int)IOManager.IOValue(key);
if (iov != control.IOValue)
{
control.IOValue = iov;
......@@ -210,7 +210,7 @@ namespace OnlineStore.ACSingleStore
} foreach (string key in this.DOControlList.Keys)
{
IOTextControl control = DOControlList[key];
int iov = (int)KNDManager.GetIOValue(boxBean.Config.StoreDOList[key]);
int iov = (int)KNDManager.DOValue(key);
if (iov != control.IOValue)
{
control.IOValue = iov;
......@@ -218,26 +218,26 @@ namespace OnlineStore.ACSingleStore
}
}
double ai1Value = KNDAIManager.GetAIValue(boxBean.Config.AIDevice_IP, StoreManager.Config.AIDI1_Addr);
double ai2Value = KNDAIManager.GetAIValue(boxBean.Config.AIDevice_IP, StoreManager.Config.AIDI2_Addr);
double ai3Value = KNDAIManager.GetAIValue(boxBean.Config.AIDevice_IP, StoreManager.Config.AIDI3_Addr);
double ai4Value = KNDAIManager.GetAIValue(boxBean.Config.AIDevice_IP, StoreManager.Config.AIDI4_Addr);
//double ai3Value = KNDAIManager.GetAIValue(boxBean.Config.AIDevice_IP, 3);
//double ai1Value = KNDAIManager.GetAIValue(boxBean.Config.AIDevice_IP, StoreManager.Config.AIDI1_Addr);
//double ai2Value = KNDAIManager.GetAIValue(boxBean.Config.AIDevice_IP, StoreManager.Config.AIDI2_Addr);
//double ai3Value = KNDAIManager.GetAIValue(boxBean.Config.AIDevice_IP, StoreManager.Config.AIDI3_Addr);
//double ai4Value = KNDAIManager.GetAIValue(boxBean.Config.AIDevice_IP, StoreManager.Config.AIDI4_Addr);
////double ai3Value = KNDAIManager.GetAIValue(boxBean.Config.AIDevice_IP, 3);
txtAI1.Text = ai1Value.ToString();
txtAI2.Text = ai2Value.ToString();
txtAI3.Text = ai3Value.ToString();
txtAI4.Text = ai4Value.ToString();
//txtAI1.Text = ai1Value.ToString();
//txtAI2.Text = ai2Value.ToString();
//txtAI3.Text = ai3Value.ToString();
//txtAI4.Text = ai4Value.ToString();
////txtAI3.Text = ai3Value.ToString();
txtAIResult1.Text = KNDAIManager.ConvertAI(ai1Value,boxBean.Config.AIDI1_DefaultPosition).ToString();
txtAIResult2.Text = KNDAIManager.ConvertAI(ai2Value, boxBean.Config.AIDI2_DefaultPosition).ToString();
txtAIResult3.Text = KNDAIManager.ConvertAI(ai3Value, boxBean.Config.AIDI3_DefaultPosition).ToString();
txtAIResult4.Text = KNDAIManager.ConvertAI(ai4Value, boxBean.Config.AIDI4_DefaultPosition).ToString();
//txtAIResult1.Text = KNDAIManager.ConvertAI(ai1Value,boxBean.Config.AIDI1_DefaultPosition).ToString();
//txtAIResult2.Text = KNDAIManager.ConvertAI(ai2Value, boxBean.Config.AIDI2_DefaultPosition).ToString();
//txtAIResult3.Text = KNDAIManager.ConvertAI(ai3Value, boxBean.Config.AIDI3_DefaultPosition).ToString();
//txtAIResult4.Text = KNDAIManager.ConvertAI(ai4Value, boxBean.Config.AIDI4_DefaultPosition).ToString();
////txtAIResult3.Text = KNDAIManager.ConvertAI(ai3Value, boxBean.Config.AIDI3_DefaultPosition).ToString();
txtHeight.Text = boxBean.GetHeight().ToString();
txtSize.Text = boxBean.GetSize().ToString();
//txtHeight.Text = boxBean.GetHeight().ToString();
//txtSize.Text = boxBean.GetSize().ToString();
}
private void btnReadAllDi_Click(object sender, EventArgs e)
......@@ -259,25 +259,25 @@ namespace OnlineStore.ACSingleStore
}
private void btnOpenDoor_Click(object sender, EventArgs e)
{
boxBean.KNDIOMove(IO_Type.Door_Up, IO_VALUE.HIGH);
boxBean.KNDIOMove(IO_Type.Door_Down, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.Door_Up, IO_VALUE.HIGH);
IOManager.IOMove(IO_Type.Door_Down, IO_VALUE.LOW);
}
private void btnCloseDoor_Click(object sender, EventArgs e)
{
boxBean.KNDIOMove(IO_Type.Door_Down, IO_VALUE.HIGH);
boxBean.KNDIOMove(IO_Type.Door_Up, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.Door_Down, IO_VALUE.HIGH);
IOManager.IOMove(IO_Type.Door_Up, IO_VALUE.LOW);
}
private void btnLocationUp_Click(object sender, EventArgs e)
{
boxBean.KNDIOMove(IO_Type.LocationCylinder_Down, IO_VALUE.LOW);
boxBean.KNDIOMove(IO_Type.LocationCylinder_Up, IO_VALUE.HIGH);
IOManager.IOMove(IO_Type.LocationCylinder_Down, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.LocationCylinder_Up, IO_VALUE.HIGH);
}
private void btnLocationDown_Click(object sender, EventArgs e)
{
boxBean.KNDIOMove(IO_Type.LocationCylinder_Down, IO_VALUE.HIGH);
boxBean.KNDIOMove(IO_Type.LocationCylinder_Up, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.LocationCylinder_Down, IO_VALUE.HIGH);
IOManager.IOMove(IO_Type.LocationCylinder_Up, IO_VALUE.LOW);
}
private void FrmIOStatus_Shown(object sender, EventArgs e)
......@@ -288,12 +288,12 @@ namespace OnlineStore.ACSingleStore
private void btnOpenAxisBreak_Click(object sender, EventArgs e)
{
boxBean.KNDIOMove(IO_Type.Axis_Brake, IO_VALUE.HIGH);
IOManager.IOMove(IO_Type.Axis_Brake, IO_VALUE.HIGH);
}
private void btnCloseAxisBreak_Click(object sender, EventArgs e)
{
boxBean.KNDIOMove(IO_Type.Axis_Brake, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.Axis_Brake, IO_VALUE.LOW);
}
private void button1_Click(object sender, EventArgs e)
......@@ -301,14 +301,6 @@ namespace OnlineStore.ACSingleStore
this.Close();
}
private void btnOpenLed_Click(object sender, EventArgs e)
{
boxBean.KNDIOMove(IO_Type.CameraLight_Power, IO_VALUE.HIGH);
}
private void btnCloseLed_Click(object sender, EventArgs e)
{
boxBean.KNDIOMove(IO_Type.CameraLight_Power, IO_VALUE.LOW);
}
}
}
......@@ -174,34 +174,8 @@
this.显示ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
this.groupComAxis = new System.Windows.Forms.GroupBox();
this.label20 = new System.Windows.Forms.Label();
this.txtComAPosition = new System.Windows.Forms.TextBox();
this.lblShuoKeMsg = new System.Windows.Forms.Label();
this.btnRelMove = new System.Windows.Forms.Button();
this.txtAddr = new System.Windows.Forms.TextBox();
this.label18 = new System.Windows.Forms.Label();
this.btnGetPosition = new System.Windows.Forms.Button();
this.cmbHomeType = new System.Windows.Forms.ComboBox();
this.label13 = new System.Windows.Forms.Label();
this.label17 = new System.Windows.Forms.Label();
this.txtSpeed = new System.Windows.Forms.TextBox();
this.btnVolMove = new System.Windows.Forms.Button();
this.btnClose = new System.Windows.Forms.Button();
this.btnOpen = new System.Windows.Forms.Button();
this.btnStatusSearch = new System.Windows.Forms.Button();
this.label19 = new System.Windows.Forms.Label();
this.txtLinePosition = new System.Windows.Forms.TextBox();
this.btnHomeMove = new System.Windows.Forms.Button();
this.btnClearPosition = new System.Windows.Forms.Button();
this.btnStop = new System.Windows.Forms.Button();
this.btnLineAbsMove = new System.Windows.Forms.Button();
this.label25 = new System.Windows.Forms.Label();
this.comboBoxPortName = new System.Windows.Forms.ComboBox();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage3 = new System.Windows.Forms.TabPage();
this.btnCloseLed = new System.Windows.Forms.Button();
this.btnOpenLed = new System.Windows.Forms.Button();
this.btnCloseDoor = new System.Windows.Forms.Button();
this.btnOpenDoor = new System.Windows.Forms.Button();
this.tabPage1 = new System.Windows.Forms.TabPage();
......@@ -239,9 +213,7 @@
this.btnDebug = new System.Windows.Forms.Button();
this.btnAxisOff = new System.Windows.Forms.Button();
this.btnAxisOn = new System.Windows.Forms.Button();
this.btnScanCode = new System.Windows.Forms.Button();
this.btnAxisP = new System.Windows.Forms.Button();
this.btnCodeLearn = new System.Windows.Forms.Button();
this.btnIO = new System.Windows.Forms.Button();
this.tabPage6 = new System.Windows.Forms.TabPage();
this.button4 = new System.Windows.Forms.Button();
......@@ -253,7 +225,6 @@
this.menuStrip1.SuspendLayout();
this.groupBox3.SuspendLayout();
this.contextMenuStrip1.SuspendLayout();
this.groupComAxis.SuspendLayout();
this.tabControl1.SuspendLayout();
this.tabPage3.SuspendLayout();
this.tabPage1.SuspendLayout();
......@@ -1907,8 +1878,7 @@
//
this.扫码测试ToolStripMenuItem.Name = "扫码测试ToolStripMenuItem";
this.扫码测试ToolStripMenuItem.Size = new System.Drawing.Size(179, 30);
this.扫码测试ToolStripMenuItem.Text = "扫码测试";
this.扫码测试ToolStripMenuItem.Click += new System.EventHandler(this.扫码测试ToolStripMenuItem_Click);
this.扫码测试ToolStripMenuItem.Text = "扫码测试";
//
// toolStripSeparator10
//
......@@ -2031,263 +2001,6 @@
this.notifyIcon1.Text = "料仓客户端";
this.notifyIcon1.Visible = true;
//
// groupComAxis
//
this.groupComAxis.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupComAxis.Controls.Add(this.label20);
this.groupComAxis.Controls.Add(this.txtComAPosition);
this.groupComAxis.Controls.Add(this.lblShuoKeMsg);
this.groupComAxis.Controls.Add(this.btnRelMove);
this.groupComAxis.Controls.Add(this.txtAddr);
this.groupComAxis.Controls.Add(this.label18);
this.groupComAxis.Controls.Add(this.btnGetPosition);
this.groupComAxis.Controls.Add(this.cmbHomeType);
this.groupComAxis.Controls.Add(this.label13);
this.groupComAxis.Controls.Add(this.label17);
this.groupComAxis.Controls.Add(this.txtSpeed);
this.groupComAxis.Controls.Add(this.btnVolMove);
this.groupComAxis.Controls.Add(this.btnClose);
this.groupComAxis.Controls.Add(this.btnOpen);
this.groupComAxis.Controls.Add(this.btnStatusSearch);
this.groupComAxis.Controls.Add(this.label19);
this.groupComAxis.Controls.Add(this.txtLinePosition);
this.groupComAxis.Controls.Add(this.btnHomeMove);
this.groupComAxis.Controls.Add(this.btnClearPosition);
this.groupComAxis.Controls.Add(this.btnStop);
this.groupComAxis.Controls.Add(this.btnLineAbsMove);
this.groupComAxis.Controls.Add(this.label25);
this.groupComAxis.Controls.Add(this.comboBoxPortName);
this.groupComAxis.Enabled = false;
this.groupComAxis.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.groupComAxis.Location = new System.Drawing.Point(7, 8);
this.groupComAxis.Name = "groupComAxis";
this.groupComAxis.Size = new System.Drawing.Size(544, 285);
this.groupComAxis.TabIndex = 271;
this.groupComAxis.TabStop = false;
this.groupComAxis.Text = "压紧轴";
//
// label20
//
this.label20.AutoSize = true;
this.label20.Location = new System.Drawing.Point(8, 167);
this.label20.Name = "label20";
this.label20.Size = new System.Drawing.Size(68, 17);
this.label20.TabIndex = 99;
this.label20.Text = "实时位置:";
//
// txtComAPosition
//
this.txtComAPosition.Location = new System.Drawing.Point(79, 160);
this.txtComAPosition.MaxLength = 15;
this.txtComAPosition.Name = "txtComAPosition";
this.txtComAPosition.Size = new System.Drawing.Size(103, 23);
this.txtComAPosition.TabIndex = 98;
this.txtComAPosition.Text = "-1";
//
// lblShuoKeMsg
//
this.lblShuoKeMsg.AutoSize = true;
this.lblShuoKeMsg.ForeColor = System.Drawing.Color.Green;
this.lblShuoKeMsg.Location = new System.Drawing.Point(76, 245);
this.lblShuoKeMsg.Name = "lblShuoKeMsg";
this.lblShuoKeMsg.Size = new System.Drawing.Size(80, 17);
this.lblShuoKeMsg.TabIndex = 97;
this.lblShuoKeMsg.Text = "步进电机信息";
//
// btnRelMove
//
this.btnRelMove.Location = new System.Drawing.Point(299, 71);
this.btnRelMove.Name = "btnRelMove";
this.btnRelMove.Size = new System.Drawing.Size(105, 33);
this.btnRelMove.TabIndex = 96;
this.btnRelMove.Text = "相对运动";
this.btnRelMove.UseVisualStyleBackColor = true;
this.btnRelMove.Click += new System.EventHandler(this.btnRelMove_Click);
//
// txtAddr
//
this.txtAddr.Enabled = false;
this.txtAddr.Location = new System.Drawing.Point(235, 31);
this.txtAddr.Name = "txtAddr";
this.txtAddr.Size = new System.Drawing.Size(48, 23);
this.txtAddr.TabIndex = 95;
this.txtAddr.Text = "1";
//
// label18
//
this.label18.AutoSize = true;
this.label18.Location = new System.Drawing.Point(192, 34);
this.label18.Name = "label18";
this.label18.Size = new System.Drawing.Size(44, 17);
this.label18.TabIndex = 94;
this.label18.Text = "地址:";
//
// btnGetPosition
//
this.btnGetPosition.Location = new System.Drawing.Point(188, 155);
this.btnGetPosition.Name = "btnGetPosition";
this.btnGetPosition.Size = new System.Drawing.Size(105, 33);
this.btnGetPosition.TabIndex = 93;
this.btnGetPosition.Text = "查询位置";
this.btnGetPosition.UseVisualStyleBackColor = true;
this.btnGetPosition.Click += new System.EventHandler(this.btnGetPosition_Click);
//
// cmbHomeType
//
this.cmbHomeType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbHomeType.FormattingEnabled = true;
this.cmbHomeType.Items.AddRange(new object[] {
"0=反方向",
"1=正方向"});
this.cmbHomeType.Location = new System.Drawing.Point(79, 202);
this.cmbHomeType.Name = "cmbHomeType";
this.cmbHomeType.Size = new System.Drawing.Size(103, 25);
this.cmbHomeType.TabIndex = 92;
//
// label13
//
this.label13.AutoSize = true;
this.label13.Location = new System.Drawing.Point(8, 209);
this.label13.Name = "label13";
this.label13.Size = new System.Drawing.Size(68, 17);
this.label13.TabIndex = 91;
this.label13.Text = "原点方向:";
//
// label17
//
this.label17.AutoSize = true;
this.label17.Location = new System.Drawing.Point(32, 124);
this.label17.Name = "label17";
this.label17.Size = new System.Drawing.Size(44, 17);
this.label17.TabIndex = 90;
this.label17.Text = "速度:";
//
// txtSpeed
//
this.txtSpeed.Location = new System.Drawing.Point(79, 118);
this.txtSpeed.MaxLength = 15;
this.txtSpeed.Name = "txtSpeed";
this.txtSpeed.Size = new System.Drawing.Size(103, 23);
this.txtSpeed.TabIndex = 89;
this.txtSpeed.Text = "10000";
//
// btnVolMove
//
this.btnVolMove.Location = new System.Drawing.Point(188, 113);
this.btnVolMove.Name = "btnVolMove";
this.btnVolMove.Size = new System.Drawing.Size(105, 33);
this.btnVolMove.TabIndex = 88;
this.btnVolMove.Text = "匀速运动";
this.btnVolMove.UseVisualStyleBackColor = true;
this.btnVolMove.Click += new System.EventHandler(this.btnVolMove_Click);
//
// btnClose
//
this.btnClose.Location = new System.Drawing.Point(409, 26);
this.btnClose.Name = "btnClose";
this.btnClose.Size = new System.Drawing.Size(105, 33);
this.btnClose.TabIndex = 87;
this.btnClose.Text = "关闭串口";
this.btnClose.UseVisualStyleBackColor = true;
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
//
// btnOpen
//
this.btnOpen.Location = new System.Drawing.Point(298, 26);
this.btnOpen.Name = "btnOpen";
this.btnOpen.Size = new System.Drawing.Size(105, 33);
this.btnOpen.TabIndex = 86;
this.btnOpen.Text = "打开串口";
this.btnOpen.UseVisualStyleBackColor = true;
this.btnOpen.Click += new System.EventHandler(this.btnOpen_Click);
//
// btnStatusSearch
//
this.btnStatusSearch.Location = new System.Drawing.Point(299, 197);
this.btnStatusSearch.Name = "btnStatusSearch";
this.btnStatusSearch.Size = new System.Drawing.Size(105, 33);
this.btnStatusSearch.TabIndex = 85;
this.btnStatusSearch.Text = "查询运动状态";
this.btnStatusSearch.UseVisualStyleBackColor = true;
this.btnStatusSearch.Click += new System.EventHandler(this.btnStatusSearch_Click);
//
// label19
//
this.label19.AutoSize = true;
this.label19.Location = new System.Drawing.Point(32, 79);
this.label19.Name = "label19";
this.label19.Size = new System.Drawing.Size(44, 17);
this.label19.TabIndex = 84;
this.label19.Text = "位置:";
//
// txtLinePosition
//
this.txtLinePosition.Location = new System.Drawing.Point(79, 76);
this.txtLinePosition.MaxLength = 15;
this.txtLinePosition.Name = "txtLinePosition";
this.txtLinePosition.Size = new System.Drawing.Size(103, 23);
this.txtLinePosition.TabIndex = 83;
this.txtLinePosition.Text = "-10000";
//
// btnHomeMove
//
this.btnHomeMove.Location = new System.Drawing.Point(188, 197);
this.btnHomeMove.Name = "btnHomeMove";
this.btnHomeMove.Size = new System.Drawing.Size(105, 33);
this.btnHomeMove.TabIndex = 12;
this.btnHomeMove.Text = "原点返回";
this.btnHomeMove.UseVisualStyleBackColor = true;
this.btnHomeMove.Click += new System.EventHandler(this.btnHomeMove_Click);
//
// btnClearPosition
//
this.btnClearPosition.Location = new System.Drawing.Point(299, 155);
this.btnClearPosition.Name = "btnClearPosition";
this.btnClearPosition.Size = new System.Drawing.Size(105, 33);
this.btnClearPosition.TabIndex = 11;
this.btnClearPosition.Text = "清理位置";
this.btnClearPosition.UseVisualStyleBackColor = true;
this.btnClearPosition.Click += new System.EventHandler(this.btnClearPosition_Click);
//
// btnStop
//
this.btnStop.Location = new System.Drawing.Point(298, 113);
this.btnStop.Name = "btnStop";
this.btnStop.Size = new System.Drawing.Size(105, 33);
this.btnStop.TabIndex = 10;
this.btnStop.Text = "紧急停止";
this.btnStop.UseVisualStyleBackColor = true;
this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
//
// btnLineAbsMove
//
this.btnLineAbsMove.Location = new System.Drawing.Point(188, 71);
this.btnLineAbsMove.Name = "btnLineAbsMove";
this.btnLineAbsMove.Size = new System.Drawing.Size(105, 33);
this.btnLineAbsMove.TabIndex = 9;
this.btnLineAbsMove.Text = "绝对运动";
this.btnLineAbsMove.UseVisualStyleBackColor = true;
this.btnLineAbsMove.Click += new System.EventHandler(this.btnLineAbsMove_Click);
//
// label25
//
this.label25.AutoSize = true;
this.label25.Location = new System.Drawing.Point(20, 34);
this.label25.Name = "label25";
this.label25.Size = new System.Drawing.Size(56, 17);
this.label25.TabIndex = 1;
this.label25.Text = "端口号:";
//
// comboBoxPortName
//
this.comboBoxPortName.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxPortName.FormattingEnabled = true;
this.comboBoxPortName.Location = new System.Drawing.Point(79, 30);
this.comboBoxPortName.Name = "comboBoxPortName";
this.comboBoxPortName.Size = new System.Drawing.Size(103, 25);
this.comboBoxPortName.TabIndex = 0;
//
// tabControl1
//
this.tabControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
......@@ -2304,9 +2017,7 @@
//
// tabPage3
//
this.tabPage3.Controls.Add(this.btnCloseLed);
this.tabPage3.Controls.Add(this.btnClearLog);
this.tabPage3.Controls.Add(this.btnOpenLed);
this.tabPage3.Controls.Add(this.btnCloseDoor);
this.tabPage3.Controls.Add(this.btnOpenDoor);
this.tabPage3.Controls.Add(this.richTextBox1);
......@@ -2317,30 +2028,6 @@
this.tabPage3.Text = " 操作日志 ";
this.tabPage3.UseVisualStyleBackColor = true;
//
// btnCloseLed
//
this.btnCloseLed.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnCloseLed.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnCloseLed.Location = new System.Drawing.Point(149, 568);
this.btnCloseLed.Name = "btnCloseLed";
this.btnCloseLed.Size = new System.Drawing.Size(105, 38);
this.btnCloseLed.TabIndex = 260;
this.btnCloseLed.Text = "关闭照明";
this.btnCloseLed.UseVisualStyleBackColor = true;
this.btnCloseLed.Click += new System.EventHandler(this.btnCloseLed_Click);
//
// btnOpenLed
//
this.btnOpenLed.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnOpenLed.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnOpenLed.Location = new System.Drawing.Point(32, 568);
this.btnOpenLed.Name = "btnOpenLed";
this.btnOpenLed.Size = new System.Drawing.Size(105, 38);
this.btnOpenLed.TabIndex = 259;
this.btnOpenLed.Text = "打开照明";
this.btnOpenLed.UseVisualStyleBackColor = true;
this.btnOpenLed.Click += new System.EventHandler(this.btnOpenLed_Click);
//
// btnCloseDoor
//
this.btnCloseDoor.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
......@@ -2380,7 +2067,6 @@
// tabPage2
//
this.tabPage2.Controls.Add(this.groupBox7);
this.tabPage2.Controls.Add(this.groupComAxis);
this.tabPage2.Location = new System.Drawing.Point(4, 29);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
......@@ -2401,9 +2087,9 @@
this.groupBox7.Controls.Add(this.label27);
this.groupBox7.Controls.Add(this.btnTempClose);
this.groupBox7.Controls.Add(this.btnTempInit);
this.groupBox7.Location = new System.Drawing.Point(7, 299);
this.groupBox7.Location = new System.Drawing.Point(5, 6);
this.groupBox7.Name = "groupBox7";
this.groupBox7.Size = new System.Drawing.Size(544, 321);
this.groupBox7.Size = new System.Drawing.Size(544, 166);
this.groupBox7.TabIndex = 272;
this.groupBox7.TabStop = false;
this.groupBox7.Text = "温控器调试";
......@@ -2427,6 +2113,7 @@
this.groupHistory.TabIndex = 260;
this.groupHistory.TabStop = false;
this.groupHistory.Text = "历史记录";
this.groupHistory.Visible = false;
//
// txtHistoryTemp
//
......@@ -2734,9 +2421,7 @@
this.tabPage5.Controls.Add(this.btnDebug);
this.tabPage5.Controls.Add(this.btnAxisOff);
this.tabPage5.Controls.Add(this.btnAxisOn);
this.tabPage5.Controls.Add(this.btnScanCode);
this.tabPage5.Controls.Add(this.btnAxisP);
this.tabPage5.Controls.Add(this.btnCodeLearn);
this.tabPage5.Controls.Add(this.btnIO);
this.tabPage5.Location = new System.Drawing.Point(4, 30);
this.tabPage5.Name = "tabPage5";
......@@ -2749,7 +2434,7 @@
// btnDebug
//
this.btnDebug.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnDebug.Location = new System.Drawing.Point(806, 4);
this.btnDebug.Location = new System.Drawing.Point(541, 4);
this.btnDebug.Name = "btnDebug";
this.btnDebug.Size = new System.Drawing.Size(132, 39);
this.btnDebug.TabIndex = 12;
......@@ -2760,7 +2445,7 @@
// btnAxisOff
//
this.btnAxisOff.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnAxisOff.Location = new System.Drawing.Point(672, 4);
this.btnAxisOff.Location = new System.Drawing.Point(407, 4);
this.btnAxisOff.Name = "btnAxisOff";
this.btnAxisOff.Size = new System.Drawing.Size(132, 39);
this.btnAxisOff.TabIndex = 11;
......@@ -2771,7 +2456,7 @@
// btnAxisOn
//
this.btnAxisOn.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnAxisOn.Location = new System.Drawing.Point(539, 4);
this.btnAxisOn.Location = new System.Drawing.Point(274, 4);
this.btnAxisOn.Name = "btnAxisOn";
this.btnAxisOn.Size = new System.Drawing.Size(132, 39);
this.btnAxisOn.TabIndex = 10;
......@@ -2779,21 +2464,10 @@
this.btnAxisOn.UseVisualStyleBackColor = true;
this.btnAxisOn.Click += new System.EventHandler(this.料仓运转ONToolStripMenuItem_Click);
//
// btnScanCode
//
this.btnScanCode.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnScanCode.Location = new System.Drawing.Point(140, 4);
this.btnScanCode.Name = "btnScanCode";
this.btnScanCode.Size = new System.Drawing.Size(132, 39);
this.btnScanCode.TabIndex = 9;
this.btnScanCode.Text = "扫码测试";
this.btnScanCode.UseVisualStyleBackColor = true;
this.btnScanCode.Click += new System.EventHandler(this.扫码测试ToolStripMenuItem_Click);
//
// btnAxisP
//
this.btnAxisP.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnAxisP.Location = new System.Drawing.Point(406, 4);
this.btnAxisP.Location = new System.Drawing.Point(141, 4);
this.btnAxisP.Name = "btnAxisP";
this.btnAxisP.Size = new System.Drawing.Size(132, 39);
this.btnAxisP.TabIndex = 8;
......@@ -2801,17 +2475,6 @@
this.btnAxisP.UseVisualStyleBackColor = true;
this.btnAxisP.Click += new System.EventHandler(this.轴卡点动ToolStripMenuItem_Click);
//
// btnCodeLearn
//
this.btnCodeLearn.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnCodeLearn.Location = new System.Drawing.Point(273, 4);
this.btnCodeLearn.Name = "btnCodeLearn";
this.btnCodeLearn.Size = new System.Drawing.Size(132, 39);
this.btnCodeLearn.TabIndex = 7;
this.btnCodeLearn.Text = "二维码学习";
this.btnCodeLearn.UseVisualStyleBackColor = true;
this.btnCodeLearn.Click += new System.EventHandler(this.学习二维码ToolStripMenuItem_Click);
//
// btnIO
//
this.btnIO.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
......@@ -2899,8 +2562,6 @@
this.groupBox3.ResumeLayout(false);
this.groupBox3.PerformLayout();
this.contextMenuStrip1.ResumeLayout(false);
this.groupComAxis.ResumeLayout(false);
this.groupComAxis.PerformLayout();
this.tabControl1.ResumeLayout(false);
this.tabPage3.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
......@@ -3071,34 +2732,10 @@
private System.Windows.Forms.TextBox txtHomeSingle;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.GroupBox groupComAxis;
private System.Windows.Forms.Button btnRelMove;
private System.Windows.Forms.TextBox txtAddr;
private System.Windows.Forms.Label label18;
private System.Windows.Forms.Button btnGetPosition;
private System.Windows.Forms.ComboBox cmbHomeType;
private System.Windows.Forms.Label label13;
private System.Windows.Forms.Label label17;
private System.Windows.Forms.TextBox txtSpeed;
private System.Windows.Forms.Button btnVolMove;
private System.Windows.Forms.Button btnClose;
private System.Windows.Forms.Button btnOpen;
private System.Windows.Forms.Button btnStatusSearch;
private System.Windows.Forms.Label label19;
private System.Windows.Forms.TextBox txtLinePosition;
private System.Windows.Forms.Button btnHomeMove;
private System.Windows.Forms.Button btnClearPosition;
private System.Windows.Forms.Button btnStop;
private System.Windows.Forms.Button btnLineAbsMove;
private System.Windows.Forms.Label label25;
private System.Windows.Forms.ComboBox comboBoxPortName;
private System.Windows.Forms.Label lblShuoKeMsg;
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage3;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.Label label20;
private System.Windows.Forms.TextBox txtComAPosition;
private System.Windows.Forms.GroupBox groupBox7;
private System.Windows.Forms.Button btnSelTemp;
private System.Windows.Forms.TextBox txtHum;
......@@ -3111,8 +2748,6 @@
private System.Windows.Forms.Button btnTempInit;
private System.Windows.Forms.Button btnCloseDoor;
private System.Windows.Forms.Button btnOpenDoor;
private System.Windows.Forms.Button btnCloseLed;
private System.Windows.Forms.Button btnOpenLed;
private System.Windows.Forms.TabControl tabControl2;
private System.Windows.Forms.TabPage tabPage4;
private System.Windows.Forms.TabPage tabPage5;
......@@ -3120,9 +2755,7 @@
private System.Windows.Forms.Button btnStoreHome;
private System.Windows.Forms.Button btnSotreReset;
private System.Windows.Forms.Button btnStoreStop;
private System.Windows.Forms.Button btnScanCode;
private System.Windows.Forms.Button btnAxisP;
private System.Windows.Forms.Button btnCodeLearn;
private System.Windows.Forms.Button btnIO;
private System.Windows.Forms.Button btnAxisOff;
private System.Windows.Forms.Button btnAxisOn;
......
......@@ -46,7 +46,7 @@ namespace OnlineStore.ACSingleStore
LogUtil.error(LOGGER, "找不到对应的料仓");
return;
}
txtSpeed.Text = store.Config.CompressAxis_EndSpeed.ToString();
//txtSpeed.Text = store.Config.CompressAxis_EndSpeed.ToString();
cmbAxisList.DataSource = new List<ConfigMoveAxis>(store.moveAxisList);
cmbAxisList.DisplayMember = "Explain";
cmbAxisList.ValueMember = "Explain";
......@@ -89,13 +89,13 @@ namespace OnlineStore.ACSingleStore
//txtUpDownP1.Text = ktkPosition.UpDownAxis_DoorOPosition_P1.ToString();
}
List<string> port = new List<string>(SerialPort.GetPortNames());
comboBoxPortName.DataSource = port;
if (port.IndexOf(store.Config.CompressAxis_PortName) >= 0)
{
comboBoxPortName.SelectedIndex = port.IndexOf(store.Config.CompressAxis_PortName);
}
cmbHomeType.SelectedIndex = 0;
//List<string> port = new List<string>(SerialPort.GetPortNames());
//comboBoxPortName.DataSource = port;
//if (port.IndexOf(store.Config.CompressAxis_PortName) >= 0)
//{
// comboBoxPortName.SelectedIndex = port.IndexOf(store.Config.CompressAxis_PortName);
//}
//cmbHomeType.SelectedIndex = 0;
timer1.Enabled = true;
}
#endregion
......@@ -154,7 +154,7 @@ namespace OnlineStore.ACSingleStore
notifyIcon1.Text = ConfigAppSettings.GetValue(Setting_Init.App_Title);
LoadOk = true;
cmbHomeType.SelectedIndex = 1;
//cmbHomeType.SelectedIndex = 1;
HideForm();
this.Opacity = 1;
txtTempPort.Text = store.Config.Humiture_Port;
......@@ -238,15 +238,15 @@ namespace OnlineStore.ACSingleStore
}
lblWarnMsg.Text = store.WarnMsg;
if (store.Config.IsHasDoorLimit.Equals(1))
{
if (store.KNDIOValue(IO_Type.Door_LimitSingle).Equals(IO_VALUE.LOW))
{
lblWarnMsg.Text = lblWarnMsg.Text + " 前门未关";
}
}
//if (store.Config.IsHasDoorLimit.Equals(1))
//{
// if (IOManager.IOValue(IO_Type.Door_LimitSingle).Equals(IO_VALUE.LOW))
// {
// lblWarnMsg.Text = lblWarnMsg.Text + " 前门未关";
// }
//}
//如果不在出入库中,且叉子上有信号,需要提示检查叉子
if (store.storeRunStatus.Equals(StoreRunStatus.Runing) && store.KNDIOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.HIGH))
if (store.storeRunStatus.Equals(StoreRunStatus.Runing) && IOManager.IOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.HIGH))
{
lblWarnMsg.Text = lblWarnMsg.Text + " 叉子料盘检测有料,请检查";
}
......@@ -857,19 +857,22 @@ namespace OnlineStore.ACSingleStore
private void btnComP2_Click(object sender, EventArgs e)
{
int value = FormUtil.GetIntValue(txtComP2);
ShuoKeControls.AbsMove(store.Config.CompressAxis_Slv, value);
AxisABSMove(store.Config.Comp_Axis, value, store.Config.Comp_Axis.TargetSpeed);
//ShuoKeControls.AbsMove(store.Config.CompressAxis_Slv, value);
}
private void btnComP1_Click(object sender, EventArgs e)
{
int value = FormUtil.GetIntValue(txtComP1);
ShuoKeControls.AbsMove(store.Config.CompressAxis_Slv, value);
AxisABSMove(store.Config.Comp_Axis, value, store.Config.Comp_Axis.TargetSpeed);
//ShuoKeControls.AbsMove(store.Config.CompressAxis_Slv, value);
}
private void btnComP3_Click(object sender, EventArgs e)
{
int value = FormUtil.GetIntValue(txtComP3);
ShuoKeControls.AbsMove(store.Config.CompressAxis_Slv, value);
AxisABSMove(store.Config.Comp_Axis, value, store.Config.Comp_Axis.TargetSpeed);
//ShuoKeControls.AbsMove(store.Config.CompressAxis_Slv, value);
}
int xWidth = SystemInformation.PrimaryMonitorSize.Width;//获取显示器屏幕宽度
int yHeight = SystemInformation.PrimaryMonitorSize.Height;//高度
......@@ -989,24 +992,11 @@ namespace OnlineStore.ACSingleStore
this.Enabled = true;
LogUtil.info("料仓运转ON完成");
}
private void 扫码测试ToolStripMenuItem_Click(object sender, EventArgs e)
{
store.KNDIOMove(IO_Type.CameraLight_Power, IO_VALUE.HIGH);
string message = "";
List<string> codeList = CodeManager.CameraScan();
foreach (string str in codeList)
{
message = message + str + "##";
}
LogUtil.info("扫码测试收到二维码 :" + message);
store.KNDIOMove(IO_Type.CameraLight_Power, IO_VALUE.LOW);
}
private void 打开舱门ToolStripMenuItem_Click(object sender, EventArgs e)
{
store.KNDIOMove(IO_Type.Door_Up, IO_VALUE.HIGH);
store.KNDIOMove(IO_Type.Door_Down, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.Door_Up, IO_VALUE.HIGH);
IOManager.IOMove(IO_Type.Door_Down, IO_VALUE.LOW);
}
private void 料仓运转OFFToolStripMenuItem_Click(object sender, EventArgs e)
......@@ -1017,8 +1007,8 @@ namespace OnlineStore.ACSingleStore
private void 关闭仓门ToolStripMenuItem_Click(object sender, EventArgs e)
{
store.KNDIOMove(IO_Type.Door_Down, IO_VALUE.HIGH);
store.KNDIOMove(IO_Type.Door_Up, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.Door_Down, IO_VALUE.HIGH);
IOManager.IOMove(IO_Type.Door_Up, IO_VALUE.LOW);
}
private void 回待机点ToolStripMenuItem_Click(object sender, EventArgs e)
......@@ -1200,17 +1190,7 @@ namespace OnlineStore.ACSingleStore
{
int value = ACServerManager.GetHomeEndStatus(GetPortName(), GetSlaveAddr());
this.txtHomeStatus.Text = value.ToString();
}
private void btnOpenWCF_Click(object sender, EventArgs e)
{
//WCFControl.OpenWCF();
}
private void btnCloseWCF_Click(object sender, EventArgs e)
{
//WCFControl.CloseWCF();
}
}
private void chbAuto_CheckedChanged(object sender, EventArgs e)
{
......@@ -1265,9 +1245,9 @@ namespace OnlineStore.ACSingleStore
stop_button_Click(null, null);
}
KNDManager.CloseAllDO();
IOManager.instance.CloseAllDO();
StoreOpenStatus(false);
KNDManager.CloseAllConnection();
IOManager.instance.CloseAllConnection();
KNDAIManager.CloseAllConnection();
//WCFControl.CloseWCF();
System.Environment.Exit(System.Environment.ExitCode);
......@@ -1314,10 +1294,10 @@ namespace OnlineStore.ACSingleStore
private void 学习二维码ToolStripMenuItem_Click(object sender, EventArgs e)
{
store.KNDIOMove(IO_Type.CameraLight_Power, IO_VALUE.HIGH);
CodeLibrary.FrmCodeDecode frm = new FrmCodeDecode();
frm.ShowDialog();
store.KNDIOMove(IO_Type.CameraLight_Power, IO_VALUE.LOW);
//IOManager.IOMove(IO_Type.CameraLight_Power, IO_VALUE.HIGH);
//CodeLibrary.FrmCodeDecode frm = new FrmCodeDecode();
//frm.ShowDialog();
//IOManager.IOMove(IO_Type.CameraLight_Power, IO_VALUE.LOW);
}
private void btnReadHomeSingle_Click(object sender, EventArgs e)
......@@ -1325,70 +1305,70 @@ namespace OnlineStore.ACSingleStore
int value = ACServerManager.GetHomeSingle(GetPortName(), GetSlaveAddr());
this.txtHomeSingle.Text = value.ToString();
}
private void btnOpen_Click(object sender, EventArgs e)
{
if (StoreManager.OpenShuoKe(store))
{
store.SetShuokeSpeed();
FormComStatus(true);
}
}
private void btnClose_Click(object sender, EventArgs e)
{
ShuoKeControls.ClosePort();
FormComStatus(false);
}
private void btnVolMove_Click(object sender, EventArgs e)
{
int speed = FormUtil.GetIntValue(txtSpeed);
ShuoKeControls.VolMove(store.Config.CompressAxis_Slv, speed);
}
private void btnGetPosition_Click(object sender, EventArgs e)
{
int value = ShuoKeControls.GetABSPosition(store.Config.CompressAxis_Slv);
txtComAPosition.Text = value.ToString();
lblShuoKeMsg.Text = DateTime.Now.ToLongTimeString() + "实时位置:" + value;
}
private void btnStop_Click(object sender, EventArgs e)
{
ShuoKeControls.SuddownStop(this.store.Config.CompressAxis_Slv);
}
private void btnClearPosition_Click(object sender, EventArgs e)
{
ShuoKeControls.PositionClear(this.store.Config.CompressAxis_Slv, ShuoKeCMD.AbsPositionClear);
ShuoKeControls.PositionClear(this.store.Config.CompressAxis_Slv, ShuoKeCMD.RelPositionClear);
}
private void btnHomeMove_Click(object sender, EventArgs e)
{
ShuoKeControls.HomeMove(this.store.Config.CompressAxis_Slv, byte.Parse(cmbHomeType.SelectedIndex.ToString()));
}
private void btnLineAbsMove_Click(object sender, EventArgs e)
{
int posi = FormUtil.GetIntValue(txtLinePosition);
ShuoKeControls.AbsMove(this.store.Config.CompressAxis_Slv, posi);
}
private void btnRelMove_Click(object sender, EventArgs e)
{
int posi = FormUtil.GetIntValue(txtLinePosition);
ShuoKeControls.RelativeMove(this.store.Config.CompressAxis_Slv, posi);
}
private void btnStatusSearch_Click(object sender, EventArgs e)
{
ShuoKeInfo info = ShuoKeControls.GetStatus(store.Config.CompressAxis_Slv);
lblShuoKeMsg.Text = info.ToShowStr();
}
private void FormComStatus(bool isOpen)
{
btnOpen.Enabled = !isOpen;
btnClose.Enabled = isOpen;
btnClearPosition.Enabled = isOpen;
btnVolMove.Enabled = isOpen;
btnGetPosition.Enabled = isOpen;
btnHomeMove.Enabled = isOpen;
btnLineAbsMove.Enabled = isOpen;
btnStatusSearch.Enabled = isOpen;
// Bt_ClearCounter.Enabled = isOpen;
}
//private void btnOpen_Click(object sender, EventArgs e)
//{
// if (StoreManager.OpenShuoKe(store))
// {
// store.SetShuokeSpeed();
// FormComStatus(true);
// }
//}
//private void btnClose_Click(object sender, EventArgs e)
//{
// ShuoKeControls.ClosePort();
// FormComStatus(false);
//}
//private void btnVolMove_Click(object sender, EventArgs e)
//{
// int speed = FormUtil.GetIntValue(txtSpeed);
// ShuoKeControls.VolMove(store.Config.CompressAxis_Slv, speed);
//}
//private void btnGetPosition_Click(object sender, EventArgs e)
//{
// int value = ShuoKeControls.GetABSPosition(store.Config.CompressAxis_Slv);
// txtComAPosition.Text = value.ToString();
// lblShuoKeMsg.Text = DateTime.Now.ToLongTimeString() + "实时位置:" + value;
//}
//private void btnStop_Click(object sender, EventArgs e)
//{
// ShuoKeControls.SuddownStop(this.store.Config.CompressAxis_Slv);
//}
//private void btnClearPosition_Click(object sender, EventArgs e)
//{
// ShuoKeControls.PositionClear(this.store.Config.CompressAxis_Slv, ShuoKeCMD.AbsPositionClear);
// ShuoKeControls.PositionClear(this.store.Config.CompressAxis_Slv, ShuoKeCMD.RelPositionClear);
//}
//private void btnHomeMove_Click(object sender, EventArgs e)
//{
// ShuoKeControls.HomeMove(this.store.Config.CompressAxis_Slv, byte.Parse(cmbHomeType.SelectedIndex.ToString()));
//}
//private void btnLineAbsMove_Click(object sender, EventArgs e)
//{
// int posi = FormUtil.GetIntValue(txtLinePosition);
// ShuoKeControls.AbsMove(this.store.Config.CompressAxis_Slv, posi);
//}
//private void btnRelMove_Click(object sender, EventArgs e)
//{
// int posi = FormUtil.GetIntValue(txtLinePosition);
// ShuoKeControls.RelativeMove(this.store.Config.CompressAxis_Slv, posi);
//}
//private void btnStatusSearch_Click(object sender, EventArgs e)
//{
// ShuoKeInfo info = ShuoKeControls.GetStatus(store.Config.CompressAxis_Slv);
// lblShuoKeMsg.Text = info.ToShowStr();
//}
//private void FormComStatus(bool isOpen)
//{
// btnOpen.Enabled = !isOpen;
// btnClose.Enabled = isOpen;
// btnClearPosition.Enabled = isOpen;
// btnVolMove.Enabled = isOpen;
// btnGetPosition.Enabled = isOpen;
// btnHomeMove.Enabled = isOpen;
// btnLineAbsMove.Enabled = isOpen;
// btnStatusSearch.Enabled = isOpen;
// // Bt_ClearCounter.Enabled = isOpen;
//}
private void btnTempInit_Click(object sender, EventArgs e)
......@@ -1415,20 +1395,10 @@ namespace OnlineStore.ACSingleStore
private void btnOpenDoor_Click(object sender, EventArgs e)
{
store.KNDIOMove(IO_Type.Door_Up, IO_VALUE.HIGH);
store.KNDIOMove(IO_Type.Door_Down, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.Door_Up, IO_VALUE.HIGH);
IOManager.IOMove(IO_Type.Door_Down, IO_VALUE.LOW);
}
private void btnOpenLed_Click(object sender, EventArgs e)
{
store.KNDIOMove(IO_Type.CameraLight_Power, IO_VALUE.HIGH);
}
private void btnCloseLed_Click(object sender, EventArgs e)
{
store.KNDIOMove(IO_Type.CameraLight_Power, IO_VALUE.LOW);
}
private void btnClearL_Click(object sender, EventArgs e)
{
LogUtil.ClearLog();
......@@ -1450,7 +1420,7 @@ namespace OnlineStore.ACSingleStore
btnDebug.Text = "启用调试";
}
groupAxis.Enabled = status;
groupComAxis.Enabled = status;
//groupComAxis.Enabled = status;
groupInout.Enabled = status;
}
......@@ -1485,8 +1455,8 @@ namespace OnlineStore.ACSingleStore
private void btnCloseDoor_Click(object sender, EventArgs e)
{
store.KNDIOMove(IO_Type.Door_Up, IO_VALUE.LOW);
store.KNDIOMove(IO_Type.Door_Down, IO_VALUE.HIGH);
IOManager.IOMove(IO_Type.Door_Up, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.Door_Down, IO_VALUE.HIGH);
}
}
}
......@@ -47,7 +47,7 @@ namespace OnlineStore.ACSingleStore.Properties {
}
/// <summary>
/// 使用此强类型资源类,为所有资源查找
/// 重写当前线程的 CurrentUICulture 属性
/// 重写当前线程的 CurrentUICulture 属性。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
......
......@@ -12,7 +12,7 @@ namespace OnlineStore.ACSingleStore.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.6.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
......
......@@ -82,8 +82,10 @@
新建料仓RC1246,作为阳光电源流水线单台料仓软件
需要修改内容:压紧轴改为伺服控制
不需要扫码,测高
前三台为7寸料盘,无舱门
第四台是13寸料盘,有舱门
修改IO
\ No newline at end of file
......@@ -84,5 +84,7 @@ namespace OnlineStore.Common
/// 温控器类型,0=壁挂王字壳温湿度变送器,1=妙昕温湿度记录仪
/// </summary>
public static string HumitureControllerType = "HumitureControllerType";
public static string UseAIOBOX = "UseAIOBOX";
}
}
......@@ -11,6 +11,7 @@ namespace OnlineStore.Common
{
public class LogUtil
{
public static readonly ILog AIOLog = LogManager.GetLogger("AIOBOXLog");
private static LogUtil instance = new LogUtil();
public delegate void ShowLog(string msg, Color color);
public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
......
......@@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>OnlineStore.DeviceLibrary</RootNamespace>
<AssemblyName>DeviceLibrary</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
......@@ -59,16 +59,18 @@
<Compile Include="acSingleStore\AC_SA_BoxBean.cs" />
<Compile Include="acSingleStore\AC_SA_BoxBean_Partial.cs" />
<Compile Include="acSingleStore\StoreManager.cs" />
<Compile Include="halcon\CodeManager.cs" />
<Compile Include="KangNaiDe\AITcpClient.cs" />
<Compile Include="KangNaiDe\KNDAIManager.cs" />
<Compile Include="KangNaiDe\KNDManager.cs" />
<Compile Include="KangNaiDe\MasterTcpClient.cs" />
<Compile Include="IO\AIOBOX\AIOBOXManager.cs" />
<Compile Include="IO\AIOBOX\BLL.cs" />
<Compile Include="IO\AIOBOX\BLL2.cs" />
<Compile Include="IO\AIOBOX\Common.cs" />
<Compile Include="IO\IOManager.cs" />
<Compile Include="IO\KangNaiDe\AITcpClient.cs" />
<Compile Include="IO\KangNaiDe\KNDAIManager.cs" />
<Compile Include="IO\KangNaiDe\KNDManager.cs" />
<Compile Include="IO\KangNaiDe\MasterTcpClient.cs" />
<Compile Include="PanasonicServo\ACCMDManager.cs" />
<Compile Include="PanasonicServo\ACServerManager.cs" />
<Compile Include="PanasonicServo\ACServerManager_Partial.cs" />
<Compile Include="ShuoKe\MeteringSignalBean.cs" />
<Compile Include="ShuoKe\ShuoKeController.cs" />
<Compile Include="store\LineMoveP.cs" />
<Compile Include="store\LineAlarm.cs">
<SubType>Code</SubType>
......@@ -76,7 +78,6 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="store\model\AxisAlarmInfo.cs" />
<Compile Include="store\model\FixtureCodeInfo.cs" />
<Compile Include="store\KTK_DeviceBase.cs" />
<Compile Include="store\InOrOutStoreParam.cs">
<SubType>Code</SubType>
</Compile>
......
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using Asa.AIOBOX;
using System.Threading;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
public class AIOBOXManager : IOManager
{
//public static uint DefaultDICount = 16;
//public static uint DefaultDOCount = 16;
public readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public Dictionary<string, AIOBOX_32> AIOMap = new Dictionary<string, AIOBOX_32>();
public string DefaultIP = "";
public Dictionary<string, List<Status>> DIValueMap = new Dictionary<string, List<Status>>();
public Dictionary<string, List<Status>> DOValueMap = new Dictionary<string, List<Status>>();
private object DIMapLock = "";
private object DOMapLock = "";
public System.Timers.Timer timer = null;
private object DILock = "";
private object DOLock = "";
public void ConnectionIP(string ioIp )
{
AIOBOX_32 aioBox = null;
if (AIOMap.ContainsKey(ioIp))
{
aioBox = AIOMap[ioIp];
if (null != aioBox)
{
aioBox.Close();
aioBox = null;
}
AIOMap.Remove(ioIp);
}
if (DIValueMap.ContainsKey(ioIp))
{
DIValueMap.Remove(ioIp);
}
if (DOValueMap.ContainsKey(ioIp))
{
DOValueMap.Remove(ioIp);
}
try
{
// Create new modbus master and add event functions
aioBox = new AIOBOX_32();
aioBox.IP = ioIp;
DefaultIP = ioIp;
aioBox.AutoReadDI = true;
aioBox.AutoReadDO = true;
aioBox.DI_Changed_Event += AioBox_DI_Changed_Event; ;
aioBox.DO_Changed_Event += AioBox_DO_Changed_Event;
LogUtil.info("开始连接IO模块【" + ioIp + "】,尝试重连三次");
for (int i = 1; i <= 3; i++)
{
bool result = aioBox.Connect();
if (result)
{
AIOMap.Add(ioIp, aioBox);
LogUtil.info("第【"+i+"】次连接IO模块【" + ioIp + "】成功:" + aioBox.ErrInfo);
Thread.Sleep(10);
//读取所有的DO
ReadAllDI(ioIp, 0);
break;
}
else
{
LogUtil.error("第【" + i + "】次连接IO模块【" + ioIp + "】失败:" + aioBox.ErrInfo + "");
}
Thread.Sleep(10);
}
}
catch (Exception error)
{
LogUtil.error(LOGGER, "连接IO模块[" + ioIp + "]出错:" + error.ToString());
}
}
private void AioBox_DI_Changed_Event(AIOBOX_32 box, Status[] sta)
{
try
{
UpdateAllDI(box.IP, sta);
}
catch (Exception ex)
{
LogUtil.error("AioBox_DI_Changed_Event出错:" + ex.ToString());
}
}
private void AioBox_DO_Changed_Event(AIOBOX_32 box, Status[] sta)
{
try
{
UpdateAllDO(box.IP, sta);
}
catch (Exception ex)
{
LogUtil.error("AioBox_DO_Changed_Event出错:" + ex.ToString());
}
}
private void UpdateAllDI(string ip, Status[] sta)
{
if (sta != null && sta.Length >= StoreManager.Config.GetDILength(ip))
{
bool needUpdate = false;
List<Status> newList = new List<Status>();
newList.AddRange(sta);
List<Status> oldList = null;
DIValueMap.TryGetValue(ip, out oldList);
if (oldList == null || oldList.Count.Equals(newList.Count).Equals(false))
{
needUpdate = true;
}
else
{
for (int i = 0; i < newList.Count; i++)
{
if (!(oldList[i].Equals(newList[i])))
{
needUpdate = true;
break;
}
}
}
if (needUpdate)
{
lock (DILock)
{
if (DIValueMap.ContainsKey(ip))
{
DIValueMap.Remove(ip);
}
DIValueMap.Add(ip, newList);
}
}
}
}
private void UpdateAllDO(string ip, Status[] sta)
{
if (sta != null && sta.Length >= StoreManager.Config.GetDOLength(ip))
{
bool needUpdate = false;
List<Status> newList = new List<Status>();
newList.AddRange(sta);
List<Status> oldList = null;
DOValueMap.TryGetValue(ip, out oldList);
if (oldList == null || oldList.Count.Equals(newList.Count).Equals(false))
{
needUpdate = true;
}
else
{
for (int i = 0; i < newList.Count; i++)
{
if (!(oldList[i].Equals(newList[i])))
{
needUpdate = true;
break;
}
}
}
if (needUpdate)
{
lock (DOLock)
{
if (DOValueMap.ContainsKey(ip))
{
DOValueMap.Remove(ip);
}
DOValueMap.Add(ip, newList);
}
}
}
}
private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
try
{
List<string> list = new List<string>(AIOMap.Keys);
foreach (string io in list)
{
//判断是否连接,如果没有连接自动重连
AIOBOX_32 clinet = AIOMap[io];
if (!clinet.IsConn)
{
LogUtil.error(LOGGER, io + "当前没有连上:" + clinet.ErrInfo);
}
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "出错啦:" + ex.ToString());
}
Thread.Sleep(1);
}
public override void ConnectionIOList(List<string> DIONameList)
{
foreach (string ip in DIONameList)
{
ConnectionIP(ip );
}
}
//关闭所有的DO
public override void CloseAllDO()
{
foreach (AIOBOX_32 aio in AIOMap.Values)
{
Status[] statuses = new Status[16];
for(int i = 0; i < 16; i++)
{
statuses[i] = Status.Off;
}
aio.WriteDO(Addr.DI_1, statuses);
}
}
public override void CloseAllConnection()
{
foreach (AIOBOX_32 aio in AIOMap.Values)
{
aio.Close();
}
AIOMap.Clear();
}
public override void WriteSingleDO(string ioIp, byte slaveId, ushort StartAddress, IO_VALUE onOff)
{
try
{
AIOBOX_32 aioBox = getAIO(ioIp);
if (aioBox != null)
{
Addr add = GetAddr(StartAddress);
for (int i = 1; i <= 3; i++)
{
bool result = aioBox.WriteDO(GetAddr(StartAddress), GetStatus(onOff));
if (!result)
{
LogUtil.error("AIO WriteSingleDO [" + StartAddress + "] 第" + i + "次失败:" + aioBox.ErrInfo);
}
else
{
break;
}
}
}
else
{
LogUtil.error(LOGGER, "ReadSingleDO出错没有连接IO模块:" + ioIp);
}
}
catch (Exception ex)
{
LOGGER.Error("出错啦:" + ex.ToString());
}
}
public override void WriteSingleDO(string ioIp, byte slaveId, ushort StartAddress, IO_VALUE onOff, int mSeconds)
{
try
{
AIOBOX_32 aioBox = getAIO(ioIp);
Status currStatus = GetStatus(onOff);
if (aioBox != null)
{
Addr add = GetAddr(StartAddress);
aioBox.WriteDO(GetAddr(StartAddress), currStatus);
//写入之后,等待指定间隔后回写
System.Timers.Timer mytimer = new System.Timers.Timer(mSeconds);
mytimer.Elapsed += (o1, e1) =>
{
try
{
aioBox.WriteDO(GetAddr(StartAddress), aioBox.ReverseStatus(currStatus));
LogUtil.debug(LOGGER, "**********定时回写入 IO【" + ioIp + "," + StartAddress + ",值" + aioBox.ReverseStatus(currStatus) + "】:");
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "**********定时回写入 出错:" + ex.StackTrace);
}
};
mytimer.AutoReset = false;//设置是否自动重启,即自动执行多次;
mytimer.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件mytask;
}
else
{
LogUtil.error(LOGGER, "WriteSingleDO出错没有连接IO模块:" + ioIp);
}
}
catch (Exception ex)
{
LogUtil.error("WriteSingleDO出错:" + ioIp);
}
}
public override void ReadAllDI(string ioIp, byte slaveId)
{
try
{
AIOBOX_32 aioBox = getAIO(ioIp);
if (aioBox != null)
{
Status[] allDi;
if (aioBox.ReadDI(Addr.DI_1, StoreManager.Config.GetDILength(ioIp), out allDi))
{
UpdateAllDI(ioIp, allDi);
}
else
{
LogUtil.error("读取所有DI出错:" + aioBox.ErrInfo);
}
}
}
catch (Exception ex)
{
LogUtil.error("ReadAllDI出错:" + ioIp);
}
}
public override void ReadAllDO(string ioIp, byte slaveId)
{
try
{
AIOBOX_32 aioBox = getAIO(ioIp);
if (aioBox != null)
{
Status[] allDO;
if (aioBox.ReadDO(Addr.DO_1, StoreManager.Config.GetDOLength(ioIp), out allDO))
{
UpdateAllDO(ioIp, allDO);
}
else
{
LogUtil.error("读取所有DO出错:" + aioBox.ErrInfo);
}
}
}
catch (Exception ex)
{
LogUtil.error("ReadAllDO出错:" + ioIp);
}
}
public override IO_VALUE GetDOValue(string ioIP, byte slaveId, ushort StartAddress)
{
IO_VALUE value = IO_VALUE.LOW;
try
{
AIOBOX_32 aioBox = getAIO(ioIP);
if (aioBox != null)
{
Status status = Status.Off;
Addr addr = GetAddr(StartAddress);
int index =(int)StartAddress - (int)StoreManager.Config.GetDILength(ioIP);
if (DOValueMap.ContainsKey(ioIP) && DOValueMap[ioIP].Count>index)
{
status = DOValueMap[ioIP][index];
}
else
{ aioBox.ReadDO(addr, out status); }
if (status.Equals(Status.On))
{
value = IO_VALUE.HIGH;
}
}
}
catch (Exception ex)
{
LogUtil.error("ReadDI 出错:" + ex.ToString());
}
return value;
}
public override IO_VALUE GetDIValue(string ioIP, byte slaveId, ushort StartAddress)
{
IO_VALUE value = IO_VALUE.LOW;
try
{
AIOBOX_32 aioBox = getAIO(ioIP);
if (aioBox != null)
{
Status status = Status.Off;
Addr addr = GetAddr(StartAddress);
int index = StartAddress;
if (DIValueMap.ContainsKey(ioIP) && DIValueMap[ioIP].Count> index)
{
status = DIValueMap[ioIP][index];
}
else
{
aioBox.ReadDI(addr, out status);
}
if (status.Equals(Status.On))
{
value = IO_VALUE.HIGH;
}
}
}
catch (Exception ex)
{
LogUtil.error("ReadDI 出错:" + ex.ToString());
}
return value;
}
public override IO_VALUE GetIOValue(ConfigIO configIO)
{
IO_VALUE value = IO_VALUE.LOW;
try
{
if (configIO.ProType.Equals(ConfigItemType.DI))
{
return GetDIValue(configIO.DeviceName, configIO.SlaveID, configIO.GetIOAddr());
}
else if (configIO.ProType.Equals(ConfigItemType.DO))
{
return GetDOValue(configIO.DeviceName, configIO.SlaveID, configIO.GetIOAddr());
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "获取数据出错:" + ex.ToString());
}
return value;
}
private Addr GetAddr(ushort StartAddress)
{
return (Addr)(StartAddress );
}
private Status GetStatus(IO_VALUE onOff)
{
if (onOff.Equals(IO_VALUE.HIGH))
{
return Status.On;
}
else
{
return Status.Off;
}
}
private AIOBOX_32 getAIO(string ioIp)
{
AIOBOX_32 aioBox = null;
if (AIOMap.ContainsKey(ioIp))
{
aioBox = AIOMap[ioIp];
}
return aioBox;
}
}
}
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System.Threading.Tasks;
using Asa.IOModule;
namespace OnlineStore.DeviceLibrary
{
public class AIOBOXManager : IOManager
{
//public static uint DefaultDICount = 16;
//public static uint DefaultDOCount = 16;
public readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public Dictionary<string, AIOBOX2> AIOMap = new Dictionary<string, AIOBOX2>();
public Dictionary<string, List<Box_Sta>> DIValueMap = new Dictionary<string, List<Box_Sta>>();
public Dictionary<string, List<Box_Sta>> DOValueMap = new Dictionary<string, List<Box_Sta>>();
private object DIMapLock = "";
private object DOMapLock = "";
public System.Timers.Timer timer = null;
private object DILock = "";
private object DOLock = "";
public void ConnectionIP(string ioIp )
{
AIOBOX2 aioBox = null;
if (AIOMap.ContainsKey(ioIp))
{
aioBox = AIOMap[ioIp];
if (null != aioBox)
{
aioBox.Close();
aioBox = null;
}
AIOMap.Remove(ioIp);
}
if (DIValueMap.ContainsKey(ioIp))
{
DIValueMap.Remove(ioIp);
}
if (DOValueMap.ContainsKey(ioIp))
{
DOValueMap.Remove(ioIp);
}
try
{
// Create new modbus master and add event functions
aioBox = new AIOBOX2();
aioBox.IP = ioIp;
int DIMS = ConfigAppSettings.GetIntValue("DIMS");
if (DIMS < 20)
{
DIMS = 20;
}
int DOMS = ConfigAppSettings.GetIntValue("DOMS");
if (DOMS < 200)
{
DOMS = 200;
}
aioBox.AutoReadDI(true, DIMS);
aioBox.AutoReadDO (true, DOMS);
aioBox.LogOut = true;
//aioBox.Reconnect_Event += AioBox_Reconnect_Event;
if (StoreManager.Config.GetDILength(ioIp).Equals(8))
{
aioBox.Type = Box_Type.DIO_16;
}
else
{
aioBox.Type = Box_Type.DIO_32;
}
aioBox.DI_Changed_Event += AioBox_DI_Changed_Event; ;
aioBox.DO_Changed_Event += AioBox_DO_Changed_Event;
aioBox.Log_Out_Event += AioBox_Log_Out_Event;
//aioBox.Log_RxTx_Event += AioBox_Log_RxTx_Event;
AIOMap.Add(ioIp, aioBox);
LogUtil.info("开始连接IO模块[" + ioIp + "]["+DIMS+"]["+DOMS+"],尝试重连三次");
for (int i = 1; i <= 3; i++)
{
bool result = aioBox.Connect();
if (result)
{
LogUtil.info("第【"+i+"】次连接IO模块【" + ioIp + "】成功:" + aioBox.ErrInfo);
Thread.Sleep(10);
//读取所有的DO
ReadAllDI(ioIp, 0);
break;
}
else
{
LogUtil.error("第【" + i + "】次连接IO模块【" + ioIp + "】失败:" + aioBox.ErrInfo + "");
}
Thread.Sleep(10);
}
if (timer == null)
{
timer = new System.Timers.Timer();
timer.Interval = 5000;
timer.AutoReset = true;
timer.Elapsed += timer_Elapsed;
timer.Enabled = true;
}
}
catch (Exception error)
{
LogUtil.error(LOGGER, "连接IO模块[" + ioIp + "]出错:" + error.ToString());
}
}
private void AioBox_Reconnect_Event(AIOBOX2 box, int times, ref bool conn, Dictionary<string, string> dict)
{
conn = true;
string msg = "重连AIO块【" + box.IP + "】次数:" + times + "【" + box.ErrInfo + "】,连接信息如下\r\n";
foreach (string key in dict.Keys)
{
msg = msg + "\t" + "[" + key + "]=[" + dict[key] + "],";
}
LogUtil.error(msg);
}
private DateTime lastLogTime = DateTime.Now;
//private void AioBox_Log_RxTx_Event(AIOBOX2 box, string[] s)
//{
// TimeSpan span = DateTime.Now - lastLogTime;
// //if (span.TotalMinutes > 1)
// {
// lastLogTime = DateTime.Now;
// foreach (string str in s)
// {
// LogUtil.AIOLog.Debug("[" + box.IP + "]" + str);
// }
// }
//}
private void AioBox_Log_Out_Event(AIOBOX2 box, string[] s)
{
foreach (string str in s)
{
LogUtil.AIOLog.Debug("[" + box.IP + "]" + str);
}
}
private void AioBox_DI_Changed_Event(AIOBOX2 box, Box_Sta[] sta)
{
try
{
UpdateAllDI(box.IP, sta);
}
catch (Exception ex)
{
LogUtil.error("AioBox_DI_Changed_Event出错:" + ex.ToString());
}
}
private void AioBox_DO_Changed_Event(AIOBOX2 box, Box_Sta[] sta)
{
try
{
UpdateAllDO(box.IP, sta);
}
catch (Exception ex)
{
LogUtil.error("AioBox_DO_Changed_Event出错:" + ex.ToString());
}
}
private void UpdateAllDI(string ip, Box_Sta[] sta)
{
if (sta != null && sta.Length >= StoreManager.Config.GetDILength(ip))
{
bool needUpdate = false;
List<Box_Sta> newList = new List<Box_Sta>();
newList.AddRange(sta);
List<Box_Sta> oldList = null;
DIValueMap.TryGetValue(ip, out oldList);
if (oldList == null || oldList.Count.Equals(newList.Count).Equals(false))
{
needUpdate = true;
}
else
{
for (int i = 0; i < newList.Count; i++)
{
if (!(oldList[i].Equals(newList[i])))
{
needUpdate = true;
break;
}
}
}
if (needUpdate)
{
lock (DILock)
{
if (DIValueMap.ContainsKey(ip))
{
DIValueMap.Remove(ip);
}
DIValueMap.Add(ip, newList);
}
}
}
}
private void UpdateAllDO(string ip, Box_Sta[] sta)
{
if (sta != null && sta.Length >= StoreManager.Config.GetDOLength(ip))
{
bool needUpdate = false;
List<Box_Sta> newList = new List<Box_Sta>();
newList.AddRange(sta);
List<Box_Sta> oldList = null;
DOValueMap.TryGetValue(ip, out oldList);
if (oldList == null || oldList.Count.Equals(newList.Count).Equals(false))
{
needUpdate = true;
}
else
{
for (int i = 0; i < newList.Count; i++)
{
if (!(oldList[i].Equals(newList[i])))
{
needUpdate = true;
break;
}
}
}
if (needUpdate)
{
lock (DOLock)
{
if (DOValueMap.ContainsKey(ip))
{
DOValueMap.Remove(ip);
}
DOValueMap.Add(ip, newList);
}
}
}
}
private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
try
{
//List<string> list = new List<string>(AIOMap.Keys);
//foreach (string io in list)
//{
// //判断是否连接,如果没有连接自动重连
// AIOBOX2 client = AIOMap[io];
// if (!client.IsConn)
// {
// //重连
// bool result = client.Connect();
// if (result)
// {
// LogUtil.info("重连O模块【" + client.IP + "】成功:" + client.ErrInfo);
// }
// else
// {
// LogUtil.error("重连O模块【" + client.IP + "】失败:" + client.ErrInfo);
// }
// }
//}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "出错啦:" + ex.ToString());
}
Thread.Sleep(1);
}
public override void ConnectionIOList(List<string> DIONameList)
{
foreach (string ip in DIONameList)
{
ConnectionIP(ip );
}
}
//关闭所有的DO
public override void CloseAllDO()
{
foreach (AIOBOX2 aio in AIOMap.Values)
{
ushort length = StoreManager.Config.GetDILength(aio.IP);
for (ushort i = 0; i < length; i++)
{
ushort u =(ushort)( i + length);
Box_Addr addr = GetAddr(u);
aio.WriteDO(addr, Box_Sta.Off);
}
}
}
public override void CloseAllConnection()
{
foreach (AIOBOX2 aio in AIOMap.Values)
{
aio.Close();
}
AIOMap.Clear();
timer.Stop();
timer = null;
}
public override void WriteSingleDO(string ioIp, byte slaveId, ushort StartAddress, IO_VALUE onOff)
{
try
{
AIOBOX2 aioBox = getAIO(ioIp);
if (aioBox != null)
{
Box_Addr add = GetAddr(StartAddress);
for (int i = 1; i <= 3; i++)
{
bool result = aioBox.WriteDO(GetAddr(StartAddress), GetBox_Sta(onOff));
if (!result)
{
LogUtil.error("AIO WriteSingleDO [" + StartAddress + "] 第" + i + "次失败:" + aioBox.ErrInfo);
}
else
{
break;
}
}
}
else
{
LogUtil.error(LOGGER, "ReadSingleDO出错没有连接IO模块:" + ioIp);
}
}
catch (Exception ex)
{
LOGGER.Error("出错啦:" + ex.ToString());
}
}
public override void WriteSingleDO(string ioIp, byte slaveId, ushort StartAddress, IO_VALUE onOff, int mSeconds)
{
try
{
AIOBOX2 aioBox = getAIO(ioIp);
Box_Sta currBox_Sta = GetBox_Sta(onOff);
if (aioBox != null)
{
Box_Addr add = GetAddr(StartAddress);
aioBox.WriteDO(GetAddr(StartAddress), currBox_Sta);
//写入之后,等待指定间隔后回写
System.Timers.Timer mytimer = new System.Timers.Timer(mSeconds);
mytimer.Elapsed += (o1, e1) =>
{
try
{
aioBox.WriteDO(GetAddr(StartAddress), aioBox.ReverseStatus(currBox_Sta));
LogUtil.debug(LOGGER, "**********定时回写入 IO【" + ioIp + "," + StartAddress + ",值" + aioBox.ReverseStatus(currBox_Sta) + "】:");
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "**********定时回写入 出错:" + ex.StackTrace);
}
};
mytimer.AutoReset = false;//设置是否自动重启,即自动执行多次;
mytimer.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件mytask;
}
else
{
LogUtil.error(LOGGER, "WriteSingleDO出错没有连接IO模块:" + ioIp);
}
}
catch (Exception ex)
{
LogUtil.error("WriteSingleDO出错:" + ioIp);
}
}
public override void ReadAllDI(string ioIp, byte slaveId)
{
try
{
AIOBOX2 aioBox = getAIO(ioIp);
if (aioBox != null)
{
Box_Sta[] allDi = aioBox.ReadDI(Box_Addr.DI_1, StoreManager.Config.GetDILength(ioIp));
UpdateAllDI(ioIp, allDi);
}
}
catch (Exception ex)
{
LogUtil.error("ReadAllDI出错:" + ioIp);
}
}
public override void ReadAllDO(string ioIp, byte slaveId)
{
try
{
AIOBOX2 aioBox = getAIO(ioIp);
if (aioBox != null)
{
Box_Sta[] allDO = aioBox.ReadDO(Box_Addr.DO_1, StoreManager.Config.GetDOLength(ioIp));
UpdateAllDO(ioIp, allDO);
}
}
catch (Exception ex)
{
LogUtil.error("ReadAllDO出错:" + ioIp);
}
}
public override IO_VALUE GetDOValue(string ioIP, byte slaveId, ushort StartAddress)
{
IO_VALUE value = IO_VALUE.LOW;
try
{
AIOBOX2 aioBox = getAIO(ioIP);
if (aioBox != null)
{
Box_Sta sta = Box_Sta.Off;
Box_Addr addr = GetAddr(StartAddress);
int index = (int)StartAddress - (int)StoreManager.Config.GetDILength(ioIP);
if (DOValueMap.ContainsKey(ioIP) && DOValueMap[ioIP].Count > index)
{
sta = DOValueMap[ioIP][index];
}
else
{ sta = aioBox.ReadDO(addr); }
if (sta.Equals(Box_Sta.On))
{
value = IO_VALUE.HIGH;
}
}
}
catch (Exception ex)
{
LogUtil.error("ReadDI 出错:" + ex.ToString());
}
return value;
}
public override IO_VALUE GetDIValue(string ioIP, byte slaveId, ushort StartAddress)
{
IO_VALUE value = IO_VALUE.LOW;
try
{
AIOBOX2 aioBox = getAIO(ioIP);
if (aioBox != null)
{
Box_Sta sta = Box_Sta.Off;
Box_Addr addr = GetAddr(StartAddress);
int index = StartAddress;
if (DIValueMap.ContainsKey(ioIP) && DIValueMap[ioIP].Count> index)
{
sta = DIValueMap[ioIP][index];
}
else
{
sta= aioBox.ReadDI(addr );
}
if (sta.Equals(Box_Sta.On))
{
value = IO_VALUE.HIGH;
}
}
}
catch (Exception ex)
{
LogUtil.error("ReadDI 出错:" + ex.ToString());
}
return value;
}
public override IO_VALUE GetIOValue(ConfigIO configIO)
{
IO_VALUE value = IO_VALUE.LOW;
try
{
if (configIO.ProType.Equals(ConfigItemType.DI))
{
return GetDIValue(configIO.DeviceName, configIO.SlaveID, configIO.GetIOAddr());
}
else if (configIO.ProType.Equals(ConfigItemType.DO))
{
return GetDOValue(configIO.DeviceName, configIO.SlaveID, configIO.GetIOAddr());
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "获取数据出错:" + ex.ToString());
}
return value;
}
private Box_Addr GetAddr(ushort StartAddress)
{
return (Box_Addr)(StartAddress );
}
private Box_Sta GetBox_Sta(IO_VALUE onOff)
{
if (onOff.Equals(IO_VALUE.HIGH))
{
return Box_Sta.On;
}
else
{
return Box_Sta.Off;
}
}
private AIOBOX2 getAIO(string ioIp)
{
AIOBOX2 aioBox = null;
if (AIOMap.ContainsKey(ioIp))
{
aioBox = AIOMap[ioIp];
}
return aioBox;
}
}
}
/*
* @Description: 用于AIOBOX-32系列一体化IO模块
* @CreateDate: 2019-02-28
* @UpdateDate: 2019-05-13
* @Author: Asa
* @Version: 1.8
*
*/
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Collections.Generic;
using OnlineStore.Common;
namespace Asa.IOModule
{
/// <summary>
/// AIOBOX操作类
/// </summary>
public class AIOBOX
{
private ushort _flag; //ModBusTCP标识
private Socket _client; //客户端
private Box_Type _type; //类型
private byte[] _addr; //地址
private Box_Sta[] _sta; //状态
private int _unrevd; //没有收到数据的时间
private int _unrevdRemote; //本地还是远程没有收到数据
private bool _readDI; //自动读取DI
private bool _readDO; //自动读取DO
private int _readDISleep; //自动读取DI间隔
private int _readDOSleep; //自动读取DO间隔
private List<string> _log; //日志
private List<string> _logRxTx; //日志
//private List<byte[]> _send; //发送的命令
private System.Collections.Concurrent.ConcurrentQueue<byte[]> _send;
private System.Collections.Concurrent.ConcurrentQueue<byte[]> _receive; //接收的数据
private Thread tSend; //发送命令处理
private Thread tReceive; //接收信息处理
private Thread tListen; //监听网络
private Thread tTrigger; //触发DI、DO改变事件
private Thread tReadDI; //自动读取DI线程
private Thread tReadDO; //自动读取DO线程
private Thread tLogOut; //日志输出
private Thread tReconn; //断开重连
private const int SEND_SLEEP = 15; //发送命令间隔
private const int NET_SLEEP = 15; //接收网络间隔
private const int TRIG_SLEEP = 20; //触发事件间隔
/// <summary>
/// 自动读取DI委托
/// </summary>
/// <param name="box">AIOBOX</param>
/// <param name="sta">所有DI状态</param>
public delegate void DI_Changed(AIOBOX box, Box_Sta[] sta);
/// <summary>
/// 自动读取DI事件触发
/// </summary>
public event DI_Changed DI_Changed_Event;
/// <summary>
/// 自动读取DO委托
/// </summary>
/// <param name="box">AIOBOX</param>
/// <param name="sta">所有DO状态</param>
public delegate void DO_Changed(AIOBOX box, Box_Sta[] sta);
/// <summary>
/// 自动读取DO事件触发
/// </summary>
public event DO_Changed DO_Changed_Event;
/// <summary>
/// 日志输出
/// </summary>
/// <param name="box"></param>
/// <param name="s"></param>
public delegate void Log_Out(AIOBOX box, string[] s);
/// <summary>
/// 日志输出事件
/// </summary>
public event Log_Out Log_Out_Event;
/// <summary>
/// 日志输出
/// </summary>
/// <param name="box"></param>
/// <param name="s"></param>
public delegate void Log_RxTx(AIOBOX box, string[] s);
/// <summary>
/// 日志输出事件,发送命令的标识减去接收命令的标识
/// </summary>
public event Log_RxTx Log_RxTx_Event;
/// <summary>
/// 断开重连
/// </summary>
/// <param name="box"></param>
/// <param name="times">断开次数</param>
/// <param name="conn"></param>
public delegate void Reconnect(AIOBOX box, int times, ref bool conn, Dictionary<string, string> dict);
/// <summary>
/// 断开重连事件
/// </summary>
public event Reconnect Reconnect_Event;
/// <summary>
/// AIOBOX
/// </summary>
public AIOBOX()
{
_unrevd = 0;
_unrevdRemote = 0;
_readDI = false;
_readDO = false;
_readDISleep = 100;
_readDOSleep = 100;
_addr = new byte[32];
_sta = new Box_Sta[32];
_log = new List<string>();
_logRxTx = new List<string>();
_send = new System.Collections.Concurrent.ConcurrentQueue<byte[]>();
_receive = new System.Collections.Concurrent.ConcurrentQueue<byte[]>();
Type = Box_Type.DIO_32;
tReconn = new Thread(new ThreadStart(Reconn));
tReconn.Start();
}
/// <summary>
/// IP地址
/// </summary>
public string IP { set; get; } = "192.168.1.100";
/// <summary>
/// ModBus端口
/// </summary>
public int Port { set; get; } = 502;
/// <summary>
/// 是否连接
/// </summary>
public bool IsConn { get; private set; } = false;
/// <summary>
/// 错误信息
/// </summary>
public string ErrInfo { get; private set; } = "";
/// <summary>
/// 日志输出
/// </summary>
public bool LogOut { set; get; } = false;
/// <summary>
/// 模块的类型
/// </summary>
public Box_Type Type
{
set
{
_type = value;
if (value == Box_Type.DIO_16)
{
_addr[(int)Box_Addr.DI_1] = 0;
_addr[(int)Box_Addr.DI_2] = 1;
_addr[(int)Box_Addr.DI_3] = 2;
_addr[(int)Box_Addr.DI_4] = 3;
_addr[(int)Box_Addr.DI_5] = 4;
_addr[(int)Box_Addr.DI_6] = 5;
_addr[(int)Box_Addr.DI_7] = 6;
_addr[(int)Box_Addr.DI_8] = 7;
_addr[(int)Box_Addr.DI_9] = 255;
_addr[(int)Box_Addr.DI_10] = 255;
_addr[(int)Box_Addr.DI_11] = 255;
_addr[(int)Box_Addr.DI_12] = 255;
_addr[(int)Box_Addr.DI_13] = 255;
_addr[(int)Box_Addr.DI_14] = 255;
_addr[(int)Box_Addr.DI_15] = 255;
_addr[(int)Box_Addr.DI_16] = 255;
_addr[(int)Box_Addr.DO_1] = 8;
_addr[(int)Box_Addr.DO_2] = 9;
_addr[(int)Box_Addr.DO_3] = 10;
_addr[(int)Box_Addr.DO_4] = 11;
_addr[(int)Box_Addr.DO_5] = 12;
_addr[(int)Box_Addr.DO_6] = 13;
_addr[(int)Box_Addr.DO_7] = 14;
_addr[(int)Box_Addr.DO_8] = 15;
_addr[(int)Box_Addr.DO_9] = 255;
_addr[(int)Box_Addr.DO_10] = 255;
_addr[(int)Box_Addr.DO_11] = 255;
_addr[(int)Box_Addr.DO_12] = 255;
_addr[(int)Box_Addr.DO_13] = 255;
_addr[(int)Box_Addr.DO_14] = 255;
_addr[(int)Box_Addr.DO_15] = 255;
_addr[(int)Box_Addr.DO_16] = 255;
}
else if (value == Box_Type.DIO_32)
{
_addr[(int)Box_Addr.DI_1] = 0;
_addr[(int)Box_Addr.DI_2] = 1;
_addr[(int)Box_Addr.DI_3] = 2;
_addr[(int)Box_Addr.DI_4] = 3;
_addr[(int)Box_Addr.DI_5] = 4;
_addr[(int)Box_Addr.DI_6] = 5;
_addr[(int)Box_Addr.DI_7] = 6;
_addr[(int)Box_Addr.DI_8] = 7;
_addr[(int)Box_Addr.DI_9] = 8;
_addr[(int)Box_Addr.DI_10] = 9;
_addr[(int)Box_Addr.DI_11] = 10;
_addr[(int)Box_Addr.DI_12] = 11;
_addr[(int)Box_Addr.DI_13] = 12;
_addr[(int)Box_Addr.DI_14] = 13;
_addr[(int)Box_Addr.DI_15] = 14;
_addr[(int)Box_Addr.DI_16] = 15;
_addr[(int)Box_Addr.DO_1] = 16;
_addr[(int)Box_Addr.DO_2] = 17;
_addr[(int)Box_Addr.DO_3] = 18;
_addr[(int)Box_Addr.DO_4] = 19;
_addr[(int)Box_Addr.DO_5] = 20;
_addr[(int)Box_Addr.DO_6] = 21;
_addr[(int)Box_Addr.DO_7] = 22;
_addr[(int)Box_Addr.DO_8] = 23;
_addr[(int)Box_Addr.DO_9] = 24;
_addr[(int)Box_Addr.DO_10] = 25;
_addr[(int)Box_Addr.DO_11] = 26;
_addr[(int)Box_Addr.DO_12] = 27;
_addr[(int)Box_Addr.DO_13] = 28;
_addr[(int)Box_Addr.DO_14] = 29;
_addr[(int)Box_Addr.DO_15] = 30;
_addr[(int)Box_Addr.DO_16] = 31;
}
else if (value == Box_Type.DO_16)
{
_addr[(int)Box_Addr.DO_1] = 0;
_addr[(int)Box_Addr.DO_2] = 1;
_addr[(int)Box_Addr.DO_3] = 2;
_addr[(int)Box_Addr.DO_4] = 3;
_addr[(int)Box_Addr.DO_5] = 4;
_addr[(int)Box_Addr.DO_6] = 5;
_addr[(int)Box_Addr.DO_7] = 6;
_addr[(int)Box_Addr.DO_8] = 7;
_addr[(int)Box_Addr.DO_9] = 8;
_addr[(int)Box_Addr.DO_10] = 9;
_addr[(int)Box_Addr.DO_11] = 10;
_addr[(int)Box_Addr.DO_12] = 11;
_addr[(int)Box_Addr.DO_13] = 12;
_addr[(int)Box_Addr.DO_14] = 13;
_addr[(int)Box_Addr.DO_15] = 14;
_addr[(int)Box_Addr.DO_16] = 15;
}
}
get
{
return _type;
}
}
/// <summary>
/// 连接
/// </summary>
/// <returns></returns>
public bool Connect()
{
IsConn = false;
try
{
//IP合法
string pattern = @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$";
bool rtn = System.Text.RegularExpressions.Regex.IsMatch(IP, pattern);
if (!rtn)
{
ErrInfo = "非法的IP地址 " + IP;
return false;
}
//Ping服务端
System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();
System.Net.NetworkInformation.PingReply result = ping.Send(IP, 5000);
if (result.Status != System.Net.NetworkInformation.IPStatus.Success)
{
ErrInfo = "Ping " + IP + " 请求没有回应";
return false;
}
_unrevd = 0;
_unrevdRemote = 0;
_flag = 0;
_send = new System.Collections.Concurrent.ConcurrentQueue<byte[]>();
_receive = new System.Collections.Concurrent.ConcurrentQueue<byte[]>();
_log.Clear();
_logRxTx.Clear();
//建立连接
//_client.Blocking = true;
_client = new Socket(IPAddress.Parse(IP).AddressFamily, SocketType.Stream, ProtocolType.Tcp);
_client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 500);
_client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 500);
_client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, 1);
_client.BeginConnect(IP, Port, new AsyncCallback(Target), null);
Thread.Sleep(100); //需要等待一会才能获取连接状态
tReadDI = new Thread(new ThreadStart(AutoReadDI));
tReadDO = new Thread(new ThreadStart(AutoReadDO));
tSend = new Thread(new ThreadStart(Send));
tReceive = new Thread(new ThreadStart(Receive));
tLogOut = new Thread(new ThreadStart(LogPrint));
tSend.Start();
tReceive.Start();
tLogOut.Start();
tReadDI.Start();
tReadDO.Start();
ErrInfo = "OK";
IsConn = true;
return true;
}
catch (Exception ex)
{
ErrInfo = ex.Message;
LogUtil.error(ex.ToString());
return false;
}
}
/// <summary>
/// 关闭连接
/// </summary>
public void Close()
{
if (tReconn != null)
tReconn.Abort();
tReconn = null;
CloseConn();
}
/// <summary>
/// 自动读取DI状态,触发DI_Changed_Event
/// </summary>
/// <param name="read">是否自动读取</param>
/// <param name="sleep">间隔,必须大于10ms</param>
public void AutoReadDI(bool read, int sleep)
{
if (_type == Box_Type.DO_16)
{
_readDI = false;
_readDISleep = 10000;
}
else
{
if (sleep < 10)
{
_readDI = false;
_readDISleep = 100;
}
else
{
if (read)
{
_readDI = true;
_readDISleep = sleep;
}
else
{
_readDI = false;
_readDISleep = 100;
}
}
}
}
/// <summary>
/// 自动读取DO状态,触发DO_Changed_Event
/// </summary>
/// <param name="read">是否自动读取</param>
/// <param name="sleep">间隔,必须大于10ms</param>
public void AutoReadDO(bool read, int sleep)
{
if (sleep < 10)
{
_readDO = false;
_readDOSleep = 100;
}
else
{
if (read)
{
_readDO = true;
_readDOSleep = sleep;
}
else
{
_readDO = false;
_readDOSleep = 100;
}
}
}
/// <summary>
/// 相反状态
/// </summary>
/// <param name="sta"></param>
/// <returns></returns>
public Box_Sta ReverseStatus(Box_Sta sta)
{
return sta == Box_Sta.On ? Box_Sta.Off : Box_Sta.On;
}
/// <summary>
/// 读取单个DI
/// </summary>
/// <param name="add"></param>
/// <returns></returns>
public Box_Sta ReadDI(Box_Addr add)
{
return _sta[(int)add];
}
/// <summary>
/// 读取多个DI
/// </summary>
/// <param name="add"></param>
/// <param name="count"></param>
/// <returns></returns>
public Box_Sta[] ReadDI(Box_Addr add, int count)
{
Box_Sta[] sta = new Box_Sta[count];
Array.Copy(_sta, (int)add, sta, 0, count);
return sta;
}
/// <summary>
/// 读取单个DO
/// </summary>
/// <param name="add"></param>
/// <returns></returns>
public Box_Sta ReadDO(Box_Addr add)
{
return _sta[(int)add];
}
/// <summary>
/// 读取多个DO
/// </summary>
/// <param name="add"></param>
/// <param name="count"></param>
/// <returns></returns>
public Box_Sta[] ReadDO(Box_Addr add, int count)
{
Box_Sta[] sta = new Box_Sta[count];
Array.Copy(_sta, (int)add, sta, 0, count);
return sta;
}
/// <summary>
/// 写入单个DO
/// </summary>
/// <param name="add"></param>
/// <param name="sta"></param>
/// <returns></returns>
public bool WriteDO(Box_Addr add, Box_Sta sta)
{
try
{
byte[] data = Command();
byte[] buff = new byte[12];
Array.Copy(data, 0, buff, 0, data.Length);
buff[7] = 5; //功能码
buff[9] = _addr[(int)add]; //地址
buff[10] = (byte)sta; //写入值
if (LogOut)
{
byte[] bb = new byte[2];
bb[0] = buff[1];
bb[1] = buff[0];
ushort flag = BitConverter.ToUInt16(bb, 0);
string s = string.Format("{0:HH:mm:ss.fff} WriteDO id={1} ({2},{3})", DateTime.Now, flag, add.ToString(), sta.ToString());
_log.Add(s);
}
//_send.Add(buff);
_send.Enqueue(buff);
if (_unrevdRemote == 0) ErrInfo = "OK";
return true;
}
catch (Exception ex)
{
ErrInfo = ex.Message;
LogUtil.error(ex.ToString());
return false;
}
}
/// <summary>
/// 获取本地IPv4地址
/// </summary>
/// <returns></returns>
public string[] GetLocalIP()
{
List<string> str = new List<string>();
IPAddress[] add = Dns.GetHostEntry(Dns.GetHostName()).AddressList;
foreach (IPAddress ip in add)
{
if (ip.AddressFamily.ToString() == "InterNetwork")
str.Add(ip.ToString());
}
return str.ToArray();
}
/// <summary>
/// 发送命令
/// </summary>
private void Send()
{
string s;
ushort flag;
while (true)
{
//if (_send.Count > 0)
//{
// if (_send[0] != null)
// {
// try
// {
// _client.Send(_send[0]);
// if (LogOut)
// {
// byte[] bb = new byte[2];
// bb[0] = _send[0][1];
// bb[1] = _send[0][0];
// flag = BitConverter.ToUInt16(bb, 0);
// s = string.Format("{0:HH:mm:ss:fff} Send {1}", DateTime.Now, flag);
// _log.Add(s);
// _logRxTx.Add(flag + "," + _send[0][7]);
// }
// _send.RemoveAt(0);
// }
// catch (Exception ex)
// {
// ErrInfo = ex.Message;
// LogUtil.error(ex.ToString());
// _unrevdRemote = 1;
// break;
// }
// }
//}
bool rtn = _send.TryDequeue(out byte[] result);
if (rtn)
{
try
{
_client.Send(result);
if (LogOut)
{
byte[] bb = new byte[2];
bb[0] = result[1];
bb[1] = result[0];
flag = BitConverter.ToUInt16(bb, 0);
s = string.Format("{0:HH:mm:ss:fff} Send id={1} fun={2} len={3}", DateTime.Now, flag, result[7], result.Length);
_log.Add(s);
_logRxTx.Add(flag + "," + result[7]);
}
}
catch (Exception ex)
{
ErrInfo = ex.Message;
LogUtil.error(ex.ToString());
_unrevdRemote = 1;
break;
}
}
Thread.Sleep(SEND_SLEEP);
}
}
/// <summary>
/// 接收命令
/// </summary>
private void Receive()
{
while (true)
{
if (_receive.TryDequeue(out byte[] buff))
{
if (buff[7] == 1)
ReadDO(buff);
else if (buff[7] == 2)
ReadDI(buff);
else if (buff[7] == 5)
ReadSingle(buff);
}
Thread.Sleep(10);
}
}
/// <summary>
/// 读取单个DO
/// </summary>
/// <param name="buff"></param>
private void ReadSingle(byte[] buff)
{
//try
//{
string s;
if (LogOut)
{
byte[] bb = new byte[2];
bb[0] = buff[1];
bb[1] = buff[0];
ushort flag = BitConverter.ToUInt16(bb, 0);
s = string.Format("{0:HH:mm:ss:fff} WriteDO Receive {1}", DateTime.Now, flag);
_log.Add(s);
}
// int n = 0;
// int move = 0;
// byte val = _receive[0][9];
// for (int i = 0; i < 8; i++)
// {
// n = (val & Convert.ToInt32(Math.Pow(2, move))) >> move;
// _sta[i + 16] = n == 1 ? Box_Sta.On : Box_Sta.Off;
// move++;
// }
// if (_receive[0][8] == 2)
// {
// move = 0;
// val = _receive[0][10];
// for (int i = 8; i < 16; i++)
// {
// n = (val & Convert.ToInt32(Math.Pow(2, move))) >> move;
// _sta[i + 16] = n == 1 ? Box_Sta.On : Box_Sta.Off;
// move++;
// }
// }
// ErrInfo = "OK";
//}
//catch (Exception ex)
//{
// ErrInfo = ex.Message;
//}
}
/// <summary>
/// 读取所有DO状态
/// </summary>
/// <param name="buff"></param>
/// <returns></returns>
private bool ReadDO(byte[] buff)
{
try
{
string s;
if (LogOut)
{
byte[] bb = new byte[2];
bb[0] = buff[1];
bb[1] = buff[0];
ushort flag = BitConverter.ToUInt16(bb, 0);
s = string.Format("{0:HH:mm:ss:fff} ReadDO id={1} fun={2} len={3}", DateTime.Now, flag, buff[7], buff.Length);
s += Convert.ToString(buff[9], 2);
if (buff[8] == 2)
s += "," + Convert.ToString(buff[10], 2);
_log.Add(s);
}
int n = 0;
int move = 0;
byte val = buff[9];
for (int i = 0; i < 8; i++)
{
n = (val & Convert.ToInt32(Math.Pow(2, move))) >> move;
_sta[i + 16] = n == 1 ? Box_Sta.On : Box_Sta.Off;
move++;
}
if (buff[8] == 2)
{
move = 0;
val = buff[10];
for (int i = 8; i < 16; i++)
{
n = (val & Convert.ToInt32(Math.Pow(2, move))) >> move;
_sta[i + 16] = n == 1 ? Box_Sta.On : Box_Sta.Off;
move++;
}
}
if (_unrevdRemote == 0) ErrInfo = "OK";
return true;
}
catch (Exception ex)
{
ErrInfo = ex.Message;
LogUtil.error(ex.ToString());
return false;
}
}
/// <summary>
/// 读取所有DI状态
/// </summary>
/// <returns></returns>
private bool ReadDI(byte[] buff)
{
try
{
string s;
if (LogOut)
{
byte[] bb = new byte[2];
bb[0] = buff[1];
bb[1] = buff[0];
ushort flag = BitConverter.ToUInt16(bb, 0);
s = string.Format("{0:HH:mm:ss:fff} ReadDI id={1} fun={2} len={3}", DateTime.Now, flag, buff[7], buff.Length);
s += Convert.ToString(buff[9], 2);
if (buff[8] == 2)
s += "," + Convert.ToString(buff[10], 2);
_log.Add(s);
}
int n = 0;
int move = 0;
byte val = buff[9];
for (int i = 0; i < 8; i++)
{
n = (val & Convert.ToInt32(Math.Pow(2, move))) >> move;
_sta[i] = n == 1 ? Box_Sta.On : Box_Sta.Off;
move++;
}
if (buff[8] == 2)
{
move = 0;
val = buff[10];
for (int i = 8; i < 16; i++)
{
n = (val & Convert.ToInt32(Math.Pow(2, move))) >> move;
_sta[i] = n == 1 ? Box_Sta.On : Box_Sta.Off;
move++;
}
}
if (_unrevdRemote == 0) ErrInfo = "OK";
return true;
}
catch (Exception ex)
{
ErrInfo = ex.Message;
LogUtil.error(ex.ToString());
return false;
}
}
/// <summary>
/// 命令,前7个字节
/// </summary>
/// <returns></returns>
private byte[] Command()
{
byte[] add = BitConverter.GetBytes(++_flag);
byte[] data = new byte[7];
data[0] = add[1];
data[1] = add[0];
data[2] = 0;
data[3] = 0;
data[4] = 0;
data[5] = 0;
data[6] = 1;
if (_flag == ushort.MaxValue) _flag = 0;
return data;
}
/// <summary>
/// 触发DIO改变事件
/// </summary>
private void TriggerDIO()
{
int n;
Box_Sta[] sta = null;
while (true)
{
n = 0;
if (_readDI && DI_Changed_Event != null)
{
if (_type == Box_Type.DIO_16) sta = new Box_Sta[8];
else if (_type == Box_Type.DIO_32) sta = new Box_Sta[16];
Array.Copy(_sta, 0, sta, 0, sta.Length);
DI_Changed_Event.Invoke(this, sta);
Thread.Sleep(TRIG_SLEEP);
n++;
}
if (_readDO && DO_Changed_Event != null)
{
if (_type == Box_Type.DIO_16) sta = new Box_Sta[8];
else if (_type == Box_Type.DIO_32) sta = new Box_Sta[16];
else if (_type == Box_Type.DO_16) sta = new Box_Sta[16];
Array.Copy(_sta, 16, sta, 0, sta.Length);
DO_Changed_Event.Invoke(this, sta);
Thread.Sleep(TRIG_SLEEP);
n++;
}
if (n == 0)
Thread.Sleep(TRIG_SLEEP);
}
}
/// <summary>
/// 日志输出线程
/// </summary>
private void LogPrint()
{
int len = 0;
while (true)
{
if (LogOut && _log.Count > len)
{
len = _log.Count;
string[] ss = new string[len + 1];
_log.CopyTo(0, ss, 0, len);
Log_Out_Event?.Invoke(this, ss);
_log.RemoveRange(0, len);
len = 0;
}
if (LogOut)
{
Log_RxTx_Event?.Invoke(this, _logRxTx.ToArray());
_logRxTx.Clear();
}
Thread.Sleep(1000);
}
}
/// <summary>
/// 自动读取DI线程
/// </summary>
private void AutoReadDI()
{
while (true)
{
if (IsConn && _readDI)
{
byte[] data = Command();
byte[] buff = new byte[12];
Array.Copy(data, 0, buff, 0, data.Length);
buff[7] = 2; //功能码
buff[9] = _addr[(int)Box_Addr.DI_1]; //地址
if (_type == Box_Type.DIO_16)
buff[11] = 8; //个数
else if (_type == Box_Type.DIO_32)
buff[11] = 16; //个数
//_send.Add(buff);
_send.Enqueue(buff);
}
Thread.Sleep(_readDISleep);
}
}
/// <summary>
/// 自动读取DO线程
/// </summary>
private void AutoReadDO()
{
while (true)
{
if (IsConn && _readDO)
{
byte[] data = Command();
byte[] buff = new byte[12];
Array.Copy(data, 0, buff, 0, data.Length);
buff[7] = 1; //功能码
buff[9] = _addr[(int)Box_Addr.DO_1]; //地址
if (_type == Box_Type.DIO_16)
buff[11] = 8; //个数
else if (_type == Box_Type.DIO_32)
buff[11] = 16; //个数
else if (_type == Box_Type.DO_16)
buff[11] = 16; //个数
//_send.Add(buff);
_send.Enqueue(buff);
}
Thread.Sleep(_readDOSleep);
}
}
/// <summary>
/// 监听结果线程
/// </summary>
private void Listen()
{
byte[] bb = new byte[100];
while (true)
{
if (_client.Available > 0)
{
Thread.Sleep(2);
int len = _client.Receive(bb);
byte[] buff = new byte[len];
Array.Copy(bb, buff, len);
_receive.Enqueue(buff);
_unrevd = 0;
}
_unrevd += NET_SLEEP;
Thread.Sleep(NET_SLEEP);
}
}
/// <summary>
/// 回调函数,开启监听线程
/// </summary>
/// <param name="args"></param>
private void Target(IAsyncResult args)
{
if (!args.IsCompleted) return;
if (_client == null || !_client.Connected) return;
tListen = new Thread(new ThreadStart(Listen)) { IsBackground = true };
tTrigger = new Thread(new ThreadStart(TriggerDIO)) { IsBackground = true };
tListen.Start();
tTrigger.Start();
}
/// <summary>
/// 断开重连
/// </summary>
private void Reconn()
{
bool rtn = false;
bool loop = false;
bool conn = false;
int times = 0;
while (true)
{
try
{
if (IsConn)
{
if (_unrevd > 10000 || _unrevdRemote > 0) //断开10s后重连
{
//临时
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("send.Count = ", _send.Count.ToString());
foreach (System.Reflection.PropertyInfo info in _client.GetType().GetProperties())
{
try
{
dic.Add(info.Name, info.GetValue(_client) == null ? "null" : info.GetValue(_client).ToString());
}
catch (Exception ex)
{
dic.Add("错误" + info.Name, ex.Message);
}
}
CloseConn();
Thread.Sleep(100);
if (Reconnect_Event != null)
{
loop = false;
conn = false;
do
{
if (!loop)
{
if (_unrevdRemote == 0)
ErrInfo = "本地缓存连续10s未收到数据";
}
times++;
Reconnect_Event.Invoke(this, times, ref conn, dic);
if (conn)
{
rtn = Connect();
if (rtn)
{
loop = false;
times = 0;
}
else
{
conn = false;
loop = true;
}
}
else
{
loop = false;
}
} while (loop);
}
}
}
}
catch (Exception ex)
{
LogUtil.error("Reconn出错:" + ex.ToString());
}
Thread.Sleep(1000);
}
}
/// <summary>
/// 关闭连接
/// </summary>
private void CloseConn()
{
IsConn = false;
if (tListen != null) tListen.Abort();
tListen = null;
if (tReadDI != null) tReadDI.Abort();
tReadDI = null;
if (tReadDO != null) tReadDO.Abort();
tReadDO = null;
if (tTrigger != null) tTrigger.Abort();
tTrigger = null;
if (tLogOut != null) tLogOut.Abort();
tLogOut = null;
if (tSend != null) tSend.Abort();
tSend = null;
if (tReceive != null) tReceive.Abort();
tReceive = null;
if (_client != null)
{
_client.Shutdown(SocketShutdown.Both);
_client.Close();
}
_client = null;
}
}
}
\ No newline at end of file
/*
* @Description: 用于AIOBOX-32系列一体化IO模块
* @CreateDate: 2019-02-28
* @UpdateDate: 2019-05-22
* @Author: Asa
* @Version: 1.9
*
*/
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Collections.Generic;
using OnlineStore.Common;
namespace Asa.IOModule
{
/// <summary>
/// AIOBOX操作类,socket同步
/// </summary>
public class AIOBOX2
{
/// <summary>
/// 暂停次数
/// WriteDO 命令非常多时,暂停一次发送 ReadDI 或 ReadDO
/// </summary>
private int suspend;
private bool suspendDI; //暂停一次DI
private bool suspendDO; //暂停一次DI
private Socket _client; //客户端
private Box_Type _type; //类型
private byte[] _addr; //地址
private Box_Sta[] _sta; //状态
private int _unrevdRemote; //本地还是远程没有收到数据
private bool _readDI; //自动读取DI
private bool _readDO; //自动读取DO
private int _readDISleep; //自动读取DI间隔
private int _readDOSleep; //自动读取DO间隔
private List<string> _log; //日志
private System.Collections.Concurrent.ConcurrentQueue<ushort> _flag;
private System.Collections.Concurrent.ConcurrentQueue<byte[]> _send;
private System.Collections.Concurrent.ConcurrentQueue<byte[]> _receive;
//private bool suspendWrite;
//private AutoResetEvent aWrite;
//private AutoResetEvent aReadDI;
//private AutoResetEvent aReadDO;
private Thread tSend; //发送命令处理
private Thread tReceive; //接收信息处理
private Thread tListen; //监听网络
private Thread tTrigger; //触发DI、DO改变事件
private Thread tReadDI; //自动读取DI线程
private Thread tReadDO; //自动读取DO线程
private Thread tLogOut; //日志输出
private Thread tFlag; //ModBusTCP标识
/// <summary>
/// 每条命令发送的间隔
/// 不能小于15,会出现IO接收不到的情况
/// 小于30时,会出现接收数据连包的情况
/// </summary>
private const int SEND_SLEEP = 15;
/// <summary>
/// 监听网络接收数据的间隔
/// 必须小于SEND_SLEEP
/// </summary>
private const int NET_SLEEP = 10;
/// <summary>
/// 触发DIO状态事件的间隔
/// </summary>
private const int TRIG_SLEEP = 20;
/// <summary>
/// 自动读取DI委托
/// </summary>
/// <param name="box">AIOBOX</param>
/// <param name="sta">所有DI状态</param>
public delegate void DI_Changed(AIOBOX2 box, Box_Sta[] sta);
/// <summary>
/// 自动读取DI事件触发
/// </summary>
public event DI_Changed DI_Changed_Event;
/// <summary>
/// 自动读取DO委托
/// </summary>
/// <param name="box">AIOBOX</param>
/// <param name="sta">所有DO状态</param>
public delegate void DO_Changed(AIOBOX2 box, Box_Sta[] sta);
/// <summary>
/// 自动读取DO事件触发
/// </summary>
public event DO_Changed DO_Changed_Event;
/// <summary>
/// 日志输出
/// </summary>
/// <param name="box"></param>
/// <param name="s"></param>
public delegate void Log_Out(AIOBOX2 box, string[] s);
/// <summary>
/// 日志输出事件
/// </summary>
public event Log_Out Log_Out_Event;
/// <summary>
/// AIOBOX
/// </summary>
public AIOBOX2()
{
_readDI = false;
_readDO = false;
_readDISleep = 100;
_readDOSleep = 100;
_addr = new byte[32];
_sta = new Box_Sta[32];
_log = new List<string>();
Type = Box_Type.DIO_32;
//aWrite = new AutoResetEvent(false);
//aReadDI = new AutoResetEvent(false);
//aReadDO = new AutoResetEvent(false);
}
/// <summary>
/// IP地址
/// </summary>
public string IP { set; get; } = "192.168.1.100";
/// <summary>
/// ModBus端口
/// </summary>
public int Port { set; get; } = 502;
/// <summary>
/// 是否连接
/// </summary>
public bool IsConn { get; private set; } = false;
/// <summary>
/// 错误信息
/// </summary>
public string ErrInfo { get; private set; } = "";
/// <summary>
/// 日志输出
/// </summary>
public bool LogOut { set; get; } = false;
/// <summary>
/// 模块的类型
/// </summary>
public Box_Type Type
{
set
{
_type = value;
if (value == Box_Type.DIO_16)
{
_addr[(int)Box_Addr.DI_1] = 0;
_addr[(int)Box_Addr.DI_2] = 1;
_addr[(int)Box_Addr.DI_3] = 2;
_addr[(int)Box_Addr.DI_4] = 3;
_addr[(int)Box_Addr.DI_5] = 4;
_addr[(int)Box_Addr.DI_6] = 5;
_addr[(int)Box_Addr.DI_7] = 6;
_addr[(int)Box_Addr.DI_8] = 7;
_addr[(int)Box_Addr.DI_9] = 255;
_addr[(int)Box_Addr.DI_10] = 255;
_addr[(int)Box_Addr.DI_11] = 255;
_addr[(int)Box_Addr.DI_12] = 255;
_addr[(int)Box_Addr.DI_13] = 255;
_addr[(int)Box_Addr.DI_14] = 255;
_addr[(int)Box_Addr.DI_15] = 255;
_addr[(int)Box_Addr.DI_16] = 255;
_addr[(int)Box_Addr.DO_1] = 8;
_addr[(int)Box_Addr.DO_2] = 9;
_addr[(int)Box_Addr.DO_3] = 10;
_addr[(int)Box_Addr.DO_4] = 11;
_addr[(int)Box_Addr.DO_5] = 12;
_addr[(int)Box_Addr.DO_6] = 13;
_addr[(int)Box_Addr.DO_7] = 14;
_addr[(int)Box_Addr.DO_8] = 15;
_addr[(int)Box_Addr.DO_9] = 255;
_addr[(int)Box_Addr.DO_10] = 255;
_addr[(int)Box_Addr.DO_11] = 255;
_addr[(int)Box_Addr.DO_12] = 255;
_addr[(int)Box_Addr.DO_13] = 255;
_addr[(int)Box_Addr.DO_14] = 255;
_addr[(int)Box_Addr.DO_15] = 255;
_addr[(int)Box_Addr.DO_16] = 255;
}
else if (value == Box_Type.DIO_32)
{
_addr[(int)Box_Addr.DI_1] = 0;
_addr[(int)Box_Addr.DI_2] = 1;
_addr[(int)Box_Addr.DI_3] = 2;
_addr[(int)Box_Addr.DI_4] = 3;
_addr[(int)Box_Addr.DI_5] = 4;
_addr[(int)Box_Addr.DI_6] = 5;
_addr[(int)Box_Addr.DI_7] = 6;
_addr[(int)Box_Addr.DI_8] = 7;
_addr[(int)Box_Addr.DI_9] = 8;
_addr[(int)Box_Addr.DI_10] = 9;
_addr[(int)Box_Addr.DI_11] = 10;
_addr[(int)Box_Addr.DI_12] = 11;
_addr[(int)Box_Addr.DI_13] = 12;
_addr[(int)Box_Addr.DI_14] = 13;
_addr[(int)Box_Addr.DI_15] = 14;
_addr[(int)Box_Addr.DI_16] = 15;
_addr[(int)Box_Addr.DO_1] = 16;
_addr[(int)Box_Addr.DO_2] = 17;
_addr[(int)Box_Addr.DO_3] = 18;
_addr[(int)Box_Addr.DO_4] = 19;
_addr[(int)Box_Addr.DO_5] = 20;
_addr[(int)Box_Addr.DO_6] = 21;
_addr[(int)Box_Addr.DO_7] = 22;
_addr[(int)Box_Addr.DO_8] = 23;
_addr[(int)Box_Addr.DO_9] = 24;
_addr[(int)Box_Addr.DO_10] = 25;
_addr[(int)Box_Addr.DO_11] = 26;
_addr[(int)Box_Addr.DO_12] = 27;
_addr[(int)Box_Addr.DO_13] = 28;
_addr[(int)Box_Addr.DO_14] = 29;
_addr[(int)Box_Addr.DO_15] = 30;
_addr[(int)Box_Addr.DO_16] = 31;
}
else if (value == Box_Type.DO_16)
{
_addr[(int)Box_Addr.DO_1] = 0;
_addr[(int)Box_Addr.DO_2] = 1;
_addr[(int)Box_Addr.DO_3] = 2;
_addr[(int)Box_Addr.DO_4] = 3;
_addr[(int)Box_Addr.DO_5] = 4;
_addr[(int)Box_Addr.DO_6] = 5;
_addr[(int)Box_Addr.DO_7] = 6;
_addr[(int)Box_Addr.DO_8] = 7;
_addr[(int)Box_Addr.DO_9] = 8;
_addr[(int)Box_Addr.DO_10] = 9;
_addr[(int)Box_Addr.DO_11] = 10;
_addr[(int)Box_Addr.DO_12] = 11;
_addr[(int)Box_Addr.DO_13] = 12;
_addr[(int)Box_Addr.DO_14] = 13;
_addr[(int)Box_Addr.DO_15] = 14;
_addr[(int)Box_Addr.DO_16] = 15;
}
}
get
{
return _type;
}
}
/// <summary>
/// 连接
/// </summary>
/// <returns></returns>
public bool Connect()
{
IsConn = false;
try
{
//IP合法
string pattern = @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$";
bool rtn = System.Text.RegularExpressions.Regex.IsMatch(IP, pattern);
if (!rtn)
{
ErrInfo = "非法的IP地址 " + IP;
return false;
}
//Ping服务端
System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();
System.Net.NetworkInformation.PingReply result = ping.Send(IP, 5000);
if (result.Status != System.Net.NetworkInformation.IPStatus.Success)
{
ErrInfo = "Ping " + IP + " 请求没有回应";
return false;
}
_unrevdRemote = 0;
//suspendWrite = false;
suspend = 0;
suspendDI = false;
suspendDO = false;
_send = new System.Collections.Concurrent.ConcurrentQueue<byte[]>();
_receive = new System.Collections.Concurrent.ConcurrentQueue<byte[]>();
_flag = new System.Collections.Concurrent.ConcurrentQueue<ushort>();
_log.Clear();
//建立连接
_client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 500);
_client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 500);
_client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, 1);
//_client.BeginConnect(IP, Port, new AsyncCallback(ConnectCallback), null);
_client.Connect(IPAddress.Parse(IP), Port);
Thread.Sleep(100); //需要等待一会才能获取连接状态
tFlag = new Thread(new ThreadStart(Flag));
tFlag.Start();
Thread.Sleep(10);
tReadDI = new Thread(new ThreadStart(AutoReadDI));
tReadDO = new Thread(new ThreadStart(AutoReadDO));
tSend = new Thread(new ThreadStart(Send));
tReceive = new Thread(new ThreadStart(Receive));
tLogOut = new Thread(new ThreadStart(LogPrint));
tListen = new Thread(new ThreadStart(Listen));
tTrigger = new Thread(new ThreadStart(TriggerDIO));
tListen.Start();
tTrigger.Start();
tSend.Start();
tReceive.Start();
tLogOut.Start();
tReadDI.Start();
tReadDO.Start();
ErrInfo = "OK";
IsConn = true;
return true;
}
catch (Exception ex)
{
ErrInfo = ex.Message;
return false;
}
}
/// <summary>
/// 关闭连接
/// </summary>
public void Close()
{
IsConn = false;
if (tListen != null) tListen.Abort();
tListen = null;
if (tReadDI != null) tReadDI.Abort();
tReadDI = null;
if (tReadDO != null) tReadDO.Abort();
tReadDO = null;
if (tTrigger != null) tTrigger.Abort();
tTrigger = null;
if (tLogOut != null) tLogOut.Abort();
tLogOut = null;
if (tSend != null) tSend.Abort();
tSend = null;
if (tReceive != null) tReceive.Abort();
tReceive = null;
if (tFlag != null) tFlag.Abort();
tFlag = null;
if (_client != null)
{
_client.Shutdown(SocketShutdown.Both);
_client.Close();
}
_client = null;
}
/// <summary>
/// 自动读取DI状态,触发DI_Changed_Event
/// </summary>
/// <param name="read">是否自动读取</param>
/// <param name="sleep">间隔,必须大于10ms</param>
public void AutoReadDI(bool read, int sleep)
{
if (_type == Box_Type.DO_16)
{
_readDI = false;
_readDISleep = 10000;
}
else
{
if (sleep < 10)
{
_readDI = false;
_readDISleep = 100;
}
else
{
if (read)
{
_readDI = true;
_readDISleep = sleep;
}
else
{
_readDI = false;
_readDISleep = 100;
}
}
}
}
/// <summary>
/// 自动读取DO状态,触发DO_Changed_Event
/// </summary>
/// <param name="read">是否自动读取</param>
/// <param name="sleep">间隔,必须大于10ms</param>
public void AutoReadDO(bool read, int sleep)
{
if (sleep < 10)
{
_readDO = false;
_readDOSleep = 100;
}
else
{
if (read)
{
_readDO = true;
_readDOSleep = sleep;
}
else
{
_readDO = false;
_readDOSleep = 100;
}
}
}
/// <summary>
/// 相反状态
/// </summary>
/// <param name="sta"></param>
/// <returns></returns>
public Box_Sta ReverseStatus(Box_Sta sta)
{
return sta == Box_Sta.On ? Box_Sta.Off : Box_Sta.On;
}
/// <summary>
/// 读取单个DI
/// </summary>
/// <param name="add"></param>
/// <returns></returns>
public Box_Sta ReadDI(Box_Addr add)
{
return _sta[(int)add];
}
/// <summary>
/// 读取多个DI
/// </summary>
/// <param name="add"></param>
/// <param name="count"></param>
/// <returns></returns>
public Box_Sta[] ReadDI(Box_Addr add, int count)
{
Box_Sta[] sta = new Box_Sta[count];
Array.Copy(_sta, (int)add, sta, 0, count);
return sta;
}
/// <summary>
/// 读取单个DO
/// </summary>
/// <param name="add"></param>
/// <returns></returns>
public Box_Sta ReadDO(Box_Addr add)
{
return _sta[(int)add];
}
/// <summary>
/// 读取多个DO
/// </summary>
/// <param name="add"></param>
/// <param name="count"></param>
/// <returns></returns>
public Box_Sta[] ReadDO(Box_Addr add, int count)
{
Box_Sta[] sta = new Box_Sta[count];
Array.Copy(_sta, (int)add, sta, 0, count);
return sta;
}
/// <summary>
/// 写入单个DO
/// </summary>
/// <param name="add"></param>
/// <param name="sta"></param>
/// <returns></returns>
public bool WriteDO(Box_Addr add, Box_Sta sta)
{
try
{
//suspendWrite = true;
//if (_readDI) aWrite.WaitOne();
//if (_readDO) aWrite.WaitOne();
//if (_send.Count > 10)
//{
// while (_send.TryDequeue(out byte[] result))
// { }
//}
byte[] data = Command();
byte[] buff = new byte[12];
Array.Copy(data, 0, buff, 0, data.Length);
buff[7] = 5; //功能码
buff[9] = _addr[(int)add]; //地址
buff[10] = (byte)sta; //写入值
if (LogOut)
{
byte[] bb = new byte[2];
bb[0] = buff[1];
bb[1] = buff[0];
ushort flag = BitConverter.ToUInt16(bb, 0);
string s = string.Format("{0:HH:mm:ss.fff} WriteDO {1} ({2},{3})", DateTime.Now, flag, add.ToString(), sta.ToString());
_log.Add(s);
}
suspend++;
_send.Enqueue(buff);
//suspendWrite = false;
//aReadDI.Set();
//aReadDO.Set();
if (_unrevdRemote == 0) ErrInfo = "OK";
return true;
}
catch (Exception ex)
{
ErrInfo = ex.Message;
return false;
}
}
/// <summary>
/// 获取本地IPv4地址
/// </summary>
/// <returns></returns>
public string[] GetLocalIP()
{
List<string> str = new List<string>();
IPAddress[] add = Dns.GetHostEntry(Dns.GetHostName()).AddressList;
foreach (IPAddress ip in add)
{
if (ip.AddressFamily.ToString() == "InterNetwork")
str.Add(ip.ToString());
}
return str.ToArray();
}
/// <summary>
/// 发送命令
/// </summary>
private void Send()
{
string s;
ushort flag;
while (true)
{
bool rtn = _send.TryDequeue(out byte[] result);
if (rtn)
{
try
{
_client.Send(result);
//_client.BeginSend(result, 0, result.Length, SocketFlags.None, new AsyncCallback(SendCallback), _client);
if (LogOut)
{
byte[] bb = new byte[2];
bb[0] = result[1];
bb[1] = result[0];
flag = BitConverter.ToUInt16(bb, 0);
s = string.Format("{0:HH:mm:ss:fff} Send {1} fun={2} len={3}", DateTime.Now, flag, result[7], result.Length);
_log.Add(s);
}
}
catch (Exception ex)
{
ErrInfo = ex.Message;
_unrevdRemote = 1;
break;
}
}
Thread.Sleep(SEND_SLEEP);
}
}
/// <summary>
/// 接收命令
/// </summary>
private void Receive()
{
while (true)
{
try
{
if (_receive.TryDequeue(out byte[] buff))
{
if (buff.Length >= 8)
{
if (buff[7] == 1)
ReadDO(buff);
else if (buff[7] == 2)
ReadDI(buff);
else if (buff[7] == 5)
ReadSingle(buff);
}
else
{
string s = "";
foreach(byte b in buff)
{
s += b + " ";
}
LogUtil.error("AIOBOX2 Receive长度不足:" + s);
}
}
}catch(Exception ex)
{
LogUtil.error("AIOBOX2 Receive出错:" + ex.ToString());
}
Thread.Sleep(10);
}
}
/// <summary>
/// 读取单个DO
/// </summary>
/// <param name="buff"></param>
private void ReadSingle(byte[] buff)
{
//try
//{
string s;
if (LogOut)
{
byte[] bb = new byte[2];
bb[0] = buff[1];
bb[1] = buff[0];
ushort flag = BitConverter.ToUInt16(bb, 0);
s = string.Format("{0:HH:mm:ss:fff} WriteDO {1} fun={2} len={3}", DateTime.Now, flag, buff[7], buff.Length);
_log.Add(s);
}
// int n = 0;
// int move = 0;
// byte val = _receive[0][9];
// for (int i = 0; i < 8; i++)
// {
// n = (val & Convert.ToInt32(Math.Pow(2, move))) >> move;
// _sta[i + 16] = n == 1 ? Box_Sta.On : Box_Sta.Off;
// move++;
// }
// if (_receive[0][8] == 2)
// {
// move = 0;
// val = _receive[0][10];
// for (int i = 8; i < 16; i++)
// {
// n = (val & Convert.ToInt32(Math.Pow(2, move))) >> move;
// _sta[i + 16] = n == 1 ? Box_Sta.On : Box_Sta.Off;
// move++;
// }
// }
// ErrInfo = "OK";
//}
//catch (Exception ex)
//{
// ErrInfo = ex.Message;
//}
}
/// <summary>
/// 读取所有DO状态
/// </summary>
/// <param name="buff"></param>
/// <returns></returns>
private bool ReadDO(byte[] buff)
{
try
{
string s;
if (LogOut)
{
byte[] bb = new byte[2];
bb[0] = buff[1];
bb[1] = buff[0];
ushort flag = BitConverter.ToUInt16(bb, 0);
s = string.Format("{0:HH:mm:ss:fff} ReadDO {1} fun={2} len={3} (", DateTime.Now, flag, buff[7], buff.Length);
s += Convert.ToString(buff[9], 2);
if (buff[8] == 2)
s += "," + Convert.ToString(buff[10], 2);
s += ")";
_log.Add(s);
}
int n = 0;
int move = 0;
byte val = buff[9];
for (int i = 0; i < 8; i++)
{
n = (val & Convert.ToInt32(Math.Pow(2, move))) >> move;
_sta[i + 16] = n == 1 ? Box_Sta.On : Box_Sta.Off;
move++;
}
if (buff[8] == 2)
{
move = 0;
val = buff[10];
for (int i = 8; i < 16; i++)
{
n = (val & Convert.ToInt32(Math.Pow(2, move))) >> move;
_sta[i + 16] = n == 1 ? Box_Sta.On : Box_Sta.Off;
move++;
}
}
if (_unrevdRemote == 0) ErrInfo = "OK";
return true;
}
catch (Exception ex)
{
ErrInfo = ex.Message;
return false;
}
}
/// <summary>
/// 读取所有DI状态
/// </summary>
/// <returns></returns>
private bool ReadDI(byte[] buff)
{
try
{
string s;
if (LogOut)
{
byte[] bb = new byte[2];
bb[0] = buff[1];
bb[1] = buff[0];
ushort flag = BitConverter.ToUInt16(bb, 0);
s = string.Format("{0:HH:mm:ss:fff} ReadDI {1} fun={2} len={3} (", DateTime.Now, flag, buff[7], buff.Length);
s += Convert.ToString(buff[9], 2);
if (buff[8] == 2)
s += "," + Convert.ToString(buff[10], 2);
s += ")";
_log.Add(s);
}
int n = 0;
int move = 0;
byte val = buff[9];
for (int i = 0; i < 8; i++)
{
n = (val & Convert.ToInt32(Math.Pow(2, move))) >> move;
_sta[i] = n == 1 ? Box_Sta.On : Box_Sta.Off;
move++;
}
if (buff[8] == 2)
{
move = 0;
val = buff[10];
for (int i = 8; i < 16; i++)
{
n = (val & Convert.ToInt32(Math.Pow(2, move))) >> move;
_sta[i] = n == 1 ? Box_Sta.On : Box_Sta.Off;
move++;
}
}
if (_unrevdRemote == 0) ErrInfo = "OK";
return true;
}
catch (Exception ex)
{
ErrInfo = ex.Message;
return false;
}
}
/// <summary>
/// 命令,前7个字节
/// </summary>
/// <returns></returns>
private byte[] Command()
{
_flag.TryDequeue(out ushort result);
byte[] add = BitConverter.GetBytes(result);
byte[] data = new byte[7];
data[0] = add[1];
data[1] = add[0];
data[2] = 0;
data[3] = 0;
data[4] = 0;
data[5] = 0;
data[6] = 1;
return data;
}
/// <summary>
/// 触发DIO改变事件
/// </summary>
private void TriggerDIO()
{
int n;
Box_Sta[] sta = null;
while (true)
{
n = 0;
if (_readDI && DI_Changed_Event != null)
{
if (_type == Box_Type.DIO_16) sta = new Box_Sta[8];
else if (_type == Box_Type.DIO_32) sta = new Box_Sta[16];
Array.Copy(_sta, 0, sta, 0, sta.Length);
DI_Changed_Event.Invoke(this, sta);
Thread.Sleep(TRIG_SLEEP);
n++;
}
if (_readDO && DO_Changed_Event != null)
{
if (_type == Box_Type.DIO_16) sta = new Box_Sta[8];
else if (_type == Box_Type.DIO_32) sta = new Box_Sta[16];
else if (_type == Box_Type.DO_16) sta = new Box_Sta[16];
Array.Copy(_sta, 16, sta, 0, sta.Length);
DO_Changed_Event.Invoke(this, sta);
Thread.Sleep(TRIG_SLEEP);
n++;
}
if (n == 0)
Thread.Sleep(TRIG_SLEEP);
}
}
/// <summary>
/// 日志输出线程
/// </summary>
private void LogPrint()
{
int len = 0;
while (true)
{
if (LogOut && _log.Count > len)
{
len = _log.Count;
string[] ss = new string[len + 1];
_log.CopyTo(0, ss, 0, len);
Log_Out_Event?.Invoke(this, ss);
_log.RemoveRange(0, len);
len = 0;
}
Thread.Sleep(1000);
}
}
/// <summary>
/// 自动读取DI线程
/// </summary>
private void AutoReadDI()
{
while (true)
{
if (IsConn && _readDI)
{
//if (suspendWrite)
//{
// aWrite.Set();
// aReadDI.WaitOne();
//}
if (suspendDI && suspend > 0)
{
suspendDI = false;
suspend--;
}
else
{
byte[] data = Command();
byte[] buff = new byte[12];
Array.Copy(data, 0, buff, 0, data.Length);
buff[7] = 2; //功能码
buff[9] = _addr[(int)Box_Addr.DI_1]; //地址
if (_type == Box_Type.DIO_16)
buff[11] = 8; //个数
else if (_type == Box_Type.DIO_32)
buff[11] = 16; //个数
_send.Enqueue(buff);
suspendDI = true;
}
}
Thread.Sleep(_readDISleep);
}
}
/// <summary>
/// 自动读取DO线程
/// </summary>
private void AutoReadDO()
{
while (true)
{
if (IsConn && _readDO)
{
//if (suspendWrite)
//{
// aWrite.Set();
// aReadDO.WaitOne();
//}
if (suspendDO && suspend > 0)
{
suspendDO = false;
suspend--;
}
else
{
byte[] data = Command();
byte[] buff = new byte[12];
Array.Copy(data, 0, buff, 0, data.Length);
buff[7] = 1; //功能码
buff[9] = _addr[(int)Box_Addr.DO_1]; //地址
if (_type == Box_Type.DIO_16)
buff[11] = 8; //个数
else if (_type == Box_Type.DIO_32)
buff[11] = 16; //个数
else if (_type == Box_Type.DO_16)
buff[11] = 16; //个数
_send.Enqueue(buff);
suspendDO = true;
}
}
Thread.Sleep(_readDOSleep);
}
}
/// <summary>
/// 监听结果线程
/// </summary>
private void Listen()
{
byte[] temp = new byte[50];
while (true)
{
if (_client.Available > 0)
{
//_client.BeginReceive(temp, 0, temp.Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), _client);
int len = _client.Receive(temp);
if (len > 15) //连包
{
byte[] aa = new byte[len / 2];
byte[] bb = new byte[len - aa.Length];
Array.Copy(temp, 0, aa, 0, aa.Length);
Array.Copy(temp, aa.Length, bb, 0, bb.Length);
_receive.Enqueue(aa);
_receive.Enqueue(bb);
}
else
{
byte[] cc = new byte[len];
Array.Copy(temp, cc, len);
_receive.Enqueue(cc);
}
}
Thread.Sleep(NET_SLEEP);
}
}
private void SendCallback(IAsyncResult ar)
{
try
{
Socket client = (Socket)ar.AsyncState;
int bytesSent = client.EndSend(ar);
}
catch (Exception ex)
{
ErrInfo = ex.Message;
}
}
private void ReceiveCallback(IAsyncResult ar)
{
try
{
int len = _client.EndReceive(ar);
//if (len > 0)
//{
// if (len > 15) //连包
// {
// byte[] aa = new byte[len / 2];
// byte[] bb = new byte[len - aa.Length];
// Array.Copy(temp, 0, aa, 0, aa.Length);
// Array.Copy(temp, aa.Length, bb, 0, bb.Length);
// _receive.Enqueue(aa);
// _receive.Enqueue(bb);
// }
// else
// {
// byte[] cc = new byte[len];
// Array.Copy(temp, cc, len);
// _receive.Enqueue(cc);
// }
//}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
private void ConnectCallback(IAsyncResult ar)
{
if (!ar.IsCompleted) return;
if (_client == null || !_client.Connected) return;
_client.EndConnect(ar);
}
private void Flag()
{
ushort n = 0;
while (true)
{
if (_flag.Count < 10)
{
_flag.Enqueue(++n);
if (n == ushort.MaxValue) n = 0;
}
Thread.Sleep(5);
}
}
}
}
\ No newline at end of file

namespace Asa.IOModule
{
/// <summary>
/// IO模块寄存器
/// </summary>
public class Reg
{
/// <summary>
/// 标识
/// </summary>
public int ID;
/// <summary>
/// 文本,仅用于显示
/// </summary>
public string Text;
/// <summary>
/// 寄存器地址
/// </summary>
public Box_Addr Address;
/// <summary>
/// 当前的状态
/// </summary>
public Box_Sta Status;
/// <summary>
/// 寄存器,文本空,状态OFF
/// </summary>
/// <param name="address">地址</param>
public Reg(Box_Addr address) : this(0, "", address, Box_Sta.Off)
{
}
/// <summary>
/// 寄存器,状态OFF
/// </summary>
/// <param name="text">文本</param>
/// <param name="addr">地址</param>
public Reg(string text, Box_Addr addr) : this(0, text, addr, Box_Sta.Off)
{
}
/// <summary>
/// 寄存器,状态OFF
/// </summary>
/// <param name="id">标志</param>
/// <param name="text">文本</param>
/// <param name="addr">地址</param>
public Reg(int id, string text, Box_Addr addr) : this(id, text, addr, Box_Sta.Off)
{
}
/// <summary>
/// 寄存器
/// </summary>
/// <param name="text">文本</param>
/// <param name="addr">地址</param>
/// <param name="status">状态</param>
public Reg(string text, Box_Addr addr, Box_Sta status) : this(0, text, addr, status)
{
}
/// <summary>
/// 寄存器
/// </summary>
/// <param name="id">标志</param>
/// <param name="text">文本</param>
/// <param name="address">地址</param>
/// <param name="status">状态</param>
public Reg(int id, string text, Box_Addr address, Box_Sta status)
{
ID = id;
Text = text;
Address = address;
Status = status;
}
}
/// <summary>
/// IO模块寄存器地址
/// </summary>
public enum Box_Addr : int
{
/// <summary>
/// 输入点,DI01
/// </summary>
DI_1,
/// <summary>
/// 输入点,DI02
/// </summary>
DI_2,
/// <summary>
/// 输入点,DI03
/// </summary>
DI_3,
/// <summary>
/// 输入点,DI04
/// </summary>
DI_4,
/// <summary>
/// 输入点,DI05
/// </summary>
DI_5,
/// <summary>
/// 输入点,DI06
/// </summary>
DI_6,
/// <summary>
/// 输入点,DI07
/// </summary>
DI_7,
/// <summary>
/// 输入点,DI08
/// </summary>
DI_8,
/// <summary>
/// 输入点,DI09
/// </summary>
DI_9,
/// <summary>
/// 输入点,DI10
/// </summary>
DI_10,
/// <summary>
/// 输入点,DI11
/// </summary>
DI_11,
/// <summary>
/// 输入点,DI12
/// </summary>
DI_12,
/// <summary>
/// 输入点,DI13
/// </summary>
DI_13,
/// <summary>
/// 输入点,DI14
/// </summary>
DI_14,
/// <summary>
/// 输入点,DI15
/// </summary>
DI_15,
/// <summary>
/// 输入点,DI16
/// </summary>
DI_16,
/// <summary>
/// 输出点,DO01
/// </summary>
DO_1,
/// <summary>
/// 输出点,DO02
/// </summary>
DO_2,
/// <summary>
/// 输出点,DO03
/// </summary>
DO_3,
/// <summary>
/// 输出点,DO04
/// </summary>
DO_4,
/// <summary>
/// 输出点,DO05
/// </summary>
DO_5,
/// <summary>
/// 输出点,DO06
/// </summary>
DO_6,
/// <summary>
/// 输出点,DO07
/// </summary>
DO_7,
/// <summary>
/// 输出点,DO08
/// </summary>
DO_8,
/// <summary>
/// 输出点,DO09
/// </summary>
DO_9,
/// <summary>
/// 输出点,DO10
/// </summary>
DO_10,
/// <summary>
/// 输出点,DO11
/// </summary>
DO_11,
/// <summary>
/// 输出点,DO12
/// </summary>
DO_12,
/// <summary>
/// 输出点,DO13
/// </summary>
DO_13,
/// <summary>
/// 输出点,DO14
/// </summary>
DO_14,
/// <summary>
/// 输出点,DO15
/// </summary>
DO_15,
/// <summary>
/// 输出点,DO16
/// </summary>
DO_16,
/// <summary>
/// 无
/// </summary>
NONE = 255
}
/// <summary>
/// IO模块类型
/// </summary>
public enum Box_Type : int
{
/// <summary>
/// 16位,8DI + 8DO
/// </summary>
DIO_16,
/// <summary>
/// 32位,16DI + 16DO
/// </summary>
DIO_32,
/// <summary>
/// 16位DO
/// </summary>
DO_16
}
/// <summary>
/// IO模块寄存器状态
/// </summary>
public enum Box_Sta : int
{
/// <summary>
/// 断开,关闭,低电平
/// </summary>
Off = 0,
/// <summary>
/// 闭合,打开,高电平
/// </summary>
On = 255
}
}
\ No newline at end of file
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace OnlineStore.DeviceLibrary
{
public abstract class IOManager
{
public static IOManager instance = null;
public abstract void ConnectionIOList(List<string> dIODeviceNameList);
#region KNDIO
public static void IOMove(string ioType, IO_VALUE ioValue)
{
if (StoreManager.Config.StoreDOList.ContainsKey(ioType))
{
ConfigIO configIo = StoreManager.Config.StoreDOList[ioType];
//DateTime time = DateTime.Now;
instance.WriteSingleDO(configIo.DeviceName, configIo.SlaveID, configIo.GetIOAddr(), ioValue);
//TimeSpan span = DateTime.Now - time;
//if (span.TotalMilliseconds > 100)
//{
// LogUtil.error("IOMove [" + ioType + "] ["+ioValue+"]耗时" + span.TotalMilliseconds);
//}
Thread.Sleep(60);
}
else
{
LogUtil.error("没有DO=" + ioType);
}
}
public static IO_VALUE IOValue(string ioType)
{
IO_VALUE ioValue = IO_VALUE.LOW;
if (StoreManager.Config.StoreDIList.ContainsKey(ioType))
{
ConfigIO configIo = StoreManager.Config.StoreDIList[ioType];
ioValue = instance.GetDIValue(configIo.DeviceName, configIo.SlaveID, configIo.GetIOAddr());
//UpdateDoValue(ioType, ioValue);
}
else if (StoreManager.Config.StoreDOList.ContainsKey(ioType))
{
ConfigIO configIo = StoreManager.Config.StoreDOList[ioType];
ioValue = instance.GetDOValue(configIo.DeviceName, configIo.SlaveID, configIo.GetIOAddr());
}
else
{
LogUtil.error("没有DO=" + ioType);
}
return ioValue;
}
public static IO_VALUE DOValue(string ioType)
{
IO_VALUE ioValue = IO_VALUE.LOW;
if (StoreManager.Config.StoreDOList.ContainsKey(ioType))
{
ConfigIO configIo = StoreManager.Config.StoreDOList[ioType];
ioValue = instance.GetDOValue(configIo.DeviceName, configIo.SlaveID, configIo.GetIOAddr());
}
else
{
LogUtil.error("没有DO=" + ioType);
}
return ioValue;
}
#endregion
public static void Init()
{
bool isAIOBox = ConfigAppSettings.GetIntValue(Setting_Init.UseAIOBOX).Equals(1);
if (isAIOBox)
{
instance = new AIOBOXManager();
}
else
{
instance = new KNDManager();
}
}
public abstract void ReadAllDI(string deviceName, byte slaveId);
public abstract void ReadAllDO(string deviceName, byte slaveId);
public abstract void WriteSingleDO(string deviceName, byte slaveId, ushort index, IO_VALUE value, int time);
public abstract void WriteSingleDO(string deviceName, byte slaveId, ushort index, IO_VALUE value);
public abstract IO_VALUE GetDIValue(string deviceName, byte slaveID, ushort v);
public abstract IO_VALUE GetDOValue(string deviceName, byte slaveID, ushort v);
public abstract IO_VALUE GetIOValue(ConfigIO configIO);
public abstract void CloseAllDO();
public abstract void CloseAllConnection();
}
}
......@@ -126,7 +126,7 @@ namespace OnlineStore.DeviceLibrary
try
{
isProcess = true;
bool IsNeedReadAI = StoreManager.Store.KNDIOValue(IO_Type.TrayCheck_Door).Equals(IO_VALUE.HIGH) || NeedShow;
bool IsNeedReadAI = IOManager.IOValue(IO_Type.TrayCheck_Door).Equals(IO_VALUE.HIGH) || NeedShow;
TimeSpan span = DateTime.Now - PreCheckTime;
List<string> list = new List<string>(mastMap.Keys);
foreach (string IP in list)
......@@ -285,7 +285,7 @@ namespace OnlineStore.DeviceLibrary
}
try
{
if (StoreManager.Store != null && StoreManager.Store.KNDIOValue(IO_Type.TrayCheck_Door).Equals(IO_VALUE.HIGH))
if (StoreManager.Store != null && IOManager.IOValue(IO_Type.TrayCheck_Door).Equals(IO_VALUE.HIGH))
{
if (StoreManager.Config.AIDI1_Addr > 0 && StoreManager.Config.AIDI2_Addr > 0)
{ //每次上传后验证下
......
......@@ -11,561 +11,586 @@ using System.Threading;
namespace OnlineStore.DeviceLibrary
{
{
//}
/// <summary>
/// 康奈德IO控制模块
/// </summary>
public class KNDManager
{
public static ushort DIStartAddress = 200;
public static ushort DoStartAddress = 100;
public static ushort DefualtLength = 16;
private static byte DefualtSlaveID = 255;
public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public static Dictionary<string, MasterTcpClient> mastMap = new Dictionary<string, MasterTcpClient>();
public static Dictionary<string, List<KNDIO>> DIValueMap = new Dictionary<string, List<KNDIO>>();
public static Dictionary<string, List<KNDIO>> DOValueMap = new Dictionary<string, List<KNDIO>>();
private static object DIMapLock = "";
private static object DOMapLock = "";
public static System.Timers.Timer timer = null;
private static bool isWrite=false;
public static void ConnectionIP(string ioIp, ushort port)
{
if (timer == null)
{
timer = new System.Timers.Timer();
timer.Interval = 300;
timer.AutoReset = true;
timer.Elapsed += timer_Elapsed;
timer.Enabled = true;
}
MasterTcpClient MBmaster = null;
if (mastMap.ContainsKey(ioIp))
{
MBmaster = mastMap[ioIp];
if (null != MBmaster)
{
MBmaster.disconnect();
MBmaster.Dispose();
MBmaster = null;
//lock (DIMapLock)
//{
// if (DIValueMap.ContainsKey(ioIp))
// {
// DIValueMap.Remove(ioIp);
// }
//}
lock (DOMapLock)
{
if (DOValueMap.ContainsKey(ioIp))
{
DOValueMap.Remove(ioIp);
}
}
}
mastMap.Remove(ioIp);
}
try
{
// Create new modbus master and add event functions
MBmaster = new MasterTcpClient(ioIp, port);
MBmaster.OnResponseData += new MasterTcpClient.ResponseData(MBmaster_OnResponseData);
MBmaster.OnException += new MasterTcpClient.ExceptionData(MBmaster_OnException);
MBmaster.autoConnectOfBreak = false;
mastMap.Add(ioIp, MBmaster);
Thread.Sleep(10);
LogUtil.info("连接IO模块[" + ioIp + "]成功");
//读取所有的DO
ReadMultipleDO(ioIp, DefualtSlaveID, DoStartAddress, DefualtLength);
}
catch (Exception error)
{
LogUtil.error(LOGGER,"连接IO模块[" + ioIp + "]出错:"+error.ToString());
}
}
/// <summary>
/// 判断Io模块是否连接
/// </summary>
public static bool IsConnection(string ip)
{
try
{
List<string> list = new List<string>(mastMap.Keys);
foreach (string io in list)
{
//判断是否连接,如果没有连接自动重连
MasterTcpClient clinet = mastMap[io];
if (clinet.ISConnection())
{
return true;
}
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "出错啦:" + ex.ToString());
} return false;
}
private static void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
try
{
List<string> list = new List<string>(mastMap.Keys);
foreach (string io in list)
{
//判断是否连接,如果没有连接自动重连
MasterTcpClient clinet = mastMap[io];
if (!clinet.ISConnection())
public class KNDManager : IOManager
{
public static ushort DIStartAddress = 200;
public static ushort DoStartAddress = 100;
//public static ushort DefaultDILength = 16;
//public static ushort DefaultDOLength = 16;
private static byte DefualtSlaveID = 255;
public static readonly ILog LOGGER = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public static Dictionary<string, MasterTcpClient> mastMap = new Dictionary<string, MasterTcpClient>();
public static Dictionary<string, List<KNDIO>> DIValueMap = new Dictionary<string, List<KNDIO>>();
public static Dictionary<string, List<KNDIO>> DOValueMap = new Dictionary<string, List<KNDIO>>();
private static object DIMapLock = "";
private static object DOMapLock = "";
public static System.Timers.Timer timer = null;
private static ushort port = 502;
public static void ConnectionIP(string ioIp)
{
if (timer == null)
{
timer = new System.Timers.Timer();
timer.Interval = 1000;
timer.AutoReset = true;
timer.Elapsed += timer_Elapsed;
timer.Enabled = true;
}
MasterTcpClient MBmaster = null;
if (mastMap.ContainsKey(ioIp))
{
MBmaster = mastMap[ioIp];
if (null != MBmaster)
{
MBmaster.disconnect();
MBmaster.Dispose();
MBmaster = null;
lock (DIMapLock)
{
if (DIValueMap.ContainsKey(ioIp))
{
DIValueMap.Remove(ioIp);
}
}
lock (DOMapLock)
{
if (DOValueMap.ContainsKey(ioIp))
{
DOValueMap.Remove(ioIp);
}
}
}
mastMap.Remove(ioIp);
}
try
{
// Create new modbus master and add event functions
MBmaster = new MasterTcpClient(ioIp, port);
MBmaster.OnResponseData += new MasterTcpClient.ResponseData(MBmaster_OnResponseData);
MBmaster.OnException += new MasterTcpClient.ExceptionData(MBmaster_OnException);
MBmaster.autoConnectOfBreak = false;
mastMap.Add(ioIp, MBmaster);
Thread.Sleep(10);
//读取所有的DO
ReadMultipleDO(ioIp, DefualtSlaveID, DoStartAddress, StoreManager.Config.GetDOLength(ioIp));
}
catch (Exception error)
{
LogUtil.error(LOGGER, "连接IO模块[" + ioIp + "]出错:" + error.ToString());
}
}
public override void ReadAllDI(string ioIp, byte slaveId)
{
ReadMultipleDI(ioIp, (byte)slaveId, (ushort)DIStartAddress, 16);
}
public override void ReadAllDO(string ioIp, byte slaveId)
{
ReadMultipleDO(ioIp, (byte)slaveId, (ushort)DoStartAddress, 16);
}
/// <summary>
/// 判断Io模块是否连接
/// </summary>
public static bool IsConnection(string ip)
{
try
{
List<string> list = new List<string>(mastMap.Keys);
foreach (string io in list)
{
if (io.Equals(ip))
{
ushort port = 502;
//判断是否连接,如果没有连接自动重连
MasterTcpClient clinet = mastMap[io];
if (clinet.ISConnection())
{
return true;
}
}
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "出错啦:" + ex.ToString());
}
return false;
}
private static void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
try
{
List<string> list = new List<string>(mastMap.Keys);
foreach (string io in list)
{
//判断是否连接,如果没有连接自动重连
MasterTcpClient clinet = mastMap[io];
if (clinet.ISConnection())
{
//ReadMultipleDI(io, DefualtSlaveID, DIStartAddress, DefualtLength);
}
else
{
ConnectionIP(io);
LogUtil.error(LOGGER, io + "当前没有连上,重连" + io);
ConnectionIP(io, port);
}
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "出错啦:"+ex.ToString());
}
Thread.Sleep(1);
}
}
public static void ConnectionKND(List<string> DIONameList)
{
//端口号暂时使用固定的502;
ushort port = 502;
foreach (string ip in DIONameList)
{
ConnectionIP(ip, port);
}
}
public static void ConnectionKND(string ip)
{
//端口号暂时使用固定的502;
ushort port = 502;
ConnectionIP(ip, port);
}
public static void ReadMultipleDI(string ioIp, byte slaveId, ushort StartAddress, ushort length)
{
isWrite = true;
ushort ID = 2;
MasterTcpClient MBmaster = null;
if (mastMap.ContainsKey(ioIp))
{
MBmaster = mastMap[ioIp];
MBmaster.ReadDiscreteInputs(ID, StartAddress, length, slaveId);
}
else
{
LogUtil.error(LOGGER, "ReadSingleDO出错没有连接IO模块:" + ioIp);
}
isWrite = false;
}
public static void ReadMultipleDO(string ioIp, byte slaveId, ushort StartAddress, ushort length)
{
isWrite = true;
ushort ID = 1;
MasterTcpClient MBmaster = null;
if (mastMap.ContainsKey(ioIp))
{
MBmaster = mastMap[ioIp];
MBmaster.ReadCoils(ID, StartAddress, length, slaveId);
}
else
{
LogUtil.error(LOGGER,"ReadSingleDO出错没有连接IO模块:" + ioIp);
}
isWrite = false;
}
//关闭所有的DO
public static void CloseAllDO()
{
isWrite = true;
foreach (string key in mastMap.Keys)
{
byte[] data = new byte[] { 0,0};
WriteMultipleDO(key, DefualtSlaveID, DoStartAddress, DefualtLength, data);
}
isWrite = false;
}
public static void CloseAllConnection()
{
foreach (MasterTcpClient tcp in mastMap.Values)
{
tcp.disconnect();
}
mastMap.Clear();
}
public static void WriteMultipleDO(string ioIp, byte slaveId, ushort StartAddress, ushort length, byte[] bytes)
{
isWrite = true;
ushort ID = 6;
MasterTcpClient MBmaster = null;
if (mastMap.ContainsKey(ioIp))
{
MBmaster = mastMap[ioIp];
MBmaster.WriteMultipleCoils(ID, StartAddress, length, bytes, slaveId);
}
else
{
LogUtil.error(LOGGER, "ReadSingleDO出错没有连接IO模块:" + ioIp);
}
isWrite = false;
}
public static void WriteSingleDO(string ioIp, byte slaveId, ushort StartAddress, IO_VALUE onOff)
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "出错啦:" + ex.ToString());
}
Thread.Sleep(1);
}
public override void ConnectionIOList(List<string> DIONameList)
{
foreach (string ip in DIONameList)
{
//if (ip.Equals("192.168.10.10"))
//{
// continue;
//}
ConnectionIP(ip);
}
}
public static void ReadMultipleDI(string ioIp, byte slaveId, ushort StartAddress, ushort length)
{
ushort ID = 2;
MasterTcpClient MBmaster = null;
if (mastMap.ContainsKey(ioIp))
{
MBmaster = mastMap[ioIp];
MBmaster.ReadDiscreteInputs(ID, StartAddress, length, slaveId);
}
else
{
LogUtil.error(LOGGER, "ReadSingleDO出错没有连接IO模块:" + ioIp);
}
}
public static void ReadMultipleDO(string ioIp, byte slaveId, ushort StartAddress, ushort length)
{
ushort ID = 1;
MasterTcpClient MBmaster = null;
if (mastMap.ContainsKey(ioIp))
{
MBmaster = mastMap[ioIp];
MBmaster.ReadCoils(ID, StartAddress, length, slaveId);
}
else
{
LogUtil.error(LOGGER, "ReadSingleDO出错没有连接IO模块:" + ioIp);
}
}
//关闭所有的DO
public override void CloseAllDO()
{
foreach (string key in mastMap.Keys)
{
byte[] data = new byte[] { 0, 0 };
WriteMultipleDO(key, DefualtSlaveID, DoStartAddress, StoreManager.Config.GetDOLength(key), data);
}
}
public override void CloseAllConnection()
{
isWrite = true;
foreach (MasterTcpClient tcp in mastMap.Values)
{
tcp.disconnect();
}
mastMap.Clear();
timer.Stop();
timer = null;
}
public static void CloseAllDO(string ioIp, byte slaveId)
{
ushort length = StoreManager.Config.GetDOLength(ioIp);
byte[] bytes = new byte[length];
for (int i = 0; i < length; i++)
{
bytes[i] = 0;
}
WriteMultipleDO(ioIp, slaveId, DoStartAddress, length, bytes);
}
public static void WriteMultipleDO(string ioIp, byte slaveId, ushort StartAddress, ushort length, byte[] bytes)
{
ushort ID = 6;
MasterTcpClient MBmaster = null;
if (mastMap.ContainsKey(ioIp))
{
MBmaster = mastMap[ioIp];
MBmaster.WriteMultipleCoils(ID, StartAddress, length, bytes, slaveId);
}
else
{
LogUtil.error(LOGGER, "ReadSingleDO出错没有连接IO模块:" + ioIp);
}
}
public override void WriteSingleDO(string ioIp, byte slaveId, ushort StartAddress, IO_VALUE onOff)
{
ushort ID = 5;
MasterTcpClient MBmaster = null;
if (mastMap.ContainsKey(ioIp))
{
MBmaster = mastMap[ioIp];
MBmaster.WriteSingleCoils(ID, StartAddress, onOff, slaveId);
KNDIO io = new KNDIO(ioIp, slaveId, StartAddress, onOff);
SaveDOValue(io, ioIp);
}
else
{
LogUtil.error(LOGGER, "ReadSingleDO出错没有连接IO模块:" + ioIp);
}
}
public override void WriteSingleDO(string ioIp, byte slaveId, ushort StartAddress, IO_VALUE onOff, int mSeconds)
{
ushort ID = 5;
MasterTcpClient MBmaster = null;
if (mastMap.ContainsKey(ioIp))
{
MBmaster = mastMap[ioIp];
MBmaster.WriteSingleCoils(ID, StartAddress, onOff, slaveId);
KNDIO io = new KNDIO(ioIp, slaveId, StartAddress, onOff);
SaveDOValue(io, ioIp);
//写入之后,等待指定间隔后回写
System.Timers.Timer mytimer = new System.Timers.Timer(mSeconds);
mytimer.Elapsed += (o1, e1) =>
{
try
{
IO_VALUE newValue = IO_VALUE.LOW;
if (onOff.Equals(IO_VALUE.LOW))
{
newValue = IO_VALUE.HIGH;
}
MBmaster.WriteSingleCoils(ID, StartAddress, newValue, slaveId);
KNDIO newIo = new KNDIO(ioIp, slaveId, StartAddress, newValue);
SaveDOValue(newIo, ioIp);
LogUtil.info(LOGGER, "**********定时回写入 IO【" + ioIp + "," + StartAddress + ",值" + onOff + "】:");
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "**********定时回写入 出错:" + ex.StackTrace);
}
};
mytimer.AutoReset = false;//设置是否自动重启,即自动执行多次;
mytimer.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件mytask;
}
else
{
LogUtil.error(LOGGER, "ReadSingleDO出错没有连接IO模块:" + ioIp);
}
}
private static void SaveDOValue(KNDIO io, string ioIp)
{
try
{
lock (DOMapLock)
{
if (!DOValueMap.ContainsKey(ioIp))
{
DOValueMap.Add(ioIp, new List<KNDIO>());
DOValueMap[ioIp].Add(io);
}
else
{
List<KNDIO> ios = DOValueMap[ioIp];
List<KNDIO> list = (from m in ios where m.SlaveId.Equals(io.SlaveId) && m.IOAddress.Equals(io.IOAddress) select m).ToList<KNDIO>();
if (list.Count > 0)
{
DOValueMap[ioIp].Remove(list[0]);
DOValueMap[ioIp].Add(io);
}
else
{
DOValueMap[ioIp].Add(io);
}
}
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "SaveDOValue出错:" + ex.ToString());
}
}
public override IO_VALUE GetDOValue(string ioIP, byte slaveId, ushort StartAddress)
{
IO_VALUE value = IO_VALUE.LOW;
if (DOValueMap.ContainsKey(ioIP))
{
List<KNDIO> allIo = new List<KNDIO>(DOValueMap[ioIP]);
List<KNDIO> list = (from m in allIo where m.SlaveId.Equals(slaveId) && m.IOAddress.Equals(StartAddress) select m).ToList<KNDIO>();
if (list.Count > 0)
{
value = list[0].IoValue;
}
}
return value;
}
public override IO_VALUE GetDIValue(string ioIP, byte slaveId, ushort StartAddress)
{
IO_VALUE value = IO_VALUE.LOW;
if (DIValueMap.ContainsKey(ioIP))
{
List<KNDIO> allIo = new List<KNDIO>(DIValueMap[ioIP]);
List<KNDIO> list = (from m in allIo where m.SlaveId.Equals(slaveId) && m.IOAddress.Equals(StartAddress) select m).ToList<KNDIO>();
if (list.Count > 0)
{
value = list[0].IoValue;
}
}
return value;
}
public override IO_VALUE GetIOValue(ConfigIO configIO)
{
IO_VALUE value = IO_VALUE.LOW;
try
{
ushort ID = 5;
MasterTcpClient MBmaster = null;
if (mastMap.ContainsKey(ioIp))
if (configIO.ProType.Equals(ConfigItemType.DI))
{
MBmaster = mastMap[ioIp];
bool result = MBmaster.WriteSingleCoils(ID, StartAddress, onOff, slaveId);
if (!result)
if (DIValueMap.ContainsKey(configIO.DeviceName))
{
LogUtil.error(LOGGER, "WriteSingleDO[" + ioIp + "][" + slaveId + "][" + StartAddress + "]失败,尝试重新写一次");
result = MBmaster.WriteSingleCoils(ID, StartAddress, onOff, slaveId);
List<KNDIO> allIo = new List<KNDIO>(DIValueMap[configIO.DeviceName]);
List<KNDIO> list = (from m in allIo where m.IOAddress.Equals(configIO.GetIOAddr()) select m).ToList<KNDIO>();
if (list.Count > 0)
{
value = list[0].IoValue;
}
}
if (!result)
}
else if (configIO.ProType.Equals(ConfigItemType.DO))
{
if (DOValueMap.ContainsKey(configIO.DeviceName))
{
LogUtil.error(LOGGER, "WriteSingleDO[" + ioIp + "][" + slaveId + "][" + StartAddress + "]失败,重新尝试仍失败");
List<KNDIO> allIo = new List<KNDIO>(DOValueMap[configIO.DeviceName]);
List<KNDIO> list = (from m in allIo where m.SlaveId.Equals(configIO.SlaveID) && m.IOAddress.Equals(configIO.GetIOAddr()) select m).ToList<KNDIO>();
if (list.Count > 0)
{
value = list[0].IoValue;
}
}
KNDIO io = new KNDIO(ioIp, slaveId, StartAddress, onOff);
SaveDOValue(io, ioIp);
}
else
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "获取数据出错:" + ex.ToString());
}
return value;
}
private static void SaveDIData(string ioIp, ushort ID, byte[] values)
{
try
{
ushort DILength = StoreManager.Config.GetDILength(ioIp);
string finalData = "";
if (values.Length == 2 && DILength.Equals(16))
{
string finalData0 = Convert.ToString(values[0], 2).PadLeft(8, '0');
string finalData1 = Convert.ToString(values[1], 2).PadLeft(8, '0');
finalData = finalData1 + finalData0;
}
else if (values.Length == 1 && DILength <= 8)
{
LogUtil.error(LOGGER, "WriteSingleDO[" + ioIp + "][" + slaveId + "][" + StartAddress + "]出错没有连接IO模块:" + ioIp);
finalData = Convert.ToString(values[0], 2).PadLeft(DILength, '0');
}
LOGGER.Debug("IO模块【" + ioIp + "】收到DI上传:【" + finalData + "】");
if (finalData.Length >= DILength)
{
List<KNDIO> kndList = new List<KNDIO>();
ushort index = (ushort)(DIStartAddress + DILength - 1);
foreach (char str in finalData)
{
KNDIO io = null;
if (str.Equals('1'))
{
io = new KNDIO(ioIp, (byte)ID, index, IO_VALUE.HIGH);
}
else
{
io = new KNDIO(ioIp, (byte)ID, index, IO_VALUE.LOW);
}
kndList.Add(io);
index--;
}
lock (DIMapLock)
{
if (DIValueMap.ContainsKey(ioIp))
{
DIValueMap.Remove(ioIp);
}
DIValueMap.Add(ioIp, kndList);
}
}
}
catch (Exception ex)
{
LOGGER.Error("出错啦:" + ex.ToString());
LogUtil.error(LOGGER, "SaveDIData出错:" + ex.ToString());
//LOGGER.Error("处理接受数据出错:", ex);
}
isWrite = false;
}
public static void WriteSingleDO(string ioIp, byte slaveId, ushort StartAddress, IO_VALUE onOff, int mSeconds)
{
isWrite = true;
ushort ID = 5;
MasterTcpClient MBmaster = null;
if (mastMap.ContainsKey(ioIp))
{
MBmaster = mastMap[ioIp];
MBmaster.WriteSingleCoils(ID, StartAddress, onOff, slaveId);
KNDIO io = new KNDIO(ioIp, slaveId, StartAddress, onOff);
SaveDOValue(io, ioIp);
//写入之后,等待指定间隔后回写
System.Timers.Timer mytimer = new System.Timers.Timer(mSeconds);
mytimer.Elapsed += (o1, e1) =>
{
try
{
IO_VALUE newValue = IO_VALUE.LOW;
if (onOff.Equals(IO_VALUE.LOW))
{
newValue = IO_VALUE.HIGH;
}
MBmaster.WriteSingleCoils(ID, StartAddress, newValue, slaveId);
KNDIO newIo = new KNDIO(ioIp, slaveId, StartAddress, newValue);
SaveDOValue(newIo, ioIp);
LogUtil.debug(LOGGER, "**********定时回写入 IO【" + ioIp + "," + StartAddress + ",值" + onOff + "】:");
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "**********定时回写入 出错:" + ex.StackTrace);
}
};
mytimer.AutoReset = false;//设置是否自动重启,即自动执行多次;
mytimer.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件mytask;
}
else
{
LogUtil.error(LOGGER, "ReadSingleDO出错没有连接IO模块:" + ioIp);
}
isWrite = false;
}
private static void SaveDOValue(KNDIO io, string ioIp)
{
try
{
lock (DOMapLock)
{
if (!DOValueMap.ContainsKey(ioIp))
{
DOValueMap.Add(ioIp, new List<KNDIO>());
DOValueMap[ioIp].Add(io);
}
else
{
List<KNDIO> ios = DOValueMap[ioIp];
List<KNDIO> list = (from m in ios where m.SlaveId.Equals(io.SlaveId) && m.IOAddress.Equals(io.IOAddress) select m).ToList<KNDIO>();
if (list.Count > 0)
{
DOValueMap[ioIp].Remove(list[0]);
DOValueMap[ioIp].Add(io);
}
else
{
DOValueMap[ioIp].Add(io);
}
}
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER,"SaveDOValue出错:"+ex.ToString());
}
}
public static IO_VALUE GetDOValue(string ioIP, byte slaveId, ushort StartAddress)
{
IO_VALUE value = IO_VALUE.LOW;
if (DOValueMap.ContainsKey(ioIP))
{
List<KNDIO> allIo = new List<KNDIO>(DOValueMap[ioIP]);
List<KNDIO> list = (from m in allIo where m.SlaveId.Equals(slaveId) && m.IOAddress.Equals(StartAddress) select m).ToList<KNDIO>();
if (list.Count > 0)
{
value = list[0].IoValue;
}
}
return value;
}
private static void SaveDOData(string ioIp, ushort ID, byte[] values)
{
ushort DoLength = StoreManager.Config.GetDOLength(ioIp);
string finalData = "";
if (values.Length == 2 && DoLength.Equals(16))
{
string finalData0 = Convert.ToString(values[0], 2).PadLeft(8, '0');
string finalData1 = Convert.ToString(values[1], 2).PadLeft(8, '0');
finalData = finalData1 + finalData0;
}
else if (values.Length == 1 && DoLength <= 8)
{
finalData = Convert.ToString(values[0], 2).PadLeft(DoLength, '0');
}
if (finalData.Length >= DoLength)
{
List<KNDIO> kndList = new List<KNDIO>();
ushort index = (ushort)(DoStartAddress + DoLength - 1);
foreach (char str in finalData)
{
KNDIO io = null;
if (str.Equals('1'))
{
io = new KNDIO(ioIp, (byte)ID, index, IO_VALUE.HIGH);
}
else
{
io = new KNDIO(ioIp, (byte)ID, index, IO_VALUE.LOW);
}
kndList.Add(io);
index--;
}
lock (DOMapLock)
{
if (DOValueMap.ContainsKey(ioIp))
{
DOValueMap.Remove(ioIp);
}
DOValueMap.Add(ioIp, kndList);
}
}
public static IO_VALUE GetDIValue(string ioIP, byte slaveId, ushort StartAddress)
{
IO_VALUE value = IO_VALUE.LOW;
if (DIValueMap.ContainsKey(ioIP))
{
List<KNDIO> allIo = new List<KNDIO>(DIValueMap[ioIP]);
List<KNDIO> list = (from m in allIo where m.SlaveId.Equals(slaveId) && m.IOAddress.Equals(StartAddress) select m).ToList<KNDIO>();
if (list.Count > 0)
{
value = list[0].IoValue;
}
}
return value;
}
public static IO_VALUE GetIOValue(LoadCSVLibrary.ConfigIO configIO)
{
IO_VALUE value = IO_VALUE.LOW;
try
{
if (configIO.ProType.Equals(ConfigItemType.DI))
{
if (DIValueMap.ContainsKey(configIO.DeviceName))
{
List<KNDIO> allIo = new List<KNDIO>(DIValueMap[configIO.DeviceName]);
List<KNDIO> list = (from m in allIo where m.IOAddress.Equals(configIO.GetIOAddr()) select m).ToList<KNDIO>();
if (list.Count > 0)
{
value = list[0].IoValue;
}
}
}
else if (configIO.ProType.Equals(ConfigItemType.DO))
{
if (DOValueMap.ContainsKey(configIO.DeviceName))
{
List<KNDIO> allIo = new List<KNDIO>(DOValueMap[configIO.DeviceName]);
List<KNDIO> list = (from m in allIo where m.SlaveId.Equals(configIO.SlaveID) && m.IOAddress.Equals(configIO.GetIOAddr()) select m).ToList<KNDIO>();
if (list.Count > 0)
{
value = list[0].IoValue;
}
}
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "获取数据出错:" + ex.ToString());
}
return value;
}
private static void SaveDIData(string ioIp, ushort ID, byte[] values)
{
try
{
if (values.Length == 2)
{
string finalData0 = Convert.ToString(values[0], 2).PadLeft(8, '0');
string finalData1 = Convert.ToString(values[1], 2).PadLeft(8, '0');
string finalData = finalData1 + finalData0;
List<KNDIO> kndList = new List<KNDIO>();
ushort index = (ushort)(DIStartAddress + DefualtLength - 1);
foreach (char str in finalData)
{
KNDIO io = null;
if (str.Equals('1'))
{
io = new KNDIO(ioIp, (byte)ID, index, IO_VALUE.HIGH);
}
else
{
io = new KNDIO(ioIp, (byte)ID, index, IO_VALUE.LOW);
}
kndList.Add(io);
index--;
}
lock (DIMapLock)
{
if (DIValueMap.ContainsKey(ioIp))
{
DIValueMap.Remove(ioIp);
}
DIValueMap.Add(ioIp, kndList);
}
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "SaveDIData出错:" + ex.ToString());
//LOGGER.Error("处理接受数据出错:", ex);
}
}
}
// ------------------------------------------------------------------------
// Event for response data
// ------------------------------------------------------------------------
private static void MBmaster_OnResponseData(string ioIp, ushort ID, byte function, byte[] values, byte[] reviceData)
{
try
{
if (ioIp.IndexOf(":") > 0)
{
ioIp = ioIp.Substring(0, ioIp.IndexOf(":"));
}
string reviceMsg = "";
foreach (byte data in reviceData)
{
reviceMsg = reviceMsg + " " + data;
if (reviceMsg.Length > 200)
{
break;
}
}
if (ID == 0xFF)
{
return;
}
// ------------------------------------------------------------------------
// Identify requested data
ushort Func = ID;
private static void SaveDOData(string ioIp, ushort ID, byte[] values)
{
if (values.Length == 2)
{
string finalData0 = Convert.ToString(values[0], 2).PadLeft(8, '0');
string finalData1 = Convert.ToString(values[1], 2).PadLeft(8, '0');
string finalData = finalData1 + finalData0;
List<KNDIO> kndList = new List<KNDIO>();
ushort index = (ushort)(DoStartAddress + DefualtLength - 1);
foreach (char str in finalData)
{
KNDIO io = null;
if (str.Equals('1'))
{
io = new KNDIO(ioIp, (byte)ID, index, IO_VALUE.HIGH);
}
else
{
io = new KNDIO(ioIp, (byte)ID, index, IO_VALUE.LOW);
}
kndList.Add(io);
index--;
}
lock (DOMapLock)
{
if (DOValueMap.ContainsKey(ioIp))
{
DOValueMap.Remove(ioIp);
}
DOValueMap.Add(ioIp, kndList);
}
}
}
// ------------------------------------------------------------------------
// Event for response data
// ------------------------------------------------------------------------
private static void MBmaster_OnResponseData(string ioIp, ushort ID, byte function, byte[] values, byte[] reviceData)
{
try
{
if (ioIp.IndexOf(":") > 0)
{
ioIp = ioIp.Substring(0, ioIp.IndexOf(":"));
}
string reviceMsg = "";
foreach (byte data in reviceData)
{
reviceMsg = reviceMsg + " " + data;
if (reviceMsg.Length > 200)
{
break;
}
}
if (ID == 0xFF)
{
return;
}
// ------------------------------------------------------------------------
// Identify requested data
ushort Func = ID;
if (Func == 0 && reviceData.Length > 8)
{
Func = reviceData[7];
}
byte SlaveId = 0xFF;
if (reviceData.Length >= 7)
{
SlaveId = reviceData[6];
}
switch (Func)
{
case 1:
LOGGER.Info("Read coils end:【" + reviceMsg + "】 ");
SaveDOData(ioIp, SlaveId, values);
break;
case 2:
//LOGGER.Info("Read discrete inputs end:【" + reviceMsg + "】 ");
SaveDIData(ioIp, SlaveId, values);
break;
case 3:
//LOGGER.Info("读入(多个)寄存器完成 end:【" + reviceMsg + "】 ");
break;
case 4:
//LOGGER.Info("读入(多个)寄存器完成 end:【" + reviceMsg + "】 ");
break;
case 5:
//LOGGER.Info("Write single coil:【" + reviceMsg + "】 ");
break;
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "处理接受数据出错:" + ex.ToString());
//LOGGER.Error("处理接受数据出错:", ex);
}
}
if (Func == 0 && reviceData.Length > 8)
{
Func = reviceData[7];
}
byte SlaveId = 0xFF;
if (reviceData.Length >= 7)
{
SlaveId = reviceData[6];
}
switch (Func)
{
case 1:
LOGGER.Info("Read coils end:【" + reviceMsg + "】 ");
SaveDOData(ioIp, SlaveId, values);
break;
case 2:
//LOGGER.Info("Read discrete inputs end:【" + reviceMsg + "】 ");
SaveDIData(ioIp, SlaveId, values);
break;
case 3:
//LOGGER.Info("读入(多个)寄存器完成 end:【" + reviceMsg + "】 ");
break;
case 4:
//LOGGER.Info("读入(多个)寄存器完成 end:【" + reviceMsg + "】 ");
break;
case 5:
//LOGGER.Info("Write single coil:【" + reviceMsg + "】 ");
break;
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "处理接受数据出错:" + ex.ToString());
//LOGGER.Error("处理接受数据出错:", ex);
}
}
// ------------------------------------------------------------------------
// Modbus TCP slave exception
// ------------------------------------------------------------------------
private static void MBmaster_OnException(string ioIp, ushort id, byte function, byte exception, byte[] reviceData)
{
string exc = "Modbus says error: ";
switch (exception)
{
case MasterTcpClient.excIllegalFunction: exc += "Illegal function!"; break;
case MasterTcpClient.excIllegalDataAdr: exc += "Illegal data adress!"; break;
case MasterTcpClient.excIllegalDataVal: exc += "Illegal data value!"; break;
case MasterTcpClient.excSlaveDeviceFailure: exc += "Slave device failure!"; break;
case MasterTcpClient.excAck: exc += "Acknoledge!"; break;
case MasterTcpClient.excSlaveIsBusy: exc += "Slave is busy!"; break;
case MasterTcpClient.excGatePathUnavailable: exc += "Gateway path unavailbale!"; break;
case MasterTcpClient.excExceptionTimeout: exc += "Slave timed out!"; break;
case MasterTcpClient.excExceptionConnectionLost: exc += "Connection is lost!"; break;
case MasterTcpClient.excExceptionNotConnected: exc += "Not connected!"; break;
default:
break;
}
LOGGER.Error("接收数据出错:"+ exc);
//MessageBox.Show(exc, "Modbus slave exception");
}
}
public class KNDIO
// ------------------------------------------------------------------------
// Modbus TCP slave exception
// ------------------------------------------------------------------------
private static void MBmaster_OnException(string ioIp, ushort id, byte function, byte exception, byte[] reviceData)
{
string exc = "Modbus says error: ";
switch (exception)
{
case MasterTcpClient.excIllegalFunction: exc += "Illegal function!"; break;
case MasterTcpClient.excIllegalDataAdr: exc += "Illegal data adress!"; break;
case MasterTcpClient.excIllegalDataVal: exc += "Illegal data value!"; break;
case MasterTcpClient.excSlaveDeviceFailure: exc += "Slave device failure!"; break;
case MasterTcpClient.excAck: exc += "Acknoledge!"; break;
case MasterTcpClient.excSlaveIsBusy: exc += "Slave is busy!"; break;
case MasterTcpClient.excGatePathUnavailable: exc += "Gateway path unavailbale!"; break;
case MasterTcpClient.excExceptionTimeout: exc += "Slave timed out!"; break;
case MasterTcpClient.excExceptionConnectionLost: exc += "Connection is lost!"; break;
case MasterTcpClient.excExceptionNotConnected: exc += "Not connected!"; break;
default:
break;
}
LOGGER.Error("接收数据出错:" + exc);
//MessageBox.Show(exc, "Modbus slave exception");
}
}
public class KNDIO
{
public KNDIO(string ioIp, byte ID, ushort index, IO_VALUE o_VALUE)
......
......@@ -13,7 +13,7 @@ using OnlineStore.LoadCSVLibrary;
namespace OnlineStore.DeviceLibrary
{
public class MasterTcpClient
{
public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
......@@ -70,7 +70,7 @@ namespace OnlineStore.DeviceLibrary
// ------------------------------------------------------------------------
/// <summary>Response data event. This event is called when new data arrives</summary>
public delegate void ResponseData(string ip, ushort id, byte function, byte[] data,byte[] reviceData);
public delegate void ResponseData(string ip, ushort id, byte function, byte[] data, byte[] reviceData);
/// <summary>Response data event. This event is called when new data arrives</summary>
public event ResponseData OnResponseData;
/// <summary>Exception data event. This event is called when the data is incorrect</summary>
......@@ -84,25 +84,25 @@ namespace OnlineStore.DeviceLibrary
public bool autoConnectOfBreak
{
get { return _autoConnectOfBreak; }
set { _autoConnectOfBreak = value; }
}
set { _autoConnectOfBreak = value; }
}
public static ushort timeout
{
get { return _timeout; }
set { _timeout = value; }
}
public ushort refresh
{
get { return _refresh; }
set { _refresh = value; }
}
public bool connected
{
get { return _connected; }
}
public MasterTcpClient()
{
}
......@@ -126,7 +126,7 @@ namespace OnlineStore.DeviceLibrary
socketClient.Connect(new IPEndPoint(IPAddress.Parse(ip), port));
socketClient.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, _timeout);
socketClient.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, _timeout);
socketClient.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, 1);
socketClient.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, 1);
}
else
{
......@@ -166,12 +166,12 @@ namespace OnlineStore.DeviceLibrary
try
{
//socketClient.BeginReceive(tcpSocketReviceBuffer, 0, tcpSocketReviceBuffer.Length, SocketFlags.None, new AsyncCallback(OnReceive), socketClient);
ReviceDataProcess();
ReviceDataProcess();
Thread.Sleep(10);
}
catch (Exception ex)
{
LOGGER.Error("IO模块["+IP+"]出错:" + ex.ToString());
LOGGER.Error("IO模块[" + IP + "]出错:" + ex.ToString());
}
}
......@@ -198,15 +198,16 @@ namespace OnlineStore.DeviceLibrary
byte dataLength = rdata[lengthIndex];
int allLength = lengthIndex + 1 + dataLength;
int currStartIndex = 0;
if (rdata.Length > allLength)
{
try
//LogUtil.info(clientipe.ToString() + "收到数据(需要分包):" + str);
int currStartIndex = 0;
for (int i = 0; i < 100; i++)
{
//LogUtil.info(clientipe.ToString() + "收到数据(需要分包):" + str);
try
{
for (int i = 0; i < 100; i++)
{
if (rdata.Length < currStartIndex + lengthIndex)
{
LogUtil.error(clientipe.ToString() + "收到数据:" + str + "分包出错 [" + currStartIndex + "]");
......@@ -228,11 +229,12 @@ namespace OnlineStore.DeviceLibrary
}
currStartIndex = currStartIndex + allLength;
}
catch (Exception ex)
{
LogUtil.error(clientipe.ToString() + "收到数据:" + str + "分包出错 [" + currStartIndex + "]:" + ex.ToString());
}
}
catch (Exception ex)
{
LogUtil.error(clientipe.ToString() + "收到数据:" + str + "分包出错 [" + currStartIndex + "]:" + ex.ToString());
}
}
else
{
......@@ -247,10 +249,7 @@ namespace OnlineStore.DeviceLibrary
private void DataProcess(string clientIp, ushort id, byte function, byte[] rdata)
{
byte[] data;
if (rdata.Length <= 9)
{
return;
}
if ((function >= fctWriteSingleCoil) && (function != fctReadWriteMultipleRegister))
{
data = new byte[2];
......@@ -274,11 +273,11 @@ namespace OnlineStore.DeviceLibrary
// Response data is regular data
else if (OnResponseData != null)
{ //收到的数据打印出来
OnResponseData(clientIp, id, function, data, rdata);
}
}
private byte[] Receive()
{
try
......@@ -287,10 +286,10 @@ namespace OnlineStore.DeviceLibrary
{
return null;
}
int size = socketClient.Available;
byte[] rData = new byte[size];
socketClient.Receive(rData, size, SocketFlags.None);
byte[] rData = new byte[size];
socketClient.Receive(rData, size, SocketFlags.None);
return rData;
}
......@@ -305,8 +304,8 @@ namespace OnlineStore.DeviceLibrary
return null;
}
}
}
// ------------------------------------------------------------------------
/// <summary>Stop connection to slave.</summary>
public void disconnect()
......@@ -341,7 +340,7 @@ namespace OnlineStore.DeviceLibrary
socketClient.Close();
}
socketClient = null;
}
}
}
internal void CallException(ushort id, byte function, byte exception, byte[] rdata)
......@@ -363,33 +362,33 @@ namespace OnlineStore.DeviceLibrary
OnException(socketClient.RemoteEndPoint.AddressFamily.ToString(), id, function, exception, rdata);
}
}
public void ReadCoils(ushort id, ushort startAddress, ushort numInputs, byte SlaveID)
{
WriteAsyncData(CreateReadHeader(id, startAddress, numInputs, fctReadCoil, SlaveID), id);
}
}
public void ReadDiscreteInputs(ushort id, ushort startAddress, ushort numInputs, byte SlaveID)
{
WriteAsyncData(CreateReadHeader(id, startAddress, numInputs, fctReadDiscreteInputs, SlaveID), id);
}
}
public void ReadHoldingRegister(ushort id, ushort startAddress, ushort numInputs, byte SlaveID)
{
WriteAsyncData(CreateReadHeader(id, startAddress, numInputs, fctReadHoldingRegister, SlaveID), id);
}
}
public void ReadInputRegister(ushort id, ushort startAddress, ushort numInputs, byte SlaveID)
{
WriteAsyncData(CreateReadHeader(id, startAddress, numInputs, fctReadInputRegister, SlaveID), id);
}
public bool WriteSingleCoils(ushort id, ushort startAddress, IO_VALUE ioValue, byte SlaveID)
public void WriteSingleCoils(ushort id, ushort startAddress, IO_VALUE ioValue, byte SlaveID)
{
byte[] data;
bool OnOff = ioValue.Equals(IO_VALUE.HIGH);
data = CreateWriteHeader(id, startAddress, 1, 1, fctWriteSingleCoil, SlaveID);
if (OnOff == true) data[10] = 255;
else data[10] = 0;
return WriteAsyncData(data, id);
WriteAsyncData(data, id);
}
public void WriteMultipleCoils(ushort id, ushort startAddress, ushort numBits, byte[] values, byte SlaveID)
{
byte numBytes = Convert.ToByte(values.Length);
......@@ -397,8 +396,8 @@ namespace OnlineStore.DeviceLibrary
data = CreateWriteHeader(id, startAddress, numBits, (byte)(numBytes + 2), fctWriteMultipleCoils, SlaveID);
Array.Copy(values, 0, data, 13, numBytes);
WriteAsyncData(data, id);
}
}
public void WriteSingleRegister(ushort id, ushort startAddress, byte[] values, byte SlaveID)
{
byte[] data;
......@@ -406,8 +405,8 @@ namespace OnlineStore.DeviceLibrary
data[10] = values[0];
data[11] = values[1];
WriteAsyncData(data, id);
}
}
public void WriteMultipleRegister(ushort id, ushort startAddress, byte[] values, byte SlaveID)
{
ushort numBytes = Convert.ToUInt16(values.Length);
......@@ -417,8 +416,8 @@ namespace OnlineStore.DeviceLibrary
data = CreateWriteHeader(id, startAddress, Convert.ToUInt16(numBytes / 2), Convert.ToUInt16(numBytes + 2), fctWriteMultipleRegister, SlaveID);
Array.Copy(values, 0, data, 13, values.Length);
WriteAsyncData(data, id);
}
}
public void ReadWriteMultipleRegister(ushort id, ushort startReadAddress, ushort numInputs, ushort startWriteAddress, byte SlaveID, byte[] values)
{
ushort numBytes = Convert.ToUInt16(values.Length);
......@@ -430,7 +429,7 @@ namespace OnlineStore.DeviceLibrary
WriteAsyncData(data, id);
}
// ------------------------------------------------------------------------
// Create modbus header for read action
private byte[] CreateReadHeader(ushort id, ushort startAddress, ushort length, byte function, byte SlaveID)
......@@ -512,12 +511,12 @@ namespace OnlineStore.DeviceLibrary
// ------------------------------------------------------------------------
// Write asynchronous data
private bool WriteAsyncData(byte[] write_data, ushort id)
private void WriteAsyncData(byte[] write_data, ushort id)
{
if (socketClient == null)
{
LOGGER.Error("MasterTcpClient发送数据时发现socketClient=null");
return false ;
LOGGER.Error("发送数据时发现socketClient=null");
return;
}
IPEndPoint clientipe = (IPEndPoint)socketClient.RemoteEndPoint;
if ((socketClient != null) && (socketClient.Connected))
......@@ -528,14 +527,13 @@ namespace OnlineStore.DeviceLibrary
string str = "";
foreach (byte by in write_data)
{
str = str +" "+ by;
str = str + " " + by;
}
//LogUtil.info( clientipe.ToString()+"发送数据:" + str);
socketClient.BeginSend(write_data, 0, write_data.Length, SocketFlags.None, new AsyncCallback(OnSend), null);
//socketClient.BeginReceive(tcpSocketReviceBuffer, 0, tcpSocketReviceBuffer.Length, SocketFlags.None, new AsyncCallback(OnReceive), socketClient);
ReviceDataProcess();
return true;
}
catch (SystemException error)
{
......@@ -544,9 +542,8 @@ namespace OnlineStore.DeviceLibrary
}
}
else CallException(id, write_data[7], excExceptionConnectionLost, tcpSocketReviceBuffer);
return false;
}
// ------------------------------------------------------------------------
// Write asynchronous data acknowledge
private void OnSend(System.IAsyncResult result)
......@@ -563,7 +560,8 @@ namespace OnlineStore.DeviceLibrary
return;
}
IPEndPoint clientipe = (IPEndPoint)socketClient.RemoteEndPoint;
if (result.IsCompleted == false) {
if (result.IsCompleted == false)
{
CallException(0xFF, 0xFF, excExceptionConnectionLost, tcpSocketReviceBuffer);
}
......@@ -590,7 +588,7 @@ namespace OnlineStore.DeviceLibrary
if (function > excExceptionOffset)
{
function -= excExceptionOffset;
CallException(id, function, tcpSocketReviceBuffer[8],tcpSocketReviceBuffer);
CallException(id, function, tcpSocketReviceBuffer[8], tcpSocketReviceBuffer);
}
// ------------------------------------------------------------
// Response data is regular data
......@@ -605,13 +603,13 @@ namespace OnlineStore.DeviceLibrary
break;
}
}
// LogUtil.info( clientipe.ToString()+"收到数据:" + str);
// LogUtil.info( clientipe.ToString()+"收到数据:" + str);
OnResponseData(clientipe.ToString(), id, function, data, tcpSocketReviceBuffer);
}
}
internal bool ISConnection()
{
{
if (socketClient == null)
{
return false;
......
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.IO.Ports;
......@@ -189,7 +190,10 @@ namespace OnlineStore.DeviceLibrary
dataArray = ACCMDManager.GetWriteData(slvAddr, ACCMDManager.CMD_WriteCoil, addr, data, length);
SendData(portName, dataArray);
}
public static void SuddenStop(ConfigMoveAxis moveAxis)
{
SuddenStop(moveAxis.DeviceName, moveAxis.GetAxisValue());
}
public static void SuddenStop(string portName, int slvAddr)
{
// RunBlock(7);
......
类型,说明,名称,属性值,设备名称,默认值,描述,电器定义,代码定义,SlaveID,
DI,急停,SuddenStop_BTN,200,192.168.200.11,0,急停,X01,DI-01,0,
DI,复位,Reset_BTN,201,192.168.200.11,0,复位,X02,DI-02,0,
DI,自动,AutoRun_Signal,202,192.168.200.11,0,自动,X03,DI-03,0,
DI,气压检测,Airpressure_Check,203,192.168.200.11,0,气压检测,X04,DI-04,0,
DI,料盘检测1(进料口),TrayCheck_Door,204,192.168.200.11,0,料盘检测1(进料口),X05,DI-05,0,
DI,料盘检测2(料叉),TrayCheck_Fixture,205,192.168.200.11,0,料盘检测2(料叉),X06,DI-06,0,
DI,进料口门上升端,Door_Up,206,192.168.200.11,0,进料口门上升端,X07,DI-07,0,
DI,进料口门下降端,Door_Down,207,192.168.200.11,0,进料口门下降端,X08,DI-08,0,
,,,208,192.168.200.11,0,,X09,DI-09,0,
,,,209,192.168.200.11,0,,X10,DI-10,0,
DI,前门限位,Door_LimitSingle,210,192.168.200.11,0,前门限位,X11,DI-11,0,
,,,211,192.168.200.11,0,,X12,DI-12,0,
DI,安全光栅,SafetyLightCurtains,212,192.168.200.11,0,安全光栅,X13,DI-13,0,
,,,213,192.168.200.11,0,,X14,DI-14,0,
,,,214,192.168.200.11,0,,X15,DI-15,0,
DI,压紧机构计量检测,CompressAxis_Check,215,192.168.200.11,0,压紧机构计量检测,X16,DI-16,0,
DO,自动指示灯,AutoRun_HddLed,100,192.168.200.11,0,自动指示灯,Y01,DO-01,0,
DO,故障指示灯,Alarm_HddLed,101,192.168.200.11,0,故障指示灯,Y02,DO-02,0,
DO,待机指示灯,RunSign_HddLed,102,192.168.200.11,0,待机指示灯,Y03,DO-03,0,
DO,吹气SOL ON,StartOrStopBlow,103,192.168.200.11,0,吹气SOL ON,Y04,DO-04,0,
DO,料仓运转ON,Run_Signal,104,192.168.200.11,0,料仓运转ON,Y05,DO-05,0,
DO,轴2刹车电源ON,Axis_Brake,105,192.168.200.11,0,轴2刹车电源ON,Y06,DO-06,0,
DO,进料口门上升SOL,Door_Up,106,192.168.200.11,0,进料口门上升SOL,Y07,DO-07,0,
DO,进料口门下降SOL,Door_Down,107,192.168.200.11,0,进料口门下降SOL,Y08,DO-08,0,
,,,108,192.168.200.11,0,,Y09,DO-09,0,
,,,109,192.168.200.11,0,,Y10,DO-10,0,
DO,相机照明开,CameraLight_Power,110,192.168.200.11,0,相机照明开,Y11,DO-11,0,
,,,111,192.168.200.11,0,,Y12,DO-12,0,
,,,112,192.168.200.11,0,,Y13,DO-13,0,
,,,113,192.168.200.11,0,,Y14,DO-14,0,
,,,114,192.168.200.11,0,,Y15,DO-15,0,
,,,115,192.168.200.11,0,,Y16,DO-16,0,
DI,急停,SuddenStop_BTN,0,192.168.200.11,0,急停,X01,DI-01,0,
DI,联机,AutoRun_Signal,1,192.168.200.11,0,联机,X02,DI-02,0,
DI,复位,Reset_BTN,2,192.168.200.11,0,复位,X03,DI-03,0,
DI,料盘检测1(进料口),TrayCheck_Door,3,192.168.200.11,0,料盘检测1(进料口),X04,DI-04,0,
DI,料盘检测2(料叉),TrayCheck_Fixture,4,192.168.200.11,0,料盘检测2(料叉),X05,DI-05,0,
DI,气压检测,Airpressure_Check,5,192.168.200.11,0,气压检测,X06,DI-06,0,
DI,进料口门上升端,Door_Up,6,192.168.200.11,0,进料口门上升端,X07,DI-07,0,
DI,进料口门下降端,Door_Down,7,192.168.200.11,0,进料口门下降端,X08,DI-08,0,
DO,自动指示灯,AutoRun_HddLed,8,192.168.200.11,0,自动指示灯,Y01,DO-01,0,
DO,故障指示灯,Alarm_HddLed,9,192.168.200.11,0,故障指示灯,Y02,DO-02,0,
DO,待机指示灯,RunSign_HddLed,10,192.168.200.11,0,待机指示灯,Y03,DO-03,0,
DO,料仓运转ON,Run_Signal,11,192.168.200.11,0,料仓运转ON,Y04,DO-04,0,
DO,轴2刹车电源ON,Axis_Brake,12,192.168.200.11,0,轴2刹车电源ON,Y05,DO-05,0,
DO,料仓吹气SOL,StartOrStopBlow,13,192.168.200.11,0,料仓吹气SOL,Y06,DO-06,0,
DO,进料口门上升SOL,Door_Up,14,192.168.200.11,0,进料口门上升SOL,Y07,DO-07,0,
DO,进料口门下降SOL,Door_Down,15,192.168.200.11,0,进料口门下降SOL,Y08,DO-08,0,
AXIS,(轴一)旋转轴,Middle_Axis,1,COM1,0,,,,,
AXIS,(轴二)升降轴轴,UpDown_Axis,2,COM1,0,,,,,
AXIS,(轴三)进出轴,InOut_Axis,3,COM1,0,,,,,
AXIS,(轴四)压紧轴,Comp_Axis,4,COM1,0,,,,,
PRO,升降轴 进料口取料点 P1,UpDownAxis_DoorOPosition_P1,403000,,,,,,,
PRO,升降轴 进料口出料前点 P2,UpDownAxis_DoorIPosition_P2,415000,,,,,,,
PRO,升降轴 进料口取料缓冲点 P7,UpDownAxis_DoorOBPosition_P7,415000,,,,,,,
......@@ -67,6 +52,13 @@ PRO,(轴三)进出轴减速度,InoutAxis_DelSpeed,300,,,,,,,
PRO,(轴三)进出轴原点低速,InoutAxis_HomeLowSpeed,20,,,,,,,
PRO,(轴三)进出轴原点高速,InoutAxis_HomeHighSpeed,60,,,,,,,
PRO,(轴三)进出轴原点加速度,InoutAxis_HomeAddSpeed,200,,,,,,,
PRO,(轴四)压紧轴目标速度,CompAxis_TargetSpeed,100,,,,,,,
PRO,(轴四)压紧轴加速度,CompAxis_AddSpeed,300,,,,,,,
PRO,(轴四)压紧轴减速度,CompAxis_DelSpeed,300,,,,,,,
PRO,(轴四)压紧轴原点低速,CompAxis_HomeLowSpeed,20,,,,,,,
PRO,(轴四)压紧轴原点高速,CompAxis_HomeHighSpeed,60,,,,,,,
PRO,(轴四)压紧轴原点加速度,CompAxis_HomeAddSpeed,200,,,,,,,
,,,,,,,,,,
PRO,升降轴(轴2)P1速度,UpDownAxis_P1_Speed,250,,,,,,,
PRO,升降轴(轴2)P2速度,UpDownAxis_P2_Speed,250,,,,,,,
PRO,升降轴(轴2)P3速度,UpDownAxis_P3_Speed,250,,,,,,,
......@@ -124,3 +116,5 @@ PRO,模拟信号1的地址,AIDI1_Addr,7,,,,,,,
PRO,模拟信号2的地址,AIDI2_Addr,8,,,,,,,
PRO,模拟信号3的地址,AIDI3_Addr,5,,,,,,,
PRO,模拟信号4的地址,AIDI4_Addr,6,,,,,,,
PRO,IO模块对应的DI数量,IO_DILength,192.168.200.11#8,,,,,, ,
PRO,模块对应的DO数量,IO_DOLength,192.168.200.11#8,,,,,,,
......@@ -66,8 +66,8 @@ namespace OnlineStore.DeviceLibrary
StoreName = ("料仓BOX_" + config.Id + " ").ToUpper();
this.StoreID = config.Id;
this.Config = config;
this.DIList = config.StoreDIList;
this.DOList = config.StoreDOList;
//this.DIList = config.StoreDIList;
//this.DOList = config.StoreDOList;
//Max_Humidity = config.Max_Humidity;
//Max_Temperature = config.Max_Temperature;
moveAxisList = new List<ConfigMoveAxis>();
......@@ -89,10 +89,10 @@ namespace OnlineStore.DeviceLibrary
//初始化摄像机配置
string nameStr = ConfigAppSettings.GetValue(Setting_Init.CameraName);
string codeStr = ConfigAppSettings.GetValue(Setting_Init.CodeType);
CodeManager.LoadConfig(nameStr, codeStr);
//CodeManager.LoadConfig(nameStr, codeStr);
IOManager.Init();
//初始化 //连接设备
KNDManager.ConnectionKND(Config.DIODeviceNameList);
IOManager.instance.ConnectionIOList(Config.DIODeviceNameList);
KNDAIManager.ConnectionIP(Config.AIDevice_IP);
//scanSocket.OnScanRevice += onCodeReceived;
......@@ -105,9 +105,9 @@ namespace OnlineStore.DeviceLibrary
Thread.Sleep(300);
//默认三个灯都亮
KNDIOMove(IO_Type.Alarm_HddLed, IO_VALUE.LOW);
KNDIOMove(IO_Type.AutoRun_HddLed, IO_VALUE.LOW);
KNDIOMove(IO_Type.RunSign_HddLed, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.Alarm_HddLed, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.RunSign_HddLed, IO_VALUE.LOW);
}
private void IoCheckTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
......@@ -115,7 +115,7 @@ namespace OnlineStore.DeviceLibrary
//判断急停
if (storeRunStatus >= StoreRunStatus.HomeMoving)
{
if (KNDIOValue(IO_Type.SuddenStop_BTN).Equals(IO_VALUE.LOW))
if (IOManager.IOValue(IO_Type.SuddenStop_BTN).Equals(IO_VALUE.LOW))
{
if (isInSuddenDown.Equals(false))
{
......@@ -127,11 +127,7 @@ namespace OnlineStore.DeviceLibrary
Alarm(StoreAlarmType.SuddenStop, "1", WarnMsg, StoreMoveType.None);
}
}
else
{
//光栅处理
SafetyLightProcess();
}
}
}
/// <summary>
......@@ -145,11 +141,17 @@ namespace OnlineStore.DeviceLibrary
moveAxisList.Add(Config.Middle_Axis);
moveAxisList.Add(Config.UpDown_Axis);
moveAxisList.Add(Config.InOut_Axis);
this.AxisAlarmCodeMap = new Dictionary<string, AxisAlarmInfo>();
this.AxisAlarmCodeMap.Add(Config.UpDown_Axis.GetNameStr(), new AxisAlarmInfo());
this.AxisAlarmCodeMap.Add(Config.InOut_Axis.GetNameStr(), new AxisAlarmInfo());
this.AxisAlarmCodeMap.Add(this.Config.Middle_Axis.GetNameStr(), new AxisAlarmInfo());
if (Config.IsHasCompress_Axis.Equals(1))
{
moveAxisList.Add(Config.Comp_Axis);
this.AxisAlarmCodeMap.Add(this.Config.Comp_Axis.GetNameStr(), new AxisAlarmInfo());
}
}
/// <summary>
......@@ -158,22 +160,14 @@ namespace OnlineStore.DeviceLibrary
public override bool StartRun()
{
LogUtil.info(LOGGER, StoreName + "开始启动,启动时间:" + StartTime.ToString());
if (IsHasCompress_Axis)
{
if (ShuoKeControls.isRun == false && (!StoreManager.OpenShuoKe(this)))
{
LogUtil.info(StoreName + "打开驱动器串口失败,启动失败!");
return false;
}
}
autoNext = false;
mainTimer.Enabled = false;
alarmType = StoreAlarmType.None;
//急停按钮和气压检测需要一起判断
IO_VALUE suddenBtn = KNDIOValue(IO_Type.SuddenStop_BTN);
IO_VALUE airCheck = KNDIOValue(IO_Type.Airpressure_Check);
IO_VALUE suddenBtn = IOManager.IOValue(IO_Type.SuddenStop_BTN);
IO_VALUE airCheck = IOManager.IOValue(IO_Type.Airpressure_Check);
//if (suddenBtn == IO_VALUE.HIGH)
if (suddenBtn == IO_VALUE.HIGH && airCheck == IO_VALUE.HIGH)
......@@ -222,33 +216,18 @@ namespace OnlineStore.DeviceLibrary
WarnMsg = "";
CurrInOutACount = 0;
CurrInOutCount = 0;
KNDIOMove(IO_Type.Alarm_HddLed, IO_VALUE.LOW);
KNDIOMove(IO_Type.AutoRun_HddLed, IO_VALUE.HIGH);
KNDIOMove(IO_Type.RunSign_HddLed, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.Alarm_HddLed, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.HIGH);
IOManager.IOMove(IO_Type.RunSign_HddLed, IO_VALUE.LOW);
storeRunStatus = StoreRunStatus.HomeMoving;
StoreMove.NewMove(StoreMoveType.ReturnHome);
StoreMove.NextMoveStep(StoreMoveStep.BOX_H_InOutBack);
ACAxisHomeMove(Config.InOut_Axis);
LogUtil.info(LOGGER, StoreName + "开始原点返回,先把进出轴回原点");
//设置速度
SetShuokeSpeed();
StoreMove.WaitList.Add(WaitResultInfo.WaitTime(2000));
}
public void SetShuokeSpeed()
{
ShuoKeControls.SetSpeed(Config.CompressAxis_Slv, ShuoKeCMD.SetAddSpeed, Config.CompressAxis_AddSpeed);
Thread.Sleep(60);
ShuoKeControls.SetSpeed(Config.CompressAxis_Slv, ShuoKeCMD.SetDelSpeed, Config.CompressAxis_DelSpeed);
Thread.Sleep(60);
ShuoKeControls.SetSpeed(Config.CompressAxis_Slv, ShuoKeCMD.SetEndSpeed, Config.CompressAxis_EndSpeed);
Thread.Sleep(60);
ShuoKeControls.SetSpeed(Config.CompressAxis_Slv, ShuoKeCMD.SetHomeSpeed, Config.CompressAxis_HomeSpeed);
Thread.Sleep(60);
ShuoKeControls.SetSpeed(Config.CompressAxis_Slv, ShuoKeCMD.SetMaxSpeed, Config.CompressAxis_MaxSpeed);
Thread.Sleep(60);
ShuoKeControls.SetSpeed(Config.CompressAxis_Slv, ShuoKeCMD.SetStartSpeed, Config.CompressAxis_StartSpeed);
}
}
public void MoveToP1()
{
//压紧轴回原点,叉子回到P1,关闭门旋转轴和升降轴回到P1
......@@ -256,7 +235,7 @@ namespace OnlineStore.DeviceLibrary
StoreMove.NextMoveStep(StoreMoveStep.BOX_M_H_TOP1_InOutToP1);
LogUtil.info(LOGGER, StoreName + "到待机状态,进出轴到P1,判断叉子没有料盘");
ACAxisMove(Config.InOut_Axis, Config.InOutAxis_P1_Position, Config.InOutAxis_P1_Speed);
ComBeforeHomeMove();
//ComBeforeHomeMove();
//判断叉子没有料盘
//StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.TrayCheck_Fixture, IO_VALUE.LOW));
}
......@@ -273,9 +252,9 @@ namespace OnlineStore.DeviceLibrary
CurrInOutCount = 0;
CurrInOutACount = 0;
KNDIOMove(IO_Type.Alarm_HddLed, IO_VALUE.LOW);
KNDIOMove(IO_Type.AutoRun_HddLed, IO_VALUE.HIGH);
KNDIOMove(IO_Type.RunSign_HddLed, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.Alarm_HddLed, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.HIGH);
IOManager.IOMove(IO_Type.RunSign_HddLed, IO_VALUE.LOW);
//复位之前先停止运行
if (isNeedClearAuto)
{
......@@ -304,8 +283,7 @@ namespace OnlineStore.DeviceLibrary
if (IsHasCompress_Axis || Config.IsHasLocationCylinder.Equals(0))
{
InoutStartReset();
//硕科压紧轴回原点
SetShuokeSpeed();
}
else
{
......@@ -320,22 +298,11 @@ namespace OnlineStore.DeviceLibrary
{
string portName = Config.InOut_Axis.DeviceName;
int slvAddr = Config.InOut_Axis.GetAxisValue();
//if (ACServerManager.GetHomeEndStatus(portName, slvAddr).Equals(1)
// && ACServerManager.GetHomeSingle(portName, slvAddr).Equals(1))
//{
// StoreMove.NextMoveStep(StoreMoveStep.BOX_H_InOutMove);
// LogUtil.info(LOGGER, StoreName + "复位中,进出轴原点亮且已经原点返回过,先相对走-5000");
// int currPos = ACServerManager.GetActualtPosition(portName, slvAddr);
// int targetPos = currPos - 5000;
// ACAxisMove(Config.InOut_Axis, targetPos, Config.InoutAxis_HomeLowSpeed);
//}
//else
//{
StoreMove.NextMoveStep(StoreMoveStep.BOX_H_InOutBack);
LogUtil.info(LOGGER, StoreName + "复位中,进出轴开始原点返回");
ACAxisHomeMove(Config.InOut_Axis);
StoreMove.WaitList.Add(WaitResultInfo.WaitTime(2000));
//}
StoreMove.WaitList.Add(WaitResultInfo.WaitTime(2000));
}
/// <summary>
/// 复位处理
......@@ -352,11 +319,7 @@ namespace OnlineStore.DeviceLibrary
}
switch (StoreMove.MoveStep)
{
case StoreMoveStep.BOX_H_LocationCylinderBack:
//StoreMove.NextMoveStep(StoreMoveStep.BOX_H_InOutBack);
//ACAxisHomeMove(Config.InOut_Axis);
//LogUtil.info(LOGGER, StoreName + "复位中:进出轴回原点。。");
//StoreMove.WaitList.Add(WaitResultInfo.WaitTime(2000));
case StoreMoveStep.BOX_H_LocationCylinderBack:
InoutStartReset();
break;
case StoreMoveStep.BOX_H_InOutMove:
......@@ -372,7 +335,7 @@ namespace OnlineStore.DeviceLibrary
//进出轴原点返回完成,将进出轴的位置设置=0
AxisCountClear(Config.InOut_Axis);
ACAxisMove(Config.InOut_Axis, Config.InOutAxis_P1_Position, Config.InOutAxis_P1_Speed);
ComBeforeHomeMove();
//ComBeforeHomeMove();
//判断叉子没有料盘
//StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.TrayCheck_Fixture, IO_VALUE.LOW));
CloseDoorAndWait();
......@@ -387,10 +350,8 @@ namespace OnlineStore.DeviceLibrary
LogUtil.info(LOGGER, StoreName + "复位中: 压紧轴,旋转轴,上下轴开始 原点返回");
StoreMove.NextMoveStep(StoreMoveStep.BOX_H_OtherAxisBack);
if (IsHasCompress_Axis)
{
StoreMove.WaitList.Add(WaitResultInfo.WaitShuoKe(Config.CompressAxis_Slv, 0, true));
ShuoKeControls.HomeMove(Config.CompressAxis_Slv, 1);
Thread.Sleep(60);
{
ACAxisHomeMove(Config.Comp_Axis);
}
ACAxisHomeMove(Config.Middle_Axis);
ACAxisHomeMove(Config.UpDown_Axis);
......@@ -402,6 +363,7 @@ namespace OnlineStore.DeviceLibrary
ACAxisMove(Config.Middle_Axis, Config.MiddleAxis_P1_Position, Config.MiddleAxis_P1_Speed);
ACAxisMove(Config.UpDown_Axis, Config.UpDownAxis_DoorOPosition_P1, Config.UpDownAxis_P1_Speed);
ComMoveToPosition(Config.CompressAxis_P1_Position);
break;
case StoreMoveStep.BOX_H_MiddleAxisToP1:
LogUtil.info(LOGGER, StoreName + "复位完成");
......@@ -418,9 +380,8 @@ namespace OnlineStore.DeviceLibrary
StoreMove.NextMoveStep(StoreMoveStep.BOX_M_H_TOP1_CompressHome);
LogUtil.info(LOGGER, StoreName + "到待机状态,压紧轴回原点,关闭舱门");
if (IsHasCompress_Axis)
{
StoreMove.WaitList.Add(WaitResultInfo.WaitShuoKe(Config.CompressAxis_Slv, 1, true));
ShuoKeControls.HomeMove(Config.CompressAxis_Slv, 1);
{
ACAxisHomeMove(Config.Comp_Axis);
}
//关闭舱门
CloseDoorAndWait();
......@@ -445,49 +406,28 @@ namespace OnlineStore.DeviceLibrary
default: break;
}
}
private void ComBeforeHomeMove()
}
private void ComMoveToPosition(int targetPosition )
{
if (IsHasCompress_Axis)
{
int relValue = -2000;
LogUtil.debug("压紧轴相对位置:" + relValue);
StoreMove.WaitList.Add(WaitResultInfo.WaitShuoKe(Config.CompressAxis_Slv, relValue, false));
ShuoKeControls.RelativeMove(Config.CompressAxis_Slv, relValue);
Thread.Sleep(100);
}
}
private void ComMoveToPosition(int targetPosition)
{
ComMoveToPosition(targetPosition, false);
}
private void ComMoveToPosition(int targetPosition, bool isNeedCheckSingle)
{
if (IsHasCompress_Axis)
{
LogUtil.debug("压紧轴绝对运动目标位置:" + targetPosition);
if (isNeedCheckSingle)
{
MeteringSignal.StartCheck(targetPosition, ShuoKeControls.GetABSPosition(Config.CompressAxis_Slv));
}
StoreMove.WaitList.Add(WaitResultInfo.WaitShuoKe(Config.CompressAxis_Slv, targetPosition, false));
ShuoKeControls.AbsMove(Config.CompressAxis_Slv, targetPosition);
Thread.Sleep(10);
{
ACAxisMove(Config.Comp_Axis, targetPosition, Config.Comp_Axis.TargetSpeed);
}
}
private void OpenDoorAndWait()
{
Thread.Sleep(60);
KNDIOMove(IO_Type.Door_Down, IO_VALUE.LOW);
KNDIOMove(IO_Type.Door_Up, IO_VALUE.HIGH);
IOManager.IOMove(IO_Type.Door_Down, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.Door_Up, IO_VALUE.HIGH);
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Door_Down, IO_VALUE.LOW));
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Door_Up, IO_VALUE.HIGH));
}
private void CloseDoorAndWait()
{
KNDIOMove(IO_Type.Door_Down, IO_VALUE.HIGH);
KNDIOMove(IO_Type.Door_Up, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.Door_Down, IO_VALUE.HIGH);
IOManager.IOMove(IO_Type.Door_Up, IO_VALUE.LOW);
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Door_Down, IO_VALUE.HIGH));
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Door_Up, IO_VALUE.LOW));
}
......@@ -521,7 +461,7 @@ namespace OnlineStore.DeviceLibrary
//进出轴原点返回完成,将进出轴的位置设置=0
AxisCountClear(Config.InOut_Axis);
ACAxisMove(Config.InOut_Axis, Config.InOutAxis_P1_Position, Config.InOutAxis_P1_Speed);
ComBeforeHomeMove();
//ComBeforeHomeMove();
//判断叉子没有料盘
//StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.TrayCheck_Fixture, IO_VALUE.LOW));
CloseDoorAndWait();
......@@ -538,10 +478,8 @@ namespace OnlineStore.DeviceLibrary
LogUtil.info(LOGGER, StoreName + "原点返回中 :压紧轴,旋转轴,上下轴开始原点返回");
StoreMove.NextMoveStep(StoreMoveStep.BOX_H_OtherAxisBack);
if (IsHasCompress_Axis)
{
StoreMove.WaitList.Add(WaitResultInfo.WaitShuoKe(Config.CompressAxis_Slv, 0, true));
ShuoKeControls.HomeMove(Config.CompressAxis_Slv, 1);
Thread.Sleep(60);
{
ACAxisHomeMove(Config.Comp_Axis);
}
ACAxisHomeMove(Config.Middle_Axis);
ACAxisHomeMove(Config.UpDown_Axis);
......@@ -568,7 +506,7 @@ namespace OnlineStore.DeviceLibrary
public bool RunAxis(bool isCheck)
{
KNDIOMove(IO_Type.Run_Signal, IO_VALUE.HIGH);
IOManager.IOMove(IO_Type.Run_Signal, IO_VALUE.HIGH);
Thread.Sleep(1000);
//打开所有轴
foreach (ConfigMoveAxis moveAxis in moveAxisList)
......@@ -598,7 +536,7 @@ namespace OnlineStore.DeviceLibrary
}
}
IsIntSlvBlock = true;
KNDIOMove(IO_Type.Axis_Brake, IO_VALUE.HIGH);
IOManager.IOMove(IO_Type.Axis_Brake, IO_VALUE.HIGH);
return true;
}
/// <summary>
......@@ -643,7 +581,7 @@ namespace OnlineStore.DeviceLibrary
public void CloseAllAxis()
{
LogUtil.info(StoreName + "关闭刹车,关闭伺服");
KNDIOMove(IO_Type.Axis_Brake, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.Axis_Brake, IO_VALUE.LOW);
foreach (ConfigMoveAxis axis in moveAxisList)
{
ACServerManager.ServoOff(axis.DeviceName, axis.GetAxisValue());
......@@ -651,7 +589,7 @@ namespace OnlineStore.DeviceLibrary
ACServerManager.ColsePort(axis.DeviceName);
}
Thread.Sleep(100);
KNDIOMove(IO_Type.Run_Signal, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.Run_Signal, IO_VALUE.LOW);
}
private int GetAlarmCodeByAxis(ConfigMoveAxis axis)
......@@ -693,10 +631,10 @@ namespace OnlineStore.DeviceLibrary
TimeSpan span = DateTime.Now - StartTime;
IsRun = false;
KNDManager.CloseAllDO();
IOManager.instance.CloseAllDO();
if (IsHasCompress_Axis)
{
ShuoKeControls.ClosePort();
//ShuoKeControls.ClosePort();
}
LogUtil.info(LOGGER, StoreName + ",停止运行,总运行时间:" + span.ToString());
......@@ -717,14 +655,14 @@ namespace OnlineStore.DeviceLibrary
if (alarmType.Equals(StoreAlarmType.AxisAlarm) | alarmType.Equals(StoreAlarmType.AxisMoveError))
{
LogUtil.error(LOGGER, StoreName + "轴报警,关闭刹车,停止运动,关闭轴,打开报警灯");
KNDIOMove(IO_Type.Axis_Brake, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.Axis_Brake, IO_VALUE.LOW);
StopMove(true);
}
else if (alarmType == StoreAlarmType.SuddenStop)
{
isInSuddenDown = true;
LogUtil.error(LOGGER, StoreName + "收到急停信号,关闭刹车,停止运动,关闭轴,打开报警灯 ");
KNDIOMove(IO_Type.Axis_Brake, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.Axis_Brake, IO_VALUE.LOW);
StoreMove.EndMove();
StopMove(true);
storeStatus = StoreStatus.SuddenStop;
......@@ -733,15 +671,11 @@ namespace OnlineStore.DeviceLibrary
{
isNoAirCheck = true;
LogUtil.error(LOGGER, StoreName + " 未检测到气压信号 ,打开刹车,停止运动,关闭轴,打开报警灯 ");
KNDIOMove(IO_Type.Axis_Brake, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.Axis_Brake, IO_VALUE.LOW);
StoreMove.EndMove();
StopMove(true);
storeStatus = StoreStatus.SuddenStop;
}
//if (alarmType != StoreAlarmType.IoSingleTimeOut)
//{
// StopMove();
//}
}
}
private bool InProcess = false;
//private DateTime preProcessTime = DateTime.Now;
......@@ -789,7 +723,7 @@ namespace OnlineStore.DeviceLibrary
private IO_VALUE preAirValue = IO_VALUE.HIGH;
private void AirCheckProcess()
{
IO_VALUE currAirValue = KNDIOValue(IO_Type.Airpressure_Check);
IO_VALUE currAirValue = IOManager.IOValue(IO_Type.Airpressure_Check);
if (isInSuddenDown)
{
return;
......@@ -864,15 +798,15 @@ namespace OnlineStore.DeviceLibrary
{
isNeedAlarmLed = true;
}
if (isNeedAlarmLed && KNDIOValue(IO_Type.Alarm_HddLed).Equals(IO_VALUE.LOW))
if (isNeedAlarmLed && IOManager.IOValue(IO_Type.Alarm_HddLed).Equals(IO_VALUE.LOW))
{
KNDIOMove(IO_Type.Alarm_HddLed, IO_VALUE.HIGH);
IOManager.IOMove(IO_Type.Alarm_HddLed, IO_VALUE.HIGH);
}
else
{
if (KNDIOValue(IO_Type.Alarm_HddLed).Equals(IO_VALUE.HIGH))
if (IOManager.IOValue(IO_Type.Alarm_HddLed).Equals(IO_VALUE.HIGH))
{
KNDIOMove(IO_Type.Alarm_HddLed, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.Alarm_HddLed, IO_VALUE.LOW);
}
}
......@@ -880,13 +814,13 @@ namespace OnlineStore.DeviceLibrary
//报警时绿灯和黄灯灭
if (isNeedAlarmLed)
{
if (KNDIOValue(IO_Type.AutoRun_HddLed).Equals(IO_VALUE.HIGH))
if (IOManager.IOValue(IO_Type.AutoRun_HddLed).Equals(IO_VALUE.HIGH))
{
KNDIOMove(IO_Type.AutoRun_HddLed, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.LOW);
}
if (KNDIOValue(IO_Type.RunSign_HddLed).Equals(IO_VALUE.HIGH))
if (IOManager.IOValue(IO_Type.RunSign_HddLed).Equals(IO_VALUE.HIGH))
{
KNDIOMove(IO_Type.AutoRun_HddLed, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.LOW);
}
return;
}
......@@ -894,32 +828,32 @@ namespace OnlineStore.DeviceLibrary
//绿灯闪
if ((StoreMove.MoveType.Equals(StoreMoveType.InStore) || StoreMove.MoveType.Equals(StoreMoveType.OutStore)
|| storeRunStatus.Equals(StoreRunStatus.HomeMoving) || storeRunStatus.Equals(StoreRunStatus.Reset))
&& KNDIOValue(IO_Type.AutoRun_HddLed).Equals(IO_VALUE.HIGH))
&& IOManager.IOValue(IO_Type.AutoRun_HddLed).Equals(IO_VALUE.HIGH))
{
KNDIOMove(IO_Type.AutoRun_HddLed, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.LOW);
}
else
{
//绿灯亮
KNDIOMove(IO_Type.AutoRun_HddLed, IO_VALUE.HIGH);
IOManager.IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.HIGH);
}
//黄灯
if (StoreMove.MoveType.Equals(StoreMoveType.InStore) || StoreMove.MoveType.Equals(StoreMoveType.OutStore) || TempOrHumidityIsAlarm || isTemp30M)
{
if (KNDIOValue(IO_Type.RunSign_HddLed).Equals(IO_VALUE.HIGH))
if (IOManager.IOValue(IO_Type.RunSign_HddLed).Equals(IO_VALUE.HIGH))
{
KNDIOMove(IO_Type.RunSign_HddLed, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.RunSign_HddLed, IO_VALUE.LOW);
}
else
{
KNDIOMove(IO_Type.RunSign_HddLed, IO_VALUE.HIGH);
IOManager.IOMove(IO_Type.RunSign_HddLed, IO_VALUE.HIGH);
}
}
else
{
if (KNDIOValue(IO_Type.RunSign_HddLed).Equals(IO_VALUE.HIGH))
if (IOManager.IOValue(IO_Type.RunSign_HddLed).Equals(IO_VALUE.HIGH))
{
KNDIOMove(IO_Type.RunSign_HddLed, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.RunSign_HddLed, IO_VALUE.LOW);
}
}
}
......@@ -936,7 +870,7 @@ namespace OnlineStore.DeviceLibrary
if (storeRunStatus.Equals(StoreRunStatus.Wait))
{
//取新的Io状态
IO_VALUE autoSingle = KNDIOValue(IO_Type.AutoRun_Signal);
IO_VALUE autoSingle = IOManager.IOValue(IO_Type.AutoRun_Signal);
if (ConfigAppSettings.GetIntValue(Setting_Init.App_AutoRun).Equals(1))
{
if (autoSingle.Equals(IO_VALUE.HIGH) && lastAutoRun.Equals(IO_VALUE.LOW))
......@@ -959,8 +893,8 @@ namespace OnlineStore.DeviceLibrary
else if (storeRunStatus >= StoreRunStatus.HomeMoving)
{
//取新的Io状态
IO_VALUE suddenBtn = KNDIOValue(IO_Type.SuddenStop_BTN);
IO_VALUE resetBtn = KNDIOValue(IO_Type.Reset_BTN);
IO_VALUE suddenBtn = IOManager.IOValue(IO_Type.SuddenStop_BTN);
IO_VALUE resetBtn = IOManager.IOValue(IO_Type.Reset_BTN);
//急停按钮
if (suddenBtn.Equals(IO_VALUE.LOW))
......@@ -999,74 +933,10 @@ namespace OnlineStore.DeviceLibrary
}
}
}
}
//ShowTimeLog("复位和启动按钮");
////检查运动轴报警
//if (storeRunStatus > StoreRunStatus.Wait && (!isInSuddenDown) )
//{
// ShowTimeLog("开始检测轴报警");
// CheckAxisAlarm();
// ShowTimeLog("轴报警检测完成");
//}
}
}
private object safetyInProcess = "";
/// <summary>
/// 光栅处理
/// </summary>
private void SafetyLightProcess()
{
if (Monitor.TryEnter(safetyInProcess))
{
try
{
//遮挡光栅信号
if (KNDIOValue(IO_Type.SafetyLightCurtains).Equals(IO_VALUE.LOW))
{
if (NeedCheckSafetyLight.Equals(1))
{
if (StoreMove.MoveType.Equals(StoreMoveType.OutStore) && StoreMove.MoveStep.Equals(StoreMoveStep.SO_10_DeviceToDoor))
{
NeedCheckSafetyLight = 2;
LOGGER.Info("出库SO_10_DeviceToDoor运动中,光栅被遮挡,停止进出轴运动");
ACServerManager.SuddenStop(Config.InOut_Axis.DeviceName, Config.InOut_Axis.GetAxisValue());
}
else if (StoreMove.MoveType.Equals(StoreMoveType.InStore) && StoreMove.MoveStep.Equals(StoreMoveStep.SI_05_DeviceToDoor))
{
NeedCheckSafetyLight = 2;
LOGGER.Info("入库SI_05_DeviceToDoor运动中,光栅被遮挡,停止进出轴运动");
ACServerManager.SuddenStop(Config.InOut_Axis.DeviceName, Config.InOut_Axis.GetAxisValue());
}
}
}
else
{
if (NeedCheckSafetyLight.Equals(2))
{
if (StoreMove.MoveType.Equals(StoreMoveType.OutStore) && StoreMove.MoveStep.Equals(StoreMoveStep.SO_10_DeviceToDoor))
{
LOGGER.Info("出库SO_10_DeviceToDoor运动中,光栅已恢复,继续进出轴运动");
SO_10_DeviceToDoorPro();
}
else if (StoreMove.MoveType.Equals(StoreMoveType.InStore) && StoreMove.MoveStep.Equals(StoreMoveStep.SI_05_DeviceToDoor))
{
LOGGER.Info("入库SI_05_DeviceToDoor运动中,光栅已恢复,继续进出轴运动");
SI_05_DeviceToDoor();
}
}
}
}
catch (Exception ex)
{
LogUtil.error("光栅处理出错:" + ex.ToString());
}
finally
{
Monitor.Exit(safetyInProcess);
}
}
}
public void TimerProcess()
{
try
......@@ -1082,10 +952,10 @@ namespace OnlineStore.DeviceLibrary
//判断是否需要出入库
if (StoreMove.MoveType.Equals(StoreMoveType.None) && alarmType.Equals(StoreAlarmType.None))
{
IO_VALUE checkIO = KNDIOValue(IO_Type.TrayCheck_Door);
int height = GetHeight();
IO_VALUE checkIO = IOManager.IOValue(IO_Type.TrayCheck_Door);
//判断料门口是否有料
if ((checkIO.Equals(IO_VALUE.HIGH)) && height > 0 && KNDIOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.LOW))
if ((checkIO.Equals(IO_VALUE.HIGH)) && IOManager.IOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.LOW))
{
if (IsScanCode)
{
......@@ -1094,15 +964,15 @@ namespace OnlineStore.DeviceLibrary
//检测到料盘,等待1.5秒后扫码
if (isWaitScan)
{
TimeSpan span = DateTime.Now - StartWaitScanTime;
if (span.TotalSeconds > 1)
{
isWaitScan = false;
IsScanCode = true;
LogUtil.info(StoreName + "检测到" + height + "寸料盘,开始扫码");
GetCameraCode();
}
//TimeSpan span = DateTime.Now - StartWaitScanTime;
//if (span.TotalSeconds > 1)
//{
// isWaitScan = false;
// IsScanCode = true;
// LogUtil.info(StoreName + "检测到" + height + "寸料盘,开始扫码");
// GetCameraCode();
//}
}
else
{
......@@ -1129,11 +999,7 @@ namespace OnlineStore.DeviceLibrary
LOGGER.Error(StoreName + "定时处理出错", ex);
}
}
//private void BeginScannering()
//{
// scanSocket.BeginScannering();
//}
private DateTime preIoTimerOutTime = DateTime.Now;
/// <summary>
......@@ -1303,22 +1169,24 @@ namespace OnlineStore.DeviceLibrary
public override void StopMove(bool IsCloseAxis)
{
KNDIOMove(IO_Type.Axis_Brake, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.Axis_Brake, IO_VALUE.LOW);
//运动版停止
ACServerManager.SuddenStop(Config.Middle_Axis.DeviceName, Config.Middle_Axis.GetAxisValue());
ACServerManager.SuddenStop(Config.UpDown_Axis.DeviceName, Config.UpDown_Axis.GetAxisValue());
ACServerManager.SuddenStop(Config.InOut_Axis.DeviceName, Config.InOut_Axis.GetAxisValue());
if (IsHasCompress_Axis)
{
ShuoKeControls.SuddownStop(Config.CompressAxis_Slv);
ACServerManager.SuddenStop(Config.Comp_Axis.DeviceName, Config.Comp_Axis.GetAxisValue());
//ShuoKeControls.SuddownStop(Config.CompressAxis_Slv);
}
else
{
if (Config.IsHasLocationCylinder >= 1)
{
//定位气缸停止
KNDIOMove(IO_Type.LocationCylinder_Down, IO_VALUE.LOW);
KNDIOMove(IO_Type.LocationCylinder_Up, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.LocationCylinder_Down, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.LocationCylinder_Up, IO_VALUE.LOW);
}
}
if (IsCloseAxis)
......@@ -1326,8 +1194,8 @@ namespace OnlineStore.DeviceLibrary
CloseAllAxis();
}
LogUtil.info(LOGGER, StoreName + "StopMove");
KNDIOMove(IO_Type.Door_Down, IO_VALUE.LOW);
KNDIOMove(IO_Type.Door_Up, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.Door_Down, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.Door_Up, IO_VALUE.LOW);
isInPro = false;
}
......@@ -1476,206 +1344,7 @@ namespace OnlineStore.DeviceLibrary
}
#endregion
#region Halcon扫码枪代码
public bool IsTestCamera = false;
//private System.Timers.Timer scanTimer = null;
public void GetCameraCode()
{
if (IsTestCamera && IsInScan())
{
LogUtil.info("上次扫码还未执行完毕,请稍后!");
return;
}
Task.Factory.StartNew(delegate { scanTimer_Elapsed(null, null); });
}
private string spiltStr = "##";
private void scanTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
int height = GetHeight();
DateTime date = DateTime.Now;
//scanTimer.Enabled = false;
KNDIOMove(IO_Type.CameraLight_Power, IO_VALUE.HIGH);
string outMsg = "";
string message = "";
List<string> codeList = CodeManager.CameraScan();
if (codeList.Count <= 0)
{
codeList = CodeManager.CameraScan();
}
//= 1 + 123.4x100.5 - 7x12 = CODE
foreach (string str in codeList)
{
string code = str;
if (str.ToUpper().StartsWith("FA"))
{
code = "=1+0x0-7x32" + "=" + code;
}
else
{
code = "=1+0x0-7x" + height + "=" + code;
}
message = message + code + spiltStr;
}
if (!outMsg.Equals(""))
{
CodeMsg = "盘尺寸错误,清理二维码【" + message + "】";
LogUtil.error("盘尺寸错误,清理二维码【" + message + "】");
message = "";
}
KNDIOMove(IO_Type.CameraLight_Power, IO_VALUE.LOW);
onCodeReceived(message);
}
private DateTime LastScanTime = DateTime.Now;
private bool IsInScan()
{
if (!IsScanCode)
{
return false;
}
TimeSpan span = DateTime.Now - LastScanTime;
if (span.TotalSeconds > 60)
{
//大于60秒表示超时了,可以重新开始扫码
return false;
}
return true;
}
#endregion
#region 高度传感器处理
public int GetSize()
{
if (Config.AIDI3_Addr <= 0 || Config.AIDI4_Addr <= 0)
{
return 7;
}
else if (Config.AIDI1_Addr <= 0 || Config.AIDI2_Addr <= 0)
{
return 13;
}
else
{
if (Get13Height() > 0)
{
return 13;
}
return 7;
}
}
public int Get7Height()
{
if (Config.AIDI1_Addr <= 0 || Config.AIDI2_Addr <= 0)
{
return 0;
}
int result = 0;
if (KNDIOValue(IO_Type.TrayCheck_Door).Equals(IO_VALUE.LOW))
{
return result;
}
double ai1Value = KNDAIManager.ConvertAI(KNDAIManager.GetAIValue(Config.AIDevice_IP, Config.AIDI1_Addr), Config.AIDI1_DefaultPosition);
double ai2Value = KNDAIManager.ConvertAI(KNDAIManager.GetAIValue(Config.AIDevice_IP, Config.AIDI2_Addr), Config.AIDI2_DefaultPosition);
double Value = Math.Round((ai1Value + ai2Value) / 2, 1);
if (Value > 14)
{
result = 16;
}
else if (Value >= 10)
{
result = 12;
}
else if (Value >= 4)
{
if (ai1Value >= 9 || ai2Value >= 9)
{
result = 12;
}
else
{
result = 8;
}
}
else
{
result = 0;
}
return result;
}
public int GetHeight()
{
if (Config.AIDI3_Addr <= 0 || Config.AIDI4_Addr <= 0)
{
return Get7Height();
}
else if (Config.AIDI1_Addr <= 0 || Config.AIDI2_Addr <= 0)
{
return Get13Height();
}
else
{
int value = Get13Height();
if (value > 0)
{
return value;
}
else
{
return Get7Height();
}
}
}
public int Get13Height()
{
if (Config.AIDI3_Addr <= 0 || Config.AIDI4_Addr <= 0)
{
return 0;
}
int result = 0;
if (KNDIOValue(IO_Type.TrayCheck_Door).Equals(IO_VALUE.LOW))
{
return result;
}
double ai1Value = KNDAIManager.ConvertAI(KNDAIManager.GetAIValue(Config.AIDevice_IP, Config.AIDI3_Addr), Config.AIDI3_DefaultPosition);
double ai2Value = KNDAIManager.ConvertAI(KNDAIManager.GetAIValue(Config.AIDevice_IP, Config.AIDI4_Addr), Config.AIDI4_DefaultPosition);
double Value = Math.Round((ai1Value + ai2Value) / 2, 1);
if (Value > 14)
{
result = 16;
}
else if (Value >= 10)
{
result = 12;
}
else if (Value >= 4)
{
if (ai1Value >= 9 || ai2Value >= 9)
{
result = 12;
}
else
{
result = 8;
}
}
else
{
result = 0;
}
return result;
}
#endregion
#region 温湿度处理
/// <summary>
......@@ -1732,7 +1401,7 @@ namespace OnlineStore.DeviceLibrary
LOGGER.Info("当前最大湿度:" + currMaxHumidity.ToString() + ",开始吹气湿度:" + startBlowHumidity + ",当前不在吹气中,且间隔超过" + Config.BlowAir_Interval + "分钟,开始吹气!");
IsInBlowing = true;
//Thread.Sleep(100);
KNDIOMove(IO_Type.StartOrStopBlow, IO_VALUE.HIGH);
IOManager.IOMove(IO_Type.StartOrStopBlow, IO_VALUE.HIGH);
LastBeginBlowTime = DateTime.Now;
LastEndBlowTime = DateTime.Now;
}
......@@ -1742,7 +1411,7 @@ namespace OnlineStore.DeviceLibrary
{
LOGGER.Info("当前最大湿度:" + currMaxHumidity.ToString() + ",停止吹气湿度:" + stopBlowHumidity + ",停止吹气!");
IsInBlowing = false;
KNDIOMove(IO_Type.StartOrStopBlow, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.StartOrStopBlow, IO_VALUE.LOW);
LastEndBlowTime = DateTime.Now;
}
if (IsInBlowing)
......@@ -1754,7 +1423,7 @@ namespace OnlineStore.DeviceLibrary
LOGGER.Info("已经吹气" + span.TotalMinutes + "分钟,超过配置的吹气时间" + Config.BlowAir_Time + "分钟,停止吹气!");
IsInBlowing = false;
//Thread.Sleep(100);
KNDIOMove(IO_Type.StartOrStopBlow, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.StartOrStopBlow, IO_VALUE.LOW);
LastEndBlowTime = DateTime.Now;
}
}
......@@ -1769,7 +1438,7 @@ namespace OnlineStore.DeviceLibrary
LOGGER.Info("当前温度【" + param.Temperate + "】超过最高温度【" + Max_Temperature + "】,开始报警!");
needAlarm = true;
//Thread.Sleep(100);
KNDIOMove(IO_Type.StartOrStopBlow, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.StartOrStopBlow, IO_VALUE.LOW);
}
else if (temp < Max_Temperature)
{
......@@ -1778,7 +1447,7 @@ namespace OnlineStore.DeviceLibrary
LOGGER.Info("不在吹气中,且当前温度【" + param.Temperate + "】低于【" + Max_Temperature + "】,关闭报警!");
TempOrHumidityIsAlarm = false;
//Thread.Sleep(100);
KNDIOMove(IO_Type.StartOrStopBlow, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.StartOrStopBlow, IO_VALUE.LOW);
}
}
else
......@@ -1880,7 +1549,7 @@ namespace OnlineStore.DeviceLibrary
}
if (CodeMsg.Equals(""))
{
if (storeRunStatus.Equals(StoreRunStatus.Runing) && KNDIOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.HIGH))
if (storeRunStatus.Equals(StoreRunStatus.Runing) && IOManager.IOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.HIGH))
{
boxStatus.msg = "叉子料盘检测有料,请检查";
lineOperation.msg = "叉子料盘检测有料,请检查";
......@@ -2058,42 +1727,7 @@ namespace OnlineStore.DeviceLibrary
}
#endregion
#region KNDIO
public void KNDIOMove(string ioType, IO_VALUE ioValue)
{
if (Config.StoreDOList.ContainsKey(ioType))
{
ConfigIO configIo = Config.StoreDOList[ioType];
KNDManager.WriteSingleDO(configIo.DeviceName, configIo.SlaveID, configIo.GetIOAddr(), ioValue);
Thread.Sleep(60);
}
else
{
LogUtil.error(LOGGER, StoreName + "没有DO=" + ioType);
}
}
public IO_VALUE KNDIOValue(string ioType)
{
IO_VALUE ioValue = IO_VALUE.LOW;
if (Config.StoreDIList.ContainsKey(ioType))
{
ConfigIO configIo = Config.StoreDIList[ioType];
ioValue = KNDManager.GetDIValue(configIo.DeviceName, configIo.SlaveID, configIo.GetIOAddr());
//UpdateDoValue(ioType, ioValue);
}
else if (Config.StoreDOList.ContainsKey(ioType))
{
ConfigIO configIo = Config.StoreDOList[ioType];
ioValue = KNDManager.GetDOValue(configIo.DeviceName, configIo.SlaveID, configIo.GetIOAddr());
}
else
{
LogUtil.error(LOGGER, StoreName + "没有DO=" + ioType);
}
return ioValue;
}
#endregion
}
}
\ No newline at end of file
......@@ -146,7 +146,7 @@ namespace OnlineStore.DeviceLibrary
}
else if (wait.WaitType == 2)
{
wait.IsEnd = KNDIOValue(wait.IoType).Equals(wait.IoValue);
wait.IsEnd = IOManager.IOValue(wait.IoType).Equals(wait.IoValue);
int timeOutMs = Config.IOSingle_TimerOut;
if (StoreMove.MoveStep == StoreMoveStep.SO_14_WaitTake)
{
......@@ -168,18 +168,18 @@ namespace OnlineStore.DeviceLibrary
}
else if (wait.WaitType == 7)
{
wait.IsEnd = (wait.HeightValue.Equals(GetHeight()));
if (wait.IsEnd)
{
LogUtil.debug("等待height=" + wait.HeightValue + "完成");
}
}
else if (wait.WaitType == 5)
{
string msg = "";
wait.IsEnd = ShuoKeIsEnd(wait, out msg);
NotOkMsg = NotOkMsg +" "+ msg;
//wait.IsEnd = (wait.HeightValue.Equals(GetHeight()));
//if (wait.IsEnd)
//{
// LogUtil.debug("等待height=" + wait.HeightValue + "完成");
//}
}
//else if (wait.WaitType == 5)
//{
// string msg = "";
// wait.IsEnd = ShuoKeIsEnd(wait, out msg);
// NotOkMsg = NotOkMsg +" "+ msg;
//}
if (wait.IsEnd)
{
if (StoreMove.OneWaitCanEndStep)
......@@ -210,54 +210,7 @@ namespace OnlineStore.DeviceLibrary
}
}
private static DateTime lastComRHomeTime = DateTime.Now;
private bool ShuoKeIsEnd(WaitResultInfo wait, out string msg)
{
//bool result = false;
msg = "";
if (wait.IsHomeMove)
{
//return ShuoKeControls.IsHomeMoveEnd(wait.SlvAddr, StoreMove.LastSetpTime, out msg);
ShuoKeInfo shuokeInfo = ShuoKeControls.GetStatus(wait.SlvAddr);
msg = " IsInMove【" + shuokeInfo.IsInMove + "】Org【" + shuokeInfo.Org + "】";
if (shuokeInfo.IsInMove.Equals(0) && shuokeInfo.Org.Equals(0) )
{
return true;
}
//如果是运动结束状态,但原点未到达,直接重新开始运动
else if (shuokeInfo.IsInMove.Equals(0) && shuokeInfo.Org.Equals(1) )
{
TimeSpan span = DateTime.Now - lastComRHomeTime;
if (span.TotalSeconds > 3 && (StoreMove.CanWhileCount > 0))
{
lastComRHomeTime = DateTime.Now;
StoreMove.CanWhileCount--;
LogUtil.error("压紧轴 已经停止运动但不在原点,重新回原点,剩余重新运动次数" + StoreMove.CanWhileCount);
ShuoKeControls.HomeMove(wait.SlvAddr);
}
}
}
else
{
bool isend = ShuoKeControls.IsMoveEnd(wait.SlvAddr, wait.TargetPosition, StoreMove.LastSetpTime, out msg);
if (isend)
{
bool isCheckOk = (MeteringSignal.TragetChangeCount <= MeteringSignal.SignalChangeCount);
if (isCheckOk || MeteringSignal.TragetChangeCount <= 0)
{
MeteringSignal.StopCheck();
return true;
}
else
{
msg = "压紧轴计量检测目标【" + MeteringSignal.TragetChangeCount + "】实际【" + MeteringSignal.SignalChangeCount + "】";
LogUtil.error("压紧轴已经停止运动,但是 " + msg);
return false ;
}
}
}
return false;
}
#endregion
......@@ -278,7 +231,7 @@ namespace OnlineStore.DeviceLibrary
LogUtil.error(LOGGER, StoreName + " 启动入库【" + posId + "】出错,找不到库位信息");
return;
}
if (KNDIOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.HIGH))
if (IOManager.IOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.HIGH))
{
LogUtil.error(LOGGER, StoreName + " 启动入库【" + posId + "】出错,叉子料盘检测有料");
return;
......@@ -333,7 +286,7 @@ namespace OnlineStore.DeviceLibrary
InStoreLog("入库:SI_05 叉子进入入料口,进出轴至P2(进料口取料点) ");
StoreMove.NextMoveStep(StoreMoveStep.SI_05_DeviceToDoor);
ACAxisMove(Config.InOut_Axis, StoreMove.MoveParam.MoveP.InOut_P2, Config.InOutAxis_P2_Speed);
NeedCheckSafetyLight = 1;
//NeedCheckSafetyLight = 1;
}
protected override void InStoreProcess()
{
......@@ -392,26 +345,16 @@ namespace OnlineStore.DeviceLibrary
}
}
else if (StoreMove.MoveStep == StoreMoveStep.SI_04_CompressWare)
{
//InStoreLog("入库:SI_05 叉子进入入料口,进出轴至P2(进料口取料点) ");
//StoreMove.NextMoveStep(StoreMoveStep.SI_05_DeviceToDoor);
//ACAxisMove(Config.InOut_Axis, moveP.InOut_P2, Config.InOutAxis_P2_Speed);
{
SI_05_DeviceToDoor();
}
else if (StoreMove.MoveStep == StoreMoveStep.SI_05_DeviceToDoor)
{
NeedCheckSafetyLight = 0;
//NeedCheckSafetyLight = 0;
InStoreLog("入库:SI_06 拿物品,压紧轴至P2(压紧点)) 升降轴至P7(进料口取料缓冲点) ");
StoreMove.NextMoveStep(StoreMoveStep.SI_06_DoorWarToDevice);
ComMoveToPosition(moveP.ComPress_P2,true);
//if (IsHasCompress_Axis)
//{
// ShuoKeControls.AbsMove(Config.CompressAxis_Slv, moveP.ComPress_P2);
// StoreMove.WaitList.Add(WaitResultInfo.WaitShuoKe(Config.CompressAxis_Slv, moveP.ComPress_P2, false));
// System.Threading.Thread.Sleep(600);
//}
ComMoveToPosition(moveP.ComPress_P2);
ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P7, Config.UpDownAxis_P7_Speed);
}
else if (StoreMove.MoveStep == StoreMoveStep.SI_06_DoorWarToDevice)
{
......@@ -429,8 +372,8 @@ namespace OnlineStore.DeviceLibrary
ACAxisMove(Config.Middle_Axis, moveP.Middle_P2, Config.MiddleAxis_P2_Speed);
ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P3, Config.UpDownAxis_P3_Speed);
//关闭舱门
KNDIOMove(IO_Type.Door_Down, IO_VALUE.HIGH);
KNDIOMove(IO_Type.Door_Up, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.Door_Down, IO_VALUE.HIGH);
IOManager.IOMove(IO_Type.Door_Up, IO_VALUE.LOW);
}
else
{
......@@ -446,8 +389,8 @@ namespace OnlineStore.DeviceLibrary
ACAxisMove(Config.Middle_Axis, moveP.Middle_P2, Config.MiddleAxis_P1_Speed);
ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P3, Config.UpDownAxis_P3_Speed);
//关闭舱门
KNDIOMove(IO_Type.Door_Down, IO_VALUE.HIGH);
KNDIOMove(IO_Type.Door_Up, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.Door_Down, IO_VALUE.HIGH);
IOManager.IOMove(IO_Type.Door_Up, IO_VALUE.LOW);
}
else if (StoreMove.MoveStep == StoreMoveStep.SI_09_MoveToBag)
{
......@@ -466,7 +409,7 @@ namespace OnlineStore.DeviceLibrary
}
else if (StoreMove.MoveStep == StoreMoveStep.SI_10_LocationCylinder_Down)
{
//KNDIOMove(IO_Type.LocationCylinder_Down, IO_VALUE.LOW);
//IOManager.IOMove(IO_Type.LocationCylinder_Down, IO_VALUE.LOW);
InStoreLog("入库:SI_11 叉子进入库位中,进出轴至P3(库位取放料点) ");
StoreMove.NextMoveStep(StoreMoveStep.SI_11_DeviceToBag);
ACAxisMove(Config.InOut_Axis, moveP.InOut_P3, Config.InOutAxis_P3_Speed);
......@@ -484,7 +427,7 @@ namespace OnlineStore.DeviceLibrary
//SendLineStatus(StoreID, posId, StoreStatus.InStoreEnd);
StoreMove.NextMoveStep(StoreMoveStep.SI_12_PutWareToBag);
ComMoveToPosition(moveP.ComPress_P3, true);
ComMoveToPosition(moveP.ComPress_P3);
ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P4, Config.UpDownAxis_P4_Speed);
}
......@@ -499,12 +442,7 @@ namespace OnlineStore.DeviceLibrary
{
InStoreLog("入库:SI_14 返回待机点,轴2/轴1/轴4动作至P1(待机点)),检测门关闭");
StoreMove.NextMoveStep(StoreMoveStep.SI_14_GoBack);
ComMoveToPosition(moveP.ComPress_P1);
//if (IsHasCompress_Axis)
//{
// ShuoKeControls.AbsMove(Config.CompressAxis_Slv, moveP.ComPress_P1);
// StoreMove.WaitList.Add(WaitResultInfo.WaitShuoKe(Config.CompressAxis_Slv, moveP.ComPress_P1, false));
//}
ComMoveToPosition(moveP.ComPress_P1);
ACAxisMove(Config.Middle_Axis, moveP.Middle_P1, Config.MiddleAxis_P1_Speed);
ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P1, Config.UpDownAxis_P1_Speed);
CloseDoorAndWait();
......@@ -523,8 +461,7 @@ namespace OnlineStore.DeviceLibrary
else
{
LogUtil.info(LOGGER, StoreName + " 入库,moveStatus=" + StoreMove.MoveStep + ",没有对应的处理!");
}
}
}
......@@ -547,7 +484,7 @@ namespace OnlineStore.DeviceLibrary
LogUtil.error(LOGGER, StoreName + " 启动出库【" + posId + "】出错,找不到库位信息");
return false ;
}
if (KNDIOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.HIGH))
if (IOManager.IOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.HIGH))
{
LogUtil.error(LOGGER, StoreName + " 启动出库【" + posId + "】出错,叉子料盘检测有料");
return false ;
......@@ -600,12 +537,7 @@ namespace OnlineStore.DeviceLibrary
{
StoreMove.NextMoveStep(StoreMoveStep.SO_03_ToBagPosition);
OutStoreLog("出库:SO_03 走到库位,压紧轴至P3(压紧前点) ,旋转轴至P2(库位点),升降轴至P5(库位出库前点)");
ComMoveToPosition(moveP.ComPress_P3);
//if (IsHasCompress_Axis)
//{
// ShuoKeControls.AbsMove(Config.CompressAxis_Slv, moveP.ComPress_P3);
// StoreMove.WaitList.Add(WaitResultInfo.WaitShuoKe(Config.CompressAxis_Slv, moveP.ComPress_P3, false));
//}
ComMoveToPosition(moveP.ComPress_P3);
ACAxisMove(Config.Middle_Axis, StoreMove.MoveParam.MoveP.Middle_P2, Config.MiddleAxis_P2_Speed);
ACAxisMove(Config.UpDown_Axis, StoreMove.MoveParam.MoveP.UpDown_P5, Config.UpDownAxis_P5_Speed);
}
......@@ -619,17 +551,9 @@ namespace OnlineStore.DeviceLibrary
{
OutStoreLog("出库:SO_05 拿起物品,升降轴至P6(库位出料缓冲点),压紧轴至P2(压紧点) ");
StoreMove.NextMoveStep(StoreMoveStep.SO_05_BagWareToDevice);
//如果是7*32的料格,升降轴先上升,压紧轴再运动
//if (StoreMove.MoveParam.GetACPosition().BagHigh.Equals(32) && StoreMove.MoveParam.GetACPosition().BagWidth.Equals(7))
//{
// ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P6, Config.UpDownAxis_P6_Speed);
// ComMoveToPosition(moveP.ComPress_P2, true);
//}
//else
//{
ComMoveToPosition(moveP.ComPress_P2, true);
ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P6, Config.UpDownAxis_P6_Speed);
//}
ComMoveToPosition(moveP.ComPress_P2);
ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P6, Config.UpDownAxis_P6_Speed);
}
else if (StoreMove.MoveStep == StoreMoveStep.SO_05_BagWareToDevice)
{
......@@ -646,7 +570,7 @@ namespace OnlineStore.DeviceLibrary
}
else if (StoreMove.MoveStep == StoreMoveStep.SO_06_BagDeviceBack)
{
if (KNDIOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.LOW))
if (IOManager.IOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.LOW))
{
string posId = StoreMove.MoveParam != null ? StoreMove.MoveParam.PositionNum : "";
CodeMsg = "出库[" + posId + "]叉子从库位退出后,未检测到料盘有料";
......@@ -673,18 +597,12 @@ namespace OnlineStore.DeviceLibrary
StoreMove.NextMoveStep(StoreMoveStep.SO_08_ToDoorPosition);
OutStoreLog("出库:SO_08 走到料门口,旋转轴至P1(待机点)升降轴至P2(进料口出料前点) ");
ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P2, Config.UpDownAxis_P2_Speed);
ACAxisMove(Config.Middle_Axis, moveP.Middle_P1, Config.MiddleAxis_P1_Speed);
//此处需要等待box门口没有盘
//StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.TrayCheck_Door, IO_VALUE.LOW));
//StoreMove.WaitList.Add(WaitResultInfo.WaitHeight(0));
//打开舱门
//OpenDoorAndWait();
//StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.TrayCheck_2, IO_VALUE.LOW));
ACAxisMove(Config.Middle_Axis, moveP.Middle_P1, Config.MiddleAxis_P1_Speed);
}
else if (StoreMove.MoveStep == StoreMoveStep.SO_08_ToDoorPosition)
{
if (IsHasCompress_Axis|| Config.IsHasLocationCylinder.Equals(0))
if (IsHasCompress_Axis || Config.IsHasLocationCylinder.Equals(0))
{
//SO_10_DeviceToDoorPro();
StoreMove.NextMoveStep(StoreMoveStep.SO_091_WaitNoTray);
......@@ -697,7 +615,7 @@ namespace OnlineStore.DeviceLibrary
{
StoreMove.NextMoveStep(StoreMoveStep.SO_09_LocationCylinder_Down);
OutStoreLog("出库:SO_09 定位气缸退回,定位气缸退回 ");
LocationDownAndWait();
LocationDownAndWait();
}
}
//此处需要等待移栽没有工作,才能把盘放入出料口
......@@ -718,13 +636,8 @@ namespace OnlineStore.DeviceLibrary
{
OutStoreLog("出库:SO_11 放下物品,升降轴至P8(进料口出料缓冲点) ");
StoreMove.NextMoveStep(StoreMoveStep.SO_11_DevicePutWare);
NeedCheckSafetyLight = 0;
ComMoveToPosition(moveP.ComPress_P1,true);
//if (IsHasCompress_Axis)
//{
// ShuoKeControls.AbsMove(Config.CompressAxis_Slv, moveP.ComPress_P1);
// StoreMove.WaitList.Add(WaitResultInfo.WaitShuoKe(Config.CompressAxis_Slv, moveP.ComPress_P1, false));
//}
//NeedCheckSafetyLight = 0;
ComMoveToPosition(moveP.ComPress_P1);
ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P8, Config.UpDownAxis_P8_Speed);
}
else if (StoreMove.MoveStep == StoreMoveStep.SO_11_DevicePutWare)
......@@ -749,7 +662,7 @@ namespace OnlineStore.DeviceLibrary
}
int ms = OutStoreWaitSeconds * 1000;
StoreMove.NextMoveStep(StoreMoveStep.SO_14_WaitTake);
OutStoreLog("出库:SO_14_WaitTake 等待拿走物品,最多等待"+OutStoreWaitSeconds+"秒");
OutStoreLog("出库:SO_14_WaitTake 等待拿走物品,最多等待" + OutStoreWaitSeconds + "秒");
StoreMove.WaitList.Add(WaitResultInfo.WaitTime(ms));
//StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.TrayCheck_Door, IO_VALUE.LOW));
StoreMove.WaitList.Add(WaitResultInfo.WaitHeight(0));
......@@ -778,7 +691,7 @@ namespace OnlineStore.DeviceLibrary
StoreMove.NextMoveStep(StoreMoveStep.SO_10_DeviceToDoor);
OutStoreLog("出库:SO_10 叉子进出料口,进出轴至P2(进料口取料点) ");
ACAxisMove(Config.InOut_Axis, moveP.InOut_P2, Config.InOutAxis_P2_Speed);
NeedCheckSafetyLight = 1;
//NeedCheckSafetyLight = 1;
}
public bool InOutAxisCanMove()
{
......@@ -787,10 +700,10 @@ namespace OnlineStore.DeviceLibrary
return true;
}
if (KNDIOValue(IO_Type.LocationCylinder_Down).Equals(IO_VALUE.HIGH)
&& KNDIOValue(IO_Type.LocationCylinder_Up).Equals(IO_VALUE.LOW)
&& KNDIOValue(IO_Type.LocationCylinder2_Down).Equals(IO_VALUE.HIGH)
&& KNDIOValue(IO_Type.LocationCylinder2_Up).Equals(IO_VALUE.LOW))
if (IOManager.IOValue(IO_Type.LocationCylinder_Down).Equals(IO_VALUE.HIGH)
&& IOManager.IOValue(IO_Type.LocationCylinder_Up).Equals(IO_VALUE.LOW)
&& IOManager.IOValue(IO_Type.LocationCylinder2_Down).Equals(IO_VALUE.HIGH)
&& IOManager.IOValue(IO_Type.LocationCylinder2_Up).Equals(IO_VALUE.LOW))
{
return true;
}
......@@ -800,8 +713,8 @@ namespace OnlineStore.DeviceLibrary
{
if (Config.IsHasLocationCylinder>=1)
{
KNDIOMove(IO_Type.LocationCylinder_Up, IO_VALUE.HIGH);
KNDIOMove(IO_Type.LocationCylinder_Down, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.LocationCylinder_Up, IO_VALUE.HIGH);
IOManager.IOMove(IO_Type.LocationCylinder_Down, IO_VALUE.LOW);
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.LocationCylinder_Up, IO_VALUE.HIGH));
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.LocationCylinder_Down, IO_VALUE.LOW));
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.LocationCylinder2_Up, IO_VALUE.HIGH));
......@@ -812,8 +725,8 @@ namespace OnlineStore.DeviceLibrary
{
if (Config.IsHasLocationCylinder>=1)
{
KNDIOMove(IO_Type.LocationCylinder_Down, IO_VALUE.HIGH);
KNDIOMove(IO_Type.LocationCylinder_Up, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.LocationCylinder_Down, IO_VALUE.HIGH);
IOManager.IOMove(IO_Type.LocationCylinder_Up, IO_VALUE.LOW);
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.LocationCylinder_Down, IO_VALUE.HIGH));
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.LocationCylinder_Up, IO_VALUE.LOW));
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.LocationCylinder2_Down, IO_VALUE.HIGH));
......@@ -845,11 +758,7 @@ namespace OnlineStore.DeviceLibrary
}
if (storeMoveType.Equals(StoreMoveType.InStore))
{
int newIndex = autoPositionIndex - 1;
//if (autoJiange == 0)
//{
// newIndex = autoPositionIndex;
//}
int newIndex = autoPositionIndex - 1;
if (newIndex < 0)
{
if (AutoStartIndex >= 0 && AutoStartIndex < PositionNumList.Count)
......
......@@ -28,24 +28,24 @@ namespace OnlineStore.DeviceLibrary
public StoreManager()
{
}
public static bool OpenShuoKe(AC_SA_BoxBean box)
{
//打开硕科步进驱动器端口
Parity parity = (Parity)box.Config.CompressAxis_PortParity;
StopBits bit = (StopBits)box.Config.CompressAxis_StopBits;
bool result = ShuoKeControls.InitPort(box.Config.CompressAxis_PortName, box.Config.CompressAxis_PortBaudrate,
box.Config.CompressAxis_PortParity, 8, bit);
if (result)
{
LogUtil.info(box.StoreName + "打开硕科步进控制器【" + box.Config.CompressAxis_PortName + "】成功");
return true;
}
else
{
LogUtil.error(box.StoreName + "打开硕科步进控制器【" + box.Config.CompressAxis_PortName + "】失败,启动失败!");
return false;
}
}
//public static bool OpenShuoKe(AC_SA_BoxBean box)
//{
// //打开硕科步进驱动器端口
// Parity parity = (Parity)box.Config.CompressAxis_PortParity;
// StopBits bit = (StopBits)box.Config.CompressAxis_StopBits;
// bool result = ShuoKeControls.InitPort(box.Config.CompressAxis_PortName, box.Config.CompressAxis_PortBaudrate,
// box.Config.CompressAxis_PortParity, 8, bit);
// if (result)
// {
// LogUtil.info(box.StoreName + "打开硕科步进控制器【" + box.Config.CompressAxis_PortName + "】成功");
// return true;
// }
// else
// {
// LogUtil.error(box.StoreName + "打开硕科步进控制器【" + box.Config.CompressAxis_PortName + "】失败,启动失败!");
// return false;
// }
//}
public static void CheckEnum(Type type)
{
if (type.IsEnum)
......
using log4net;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
namespace OnlineStore.DeviceLibrary
{
public abstract class KTK_DeviceBase
{
/// <summary>
/// 料仓单个调试状态(默认不是调试状态)
/// </summary>
public bool IsDebug = false;
public Dictionary<string, ConfigIO> DIList { get; set; }
public Dictionary<string, ConfigIO> DOList { get; set; }
/// <summary>
///1=设备联机(正常就绪)(入库后,BOX恢复原始状态)(出库后,移载装置恢复原始状态),
///2=急停,3=故障,4=警告,5=调试
/// 6=入库执行中,7=入仓完成,8=入仓失败
/// 9=出库执行,10=出仓完成,11=出库失败
/// </summary>
public StoreStatus storeStatus = StoreStatus.ResetMove;
/// <summary>
/// 提示消息,一般发给服务器后清空(LineBean表示报警提示消息,BoxBean表示出入库失败的原因记录)
/// </summary>
public string WarnMsg = "";
/// <summary>
/// 日志颜色
/// </summary>
protected static Color storeMoveColor = Color.Blue;
protected static readonly ILog LOGGER = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public string StoreName { get; set; }
public int StoreID { get; set; }
/// <summary>
/// 料仓状态
/// </summary>
private StoreRunStatus storerunstatus = StoreRunStatus.Wait;
/// <summary>
/// 定时器
/// </summary>
protected System.Timers.Timer mainTimer;
private bool isInit = false;
/// <summary>
/// 初始化
/// </summary>
protected virtual void Init()
{
if (!isInit)
{
StoreMove = new StoreMoveInfo(StoreID);
mainTimer = new System.Timers.Timer();
mainTimer.Enabled = false;
mainTimer.Interval = 300;
mainTimer.Elapsed += timersTimer_Elapsed;
mainTimer.AutoReset = true;
isInit = true;
}
}
public StoreRunStatus storeRunStatus
{
get
{
return storerunstatus;
}
set
{
StoreRunStatus oldStatus = storerunstatus;
storerunstatus = value;
}
}
/// <summary>
/// 移动信息
/// </summary>
public StoreMoveInfo StoreMove = null;
/// <summary>
/// 定时处理,监听信号,监听IO
/// </summary>
protected abstract void timersTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e);
#region 出库
/// <summary>
/// 开始出库运动
/// </summary>
public abstract bool StartOutStoreMove(InOutStoreParam param);
protected abstract void OutStoreProcess();
#endregion
#region 入库
/// <summary>
/// 开始入库移动移动
/// </summary>
public abstract void StartInStoreMove(InOutStoreParam param);
protected abstract void InStoreProcess();
#endregion
public string GetRunStr()
{
string sta = "运行中";
string aa = "";
switch (storeRunStatus)
{
case StoreRunStatus.Busy:
sta = "忙碌";
break;
case StoreRunStatus.HomeMoving:
sta = "原点返回";
break;
case StoreRunStatus.Reset:
sta = "重置";
break;
case StoreRunStatus.Runing:
sta = "运行中";
break;
case StoreRunStatus.Wait:
sta = "等待启动";
break;
}
if (storeRunStatus > StoreRunStatus.Wait)
{
//"0":"急停中", "1":"设备联机", "2":"故障中", "3":"入库执行中", "4":"出库执行中", 5":"料盘入仓位完成", "6":"料盘出仓位完成", 7":"设备调试中",
switch (storeStatus)
{
case StoreStatus.Debugging:
aa = "设备调试中";
break;
case StoreStatus.InStoreEnd:
aa = "料盘入仓位完成";
break;
case StoreStatus.InStoreExecute:
aa = "入库执行中";
break;
case StoreStatus.InTrouble:
aa = "故障中";
break;
case StoreStatus.OutStoreBoxEnd:
aa = "料盘出仓位完成";
break;
case StoreStatus.OutStoreExecute:
aa = "出库执行中";
break;
case StoreStatus.StoreOnline:
aa = "设备联机";
break;
case StoreStatus.SuddenStop:
aa = "急停中";
break;
case StoreStatus.OutMoveExecute:
aa = "出库完成";
break;
case StoreStatus.InStoreFaild:
aa = "入库失败(" + WarnMsg + ")";
break;
case StoreStatus.OutStoreFaild:
aa = "出库失败(" + WarnMsg + ")";
break;
}
if (!aa.Equals(""))
{
return sta + "_" + aa;
}
else
{
return sta;
}
}
else
{
return sta;
}
}
}
}
......@@ -7,16 +7,46 @@ using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
namespace OnlineStore.DeviceLibrary
{
/// <summary>
/// 康泰克单台自动料仓
/// </summary>
public abstract class KTK_Store : KTK_DeviceBase
public abstract class KTK_Store
{
/// <summary>
///1=设备联机(正常就绪)(入库后,BOX恢复原始状态)(出库后,移载装置恢复原始状态),
///2=急停,3=故障,4=警告,5=调试
/// 6=入库执行中,7=入仓完成,8=入仓失败
/// 9=出库执行,10=出仓完成,11=出库失败
/// </summary>
public StoreStatus storeStatus = StoreStatus.ResetMove;
/// <summary>
/// 提示消息,一般发给服务器后清空(LineBean表示报警提示消息,BoxBean表示出入库失败的原因记录)
/// </summary>
public string WarnMsg = "";
/// <summary>
/// 日志颜色
/// </summary>
protected static Color storeMoveColor = Color.Blue;
protected static readonly ILog LOGGER = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public string StoreName { get; set; }
public int StoreID { get; set; }
/// <summary>
/// 料仓状态
/// </summary>
private StoreRunStatus storerunstatus = StoreRunStatus.Wait;
/// <summary>
/// 定时器
/// </summary>
protected System.Timers.Timer mainTimer;
private bool isInit = false;
protected bool IsDebug = false;
public KTK_Store()
{
}
......@@ -24,14 +54,7 @@ namespace OnlineStore.DeviceLibrary
/// 开始运行的时间
/// </summary>
public DateTime StartTime { get; set; }
public DateTime statusTime = DateTime.Now;
/// <summary>
/// 伺服运行时间列表,key=轴,key=开始时间,value=结束时间
/// </summary>
//public Dictionary<int, Dictionary<DateTime, DateTime>> AxisRunTimeMap = new Dictionary<int, Dictionary<DateTime, DateTime>>();
//public Dictionary<int, DateTime> AxisLastStartTime = new Dictionary<int, DateTime>();
/// <summary>
/// 最后一次气压检测变为0的时间
/// </summary>
......@@ -45,7 +68,7 @@ namespace OnlineStore.DeviceLibrary
/// </summary>
public bool isNoAirCheck = false;
protected int NeedCheckSafetyLight = 0;
//protected int NeedCheckSafetyLight = 0;
/// <summary>
/// 是否再报警中
/// </summary>
......@@ -61,7 +84,7 @@ namespace OnlineStore.DeviceLibrary
public object lastDiListLock = "";
public void addLastDI(string type, IO_VALUE value)
{
try
{
lock (lastDiListLock)
......@@ -78,8 +101,8 @@ namespace OnlineStore.DeviceLibrary
LOGGER.Error(ex.ToString());
}
}
/// <summary>
/// 获取料仓运行的时间
/// </summary>
......@@ -94,8 +117,8 @@ namespace OnlineStore.DeviceLibrary
{
return new TimeSpan(0);
}
}
}
protected void AddAxisMoveTime(ConfigMoveAxis axis)
{
//int axisNo = axis.GetAxisValue();
......@@ -105,8 +128,8 @@ namespace OnlineStore.DeviceLibrary
//}
//AxisLastStartTime.Add(axisNo, DateTime.Now);
}
/// <summary>
/// 运动处理
/// </summary>
......@@ -140,12 +163,13 @@ namespace OnlineStore.DeviceLibrary
break;
default: break;
}
}catch(Exception ex)
}
catch (Exception ex)
{
LogUtil.error("BusyMoveProcess出错:"+ex.ToString());
LogUtil.error("BusyMoveProcess出错:" + ex.ToString());
}
isInPro = false;
}
}
protected void SaveAlarmInfo(StoreAlarmType alarmType, string alarmDetial, string alarmMsg, StoreMoveType storeMoveType)
{
alarmMsg = alarmMsg.Replace(StoreName, "");
......@@ -190,7 +214,7 @@ namespace OnlineStore.DeviceLibrary
/// <summary>
/// 开始运行
/// </summary>
public abstract bool StartRun();
public abstract bool StartRun();
/// <summary>
/// 停止运行
/// </summary>
......@@ -204,12 +228,12 @@ namespace OnlineStore.DeviceLibrary
/// 重置(夹料装置状态不变)
/// </summary>
public abstract void Reset();
/// <summary>
/// 停止所有运动
/// </summary>
public abstract void StopMove( bool IsCloseAxis);
public abstract void StopMove(bool IsCloseAxis);
/// <summary>
/// 重置处理
/// </summary>
......@@ -228,7 +252,7 @@ namespace OnlineStore.DeviceLibrary
LogUtil.info(LOGGER, moveAxis.DisplayStr + "speed[" + moveAxis.TargetSpeed + "]开始原点返回");
StoreMove.WaitList.Add(WaitResultInfo.WaitAxis(moveAxis, true));
AddAxisMoveTime(moveAxis);
ACServerManager.HomeMove(moveAxis.DeviceName, (short)moveAxis.GetAxisValue(), moveAxis.HomeHighSpeed);
ACServerManager.HomeMove(moveAxis.DeviceName, (short)moveAxis.GetAxisValue(), moveAxis.HomeHighSpeed);
}
/// <summary>
......@@ -239,7 +263,7 @@ namespace OnlineStore.DeviceLibrary
StoreMove.WaitList.Add(WaitResultInfo.WaitAxis(moveAxis, targetPosition, targetSpeed));
moveAxis.TargetPosition = targetPosition;
AddAxisMoveTime(moveAxis);
ACServerManager.AbsMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), targetPosition,targetSpeed);
ACServerManager.AbsMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), targetPosition, targetSpeed);
}
/// <summary>
......@@ -252,20 +276,20 @@ namespace OnlineStore.DeviceLibrary
short axisNo = moveAxis.GetAxisValue();
//如果是进出轴,并且光栅被遮挡,直接返回false
if (NeedCheckSafetyLight.Equals(2))
{
if (StoreMove.MoveStep.Equals(StoreMoveStep.SO_10_DeviceToDoor) ||
StoreMove.MoveStep.Equals(StoreMoveStep.SI_05_DeviceToDoor))
{
return false;
}
}
//if (NeedCheckSafetyLight.Equals(2))
//{
// if (StoreMove.MoveStep.Equals(StoreMoveStep.SO_10_DeviceToDoor) ||
// StoreMove.MoveStep.Equals(StoreMoveStep.SI_05_DeviceToDoor))
// {
// return false;
// }
//}
bool isOk = ACServerManager.GetBusyStatus(deviceName, axisNo).Equals(0);
int outCount = ACServerManager.GetActualtPosition(deviceName, axisNo);
int errorCount = Math.Abs(outCount - targetPosition);
if (isOk)
{
{
if (errorCount <= moveAxis.CanErrorCountMax)
{
return true;
......@@ -274,7 +298,7 @@ namespace OnlineStore.DeviceLibrary
if (StoreMove.CanWhileCount > 0)
{
LogUtil.error(LOGGER, moveAxis.DisplayStr + "目标位置[" + targetPosition + "]当前位置[" + outCount +
"],误差过大,重新开始运动,剩余[" + StoreMove.CanWhileCount + "]次");
"],误差过大,重新开始运动,剩余[" + StoreMove.CanWhileCount + "]次");
ACServerManager.AbsMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), targetPosition, targetSpeed);
StoreMove.CanWhileCount--;
}
......@@ -311,7 +335,7 @@ namespace OnlineStore.DeviceLibrary
{
msg = StoreName + " storeMoveStep=" + StoreMove.MoveStep + moveAxis.DisplayStr + "收到原点完成信号,当前位置[" + outCount + "],误差过大,需要报警";
LogUtil.error(LOGGER, msg);
}
}
}
return false;
}
......@@ -321,5 +345,139 @@ namespace OnlineStore.DeviceLibrary
}
/// <summary>
/// 初始化
/// </summary>
protected virtual void Init()
{
if (!isInit)
{
StoreMove = new StoreMoveInfo(StoreID);
mainTimer = new System.Timers.Timer();
mainTimer.Enabled = false;
mainTimer.Interval = 300;
mainTimer.Elapsed += timersTimer_Elapsed;
mainTimer.AutoReset = true;
isInit = true;
}
}
public StoreRunStatus storeRunStatus
{
get
{
return storerunstatus;
}
set
{
StoreRunStatus oldStatus = storerunstatus;
storerunstatus = value;
}
}
/// <summary>
/// 移动信息
/// </summary>
public StoreMoveInfo StoreMove = null;
/// <summary>
/// 定时处理,监听信号,监听IO
/// </summary>
protected abstract void timersTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e);
#region 出库
/// <summary>
/// 开始出库运动
/// </summary>
public abstract bool StartOutStoreMove(InOutStoreParam param);
protected abstract void OutStoreProcess();
#endregion
#region 入库
/// <summary>
/// 开始入库移动移动
/// </summary>
public abstract void StartInStoreMove(InOutStoreParam param);
protected abstract void InStoreProcess();
#endregion
public string GetRunStr()
{
string sta = "运行中";
string aa = "";
switch (storeRunStatus)
{
case StoreRunStatus.Busy:
sta = "忙碌";
break;
case StoreRunStatus.HomeMoving:
sta = "原点返回";
break;
case StoreRunStatus.Reset:
sta = "重置";
break;
case StoreRunStatus.Runing:
sta = "运行中";
break;
case StoreRunStatus.Wait:
sta = "等待启动";
break;
}
if (storeRunStatus > StoreRunStatus.Wait)
{
//"0":"急停中", "1":"设备联机", "2":"故障中", "3":"入库执行中", "4":"出库执行中", 5":"料盘入仓位完成", "6":"料盘出仓位完成", 7":"设备调试中",
switch (storeStatus)
{
case StoreStatus.Debugging:
aa = "设备调试中";
break;
case StoreStatus.InStoreEnd:
aa = "料盘入仓位完成";
break;
case StoreStatus.InStoreExecute:
aa = "入库执行中";
break;
case StoreStatus.InTrouble:
aa = "故障中";
break;
case StoreStatus.OutStoreBoxEnd:
aa = "料盘出仓位完成";
break;
case StoreStatus.OutStoreExecute:
aa = "出库执行中";
break;
case StoreStatus.StoreOnline:
aa = "设备联机";
break;
case StoreStatus.SuddenStop:
aa = "急停中";
break;
case StoreStatus.OutMoveExecute:
aa = "出库完成";
break;
case StoreStatus.InStoreFaild:
aa = "入库失败(" + WarnMsg + ")";
break;
case StoreStatus.OutStoreFaild:
aa = "出库失败(" + WarnMsg + ")";
break;
}
if (!aa.Equals(""))
{
return sta + "_" + aa;
}
else
{
return sta;
}
}
else
{
return sta;
}
}
}
}
......@@ -17,16 +17,7 @@ namespace OnlineStore.LoadCSVLibrary
{
}
///// <summary>
///// 温湿度传感器地址/COM口配置
///// </summary>
//[ConfigProAttribute("TemperateServer_Port")]
//public int TemperateServer_Port { get; set; }
///// <summary>
///// 温湿度 传感器地址
///// </summary>
//[ConfigProAttribute("Temperate_ServerAddress")]
//public string Temperate_Serveraddress { get; set; }
/// <summary>
/// 预警温度
/// </summary>
......@@ -318,13 +309,7 @@ namespace OnlineStore.LoadCSVLibrary
/// </summary>
[ConfigProAttribute("UpDownAxis_DoorIBPosition_P8")]
public int UpDownAxis_DoorIBPosition_P8 { get; set; }
///// <summary>
///// 进出轴进料口取料点 P2
///// </summary>
//[ConfigProAttribute("InOutAxis_DoorPosition_P2")]
//public int InOutAxis_DoorPosition_P2 { get; set; }
/// <summary>
/// PRO 旋转轴(轴1)P1 待机原位点 MiddleAxis_P1_Position
/// </summary>
......@@ -368,62 +353,44 @@ namespace OnlineStore.LoadCSVLibrary
/// </summary>
[ConfigProAttribute("InOut_Axis")]
public ConfigMoveAxis InOut_Axis { get; set; }
/// <summary>
/// PRO 硕科步进电机(压紧轴)控制端口号 CompressAxis_PortName COM4
/// </summary>
[ConfigProAttribute("CompressAxis_PortName")]
public string CompressAxis_PortName { get; set; }
/// <summary>
/// PRO 硕科步进电机(压紧轴)控制波特率 CompressAxis_PortBaudrate 9600
/// </summary>
[ConfigProAttribute("CompressAxis_PortBaudrate")]
public int CompressAxis_PortBaudrate { get; set; }
/// <summary>
/// PRO 硕科步进电机(压紧轴)控制奇偶校验 CompressAxis_PortParity 2
/// 轴3压紧轴
/// </summary>
[ConfigProAttribute("CompressAxis_PortParity")]
public int CompressAxis_PortParity { get; set; }
/// <summary>
/// PRO 硕科步进电机(压紧轴)控制停止位 CompressAxis_StopBits 1
/// </summary>
[ConfigProAttribute("CompressAxis_StopBits")]
public int CompressAxis_StopBits { get; set; }
/// <summary>
/// PRO 硕科步进电机(压紧轴)控制初速度 CompressAxis_StartSpeed 100
/// </summary>
[ConfigProAttribute("CompressAxis_StartSpeed")]
public int CompressAxis_StartSpeed { get; set; }
[ConfigProAttribute("Comp_Axis")]
public ConfigMoveAxis Comp_Axis { get; set; }
/// <summary>
/// PRO 硕科步进电机(压紧轴)控制最大速度 CompressAxis_MaxSpeed 10000
/// PRO (轴四)压紧轴目标速度 CompAxis_TargetSpeed 100
/// </summary>
[ConfigProAttribute("CompressAxis_MaxSpeed")]
public int CompressAxis_MaxSpeed { get; set; }
[ConfigProAttribute("CompAxis_TargetSpeed")]
public int CompAxis_TargetSpeed { get; set; }
/// <summary>
/// PRO 硕科步进电机(压紧轴)控制末速度 CompressAxis_EndSpeed 10000
/// PRO (轴四)压紧轴加速度 CompAxis_AddSpeed 300
/// </summary>
[ConfigProAttribute("CompressAxis_EndSpeed")]
public int CompressAxis_EndSpeed { get; set; }
[ConfigProAttribute("CompAxis_AddSpeed")]
public short CompAxis_AddSpeed { get; set; }
/// <summary>
/// PRO 硕科步进电机(压紧轴)控制加速度 CompressAxis_AddSpeed 5000
/// PRO (轴四)压紧轴减速度 CompAxis_DelSpeed 300
/// </summary>
[ConfigProAttribute("CompressAxis_AddSpeed")]
public int CompressAxis_AddSpeed { get; set; }
[ConfigProAttribute("CompAxis_DelSpeed")]
public short CompAxis_DelSpeed { get; set; }
/// <summary>
/// PRO 硕科步进电机(压紧轴)控制减速度 CompressAxis_DelSpeed 1000
/// PRO (轴四)压紧轴原点低速 CompAxis_HomeLowSpeed 20
/// </summary>
[ConfigProAttribute("CompressAxis_DelSpeed")]
public int CompressAxis_DelSpeed { get; set; }
[ConfigProAttribute("CompAxis_HomeLowSpeed")]
public int CompAxis_HomeLowSpeed { get; set; }
/// <summary>
/// PRO 硕科步进电机(压紧轴)控制归零速度(原点返回速度) CompressAxis_HomeSpeed 10000
/// PRO (轴四)压紧轴原点高速 CompAxis_HomeHighSpeed 60
/// </summary>
[ConfigProAttribute("CompressAxis_HomeSpeed")]
public int CompressAxis_HomeSpeed { get; set; }
[ConfigProAttribute("CompAxis_HomeHighSpeed")]
public int CompAxis_HomeHighSpeed { get; set; }
/// <summary>
/// PRO,硕科步进电机轴地址(压紧轴),CompressAxis_Slv,1,,,,,,
/// PRO (轴四)压紧轴原点加速度 CompAxis_HomeAddSpeed 200
/// </summary>
[ConfigProAttribute("CompressAxis_Slv")]
public int CompressAxis_Slv { get; set; }
[ConfigProAttribute("CompAxis_HomeAddSpeed")]
public int CompAxis_HomeAddSpeed { get; set; }
/// <summary>
/// PRO (轴一)旋转轴最小限位 MiddleAxis_PositionMin
......@@ -532,30 +499,18 @@ namespace OnlineStore.LoadCSVLibrary
/// </summary>
[ConfigProAttribute("AIDI4_Addr", false )]
public int AIDI4_Addr { get; set; }
//private List<string> TempAddrList = null;
//public static char TempAddrSpilt = '#';
///// <summary>
///// 温湿度地址列表
///// </summary>
//public List<string> GetTempAddrList()
//{
// if (TempAddrList == null)
// {
// TempAddrList = new List<string>();
// string[] array = Temperate_Serveraddress.Split(TempAddrSpilt);
// if (array.Length > 0)
// {
// foreach (string str in array)
// {
// if (!str.Equals(""))
// {
// TempAddrList.Add(str);
// }
// }
// }
// }
// return TempAddrList;
//}
/// <summary>
/// PRO IO模块对应的DI数量 IO_DILength 192.168.200.10#16;192.168.200.11#4
/// </summary>
[ConfigProAttribute("IO_DILength")]
public string IO_DILength { get; set; }
/// <summary>
/// PRO 模块对应的DO数量 IO_DOLength 192.168.200.10#16;192.168.200.11#4
/// </summary>
[ConfigProAttribute("IO_DOLength")]
public string IO_DOLength { get; set; }
protected override void initMustHavePro()
{
......@@ -570,20 +525,7 @@ namespace OnlineStore.LoadCSVLibrary
MustHaveDIList.Add(IO_Type.Door_Up);
MustHaveDIList.Add(IO_Type.Door_Down);
MustHaveDIList.Add(IO_Type.Door_LimitSingle);
MustHaveDIList.Add(IO_Type.SafetyLightCurtains);
MustHaveDIList.Add(IO_Type.CompressAxis_Check);
//MustHaveDIList.Add(IO_Type.LocationCylinder_Down);
//MustHaveDIList.Add(IO_Type.LocationCylinder_Up);
//MustHaveDIList.Add(IO_Type.LocationCylinder2_Down);
//MustHaveDIList.Add(IO_Type.LocationCylinder2_Up);
//MustHaveDIList.Add(IO_Type.Left_Door_LimitSingle);
//MustHaveDIList.Add(IO_Type.Right_Door_LimitSingle);
//MustHaveDIList.Add(IO_Type.TrayCheck_3);
//MustHaveDIList.Add(IO_Type.TrayCheck_4);
//MustHaveDIList.Add(IO_Type.LocationCylinder2_Down);
//MustHaveDIList.Add(IO_Type.LocationCylinder2_Up);
MustHaveDOList.Add(IO_Type.AutoRun_HddLed);
MustHaveDOList.Add(IO_Type.Alarm_HddLed);
......@@ -591,11 +533,8 @@ namespace OnlineStore.LoadCSVLibrary
MustHaveDOList.Add(IO_Type.StartOrStopBlow);
MustHaveDOList.Add(IO_Type.Run_Signal);
MustHaveDOList.Add(IO_Type.Door_Up);
MustHaveDOList.Add(IO_Type.Door_Down);
//MustHaveDOList.Add(IO_Type.LocationCylinder_Down);
//MustHaveDOList.Add(IO_Type.LocationCylinder_Up);
MustHaveDOList.Add(IO_Type.Axis_Brake);
MustHaveDOList.Add(IO_Type.CameraLight_Power);
MustHaveDOList.Add(IO_Type.Door_Down);
MustHaveDOList.Add(IO_Type.Axis_Brake);
}
public static void ConfigAxis(AC_SA_Config Config)
{
......@@ -620,6 +559,13 @@ namespace OnlineStore.LoadCSVLibrary
Config.UpDown_Axis.HomeHighSpeed = Config.UpdownAxis_HomeHighSpeed;
Config.UpDown_Axis.HomeLowSpeed = Config.UpdownAxis_HomeLowSpeed;
Config.Comp_Axis.TargetSpeed = Config.CompAxis_TargetSpeed;
Config.Comp_Axis.AddSpeed = Config.CompAxis_AddSpeed;
Config.Comp_Axis.DelSpeed = Config.CompAxis_DelSpeed;
Config.Comp_Axis.HomeAddSpeed = Config.CompAxis_HomeAddSpeed;
Config.Comp_Axis.HomeHighSpeed = Config.CompAxis_HomeHighSpeed;
Config.Comp_Axis.HomeLowSpeed = Config.CompAxis_HomeLowSpeed;
Config.Middle_Axis.CanErrorCountMin = Config.MiddleAxis_ErrorCountMin;
Config.InOut_Axis.CanErrorCountMin = Config.InoutAxis_ErrorCountMin;
Config.UpDown_Axis.CanErrorCountMin = Config.UpdownAxis_ErrorCountMin;
......@@ -642,6 +588,75 @@ namespace OnlineStore.LoadCSVLibrary
Config.Middle_Axis.DefaultPosition = Config.MiddleAxis_P1_Position;
Config.InOut_Axis.DefaultPosition = Config.InOutAxis_P1_Position;
Config.UpDown_Axis.DefaultPosition = Config.UpDownAxis_DoorOPosition_P1;
Config.Comp_Axis.DefaultPosition = Config.CompressAxis_P1_Position;
Config.Comp_Axis.CanErrorCountMax = 1000;
Config.Comp_Axis.CanErrorCountMin = 10;
Config.Comp_Axis.PositionMin = 0;
Config.Comp_Axis.PositionMax = 0;
}
private Dictionary<string, ushort> DILengthMap = null;
private Dictionary<string, ushort> DOLengthMap = null;
public ushort GetDILength(string ip)
{
try
{
if (DILengthMap == null)
{
DILengthMap = new Dictionary<string, ushort>();
string[] arrayList = IO_DILength.Split(';');
foreach (string str in arrayList)
{
string[] arrStr = str.Split('#');
if (arrStr.Length == 2)
{
string ioip = arrStr[0];
ushort length = Convert.ToUInt16(arrStr[1]);
DILengthMap.Add(ioip, length);
}
}
}
}
catch (Exception ex)
{
}
if (DILengthMap.ContainsKey(ip))
{
return DILengthMap[ip];
}
return 16;
}
public ushort GetDOLength(string ip)
{
try
{
if (DOLengthMap == null)
{
DOLengthMap = new Dictionary<string, ushort>();
string[] arrayList = IO_DOLength.Split(';');
foreach (string str in arrayList)
{
string[] arrStr = str.Split('#');
if (arrStr.Length == 2)
{
string ioip = arrStr[0];
ushort length = Convert.ToUInt16(arrStr[1]);
DOLengthMap.Add(ioip, length);
}
}
}
}
catch (Exception ex)
{
}
if (DOLengthMap.ContainsKey(ip))
{
return DOLengthMap[ip];
}
return 16;
}
}
}
......@@ -114,31 +114,7 @@ namespace OnlineStore.LoadCSVLibrary
/// </summary>
public static string Door_Down = "Door_Down";
/// <summary>
/// 左侧门限位
/// </summary>
public static string Left_Door_LimitSingle = "Left_Door_LimitSingle";
/// <summary>
/// 右侧门限位
/// </summary>
public static string Right_Door_LimitSingle = "Right_Door_LimitSingle";
/// <summary>
/// 前门限位
/// </summary>
public static string Door_LimitSingle = "Door_LimitSingle";
/// <summary>
/// 安全光栅
/// </summary>
public static string SafetyLightCurtains = "SafetyLightCurtains";
/// <summary>
/// 摄像机光源
/// </summary>
public static string CameraLight_Power = "CameraLight_Power";
/// <summary>
/// 压紧机构计量检测 CompressAxis_Check X16 DI-16
/// </summary>
public static string CompressAxis_Check = "CompressAxis_Check";
}
public enum IO_VALUE
{
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!