Commit 49c28c58 LN

1

1 个父辈 0fbcb89e
正在显示 48 个修改的文件 包含 1373 行增加5183 行删除
此文件类型无法预览
此文件类型无法预览
此文件类型无法预览
此文件类型无法预览
此文件类型无法预览
此文件类型无法预览
此文件类型无法预览
此文件类型无法预览
<?xml version="1.0"?>
<doc>
<assembly>
<name>Asa.RFID</name>
</assembly>
<members>
<member name="T:Asa.RFID.Reader">
<summary>
RFID读卡器
</summary>
</member>
<member name="E:Asa.RFID.Reader.Data_Received">
<summary>
自动扫描接收到的数据
</summary>
</member>
<member name="M:Asa.RFID.Reader.#ctor">
<summary>
RFID读卡器
</summary>
</member>
<member name="P:Asa.RFID.Reader.LocalIP">
<summary>
本地IP地址,用于查找或修改远程IP
</summary>
</member>
<member name="P:Asa.RFID.Reader.RemoteIP">
<summary>
远程IP地址
</summary>
</member>
<member name="P:Asa.RFID.Reader.IsConn">
<summary>
是否连接
</summary>
</member>
<member name="P:Asa.RFID.Reader.IsAutoScan">
<summary>
是否自动扫描
</summary>
</member>
<member name="P:Asa.RFID.Reader.IsExist">
<summary>
是否存在ID卡
</summary>
</member>
<member name="M:Asa.RFID.Reader.Connect">
<summary>
连接
</summary>
<returns></returns>
</member>
<member name="M:Asa.RFID.Reader.Close">
<summary>
关闭
</summary>
</member>
<member name="M:Asa.RFID.Reader.FindRFID">
<summary>
查找电子标签
</summary>
<returns></returns>
</member>
<member name="M:Asa.RFID.Reader.AutoScan(System.Boolean,System.Int32)">
<summary>
自动读取扫描,使用查找模式
</summary>
<param name="open">扫描模式开启,true扫描</param>
<param name="time">间隔时间</param>
</member>
<member name="M:Asa.RFID.Reader.AutoScan(System.Boolean)">
<summary>
自动读取扫描,使用扫描模式,扫描模式只读
</summary>
<param name="open">扫描模式开启,true扫描</param>
<returns></returns>
</member>
<member name="M:Asa.RFID.Reader.Read">
<summary>
读取电子标签
</summary>
<returns></returns>
</member>
<member name="M:Asa.RFID.Reader.Read(System.Int32,System.Int32)">
<summary>
读取电子标签
</summary>
<param name="start"></param>
<param name="len"></param>
<returns></returns>
</member>
<member name="M:Asa.RFID.Reader.Write(System.Byte[])">
<summary>
写入数据到电子标签
</summary>
<param name="buff">数据,必须小于等于112字节</param>
<returns></returns>
</member>
<member name="M:Asa.RFID.Reader.Write(System.Byte[],System.Int32)">
<summary>
写入数据到电子标签
</summary>
<param name="buff"></param>
<param name="start"></param>
<returns></returns>
</member>
<member name="M:Asa.RFID.Reader.FindIP">
<summary>
查找IP地址,需要设置LocalIP
</summary>
<returns></returns>
</member>
<member name="M:Asa.RFID.Reader.ModifyIP(System.String)">
<summary>
修改IP地址
</summary>
<param name="IP"></param>
</member>
<member name="M:Asa.RFID.Reader.Receive(System.Object)">
<summary>
自动扫描接受数据事件
</summary>
<param name="param"></param>
</member>
<member name="M:Asa.RFID.Reader.Receive2">
<summary>
自动扫描接受数据事件
</summary>
</member>
<member name="M:Asa.RFID.Reader.ReadRFID">
<summary>
读取电子标签内所有数据
</summary>
</member>
<member name="M:Asa.RFID.Reader.ReadRFID(System.Int32)">
<summary>
读取电子标签指定块
</summary>
<param name="num"></param>
<returns></returns>
</member>
<member name="M:Asa.RFID.Reader.WriteRFID(System.Int32)">
<summary>
写入指定块数据到电子标签
</summary>
<param name="num"></param>
<returns></returns>
</member>
<member name="M:Asa.RFID.Reader.InitBuff(System.Int32,System.Int32)">
<summary>
初始buff为0
</summary>
<param name="start"></param>
<param name="len"></param>
</member>
<member name="T:Asa.RFID.ReaderInfo">
<summary>
读卡设备信息
</summary>
</member>
<member name="F:Asa.RFID.ReaderInfo.IP">
<summary>
IP地址
</summary>
</member>
<member name="F:Asa.RFID.ReaderInfo.Mac">
<summary>
MAC地址
</summary>
</member>
<member name="F:Asa.RFID.ReaderInfo.Port">
<summary>
端口
</summary>
</member>
</members>
</doc>
此文件类型无法预览
此文件类型无法预览
此文件类型无法预览
此文件类型无法预览
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
<add key ="LineServerPort" value ="5246"/> <add key ="LineServerPort" value ="5246"/>
<!--是否调试状态--> <!--是否调试状态-->
<add key ="IsInDebug" value ="1"/> <add key ="IsInDebug" value ="1"/>
<add key ="UseBuzzer" value ="1"/>
</appSettings> </appSettings>
<log4net> <log4net>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender"> <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
......
...@@ -13,7 +13,7 @@ namespace OnlineStore.ACPackingStore ...@@ -13,7 +13,7 @@ namespace OnlineStore.ACPackingStore
{ {
public partial class FrmBase : Form public partial class FrmBase : Form
{ {
internal static string GetVersion() internal static string GetVersion(bool isShow=false)
{ {
string str = ""; string str = "";
string version = ""; string version = "";
...@@ -38,7 +38,10 @@ namespace OnlineStore.ACPackingStore ...@@ -38,7 +38,10 @@ namespace OnlineStore.ACPackingStore
str = version; str = version;
LogUtil.error("解析版本号【" + str + "】出错:" + ex.ToString()); LogUtil.error("解析版本号【" + str + "】出错:" + ex.ToString());
} }
if (isShow)
{
LogUtil.info("版本号[" + version + "][" + str + "][" + GetCodeNum() + "]"); LogUtil.info("版本号[" + version + "][" + str + "][" + GetCodeNum() + "]");
}
return str; return str;
} }
internal static string GetCodeNum(string codeName = "RC1250-ACPackingStore") internal static string GetCodeNum(string codeName = "RC1250-ACPackingStore")
......
...@@ -2093,7 +2093,6 @@ ...@@ -2093,7 +2093,6 @@
this.Name = "FrmBox"; this.Name = "FrmBox";
this.Opacity = 0D; this.Opacity = 0D;
this.Text = "AC_SA_料仓"; this.Text = "AC_SA_料仓";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FrmTest_FormClosing); this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FrmTest_FormClosing);
this.Load += new System.EventHandler(this.FrmTest_Load); this.Load += new System.EventHandler(this.FrmTest_Load);
this.Shown += new System.EventHandler(this.FrmStoreBox_Shown); this.Shown += new System.EventHandler(this.FrmStoreBox_Shown);
......
...@@ -18,25 +18,18 @@ ...@@ -18,25 +18,18 @@
this.components = new System.ComponentModel.Container(); this.components = new System.ComponentModel.Container();
this.timer1 = new System.Windows.Forms.Timer(this.components); this.timer1 = new System.Windows.Forms.Timer(this.components);
this.groupBox1 = new System.Windows.Forms.GroupBox(); this.groupBox1 = new System.Windows.Forms.GroupBox();
this.btnOpenDo = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label();
this.txtSlaveId = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.txtDOIndex = new System.Windows.Forms.TextBox(); this.txtDOIndex = new System.Windows.Forms.TextBox();
this.txtDoName = new System.Windows.Forms.TextBox(); this.txtDoName = new System.Windows.Forms.TextBox();
this.btnCloseAxisBreak = new System.Windows.Forms.Button();
this.label17 = new System.Windows.Forms.Label(); this.label17 = new System.Windows.Forms.Label();
this.btnReadIO = new System.Windows.Forms.Button();
this.btnOpenAxisBreak = new System.Windows.Forms.Button(); this.btnOpenAxisBreak = new System.Windows.Forms.Button();
this.label14 = new System.Windows.Forms.Label(); this.label14 = new System.Windows.Forms.Label();
this.btnWriteSingleDO = new System.Windows.Forms.Button();
this.txtWriteTime = new System.Windows.Forms.TextBox(); this.txtWriteTime = new System.Windows.Forms.TextBox();
this.btnLocationDown = new System.Windows.Forms.Button(); this.btnLocationDown = new System.Windows.Forms.Button();
this.label5 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label();
this.btnReadAllDi = new System.Windows.Forms.Button();
this.cmbWriteValue = new System.Windows.Forms.ComboBox();
this.btnLocationUp = new System.Windows.Forms.Button(); this.btnLocationUp = new System.Windows.Forms.Button();
this.label6 = new System.Windows.Forms.Label();
this.btnReadAllDo = new System.Windows.Forms.Button();
this.cmbWriteIO = new System.Windows.Forms.ComboBox(); this.cmbWriteIO = new System.Windows.Forms.ComboBox();
this.btnCloseDoor = new System.Windows.Forms.Button(); this.btnCloseDoor = new System.Windows.Forms.Button();
this.btnOpenDoor = new System.Windows.Forms.Button(); this.btnOpenDoor = new System.Windows.Forms.Button();
...@@ -46,6 +39,14 @@ ...@@ -46,6 +39,14 @@
this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel(); this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel();
this.groupBox3 = new System.Windows.Forms.GroupBox(); this.groupBox3 = new System.Windows.Forms.GroupBox();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.txtSlaveId = new System.Windows.Forms.TextBox();
this.btnNGDoorDown = new System.Windows.Forms.Button();
this.btnNGDoorUp = new System.Windows.Forms.Button();
this.btnTopDown = new System.Windows.Forms.Button();
this.btnTopUp = new System.Windows.Forms.Button();
this.btnCamerLed = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.btnStopMove = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout(); this.groupBox1.SuspendLayout();
this.groupBox4.SuspendLayout(); this.groupBox4.SuspendLayout();
this.groupBox3.SuspendLayout(); this.groupBox3.SuspendLayout();
...@@ -60,25 +61,26 @@ ...@@ -60,25 +61,26 @@
// //
this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left))); | System.Windows.Forms.AnchorStyles.Left)));
this.groupBox1.Controls.Add(this.label3); this.groupBox1.Controls.Add(this.btnStopMove);
this.groupBox1.Controls.Add(this.button4);
this.groupBox1.Controls.Add(this.btnCamerLed);
this.groupBox1.Controls.Add(this.btnTopDown);
this.groupBox1.Controls.Add(this.btnTopUp);
this.groupBox1.Controls.Add(this.btnNGDoorDown);
this.groupBox1.Controls.Add(this.btnNGDoorUp);
this.groupBox1.Controls.Add(this.txtSlaveId); this.groupBox1.Controls.Add(this.txtSlaveId);
this.groupBox1.Controls.Add(this.label2); this.groupBox1.Controls.Add(this.btnOpenDo);
this.groupBox1.Controls.Add(this.button2);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.txtDOIndex); this.groupBox1.Controls.Add(this.txtDOIndex);
this.groupBox1.Controls.Add(this.txtDoName); this.groupBox1.Controls.Add(this.txtDoName);
this.groupBox1.Controls.Add(this.btnCloseAxisBreak);
this.groupBox1.Controls.Add(this.label17); this.groupBox1.Controls.Add(this.label17);
this.groupBox1.Controls.Add(this.btnReadIO);
this.groupBox1.Controls.Add(this.btnOpenAxisBreak); this.groupBox1.Controls.Add(this.btnOpenAxisBreak);
this.groupBox1.Controls.Add(this.label14); this.groupBox1.Controls.Add(this.label14);
this.groupBox1.Controls.Add(this.btnWriteSingleDO);
this.groupBox1.Controls.Add(this.txtWriteTime); this.groupBox1.Controls.Add(this.txtWriteTime);
this.groupBox1.Controls.Add(this.btnLocationDown); this.groupBox1.Controls.Add(this.btnLocationDown);
this.groupBox1.Controls.Add(this.label5); this.groupBox1.Controls.Add(this.label5);
this.groupBox1.Controls.Add(this.btnReadAllDi);
this.groupBox1.Controls.Add(this.cmbWriteValue);
this.groupBox1.Controls.Add(this.btnLocationUp); this.groupBox1.Controls.Add(this.btnLocationUp);
this.groupBox1.Controls.Add(this.label6);
this.groupBox1.Controls.Add(this.btnReadAllDo);
this.groupBox1.Controls.Add(this.cmbWriteIO); this.groupBox1.Controls.Add(this.cmbWriteIO);
this.groupBox1.Controls.Add(this.btnCloseDoor); this.groupBox1.Controls.Add(this.btnCloseDoor);
this.groupBox1.Controls.Add(this.btnOpenDoor); this.groupBox1.Controls.Add(this.btnOpenDoor);
...@@ -90,103 +92,85 @@ ...@@ -90,103 +92,85 @@
this.groupBox1.TabStop = false; this.groupBox1.TabStop = false;
this.groupBox1.Text = "DO写入"; this.groupBox1.Text = "DO写入";
// //
// btnOpenDo
//
this.btnOpenDo.BackColor = System.Drawing.Color.White;
this.btnOpenDo.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnOpenDo.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnOpenDo.Location = new System.Drawing.Point(41, 108);
this.btnOpenDo.Name = "btnOpenDo";
this.btnOpenDo.Size = new System.Drawing.Size(125, 34);
this.btnOpenDo.TabIndex = 282;
this.btnOpenDo.Text = "打开";
this.btnOpenDo.UseVisualStyleBackColor = false;
this.btnOpenDo.Click += new System.EventHandler(this.btnOpenDo_Click);
//
// button2
//
this.button2.BackColor = System.Drawing.Color.White;
this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button2.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.button2.Location = new System.Drawing.Point(175, 108);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(125, 34);
this.button2.TabIndex = 281;
this.button2.Text = "关闭";
this.button2.UseVisualStyleBackColor = false;
//
// label3 // label3
// //
this.label3.AutoSize = true; this.label3.AutoSize = true;
this.label3.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.label3.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label3.ImageAlign = System.Drawing.ContentAlignment.MiddleRight; this.label3.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.label3.Location = new System.Drawing.Point(14, 79); this.label3.Location = new System.Drawing.Point(12, 23);
this.label3.Name = "label3"; this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(54, 17); this.label3.Size = new System.Drawing.Size(54, 17);
this.label3.TabIndex = 247; this.label3.TabIndex = 247;
this.label3.Text = "选择DO:"; this.label3.Text = "选择DO:";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight; this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
// //
// txtSlaveId
//
this.txtSlaveId.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.txtSlaveId.Location = new System.Drawing.Point(238, 48);
this.txtSlaveId.MaxLength = 10;
this.txtSlaveId.Name = "txtSlaveId";
this.txtSlaveId.Size = new System.Drawing.Size(74, 23);
this.txtSlaveId.TabIndex = 246;
this.txtSlaveId.Text = "0";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label2.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.label2.Location = new System.Drawing.Point(181, 51);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(50, 17);
this.label2.TabIndex = 245;
this.label2.Text = "SlaveId";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// txtDOIndex // txtDOIndex
// //
this.txtDOIndex.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.txtDOIndex.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.txtDOIndex.Location = new System.Drawing.Point(75, 48); this.txtDOIndex.Location = new System.Drawing.Point(75, 77);
this.txtDOIndex.MaxLength = 10; this.txtDOIndex.MaxLength = 10;
this.txtDOIndex.Name = "txtDOIndex"; this.txtDOIndex.Name = "txtDOIndex";
this.txtDOIndex.Size = new System.Drawing.Size(74, 23); this.txtDOIndex.Size = new System.Drawing.Size(70, 23);
this.txtDOIndex.TabIndex = 242; this.txtDOIndex.TabIndex = 242;
this.txtDOIndex.Text = "0"; this.txtDOIndex.Text = "0";
// //
// txtDoName // txtDoName
// //
this.txtDoName.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.txtDoName.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.txtDoName.Location = new System.Drawing.Point(75, 22); this.txtDoName.Location = new System.Drawing.Point(75, 48);
this.txtDoName.MaxLength = 10; this.txtDoName.MaxLength = 10;
this.txtDoName.Name = "txtDoName"; this.txtDoName.Name = "txtDoName";
this.txtDoName.Size = new System.Drawing.Size(237, 23); this.txtDoName.Size = new System.Drawing.Size(233, 23);
this.txtDoName.TabIndex = 241; this.txtDoName.TabIndex = 241;
this.txtDoName.Text = "0"; this.txtDoName.Text = "0";
// //
// btnCloseAxisBreak
//
this.btnCloseAxisBreak.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnCloseAxisBreak.Location = new System.Drawing.Point(173, 283);
this.btnCloseAxisBreak.Name = "btnCloseAxisBreak";
this.btnCloseAxisBreak.Size = new System.Drawing.Size(102, 34);
this.btnCloseAxisBreak.TabIndex = 253;
this.btnCloseAxisBreak.Text = "关闭刹车";
this.btnCloseAxisBreak.UseVisualStyleBackColor = true;
this.btnCloseAxisBreak.Click += new System.EventHandler(this.btnCloseAxisBreak_Click);
//
// label17 // label17
// //
this.label17.AutoSize = true; this.label17.AutoSize = true;
this.label17.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.label17.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label17.ImageAlign = System.Drawing.ContentAlignment.MiddleRight; this.label17.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.label17.Location = new System.Drawing.Point(22, 25); this.label17.Location = new System.Drawing.Point(20, 51);
this.label17.Name = "label17"; this.label17.Name = "label17";
this.label17.Size = new System.Drawing.Size(46, 17); this.label17.Size = new System.Drawing.Size(46, 17);
this.label17.TabIndex = 240; this.label17.TabIndex = 240;
this.label17.Text = "设备IP:"; this.label17.Text = "设备IP:";
this.label17.TextAlign = System.Drawing.ContentAlignment.MiddleRight; this.label17.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
// //
// btnReadIO
//
this.btnReadIO.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnReadIO.Location = new System.Drawing.Point(56, 133);
this.btnReadIO.Name = "btnReadIO";
this.btnReadIO.Size = new System.Drawing.Size(102, 34);
this.btnReadIO.TabIndex = 243;
this.btnReadIO.Text = "读取IO状态";
this.btnReadIO.UseVisualStyleBackColor = true;
this.btnReadIO.Click += new System.EventHandler(this.btnReadIO_Click);
//
// btnOpenAxisBreak // btnOpenAxisBreak
// //
this.btnOpenAxisBreak.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnOpenAxisBreak.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btnOpenAxisBreak.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnOpenAxisBreak.Location = new System.Drawing.Point(56, 283); this.btnOpenAxisBreak.Location = new System.Drawing.Point(41, 375);
this.btnOpenAxisBreak.Name = "btnOpenAxisBreak"; this.btnOpenAxisBreak.Name = "btnOpenAxisBreak";
this.btnOpenAxisBreak.Size = new System.Drawing.Size(102, 34); this.btnOpenAxisBreak.Size = new System.Drawing.Size(125, 34);
this.btnOpenAxisBreak.TabIndex = 252; this.btnOpenAxisBreak.TabIndex = 252;
this.btnOpenAxisBreak.Text = "打开刹车"; this.btnOpenAxisBreak.Text = "打开刹车";
this.btnOpenAxisBreak.UseVisualStyleBackColor = true; this.btnOpenAxisBreak.UseVisualStyleBackColor = false;
this.btnOpenAxisBreak.Click += new System.EventHandler(this.btnOpenAxisBreak_Click); this.btnOpenAxisBreak.Click += new System.EventHandler(this.btnOpenAxisBreak_Click);
// //
// label14 // label14
...@@ -194,28 +178,17 @@ ...@@ -194,28 +178,17 @@
this.label14.AutoSize = true; this.label14.AutoSize = true;
this.label14.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.label14.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label14.ImageAlign = System.Drawing.ContentAlignment.MiddleRight; this.label14.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.label14.Location = new System.Drawing.Point(24, 51); this.label14.Location = new System.Drawing.Point(22, 80);
this.label14.Name = "label14"; this.label14.Name = "label14";
this.label14.Size = new System.Drawing.Size(44, 17); this.label14.Size = new System.Drawing.Size(44, 17);
this.label14.TabIndex = 239; this.label14.TabIndex = 239;
this.label14.Text = "地址:"; this.label14.Text = "地址:";
this.label14.TextAlign = System.Drawing.ContentAlignment.MiddleRight; this.label14.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
// //
// btnWriteSingleDO
//
this.btnWriteSingleDO.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnWriteSingleDO.Location = new System.Drawing.Point(173, 133);
this.btnWriteSingleDO.Name = "btnWriteSingleDO";
this.btnWriteSingleDO.Size = new System.Drawing.Size(102, 34);
this.btnWriteSingleDO.TabIndex = 232;
this.btnWriteSingleDO.Text = "写入DO";
this.btnWriteSingleDO.UseVisualStyleBackColor = true;
this.btnWriteSingleDO.Click += new System.EventHandler(this.btnWriteSingleDO_Click);
//
// txtWriteTime // txtWriteTime
// //
this.txtWriteTime.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.txtWriteTime.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.txtWriteTime.Location = new System.Drawing.Point(238, 103); this.txtWriteTime.Location = new System.Drawing.Point(236, 77);
this.txtWriteTime.MaxLength = 10; this.txtWriteTime.MaxLength = 10;
this.txtWriteTime.Name = "txtWriteTime"; this.txtWriteTime.Name = "txtWriteTime";
this.txtWriteTime.Size = new System.Drawing.Size(74, 23); this.txtWriteTime.Size = new System.Drawing.Size(74, 23);
...@@ -224,13 +197,14 @@ ...@@ -224,13 +197,14 @@
// //
// btnLocationDown // btnLocationDown
// //
this.btnLocationDown.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnLocationDown.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btnLocationDown.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnLocationDown.Location = new System.Drawing.Point(173, 248); this.btnLocationDown.Location = new System.Drawing.Point(175, 327);
this.btnLocationDown.Name = "btnLocationDown"; this.btnLocationDown.Name = "btnLocationDown";
this.btnLocationDown.Size = new System.Drawing.Size(102, 34); this.btnLocationDown.Size = new System.Drawing.Size(125, 34);
this.btnLocationDown.TabIndex = 251; this.btnLocationDown.TabIndex = 251;
this.btnLocationDown.Text = "定位气缸下降"; this.btnLocationDown.Text = "定位装置下降";
this.btnLocationDown.UseVisualStyleBackColor = true; this.btnLocationDown.UseVisualStyleBackColor = false;
this.btnLocationDown.Click += new System.EventHandler(this.btnLocationDown_Click); this.btnLocationDown.Click += new System.EventHandler(this.btnLocationDown_Click);
// //
// label5 // label5
...@@ -238,73 +212,25 @@ ...@@ -238,73 +212,25 @@
this.label5.AutoSize = true; this.label5.AutoSize = true;
this.label5.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.label5.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label5.ImageAlign = System.Drawing.ContentAlignment.MiddleRight; this.label5.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.label5.Location = new System.Drawing.Point(172, 106); this.label5.Location = new System.Drawing.Point(170, 80);
this.label5.Name = "label5"; this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(60, 17); this.label5.Size = new System.Drawing.Size(60, 17);
this.label5.TabIndex = 237; this.label5.TabIndex = 237;
this.label5.Text = "定时(ms):"; this.label5.Text = "定时(ms):";
this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight; this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
// //
// btnReadAllDi
//
this.btnReadAllDi.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnReadAllDi.Location = new System.Drawing.Point(56, 168);
this.btnReadAllDi.Name = "btnReadAllDi";
this.btnReadAllDi.Size = new System.Drawing.Size(102, 34);
this.btnReadAllDi.TabIndex = 244;
this.btnReadAllDi.Text = "读取所有DI";
this.btnReadAllDi.UseVisualStyleBackColor = true;
this.btnReadAllDi.Click += new System.EventHandler(this.btnReadAllDi_Click);
//
// cmbWriteValue
//
this.cmbWriteValue.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable;
this.cmbWriteValue.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbWriteValue.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.cmbWriteValue.FormattingEnabled = true;
this.cmbWriteValue.Items.AddRange(new object[] {
"0",
"1"});
this.cmbWriteValue.Location = new System.Drawing.Point(75, 101);
this.cmbWriteValue.Name = "cmbWriteValue";
this.cmbWriteValue.Size = new System.Drawing.Size(74, 24);
this.cmbWriteValue.TabIndex = 236;
this.cmbWriteValue.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.cmbWriteValue_DrawItem);
//
// btnLocationUp // btnLocationUp
// //
this.btnLocationUp.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnLocationUp.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btnLocationUp.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnLocationUp.Location = new System.Drawing.Point(56, 248); this.btnLocationUp.Location = new System.Drawing.Point(41, 327);
this.btnLocationUp.Name = "btnLocationUp"; this.btnLocationUp.Name = "btnLocationUp";
this.btnLocationUp.Size = new System.Drawing.Size(102, 34); this.btnLocationUp.Size = new System.Drawing.Size(125, 34);
this.btnLocationUp.TabIndex = 250; this.btnLocationUp.TabIndex = 250;
this.btnLocationUp.Text = "定位气缸上升"; this.btnLocationUp.Text = "定位装置上升";
this.btnLocationUp.UseVisualStyleBackColor = true; this.btnLocationUp.UseVisualStyleBackColor = false;
this.btnLocationUp.Click += new System.EventHandler(this.btnLocationUp_Click); this.btnLocationUp.Click += new System.EventHandler(this.btnLocationUp_Click);
// //
// label6
//
this.label6.AutoSize = true;
this.label6.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label6.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.label6.Location = new System.Drawing.Point(21, 106);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(47, 17);
this.label6.TabIndex = 235;
this.label6.Text = "写入值:";
this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// btnReadAllDo
//
this.btnReadAllDo.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnReadAllDo.Location = new System.Drawing.Point(173, 168);
this.btnReadAllDo.Name = "btnReadAllDo";
this.btnReadAllDo.Size = new System.Drawing.Size(102, 34);
this.btnReadAllDo.TabIndex = 245;
this.btnReadAllDo.Text = "读取所有DO";
this.btnReadAllDo.UseVisualStyleBackColor = true;
this.btnReadAllDo.Click += new System.EventHandler(this.btnReadAllDo_Click);
//
// cmbWriteIO // cmbWriteIO
// //
this.cmbWriteIO.DisplayMember = "ProName"; this.cmbWriteIO.DisplayMember = "ProName";
...@@ -312,9 +238,9 @@ ...@@ -312,9 +238,9 @@
this.cmbWriteIO.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cmbWriteIO.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbWriteIO.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.cmbWriteIO.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.cmbWriteIO.FormattingEnabled = true; this.cmbWriteIO.FormattingEnabled = true;
this.cmbWriteIO.Location = new System.Drawing.Point(75, 74); this.cmbWriteIO.Location = new System.Drawing.Point(75, 18);
this.cmbWriteIO.Name = "cmbWriteIO"; this.cmbWriteIO.Name = "cmbWriteIO";
this.cmbWriteIO.Size = new System.Drawing.Size(237, 24); this.cmbWriteIO.Size = new System.Drawing.Size(233, 24);
this.cmbWriteIO.TabIndex = 234; this.cmbWriteIO.TabIndex = 234;
this.cmbWriteIO.ValueMember = "ProName"; this.cmbWriteIO.ValueMember = "ProName";
this.cmbWriteIO.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.cmbWriteIO_DrawItem); this.cmbWriteIO.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.cmbWriteIO_DrawItem);
...@@ -322,24 +248,26 @@ ...@@ -322,24 +248,26 @@
// //
// btnCloseDoor // btnCloseDoor
// //
this.btnCloseDoor.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnCloseDoor.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btnCloseDoor.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnCloseDoor.Location = new System.Drawing.Point(173, 213); this.btnCloseDoor.Location = new System.Drawing.Point(175, 183);
this.btnCloseDoor.Name = "btnCloseDoor"; this.btnCloseDoor.Name = "btnCloseDoor";
this.btnCloseDoor.Size = new System.Drawing.Size(102, 34); this.btnCloseDoor.Size = new System.Drawing.Size(125, 34);
this.btnCloseDoor.TabIndex = 249; this.btnCloseDoor.TabIndex = 249;
this.btnCloseDoor.Text = "关闭仓门"; this.btnCloseDoor.Text = "入料口移门关闭";
this.btnCloseDoor.UseVisualStyleBackColor = true; this.btnCloseDoor.UseVisualStyleBackColor = false;
this.btnCloseDoor.Click += new System.EventHandler(this.btnCloseDoor_Click); this.btnCloseDoor.Click += new System.EventHandler(this.btnCloseDoor_Click);
// //
// btnOpenDoor // btnOpenDoor
// //
this.btnOpenDoor.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnOpenDoor.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btnOpenDoor.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnOpenDoor.Location = new System.Drawing.Point(56, 213); this.btnOpenDoor.Location = new System.Drawing.Point(41, 183);
this.btnOpenDoor.Name = "btnOpenDoor"; this.btnOpenDoor.Name = "btnOpenDoor";
this.btnOpenDoor.Size = new System.Drawing.Size(102, 34); this.btnOpenDoor.Size = new System.Drawing.Size(125, 34);
this.btnOpenDoor.TabIndex = 248; this.btnOpenDoor.TabIndex = 248;
this.btnOpenDoor.Text = "打开仓门"; this.btnOpenDoor.Text = "入料口移门打开";
this.btnOpenDoor.UseVisualStyleBackColor = true; this.btnOpenDoor.UseVisualStyleBackColor = false;
this.btnOpenDoor.Click += new System.EventHandler(this.btnOpenDoor_Click); this.btnOpenDoor.Click += new System.EventHandler(this.btnOpenDoor_Click);
// //
// button1 // button1
...@@ -421,6 +349,101 @@ ...@@ -421,6 +349,101 @@
this.tableLayoutPanel1.Size = new System.Drawing.Size(218, 570); this.tableLayoutPanel1.Size = new System.Drawing.Size(218, 570);
this.tableLayoutPanel1.TabIndex = 102; this.tableLayoutPanel1.TabIndex = 102;
// //
// txtSlaveId
//
this.txtSlaveId.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.txtSlaveId.Location = new System.Drawing.Point(6, 108);
this.txtSlaveId.MaxLength = 10;
this.txtSlaveId.Name = "txtSlaveId";
this.txtSlaveId.Size = new System.Drawing.Size(43, 23);
this.txtSlaveId.TabIndex = 283;
this.txtSlaveId.Text = "0";
this.txtSlaveId.Visible = false;
//
// btnNGDoorDown
//
this.btnNGDoorDown.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnNGDoorDown.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnNGDoorDown.Location = new System.Drawing.Point(175, 231);
this.btnNGDoorDown.Name = "btnNGDoorDown";
this.btnNGDoorDown.Size = new System.Drawing.Size(125, 34);
this.btnNGDoorDown.TabIndex = 287;
this.btnNGDoorDown.Text = "NG料口门下降";
this.btnNGDoorDown.UseVisualStyleBackColor = false;
this.btnNGDoorDown.Click += new System.EventHandler(this.btnNGDoorDown_Click);
//
// btnNGDoorUp
//
this.btnNGDoorUp.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnNGDoorUp.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnNGDoorUp.Location = new System.Drawing.Point(41, 231);
this.btnNGDoorUp.Name = "btnNGDoorUp";
this.btnNGDoorUp.Size = new System.Drawing.Size(125, 34);
this.btnNGDoorUp.TabIndex = 286;
this.btnNGDoorUp.Text = "NG料口门上升";
this.btnNGDoorUp.UseVisualStyleBackColor = false;
this.btnNGDoorUp.Click += new System.EventHandler(this.btnNGDoorUp_Click);
//
// btnTopDown
//
this.btnTopDown.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnTopDown.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnTopDown.Location = new System.Drawing.Point(175, 279);
this.btnTopDown.Name = "btnTopDown";
this.btnTopDown.Size = new System.Drawing.Size(125, 34);
this.btnTopDown.TabIndex = 289;
this.btnTopDown.Text = "顶升装置下降";
this.btnTopDown.UseVisualStyleBackColor = false;
this.btnTopDown.Click += new System.EventHandler(this.btnTopDown_Click);
//
// btnTopUp
//
this.btnTopUp.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnTopUp.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnTopUp.Location = new System.Drawing.Point(41, 279);
this.btnTopUp.Name = "btnTopUp";
this.btnTopUp.Size = new System.Drawing.Size(125, 34);
this.btnTopUp.TabIndex = 288;
this.btnTopUp.Text = "顶升装置上升";
this.btnTopUp.UseVisualStyleBackColor = false;
this.btnTopUp.Click += new System.EventHandler(this.btnTopUp_Click);
//
// btnCamerLed
//
this.btnCamerLed.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnCamerLed.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnCamerLed.Location = new System.Drawing.Point(175, 375);
this.btnCamerLed.Name = "btnCamerLed";
this.btnCamerLed.Size = new System.Drawing.Size(125, 34);
this.btnCamerLed.TabIndex = 290;
this.btnCamerLed.Text = "打开光源";
this.btnCamerLed.UseVisualStyleBackColor = false;
this.btnCamerLed.Click += new System.EventHandler(this.btnCamerLed_Click);
//
// button4
//
this.button4.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button4.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.button4.Location = new System.Drawing.Point(41, 423);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(125, 34);
this.button4.TabIndex = 291;
this.button4.Text = "线体正转";
this.button4.UseVisualStyleBackColor = false;
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// btnStopMove
//
this.btnStopMove.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnStopMove.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnStopMove.Location = new System.Drawing.Point(175, 423);
this.btnStopMove.Name = "btnStopMove";
this.btnStopMove.Size = new System.Drawing.Size(125, 34);
this.btnStopMove.TabIndex = 292;
this.btnStopMove.Text = "线体停止转动";
this.btnStopMove.UseVisualStyleBackColor = false;
this.btnStopMove.Click += new System.EventHandler(this.btnStopMove_Click);
//
// FrmIOStatus // FrmIOStatus
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
...@@ -460,25 +483,26 @@ ...@@ -460,25 +483,26 @@
private System.Windows.Forms.Label label14; private System.Windows.Forms.Label label14;
private System.Windows.Forms.TextBox txtWriteTime; private System.Windows.Forms.TextBox txtWriteTime;
private System.Windows.Forms.Label label5; private System.Windows.Forms.Label label5;
private System.Windows.Forms.ComboBox cmbWriteValue;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Button btnWriteSingleDO;
private System.Windows.Forms.ComboBox cmbWriteIO; private System.Windows.Forms.ComboBox cmbWriteIO;
private System.Windows.Forms.Button btnReadIO;
private System.Windows.Forms.CheckBox chbAutoRead; private System.Windows.Forms.CheckBox chbAutoRead;
private System.Windows.Forms.TextBox txtSlaveId;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button btnReadAllDi;
private System.Windows.Forms.Button btnReadAllDo;
private System.Windows.Forms.TextBox txtDoName; private System.Windows.Forms.TextBox txtDoName;
private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button btnCloseDoor; private System.Windows.Forms.Button btnCloseDoor;
private System.Windows.Forms.Button btnOpenDoor; private System.Windows.Forms.Button btnOpenDoor;
private System.Windows.Forms.Button btnLocationDown; private System.Windows.Forms.Button btnLocationDown;
private System.Windows.Forms.Button btnLocationUp; private System.Windows.Forms.Button btnLocationUp;
private System.Windows.Forms.Button btnCloseAxisBreak;
private System.Windows.Forms.Button btnOpenAxisBreak; private System.Windows.Forms.Button btnOpenAxisBreak;
private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button btnOpenDo;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.TextBox txtSlaveId;
private System.Windows.Forms.Button btnNGDoorDown;
private System.Windows.Forms.Button btnNGDoorUp;
private System.Windows.Forms.Button btnTopDown;
private System.Windows.Forms.Button btnTopUp;
private System.Windows.Forms.Button btnStopMove;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button btnCamerLed;
} }
} }
...@@ -40,6 +40,11 @@ namespace OnlineStore.ACPackingStore ...@@ -40,6 +40,11 @@ namespace OnlineStore.ACPackingStore
LoadIOList(); LoadIOList();
} }
private void FrmStoreIOStatus_Load(object sender, EventArgs e)
{
//KNDAIManager.NeedShow = true;
this.Text = boxBean.Name + "_IO查看";
}
Dictionary<string, IOTextControl> DIControlList = new Dictionary<string, IOTextControl>(); Dictionary<string, IOTextControl> DIControlList = new Dictionary<string, IOTextControl>();
Dictionary<string, IOTextControl> DOControlList = new Dictionary<string, IOTextControl>(); Dictionary<string, IOTextControl> DOControlList = new Dictionary<string, IOTextControl>();
private void LoadIOList() private void LoadIOList()
...@@ -72,7 +77,6 @@ namespace OnlineStore.ACPackingStore ...@@ -72,7 +77,6 @@ namespace OnlineStore.ACPackingStore
cmbWriteIO.DataSource = new List<ConfigIO>(boxBean.Config.DOList.Values); cmbWriteIO.DataSource = new List<ConfigIO>(boxBean.Config.DOList.Values);
cmbWriteIO.ValueMember = "ProName"; cmbWriteIO.ValueMember = "ProName";
cmbWriteIO.DisplayMember = "DisplayStr"; cmbWriteIO.DisplayMember = "DisplayStr";
cmbWriteValue.SelectedIndex = 0;
} }
private void timer1_Tick(object sender, EventArgs e) private void timer1_Tick(object sender, EventArgs e)
...@@ -99,22 +103,6 @@ namespace OnlineStore.ACPackingStore ...@@ -99,22 +103,6 @@ namespace OnlineStore.ACPackingStore
LogUtil.error(LOGGER, ex.StackTrace); LogUtil.error(LOGGER, ex.StackTrace);
} }
} }
private void btnWriteSingleDO_Click(object sender, EventArgs e)
{
string deviceName = txtDoName.Text;
int index = FormUtil.GetIntValue(txtDOIndex);
IO_VALUE value = (IO_VALUE)cmbWriteValue.SelectedIndex;
int time = FormUtil.GetIntValue(txtWriteTime);
int slaveId = FormUtil.GetIntValue(txtSlaveId);
if (time > 0)
{
IOManager.instance.WriteSingleDO(deviceName, (byte)slaveId, (ushort)index, (IO_VALUE)value, time);
}
else
{
IOManager.instance.WriteSingleDO(deviceName, (byte)slaveId, (ushort)index, (IO_VALUE)value);
}
}
private ConfigIO GetSelectDO() private ConfigIO GetSelectDO()
{ {
...@@ -144,10 +132,6 @@ namespace OnlineStore.ACPackingStore ...@@ -144,10 +132,6 @@ namespace OnlineStore.ACPackingStore
} }
} }
private void FrmStoreIOStatus_Load(object sender, EventArgs e)
{
//KNDAIManager.NeedShow = true;
}
private void cmbWriteIO_DrawItem(object sender, DrawItemEventArgs e) private void cmbWriteIO_DrawItem(object sender, DrawItemEventArgs e)
{ {
...@@ -164,19 +148,6 @@ namespace OnlineStore.ACPackingStore ...@@ -164,19 +148,6 @@ namespace OnlineStore.ACPackingStore
} }
} }
private void cmbWriteValue_DrawItem(object sender, DrawItemEventArgs e)
{
if (e.Index < 0)
{
return;
}
e.DrawBackground();
e.DrawFocusRectangle();
if (cmbWriteValue.Items.Count > e.Index)
{
e.Graphics.DrawString(cmbWriteValue.Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds.X, e.Bounds.Y + 3);
}
}
private void btnReadIO_Click(object sender, EventArgs e) private void btnReadIO_Click(object sender, EventArgs e)
{ {
...@@ -194,7 +165,8 @@ namespace OnlineStore.ACPackingStore ...@@ -194,7 +165,8 @@ namespace OnlineStore.ACPackingStore
control.IOValue = iov; control.IOValue = iov;
control.ShowData(); control.ShowData();
} }
} foreach (string key in this.DOControlList.Keys) }
foreach (string key in this.DOControlList.Keys)
{ {
IOTextControl control = DOControlList[key]; IOTextControl control = DOControlList[key];
int iov = (int)IOManager.DOValue(key); int iov = (int)IOManager.DOValue(key);
...@@ -206,41 +178,58 @@ namespace OnlineStore.ACPackingStore ...@@ -206,41 +178,58 @@ namespace OnlineStore.ACPackingStore
} }
} }
protected void BtnMove(Button btn, string defaultText, string targetText, string ioHighType)
private void btnReadAllDi_Click(object sender, EventArgs e)
{ {
string deviceName = txtDoName.Text; LogUtil.info("点击【" + btn.Text + "】 ");
IO_VALUE value = (IO_VALUE)cmbWriteValue.SelectedIndex; if (btn.Text.Equals(defaultText))
int time = FormUtil.GetIntValue(txtWriteTime); {
int slaveId = FormUtil.GetIntValue(txtSlaveId); boxBean.IOMove(ioHighType, IO_VALUE.HIGH);
IOManager.instance.ReadAllDI(deviceName, (byte)slaveId ); btn.Text = targetText;
btn.BackColor = Color.Aqua;
} }
private void btnReadAllDo_Click(object sender, EventArgs e) else
{ {
string deviceName = txtDoName.Text; boxBean.IOMove(ioHighType, IO_VALUE.LOW);
btn.Text = defaultText;
btn.BackColor = Color.White;
}
}
IO_VALUE value = (IO_VALUE)cmbWriteValue.SelectedIndex; protected void BtnMove(Button btn, string defaultText, string targetText, string ioLowType, string ioHighType)
int time = FormUtil.GetIntValue(txtWriteTime); {
int slaveId = FormUtil.GetIntValue(txtSlaveId); LogUtil.info("点击【" + btn.Text + "】 ");
IOManager.instance.ReadAllDO(deviceName, (byte)slaveId ); if (btn.Text.Equals(defaultText))
{
boxBean.CylinderMove(null, ioLowType, ioHighType);
btn.Text = targetText;
btn.BackColor = Color.Aqua;
}
else
{
boxBean.CylinderMove(null, ioHighType, ioLowType);
btn.Text = defaultText;
btn.BackColor = Color.SkyBlue;
}
} }
private void btnOpenDoor_Click(object sender, EventArgs e) private void btnOpenDoor_Click(object sender, EventArgs e)
{ {
boxBean.CylinderMove(null, IO_Type.EntranceDoor_Close, IO_Type.EntranceDoor_Open);
} }
private void btnCloseDoor_Click(object sender, EventArgs e) private void btnCloseDoor_Click(object sender, EventArgs e)
{ {
boxBean.CylinderMove(null, IO_Type.EntranceDoor_Open, IO_Type.EntranceDoor_Close);
} }
private void btnLocationUp_Click(object sender, EventArgs e) private void btnLocationUp_Click(object sender, EventArgs e)
{ {
IOManager.IOMove(IO_Type.LocationCylinder_Down, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.LocationCylinder_Up, IO_VALUE.HIGH); boxBean.CylinderMove(null, IO_Type.LocationCylinder_Down, IO_Type.LocationCylinder_Up);
} }
private void btnLocationDown_Click(object sender, EventArgs e) private void btnLocationDown_Click(object sender, EventArgs e)
{ {
IOManager.IOMove(IO_Type.LocationCylinder_Down, IO_VALUE.HIGH); boxBean.CylinderMove(null, IO_Type.LocationCylinder_Up, IO_Type.LocationCylinder_Down);
IOManager.IOMove(IO_Type.LocationCylinder_Up, IO_VALUE.LOW);
} }
private void FrmIOStatus_Shown(object sender, EventArgs e) private void FrmIOStatus_Shown(object sender, EventArgs e)
...@@ -250,7 +239,7 @@ namespace OnlineStore.ACPackingStore ...@@ -250,7 +239,7 @@ namespace OnlineStore.ACPackingStore
private void btnOpenAxisBreak_Click(object sender, EventArgs e) private void btnOpenAxisBreak_Click(object sender, EventArgs e)
{ {
IOManager.IOMove(IO_Type.Axis_Brake, IO_VALUE.HIGH); BtnMove(btnOpenAxisBreak, "打开刹车", "关闭刹车", IO_Type.Axis_Brake);
} }
private void btnCloseAxisBreak_Click(object sender, EventArgs e) private void btnCloseAxisBreak_Click(object sender, EventArgs e)
...@@ -263,6 +252,65 @@ namespace OnlineStore.ACPackingStore ...@@ -263,6 +252,65 @@ namespace OnlineStore.ACPackingStore
this.Close(); this.Close();
} }
private void btnOpenDo_Click(object sender, EventArgs e)
{
WriteDO(IO_VALUE.HIGH);
}
private void btnWriteSingleDO_Click(object sender, EventArgs e)
{
WriteDO(IO_VALUE.LOW);
}
private void WriteDO(IO_VALUE value)
{
string deviceName = txtDoName.Text;
int index = FormUtil.GetIntValue(txtDOIndex);
// IO_VALUE value = checkBox1.Checked ? IO_VALUE.HIGH : IO_VALUE.LOW;
int time = FormUtil.GetIntValue(txtWriteTime);
int slaveId = FormUtil.GetIntValue(txtSlaveId);
if (time > 0)
{
IOManager.instance.WriteSingleDO(deviceName, (byte)slaveId, (ushort)index, (IO_VALUE)value, time);
}
else
{
IOManager.instance.WriteSingleDO(deviceName, (byte)slaveId, (ushort)index, (IO_VALUE)value);
}
}
private void btnTopUp_Click(object sender, EventArgs e)
{
boxBean.CylinderMove(null, IO_Type.TopCylinder_Down, IO_Type.TopCylinder_Up);
}
private void btnTopDown_Click(object sender, EventArgs e)
{
boxBean.CylinderMove(null, IO_Type.TopCylinder_Up, IO_Type.TopCylinder_Down);
}
private void btnNGDoorUp_Click(object sender, EventArgs e)
{
boxBean.CylinderMove(null, IO_Type.NGDoorCylinder_Down, IO_Type.NGDoowCylinder_Up);
}
private void btnNGDoorDown_Click(object sender, EventArgs e)
{
boxBean.CylinderMove(null, IO_Type.NGDoowCylinder_Up, IO_Type.NGDoorCylinder_Down);
}
private void btnCamerLed_Click(object sender, EventArgs e)
{
BtnMove(btnCamerLed, "打开光源", "关闭光源", IO_Type.Camera_Led);
}
private void button4_Click(object sender, EventArgs e)
{
BtnMove(button4, "线体正转", "线体反转", IO_Type.Line_Run, IO_Type.Line_BackRun);
}
private void btnStopMove_Click(object sender, EventArgs e)
{
boxBean.IOMove(IO_Type.Line_Run, IO_VALUE.LOW);
boxBean.IOMove(IO_Type.Line_BackRun, IO_VALUE.LOW);
}
} }
} }
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmStore)); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmStore));
this.tabControl1 = new System.Windows.Forms.TabControl(); this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage(); this.tabPage1 = new System.Windows.Forms.TabPage();
this.chbUseBuzzer = new System.Windows.Forms.CheckBox();
this.chkDebug = new System.Windows.Forms.CheckBox(); this.chkDebug = new System.Windows.Forms.CheckBox();
this.chbAutoRun = new System.Windows.Forms.CheckBox(); this.chbAutoRun = new System.Windows.Forms.CheckBox();
this.btnCopyLog = new System.Windows.Forms.Button(); this.btnCopyLog = new System.Windows.Forms.Button();
...@@ -85,6 +86,7 @@ ...@@ -85,6 +86,7 @@
// //
// tabPage1 // tabPage1
// //
this.tabPage1.Controls.Add(this.chbUseBuzzer);
this.tabPage1.Controls.Add(this.chkDebug); this.tabPage1.Controls.Add(this.chkDebug);
this.tabPage1.Controls.Add(this.chbAutoRun); this.tabPage1.Controls.Add(this.chbAutoRun);
this.tabPage1.Controls.Add(this.btnCopyLog); this.tabPage1.Controls.Add(this.btnCopyLog);
...@@ -97,6 +99,18 @@ ...@@ -97,6 +99,18 @@
this.tabPage1.Text = " 日志信息 "; this.tabPage1.Text = " 日志信息 ";
this.tabPage1.UseVisualStyleBackColor = true; this.tabPage1.UseVisualStyleBackColor = true;
// //
// chbUseBuzzer
//
this.chbUseBuzzer.AutoSize = true;
this.chbUseBuzzer.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.chbUseBuzzer.Location = new System.Drawing.Point(623, 31);
this.chbUseBuzzer.Name = "chbUseBuzzer";
this.chbUseBuzzer.Size = new System.Drawing.Size(98, 24);
this.chbUseBuzzer.TabIndex = 195;
this.chbUseBuzzer.Text = "启用蜂鸣器";
this.chbUseBuzzer.UseVisualStyleBackColor = true;
this.chbUseBuzzer.CheckedChanged += new System.EventHandler(this.chbUseBuzzer_CheckedChanged);
//
// chkDebug // chkDebug
// //
this.chkDebug.AutoSize = true; this.chkDebug.AutoSize = true;
...@@ -298,7 +312,7 @@ ...@@ -298,7 +312,7 @@
// 版本号ToolStripMenuItem // 版本号ToolStripMenuItem
// //
this.版本号ToolStripMenuItem.Name = "版本号ToolStripMenuItem"; this.版本号ToolStripMenuItem.Name = "版本号ToolStripMenuItem";
this.版本号ToolStripMenuItem.Size = new System.Drawing.Size(180, 26); this.版本号ToolStripMenuItem.Size = new System.Drawing.Size(144, 26);
this.版本号ToolStripMenuItem.Text = "关于软件"; this.版本号ToolStripMenuItem.Text = "关于软件";
this.版本号ToolStripMenuItem.Click += new System.EventHandler(this.版本号ToolStripMenuItem_Click); this.版本号ToolStripMenuItem.Click += new System.EventHandler(this.版本号ToolStripMenuItem_Click);
// //
...@@ -401,6 +415,7 @@ ...@@ -401,6 +415,7 @@
private System.Windows.Forms.ToolStripMenuItem 退出ToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem 退出ToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator7; private System.Windows.Forms.ToolStripSeparator toolStripSeparator7;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem2; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem2;
private System.Windows.Forms.CheckBox chbUseBuzzer;
} }
} }
...@@ -54,6 +54,7 @@ namespace OnlineStore.ACPackingStore ...@@ -54,6 +54,7 @@ namespace OnlineStore.ACPackingStore
this.Text = ConfigAppSettings.GetValue(Setting_Init.App_Title); this.Text = ConfigAppSettings.GetValue(Setting_Init.App_Title);
chbAutoRun.Checked = ConfigAppSettings.GetValue(Setting_Init.App_AutoRun).Equals(1); chbAutoRun.Checked = ConfigAppSettings.GetValue(Setting_Init.App_AutoRun).Equals(1);
HideForm(); HideForm();
chbAutoRun.Checked = store.UseBuzzer;
LoadOk = true; LoadOk = true;
} }
...@@ -386,5 +387,26 @@ namespace OnlineStore.ACPackingStore ...@@ -386,5 +387,26 @@ namespace OnlineStore.ACPackingStore
toolStripMenuItem2.Text = "启用调试"; toolStripMenuItem2.Text = "启用调试";
} }
} }
private void chbUseBuzzer_CheckedChanged(object sender, EventArgs e)
{
if (!LoadOk)
{
return;
}
if (chbUseBuzzer.Checked)
{
store.UseBuzzer = true;
ConfigAppSettings.SaveValue(Setting_Init.UseBuzzer, 1);
LogUtil.info("勾选:启用蜂鸣器");
}
else
{
store.UseBuzzer = false;
ConfigAppSettings.SaveValue(Setting_Init.UseBuzzer, 0);
LogUtil.info("去掉:启用蜂鸣器");
}
}
} }
} }
此文件的差异太大,无法显示。
...@@ -85,5 +85,7 @@ namespace OnlineStore.Common ...@@ -85,5 +85,7 @@ namespace OnlineStore.Common
public static string ACBaudRate = "ACBaudRate"; public static string ACBaudRate = "ACBaudRate";
public static string Store_ConfigPath = "Store_ConfigPath"; public static string Store_ConfigPath = "Store_ConfigPath";
public static string UseBuzzer = "UseBuzzer";
} }
} }
...@@ -323,7 +323,7 @@ namespace OnlineStore.Common ...@@ -323,7 +323,7 @@ namespace OnlineStore.Common
catch (Exception ex) catch (Exception ex)
{ {
isOk = false; isOk = false;
LogUtil.error(LOGGER, "SendCommand ERROR:" + ex.ToString(), 20); LogUtil.error( "SendCommand ERROR:" + ex.ToString(), 20);
} }
finally finally
{ {
......
...@@ -111,7 +111,7 @@ namespace OnlineStore.Common ...@@ -111,7 +111,7 @@ namespace OnlineStore.Common
} }
catch (Exception e) catch (Exception e)
{ {
LogUtil.error(LOGGER, "POST ERROR:" + e.StackTrace, 1); LogUtil.error( "POST ERROR:" + e.StackTrace, 1);
} }
if (!result.Contains("null") && result.Length != 0) if (!result.Contains("null") && result.Length != 0)
{ {
...@@ -145,7 +145,7 @@ namespace OnlineStore.Common ...@@ -145,7 +145,7 @@ namespace OnlineStore.Common
} }
catch (Exception e) catch (Exception e)
{ {
LogUtil.error(LOGGER, "HTTP GET ERROR:" + e.Message, 2); LogUtil.error( "HTTP GET ERROR:" + e.Message, 2);
} }
return ""; return "";
} }
......
...@@ -77,7 +77,7 @@ namespace OnlineStore.Common ...@@ -77,7 +77,7 @@ namespace OnlineStore.Common
private static List<string> lasErrorLogList = new List<string>(); private static List<string> lasErrorLogList = new List<string>();
private static int errCount = 5; private static int errCount = 5;
public static void error(ILog log, string errorMsg,int type,int spanSeconds=10) public static void error( string errorMsg,int type,int spanSeconds=10)
{ {
if (lastErrorLogTime.ContainsKey(type)) if (lastErrorLogTime.ContainsKey(type))
{ {
...@@ -90,13 +90,13 @@ namespace OnlineStore.Common ...@@ -90,13 +90,13 @@ namespace OnlineStore.Common
{ {
lastErrorLogTime.Remove(type); lastErrorLogTime.Remove(type);
lastErrorLogTime.Add(type, DateTime.Now); lastErrorLogTime.Add(type, DateTime.Now);
error(log, errorMsg); error(LOGGER, errorMsg);
} }
} }
else else
{ {
lastErrorLogTime.Add(type, DateTime.Now); lastErrorLogTime.Add(type, DateTime.Now);
error(log, errorMsg); error(LOGGER, errorMsg);
} }
} }
public static void error(ILog log, string errorMsg) public static void error(ILog log, string errorMsg)
......
...@@ -112,18 +112,18 @@ namespace OnlineStore.Common ...@@ -112,18 +112,18 @@ namespace OnlineStore.Common
{ {
m_clientSocket.BeginReceive(m_receiveBuffer, 0, m_receiveBuffer.Length, 0, new AsyncCallback(ReceiveCallBack), null); m_clientSocket.BeginReceive(m_receiveBuffer, 0, m_receiveBuffer.Length, 0, new AsyncCallback(ReceiveCallBack), null);
onReceived = HandleMessage; onReceived = HandleMessage;
LogUtil.info(LOGGER, "Connect to " + serverIP + ":" + serverPort + " success!"); LogUtil.info( "Connect to " + serverIP + ":" + serverPort + " success!");
ReConnectTimer.Start(); ReConnectTimer.Start();
return true; return true;
} }
else else
{ {
LogUtil.info(LOGGER, "Connect to " + serverIP + ":" + serverPort + " fail!"); LogUtil.info( "Connect to " + serverIP + ":" + serverPort + " fail!");
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.error(LOGGER,"Connect to " + serverIP + ":" + serverPort + " fail!" + ex.ToString(),3); LogUtil.error("Connect to " + serverIP + ":" + serverPort + " fail!" + ex.ToString(),3);
m_clientSocket = null; m_clientSocket = null;
} }
...@@ -176,7 +176,7 @@ namespace OnlineStore.Common ...@@ -176,7 +176,7 @@ namespace OnlineStore.Common
catch (Exception ex) catch (Exception ex)
{ {
isInProcess = false; isInProcess = false;
LogUtil.error(LOGGER, "重连处理出错:" + ex.ToString(),9,180); LogUtil.error( "重连处理出错:" + ex.ToString(),9,180);
} }
} }
...@@ -227,7 +227,7 @@ namespace OnlineStore.Common ...@@ -227,7 +227,7 @@ namespace OnlineStore.Common
} }
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.error(LOGGER,"socket received error:" + ex.ToString(),4); LogUtil.error("socket received error:" + ex.ToString(),4);
} }
} }
} }
......
...@@ -158,11 +158,11 @@ namespace OnlineStore.Common ...@@ -158,11 +158,11 @@ namespace OnlineStore.Common
} }
catch (SocketException e) catch (SocketException e)
{ {
LogUtil.error(LOGGER, e.ToString(), 6); LogUtil.error( e.ToString(), 6);
} }
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.error(LOGGER, ex.ToString(), 5); LogUtil.error( ex.ToString(), 5);
} }
} }
//private void ReceiveMessages(Client client) //private void ReceiveMessages(Client client)
......
...@@ -57,7 +57,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -57,7 +57,7 @@ namespace OnlineStore.DeviceLibrary
IoCheckTimer.Elapsed += IoCheckTimer_Elapsed; IoCheckTimer.Elapsed += IoCheckTimer_Elapsed;
//添加调试 //添加调试
IsDebug =config.IsInDebug.Equals(1); IsDebug = config.IsInDebug.Equals(1);
Name = ("料仓BOX_" + config.DeviceID + " ").ToUpper(); Name = ("料仓BOX_" + config.DeviceID + " ").ToUpper();
this.DeviceID = config.DeviceID; this.DeviceID = config.DeviceID;
...@@ -68,15 +68,11 @@ namespace OnlineStore.DeviceLibrary ...@@ -68,15 +68,11 @@ namespace OnlineStore.DeviceLibrary
PositionNumList = new List<string>(); PositionNumList = new List<string>();
foreach (ACBoxPosition position in positionList) foreach (ACBoxPosition position in positionList)
{ {
if (position.StoreId.Equals(DeviceID)) if (position.StoreId.Equals(DeviceID) && ACBoxPosition.CheckPosition(position, Config))
{
bool result = ACBoxPosition.CheckPosition(position, Config);
if (result)
{ {
PositionNumList.Add(position.PositionNum); PositionNumList.Add(position.PositionNum);
} }
} }
}
mainTimer.Enabled = false; mainTimer.Enabled = false;
int isAuto = ConfigAppSettings.GetIntValue(Setting_Init.App_AutoRun); int isAuto = ConfigAppSettings.GetIntValue(Setting_Init.App_AutoRun);
if (isAuto == 1) if (isAuto == 1)
...@@ -95,14 +91,13 @@ namespace OnlineStore.DeviceLibrary ...@@ -95,14 +91,13 @@ namespace OnlineStore.DeviceLibrary
if (isInSuddenDown.Equals(false)) if (isInSuddenDown.Equals(false))
{ {
isInSuddenDown = true; isInSuddenDown = true;
LogUtil.error(LOGGER, Name + "收到急停信号,报警急停"); LogUtil.error( Name + "收到急停信号,报警急停");
WarnMsg = Name + "收到急停信号,报警急停"; WarnMsg = Name + "收到急停信号,报警急停";
//报警时会关闭所有轴 //报警时会关闭所有轴
Alarm(StoreAlarmType.SuddenStop, "1", WarnMsg, StoreMoveType.None); Alarm(StoreAlarmType.SuddenStop, "1", WarnMsg, StoreMoveType.None);
} }
} }
} }
} }
/// <summary> /// <summary>
...@@ -124,7 +119,6 @@ namespace OnlineStore.DeviceLibrary ...@@ -124,7 +119,6 @@ namespace OnlineStore.DeviceLibrary
moveAxisList.Add(Config.Comp_Axis); moveAxisList.Add(Config.Comp_Axis);
this.AxisAlarmCodeMap.Add(this.Config.Comp_Axis.GetNameStr(), new AxisAlarmInfo()); this.AxisAlarmCodeMap.Add(this.Config.Comp_Axis.GetNameStr(), new AxisAlarmInfo());
} }
/// <summary> /// <summary>
...@@ -132,7 +126,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -132,7 +126,7 @@ namespace OnlineStore.DeviceLibrary
/// </summary> /// </summary>
public override bool StartRun() public override bool StartRun()
{ {
LogUtil.info(LOGGER, Name + "开始启动,启动时间:" + StartTime.ToString()); LogInfo( "开始启动,启动时间:" + StartTime.ToString());
autoNext = false; autoNext = false;
mainTimer.Enabled = false; mainTimer.Enabled = false;
...@@ -142,7 +136,6 @@ namespace OnlineStore.DeviceLibrary ...@@ -142,7 +136,6 @@ namespace OnlineStore.DeviceLibrary
IO_VALUE suddenBtn = IOValue(IO_Type.SuddenStop_BTN); IO_VALUE suddenBtn = IOValue(IO_Type.SuddenStop_BTN);
IO_VALUE airCheck = IOValue(IO_Type.Airpressure_Check); IO_VALUE airCheck = IOValue(IO_Type.Airpressure_Check);
//if (suddenBtn == IO_VALUE.HIGH)
if (suddenBtn.Equals(IO_VALUE.HIGH) && (airCheck.Equals(IO_VALUE.HIGH)) ) if (suddenBtn.Equals(IO_VALUE.HIGH) && (airCheck.Equals(IO_VALUE.HIGH)) )
{ {
//lastAirValue = airCheck; //lastAirValue = airCheck;
...@@ -157,7 +150,6 @@ namespace OnlineStore.DeviceLibrary ...@@ -157,7 +150,6 @@ namespace OnlineStore.DeviceLibrary
storeStatus = StoreStatus.ResetMove; storeStatus = StoreStatus.ResetMove;
//启动温湿度服务器 //启动温湿度服务器
HumitureController.Init(Config.Humiture_Port); HumitureController.Init(Config.Humiture_Port);
// LineConnect.StartConnect();
ReturnHome(); ReturnHome();
StartTime = DateTime.Now; StartTime = DateTime.Now;
...@@ -171,11 +163,11 @@ namespace OnlineStore.DeviceLibrary ...@@ -171,11 +163,11 @@ namespace OnlineStore.DeviceLibrary
{ {
if (suddenBtn.Equals(IO_VALUE.LOW)) if (suddenBtn.Equals(IO_VALUE.LOW))
{ {
LogUtil.error(LOGGER, " (" + Name + ")启动出现错误:急停没开 !启动失败!"); LogUtil.error( " (" + Name + ")启动出现错误:急停没开 !启动失败!");
} }
else else
{ {
LogUtil.error(LOGGER, " (" + Name + ")启动出现错误:没有气压信号 !启动失败!"); LogUtil.error( " (" + Name + ")启动出现错误:没有气压信号 !启动失败!");
} }
return false; return false;
} }
...@@ -198,7 +190,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -198,7 +190,7 @@ namespace OnlineStore.DeviceLibrary
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H_InOutBack); MoveInfo.NextMoveStep(StoreMoveStep.BOX_H_InOutBack);
ACAxisHomeMove(Config.InOut_Axis); ACAxisHomeMove(Config.InOut_Axis);
LogUtil.info(LOGGER, Name + "开始原点返回,先把进出轴回原点"); LogInfo( "开始原点返回,先把进出轴回原点");
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000)); MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000));
} }
...@@ -207,7 +199,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -207,7 +199,7 @@ namespace OnlineStore.DeviceLibrary
//压紧轴回原点,叉子回到P1,关闭门旋转轴和升降轴回到P1 //压紧轴回原点,叉子回到P1,关闭门旋转轴和升降轴回到P1
MoveInfo.NewMove(StoreMoveType.StoreReset); MoveInfo.NewMove(StoreMoveType.StoreReset);
MoveInfo.NextMoveStep(StoreMoveStep.BOX_M_H_TOP1_InOutToP1); MoveInfo.NextMoveStep(StoreMoveStep.BOX_M_H_TOP1_InOutToP1);
LogUtil.info(LOGGER, Name + "到待机状态,进出轴到P1,判断叉子没有料盘"); LogInfo( "到待机状态,进出轴到P1,判断叉子没有料盘");
ACAxisMove(Config.InOut_Axis, Config.InOutAxis_P1_Position, Config.InOutAxis_P1_Speed); ACAxisMove(Config.InOut_Axis, Config.InOutAxis_P1_Position, Config.InOutAxis_P1_Speed);
//ComBeforeHomeMove(); //ComBeforeHomeMove();
//判断叉子没有料盘 //判断叉子没有料盘
...@@ -244,7 +236,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -244,7 +236,7 @@ namespace OnlineStore.DeviceLibrary
////打开四个轴 ////打开四个轴
//if (!OpenAllAxis()) //if (!OpenAllAxis())
{ {
LogUtil.info(LOGGER, Name + "复位时打开轴失败,需要再次复位,直接报警停止复位"); LogInfo( "复位时打开轴失败,需要再次复位,直接报警停止复位");
return; return;
} }
...@@ -258,7 +250,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -258,7 +250,7 @@ namespace OnlineStore.DeviceLibrary
int slvAddr = Config.InOut_Axis.GetAxisValue(); int slvAddr = Config.InOut_Axis.GetAxisValue();
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H_InOutBack); MoveInfo.NextMoveStep(StoreMoveStep.BOX_H_InOutBack);
LogUtil.info(LOGGER, Name + "复位中,进出轴开始原点返回"); LogInfo( "复位中,进出轴开始原点返回");
ACAxisHomeMove(Config.InOut_Axis); ACAxisHomeMove(Config.InOut_Axis);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000)); MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000));
} }
...@@ -283,17 +275,16 @@ namespace OnlineStore.DeviceLibrary ...@@ -283,17 +275,16 @@ namespace OnlineStore.DeviceLibrary
case StoreMoveStep.BOX_H_InOutMove: case StoreMoveStep.BOX_H_InOutMove:
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H_InOutBack); MoveInfo.NextMoveStep(StoreMoveStep.BOX_H_InOutBack);
ACAxisHomeMove(Config.InOut_Axis); ACAxisHomeMove(Config.InOut_Axis);
LogUtil.info(LOGGER, Name + "复位中:进出轴开始原点返回"); LogInfo( "复位中:进出轴开始原点返回");
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000)); MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000));
break; break;
case StoreMoveStep.BOX_H_InOutBack: case StoreMoveStep.BOX_H_InOutBack:
Thread.Sleep(200); Thread.Sleep(200);
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H_InOutToP1); MoveInfo.NextMoveStep(StoreMoveStep.BOX_H_InOutToP1);
LogUtil.info(LOGGER, Name + "复位中:进出轴到待机点P1,关闭舱门"); LogInfo( "复位中:进出轴到待机点P1,关闭舱门");
//进出轴原点返回完成,将进出轴的位置设置=0 //进出轴原点返回完成,将进出轴的位置设置=0
AxisCountClear(Config.InOut_Axis); AxisCountClear(Config.InOut_Axis);
ACAxisMove(Config.InOut_Axis, Config.InOutAxis_P1_Position, Config.InOutAxis_P1_Speed); ACAxisMove(Config.InOut_Axis, Config.InOutAxis_P1_Position, Config.InOutAxis_P1_Speed);
//ComBeforeHomeMove();
//判断叉子没有料盘 //判断叉子没有料盘
//StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.TrayCheck_Fixture, IO_VALUE.LOW)); //StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.TrayCheck_Fixture, IO_VALUE.LOW));
CloseDoor(); CloseDoor();
...@@ -302,10 +293,10 @@ namespace OnlineStore.DeviceLibrary ...@@ -302,10 +293,10 @@ namespace OnlineStore.DeviceLibrary
//如果此时轴三还在报警,需要提示错误并等待 //如果此时轴三还在报警,需要提示错误并等待
if (ACServerManager.GetAlarmStatus(Config.InOut_Axis.DeviceName, Config.InOut_Axis.GetAxisValue()) > 0) if (ACServerManager.GetAlarmStatus(Config.InOut_Axis.DeviceName, Config.InOut_Axis.GetAxisValue()) > 0)
{ {
LogUtil.error(LOGGER, "进出轴报警!复位失败,请检查!"); LogUtil.error(Name+ "进出轴报警!复位失败,请检查!");
} }
//复位和回原点要等轴3进出轴ORG亮了以后才能返回其他轴 //复位和回原点要等轴3进出轴ORG亮了以后才能返回其他轴
LogUtil.info(LOGGER, Name + "复位中: 压紧轴,旋转轴,上下轴开始 原点返回"); LogInfo( "复位中: 压紧轴,旋转轴,上下轴开始 原点返回");
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H_OtherAxisBack); MoveInfo.NextMoveStep(StoreMoveStep.BOX_H_OtherAxisBack);
ACAxisHomeMove(Config.Comp_Axis); ACAxisHomeMove(Config.Comp_Axis);
...@@ -316,14 +307,14 @@ namespace OnlineStore.DeviceLibrary ...@@ -316,14 +307,14 @@ namespace OnlineStore.DeviceLibrary
case StoreMoveStep.BOX_H_OtherAxisBack: case StoreMoveStep.BOX_H_OtherAxisBack:
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H_MiddleAxisToP1); MoveInfo.NextMoveStep(StoreMoveStep.BOX_H_MiddleAxisToP1);
LogUtil.info(LOGGER, Name + "复位中:旋转轴运动到P1,上下轴走到P1,压紧轴到P1!"); LogInfo( "复位中:旋转轴运动到P1,上下轴走到P1,压紧轴到P1!");
ACAxisMove(Config.Middle_Axis, Config.MiddleAxis_P1_Position, Config.MiddleAxis_P1_Speed); ACAxisMove(Config.Middle_Axis, Config.MiddleAxis_P1_Position, Config.MiddleAxis_P1_Speed);
ACAxisMove(Config.UpDown_Axis, Config.UpDownAxis_DoorOPosition_P1, Config.UpDownAxis_P1_Speed); ACAxisMove(Config.UpDown_Axis, Config.UpDownAxis_DoorOPosition_P1, Config.UpDownAxis_P1_Speed);
ComMoveToPosition(Config.CompressAxis_P1_Position, Config.CompAxis_P1_Speed); ComMoveToPosition(Config.CompressAxis_P1_Position, Config.CompAxis_P1_Speed);
break; break;
case StoreMoveStep.BOX_H_MiddleAxisToP1: case StoreMoveStep.BOX_H_MiddleAxisToP1:
LogUtil.info(LOGGER, Name + "复位完成"); LogInfo( "复位完成");
storeRunStatus = StoreRunStatus.Runing; storeRunStatus = StoreRunStatus.Runing;
MoveInfo.EndMove(); MoveInfo.EndMove();
storeStatus = StoreStatus.StoreOnline; storeStatus = StoreStatus.StoreOnline;
...@@ -335,7 +326,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -335,7 +326,7 @@ namespace OnlineStore.DeviceLibrary
case StoreMoveStep.BOX_M_H_TOP1_InOutToP1: case StoreMoveStep.BOX_M_H_TOP1_InOutToP1:
MoveInfo.NextMoveStep(StoreMoveStep.BOX_M_H_TOP1_CompressHome); MoveInfo.NextMoveStep(StoreMoveStep.BOX_M_H_TOP1_CompressHome);
LogUtil.info(LOGGER, Name + "到待机状态,压紧轴回原点,关闭舱门"); LogInfo( "到待机状态,压紧轴回原点,关闭舱门");
ACAxisHomeMove(Config.Comp_Axis); ACAxisHomeMove(Config.Comp_Axis);
...@@ -344,13 +335,13 @@ namespace OnlineStore.DeviceLibrary ...@@ -344,13 +335,13 @@ namespace OnlineStore.DeviceLibrary
break; break;
case StoreMoveStep.BOX_M_H_TOP1_CompressHome: case StoreMoveStep.BOX_M_H_TOP1_CompressHome:
MoveInfo.NextMoveStep(StoreMoveStep.BOX_M_H_TOP1_OtherAxisToP1); MoveInfo.NextMoveStep(StoreMoveStep.BOX_M_H_TOP1_OtherAxisToP1);
LogUtil.info(LOGGER, Name + "复位中:旋转轴运动到P1,上下轴走到P1,压紧轴到P1!"); LogInfo( "复位中:旋转轴运动到P1,上下轴走到P1,压紧轴到P1!");
ACAxisMove(Config.Middle_Axis, Config.MiddleAxis_P1_Position, Config.MiddleAxis_P1_Speed); ACAxisMove(Config.Middle_Axis, Config.MiddleAxis_P1_Position, Config.MiddleAxis_P1_Speed);
ACAxisMove(Config.UpDown_Axis, Config.UpDownAxis_DoorOPosition_P1, Config.UpDownAxis_P1_Speed); ACAxisMove(Config.UpDown_Axis, Config.UpDownAxis_DoorOPosition_P1, Config.UpDownAxis_P1_Speed);
ComMoveToPosition(Config.CompressAxis_P1_Position, Config.CompAxis_P1_Speed); ComMoveToPosition(Config.CompressAxis_P1_Position, Config.CompAxis_P1_Speed);
break; break;
case StoreMoveStep.BOX_M_H_TOP1_OtherAxisToP1: case StoreMoveStep.BOX_M_H_TOP1_OtherAxisToP1:
LogUtil.info(LOGGER, Name + "到待机状态完成"); LogInfo( "到待机状态完成");
MoveInfo.EndMove(); MoveInfo.EndMove();
storeStatus = StoreStatus.StoreOnline; storeStatus = StoreStatus.StoreOnline;
storeRunStatus = StoreRunStatus.Runing; storeRunStatus = StoreRunStatus.Runing;
...@@ -367,8 +358,6 @@ namespace OnlineStore.DeviceLibrary ...@@ -367,8 +358,6 @@ namespace OnlineStore.DeviceLibrary
private void ComMoveToPosition(int targetPosition, int targetSpeed) private void ComMoveToPosition(int targetPosition, int targetSpeed)
{ {
ACAxisMove(Config.Comp_Axis, targetPosition, targetSpeed); ACAxisMove(Config.Comp_Axis, targetPosition, targetSpeed);
} }
public void OpenDoor(bool IsWait = true) public void OpenDoor(bool IsWait = true)
{ {
...@@ -411,7 +400,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -411,7 +400,7 @@ namespace OnlineStore.DeviceLibrary
{ {
case StoreMoveStep.BOX_H_LocationCylinderBack: case StoreMoveStep.BOX_H_LocationCylinderBack:
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H_InOutBack); MoveInfo.NextMoveStep(StoreMoveStep.BOX_H_InOutBack);
LogUtil.info(LOGGER, Name + "原点返回中,进出轴回原点"); LogInfo( "原点返回中,进出轴回原点");
//复位和回原点要等轴3进出轴ORG亮了以后才能返回其他轴 //复位和回原点要等轴3进出轴ORG亮了以后才能返回其他轴
ACAxisHomeMove(Config.InOut_Axis); ACAxisHomeMove(Config.InOut_Axis);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000)); MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000));
...@@ -419,7 +408,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -419,7 +408,7 @@ namespace OnlineStore.DeviceLibrary
case StoreMoveStep.BOX_H_InOutBack: case StoreMoveStep.BOX_H_InOutBack:
Thread.Sleep(200); Thread.Sleep(200);
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H_InOutToP1); MoveInfo.NextMoveStep(StoreMoveStep.BOX_H_InOutToP1);
LogUtil.info(LOGGER, Name + "原点返回中,进出轴退回P1点,关闭仓门,检测叉子没有料盘"); LogInfo( "原点返回中,进出轴退回P1点,关闭仓门,检测叉子没有料盘");
//进出轴原点返回完成,将进出轴的位置设置=0 //进出轴原点返回完成,将进出轴的位置设置=0
AxisCountClear(Config.InOut_Axis); AxisCountClear(Config.InOut_Axis);
ACAxisMove(Config.InOut_Axis, Config.InOutAxis_P1_Position, Config.InOutAxis_P1_Speed); ACAxisMove(Config.InOut_Axis, Config.InOutAxis_P1_Position, Config.InOutAxis_P1_Speed);
...@@ -434,10 +423,10 @@ namespace OnlineStore.DeviceLibrary ...@@ -434,10 +423,10 @@ namespace OnlineStore.DeviceLibrary
if (ACServerManager.GetAlarmStatus(Config.InOut_Axis.DeviceName, Config.InOut_Axis.GetAxisValue()) > 0) if (ACServerManager.GetAlarmStatus(Config.InOut_Axis.DeviceName, Config.InOut_Axis.GetAxisValue()) > 0)
{ {
WarnMsg = "进出轴报警!复位失败,请检查!"; WarnMsg = "进出轴报警!复位失败,请检查!";
LogUtil.error(LOGGER, "进出轴报警!复位失败,请检查!"); LogUtil.error(Name+ "进出轴报警!复位失败,请检查!");
} }
//复位和回原点要等轴3进出轴ORG亮了以后才能返回其他轴 //复位和回原点要等轴3进出轴ORG亮了以后才能返回其他轴
LogUtil.info(LOGGER, Name + "原点返回中 :压紧轴,旋转轴,上下轴开始原点返回"); LogInfo( "原点返回中 :压紧轴,旋转轴,上下轴开始原点返回");
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H_OtherAxisBack); MoveInfo.NextMoveStep(StoreMoveStep.BOX_H_OtherAxisBack);
ACAxisHomeMove(Config.Comp_Axis); ACAxisHomeMove(Config.Comp_Axis);
...@@ -448,13 +437,13 @@ namespace OnlineStore.DeviceLibrary ...@@ -448,13 +437,13 @@ namespace OnlineStore.DeviceLibrary
case StoreMoveStep.BOX_H_OtherAxisBack: case StoreMoveStep.BOX_H_OtherAxisBack:
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H_MiddleAxisToP1); MoveInfo.NextMoveStep(StoreMoveStep.BOX_H_MiddleAxisToP1);
LogUtil.info(LOGGER, Name + "回原点:旋转轴运动到P1,上下轴到P1,压紧轴到P1!"); LogInfo( "回原点:旋转轴运动到P1,上下轴到P1,压紧轴到P1!");
ACAxisMove(Config.Middle_Axis, Config.MiddleAxis_P1_Position, Config.MiddleAxis_P1_Speed); ACAxisMove(Config.Middle_Axis, Config.MiddleAxis_P1_Position, Config.MiddleAxis_P1_Speed);
ACAxisMove(Config.UpDown_Axis, Config.UpDownAxis_DoorOPosition_P1, Config.UpDownAxis_P1_Speed); ACAxisMove(Config.UpDown_Axis, Config.UpDownAxis_DoorOPosition_P1, Config.UpDownAxis_P1_Speed);
ComMoveToPosition(Config.CompressAxis_P1_Position, Config.CompAxis_P1_Speed); ComMoveToPosition(Config.CompressAxis_P1_Position, Config.CompAxis_P1_Speed);
break; break;
case StoreMoveStep.BOX_H_MiddleAxisToP1: case StoreMoveStep.BOX_H_MiddleAxisToP1:
LogUtil.info(LOGGER, Name + "回原点完成"); LogInfo( "回原点完成");
storeRunStatus = StoreRunStatus.Runing; storeRunStatus = StoreRunStatus.Runing;
MoveInfo.EndMove(); MoveInfo.EndMove();
storeStatus = StoreStatus.StoreOnline; storeStatus = StoreStatus.StoreOnline;
...@@ -511,26 +500,26 @@ namespace OnlineStore.DeviceLibrary ...@@ -511,26 +500,26 @@ namespace OnlineStore.DeviceLibrary
{ {
if (ACServerManager.ServerOnStatus(axis.DeviceName, axis.GetAxisValue())) if (ACServerManager.ServerOnStatus(axis.DeviceName, axis.GetAxisValue()))
{ {
LogUtil.info(LOGGER, Name + "成功打开轴:" + axis.Explain); LogInfo( "成功打开轴:" + axis.Explain);
} }
else else
{ {
//清理报警,再重新打开一次 //清理报警,再重新打开一次
LogUtil.info(LOGGER, Name + "第一次打开轴" + axis.Explain + "失败,先清理一下报警,再重新打开一次"); LogInfo( "第一次打开轴" + axis.Explain + "失败,先清理一下报警,再重新打开一次");
ACServerManager.AlarmClear(axis.DeviceName, axis.GetAxisValue()); ACServerManager.AlarmClear(axis.DeviceName, axis.GetAxisValue());
System.Threading.Thread.Sleep(1200); System.Threading.Thread.Sleep(1200);
ACServerManager.ServoOn(axis.DeviceName, axis.GetAxisValue()); ACServerManager.ServoOn(axis.DeviceName, axis.GetAxisValue());
System.Threading.Thread.Sleep(100); System.Threading.Thread.Sleep(100);
if (ACServerManager.ServerOnStatus(axis.DeviceName, axis.GetAxisValue())) if (ACServerManager.ServerOnStatus(axis.DeviceName, axis.GetAxisValue()))
{ {
LogUtil.info(LOGGER, Name + "清理报警后重新打卡轴成功:" + axis.Explain); LogInfo( "清理报警后重新打卡轴成功:" + axis.Explain);
} }
else else
{ {
ACServerManager.ServoOff(axis.DeviceName, axis.GetAxisValue()); ACServerManager.ServoOff(axis.DeviceName, axis.GetAxisValue());
int alarmCode = GetAlarmCodeByAxis(axis); int alarmCode = GetAlarmCodeByAxis(axis);
WarnMsg = Name + "打开轴" + axis.Explain + "失败 "; WarnMsg = Name + "打开轴" + axis.Explain + "失败 ";
LogUtil.info(LOGGER, Name + WarnMsg); LogInfo( WarnMsg);
Alarm(StoreAlarmType.AxisAlarm, GetAlarmCodeByAxis(axis).ToString(), WarnMsg, MoveInfo.MoveType); Alarm(StoreAlarmType.AxisAlarm, GetAlarmCodeByAxis(axis).ToString(), WarnMsg, MoveInfo.MoveType);
return false; return false;
} }
...@@ -553,28 +542,6 @@ namespace OnlineStore.DeviceLibrary ...@@ -553,28 +542,6 @@ namespace OnlineStore.DeviceLibrary
IOMove(IO_Type.Run_Signal, IO_VALUE.LOW); IOMove(IO_Type.Run_Signal, IO_VALUE.LOW);
} }
private int GetAlarmCodeByAxis(ConfigMoveAxis axis)
{
int alarmCode = LineAlarm.InOutAxisAlarm;
int axisType = axis.GetAxisValue() % 4;
if (axisType == 1)
{
alarmCode = LineAlarm.MiddleAxisAlarm;
}
else if (axisType == 2)
{
alarmCode = LineAlarm.UpDownAxisAlarm;
}
else if (axisType == 3)
{
alarmCode = LineAlarm.InOutAxisAlarm;
}
else
{
alarmCode = LineAlarm.CompressAxisAlarm;
}
return alarmCode;
}
/// <summary> /// <summary>
/// 停止运行 /// 停止运行
...@@ -595,7 +562,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -595,7 +562,7 @@ namespace OnlineStore.DeviceLibrary
//LineConnect.StopConnect(); //LineConnect.StopConnect();
IOManager.instance.CloseAllDO(); IOManager.instance.CloseAllDO();
LogUtil.info(LOGGER, Name + ",停止运行,总运行时间:" + span.ToString()); LogInfo( ",停止运行,总运行时间:" + span.ToString());
} }
public override void Alarm(StoreAlarmType alarmType, string alarmDetial, string alarmMsg, StoreMoveType storeMoveType) public override void Alarm(StoreAlarmType alarmType, string alarmDetial, string alarmMsg, StoreMoveType storeMoveType)
...@@ -607,19 +574,19 @@ namespace OnlineStore.DeviceLibrary ...@@ -607,19 +574,19 @@ namespace OnlineStore.DeviceLibrary
{ {
return; return;
} }
LogUtil.error(LOGGER, Name + " 报警,报警类型:" + alarmType); LogUtil.error( Name + " 报警,报警类型:" + alarmType);
this.alarmType = alarmType; this.alarmType = alarmType;
if (alarmType.Equals(StoreAlarmType.AxisAlarm) | alarmType.Equals(StoreAlarmType.AxisMoveError)) if (alarmType.Equals(StoreAlarmType.AxisAlarm) | alarmType.Equals(StoreAlarmType.AxisMoveError))
{ {
LogUtil.error(LOGGER, Name + "轴报警,关闭刹车,停止运动,关闭轴,打开报警灯"); LogUtil.error( Name + "轴报警,关闭刹车,停止运动,关闭轴,打开报警灯");
IOMove(IO_Type.Axis_Brake, IO_VALUE.LOW); IOMove(IO_Type.Axis_Brake, IO_VALUE.LOW);
StopMove( ); StopMove( );
} }
else if (alarmType == StoreAlarmType.SuddenStop) else if (alarmType == StoreAlarmType.SuddenStop)
{ {
isInSuddenDown = true; isInSuddenDown = true;
LogUtil.error(LOGGER, Name + "收到急停信号,关闭刹车,停止运动,关闭轴,打开报警灯 "); LogUtil.error( Name + "收到急停信号,关闭刹车,停止运动,关闭轴,打开报警灯 ");
IOMove(IO_Type.Axis_Brake, IO_VALUE.LOW); IOMove(IO_Type.Axis_Brake, IO_VALUE.LOW);
MoveInfo.EndMove(); MoveInfo.EndMove();
StopMove( ); StopMove( );
...@@ -628,7 +595,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -628,7 +595,7 @@ namespace OnlineStore.DeviceLibrary
else if (alarmType.Equals(StoreAlarmType.NoAirCheck)) else if (alarmType.Equals(StoreAlarmType.NoAirCheck))
{ {
isNoAirCheck = true; isNoAirCheck = true;
LogUtil.error(LOGGER, Name + " 未检测到气压信号 ,打开刹车,停止运动,关闭轴,打开报警灯 "); LogUtil.error( Name + " 未检测到气压信号 ,打开刹车,停止运动,关闭轴,打开报警灯 ");
IOMove(IO_Type.Axis_Brake, IO_VALUE.LOW); IOMove(IO_Type.Axis_Brake, IO_VALUE.LOW);
MoveInfo.EndMove(); MoveInfo.EndMove();
StopMove( ); StopMove( );
...@@ -673,7 +640,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -673,7 +640,7 @@ namespace OnlineStore.DeviceLibrary
} }
catch (Exception ex) catch (Exception ex)
{ {
LOGGER.Error(Name + "定时处理出错:" + ex.ToString()); LogUtil.error(Name + "定时处理出错:" + ex.ToString());
} }
IsChongfu = false; IsChongfu = false;
InProcess = false; InProcess = false;
...@@ -725,104 +692,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -725,104 +692,8 @@ namespace OnlineStore.DeviceLibrary
LogUtil.info("【" + info + "】 处理完成,耗时:" + stopwatch.Elapsed.ToString()); LogUtil.info("【" + info + "】 处理完成,耗时:" + stopwatch.Elapsed.ToString());
} }
} }
private void LedProcess()
{
try
{
// 机器状态 顶灯显示
// 绿 黄 红
//机器复位中 闪 灭 灭
//机器待机中 亮 灭 灭
//机器出入库中 闪 闪 灭
//温湿度超限报警中 亮 闪 灭
//温湿度超限报警中超过30分钟 亮 闪 闪
//机器未启动 灭 灭 灭
//机器设备故障(非温湿度)报警 亮 灭 闪
//报警时只需要亮红灯
DateTime time = DateTime.Now;
bool isTemp30M = false;
if (TempOrHumidityIsAlarm)
{
TimeSpan span = DateTime.Now - TempAlarmTime;
if (span.Minutes > 30)
{
isTemp30M = true;
}
}
bool isNeedAlarmLed = false;
//报警灯
if (!alarmType.Equals(StoreAlarmType.None) || isTemp30M)
{
isNeedAlarmLed = true;
}
if (isNeedAlarmLed && IOValue(IO_Type.Alarm_HddLed).Equals(IO_VALUE.LOW))
{
IOMove(IO_Type.Alarm_HddLed, IO_VALUE.HIGH);
}
else
{
if (IOValue(IO_Type.Alarm_HddLed).Equals(IO_VALUE.HIGH))
{
IOMove(IO_Type.Alarm_HddLed, IO_VALUE.LOW);
}
}
//报警时绿灯和黄灯灭
if (isNeedAlarmLed)
{
if (IOValue(IO_Type.AutoRun_HddLed).Equals(IO_VALUE.HIGH))
{
IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.LOW);
}
if (IOValue(IO_Type.RunSign_HddLed).Equals(IO_VALUE.HIGH))
{
IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.LOW);
}
return;
}
//绿灯闪
if ((MoveInfo.MoveType.Equals(StoreMoveType.InStore) || MoveInfo.MoveType.Equals(StoreMoveType.OutStore)
|| storeRunStatus.Equals(StoreRunStatus.HomeMoving) || storeRunStatus.Equals(StoreRunStatus.Reset))
&& IOValue(IO_Type.AutoRun_HddLed).Equals(IO_VALUE.HIGH))
{
IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.LOW);
}
else
{
//绿灯亮
IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.HIGH);
}
//黄灯
if (MoveInfo.MoveType.Equals(StoreMoveType.InStore) || MoveInfo.MoveType.Equals(StoreMoveType.OutStore) || TempOrHumidityIsAlarm || isTemp30M)
{
if (IOValue(IO_Type.RunSign_HddLed).Equals(IO_VALUE.HIGH))
{
IOMove(IO_Type.RunSign_HddLed, IO_VALUE.LOW);
}
else
{
IOMove(IO_Type.RunSign_HddLed, IO_VALUE.HIGH);
}
}
else
{
if (IOValue(IO_Type.RunSign_HddLed).Equals(IO_VALUE.HIGH))
{
IOMove(IO_Type.RunSign_HddLed, IO_VALUE.LOW);
}
}
}
catch (Exception ex)
{
LOGGER.Error(Name + "灯处理定时器出错:", ex);
}
}
private IO_VALUE lastAutoRun = IO_VALUE.LOW; private IO_VALUE lastAutoRun = IO_VALUE.LOW;
// private IO_VALUE lastAirValue = IO_VALUE.LOW;
public void IoCheckProcess() public void IoCheckProcess()
{ {
DateTime time = DateTime.Now; DateTime time = DateTime.Now;
...@@ -835,11 +706,11 @@ namespace OnlineStore.DeviceLibrary ...@@ -835,11 +706,11 @@ namespace OnlineStore.DeviceLibrary
if (autoSingle.Equals(IO_VALUE.HIGH) && lastAutoRun.Equals(IO_VALUE.LOW)) if (autoSingle.Equals(IO_VALUE.HIGH) && lastAutoRun.Equals(IO_VALUE.LOW))
{ {
//没有启动时收到复位按钮,相当于启动按钮 //没有启动时收到复位按钮,相当于启动按钮
LogUtil.info(LOGGER, Name + "没有启动时收到复位按钮,相当于启动按钮,开始调用启动方法!"); LogInfo( "没有启动时收到复位按钮,相当于启动按钮,开始调用启动方法!");
bool result = StartRun(); bool result = StartRun();
if (result.Equals(false)) if (result.Equals(false))
{ {
LogUtil.error("料仓启动失败,继续等待下次启动!"); LogUtil.error(Name+"料仓启动失败,继续等待下次启动!");
mainTimer.Enabled = true; mainTimer.Enabled = true;
} }
} }
...@@ -867,18 +738,18 @@ namespace OnlineStore.DeviceLibrary ...@@ -867,18 +738,18 @@ namespace OnlineStore.DeviceLibrary
{ {
if (MoveInfo.MoveType.Equals(StoreMoveType.None)) if (MoveInfo.MoveType.Equals(StoreMoveType.None))
{ {
LogUtil.info(LOGGER, "收到复位信号,当前无报警,且空闲中,只回到待机点"); LogUtil.info( Name+"收到复位信号,当前无报警,且空闲中,只回到待机点");
MoveToP1(); MoveToP1();
} }
else else
{ {
LogUtil.info(LOGGER, "收到复位信号,当前无报警, 在" + MoveInfo.MoveType + "处理中,不处理复位"); LogUtil.info(Name+ "收到复位信号,当前无报警, 在" + MoveInfo.MoveType + "处理中,不处理复位");
} }
} }
else else
{ {
//收到复位信号 //收到复位信号
LogUtil.info(LOGGER, "收到复位信号,自动复位"); LogUtil.info( "收到复位信号,自动复位");
WarnMsg = "收到复位信号,自动复位"; WarnMsg = "收到复位信号,自动复位";
Reset(); Reset();
} }
...@@ -910,7 +781,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -910,7 +781,7 @@ namespace OnlineStore.DeviceLibrary
} }
catch (Exception ex) catch (Exception ex)
{ {
LOGGER.Error(Name + "定时处理出错", ex); LogUtil.error(Name + "定时处理出错"+ ex.ToString());
} }
} }
...@@ -951,7 +822,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -951,7 +822,7 @@ namespace OnlineStore.DeviceLibrary
} }
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.error(LOGGER, "IOTimeOutProcess出错:" + ex.ToString()); LogUtil.error(Name+ "IOTimeOutProcess出错:" + ex.ToString());
} }
} }
...@@ -968,11 +839,11 @@ namespace OnlineStore.DeviceLibrary ...@@ -968,11 +839,11 @@ namespace OnlineStore.DeviceLibrary
{ {
if (storeRunStatus < StoreRunStatus.Runing || MoveInfo.MoveType == StoreMoveType.InStore || MoveInfo.MoveType == StoreMoveType.OutStore) if (storeRunStatus < StoreRunStatus.Runing || MoveInfo.MoveType == StoreMoveType.InStore || MoveInfo.MoveType == StoreMoveType.OutStore)
{ {
LogUtil.info(LOGGER, Name + "已经累计出入库" + CurrInOutACount + "次,当时当前正在忙碌中暂不复位"); LogInfo( "已经累计出入库" + CurrInOutACount + "次,当时当前正在忙碌中暂不复位");
} }
else else
{ {
LogUtil.info(LOGGER, Name + "已经累计出入库" + CurrInOutACount + "次,需要复位一下"); LogInfo( "已经累计出入库" + CurrInOutACount + "次,需要复位一下");
Reset(); Reset();
} }
} }
...@@ -980,11 +851,11 @@ namespace OnlineStore.DeviceLibrary ...@@ -980,11 +851,11 @@ namespace OnlineStore.DeviceLibrary
{ {
if (storeRunStatus < StoreRunStatus.Runing || MoveInfo.MoveType == StoreMoveType.InStore || MoveInfo.MoveType == StoreMoveType.OutStore) if (storeRunStatus < StoreRunStatus.Runing || MoveInfo.MoveType == StoreMoveType.InStore || MoveInfo.MoveType == StoreMoveType.OutStore)
{ {
LogUtil.info(LOGGER, Name + "已经累计出入库" + CurrInOutCount + "次,当时当前正在忙碌中暂不复位旋转轴"); LogInfo( "已经累计出入库" + CurrInOutCount + "次,当时当前正在忙碌中暂不复位旋转轴");
} }
else else
{ {
LogUtil.info(LOGGER, Name + "已经累计出入库" + CurrInOutCount + "次,需要复位一下旋转轴"); LogInfo( "已经累计出入库" + CurrInOutCount + "次,需要复位一下旋转轴");
} }
} }
//else if (LineConnect.CanStartOut() || IsDebug) //else if (LineConnect.CanStartOut() || IsDebug)
...@@ -1002,11 +873,11 @@ namespace OnlineStore.DeviceLibrary ...@@ -1002,11 +873,11 @@ namespace OnlineStore.DeviceLibrary
if (currInOutFixture != null) if (currInOutFixture != null)
{ //出库 { //出库
LogUtil.info(LOGGER, Name + "开始执行排队中的出库【" + currInOutFixture.ToStr() + "】"); LogInfo( "开始执行排队中的出库【" + currInOutFixture.ToStr() + "】");
bool result = StartOutStoreMove(new InOutParam("", currInOutFixture.PosId, currInOutFixture.plateH, currInOutFixture.plateW)); bool result = StartOutStoreMove(new InOutParam("", currInOutFixture.PosId, currInOutFixture.plateH, currInOutFixture.plateW));
if (!result) if (!result)
{ {
LogUtil.info(LOGGER, Name + " 执行排队中的出库【" + currInOutFixture.ToStr() + "】失败,重新加入等待队列"); LogInfo( " 执行排队中的出库【" + currInOutFixture.ToStr() + "】失败,重新加入等待队列");
AddWaitOutInfo(currInOutFixture); AddWaitOutInfo(currInOutFixture);
} }
} }
...@@ -1014,7 +885,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -1014,7 +885,7 @@ namespace OnlineStore.DeviceLibrary
} }
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.error(LOGGER, "处理出入库排队列表出错:" + ex.ToString()); LogUtil.error(Name+ "处理出入库排队列表出错:" + ex.ToString());
} }
} }
...@@ -1068,7 +939,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -1068,7 +939,7 @@ namespace OnlineStore.DeviceLibrary
{ {
if (!info.AlarmIoValue.Equals(alarmIo)) if (!info.AlarmIoValue.Equals(alarmIo))
{ {
LogUtil.error(LOGGER, Name + " 运动轴 " + axisInfo.Explain + ",报警已解除!"); LogUtil.error( Name + " 运动轴 " + axisInfo.Explain + ",报警已解除!");
info.AlarmIoValue = alarmIo; info.AlarmIoValue = alarmIo;
} }
} }
...@@ -1095,7 +966,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -1095,7 +966,7 @@ namespace OnlineStore.DeviceLibrary
CloseAllAxis(); CloseAllAxis();
LogUtil.info(LOGGER, Name + "StopMove"); LogInfo( "StopMove");
//IOMove(IO_Type.Door_Down, IO_VALUE.LOW); //IOMove(IO_Type.Door_Down, IO_VALUE.LOW);
//IOMove(IO_Type.Door_Up, IO_VALUE.LOW); //IOMove(IO_Type.Door_Up, IO_VALUE.LOW);
...@@ -1136,8 +1007,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -1136,8 +1007,8 @@ namespace OnlineStore.DeviceLibrary
if (!(posArray.Length == 2)) if (!(posArray.Length == 2))
{ {
WarnMsg = Name + "入库库位格式错误:二维码【" + message + "】库位【" + posId + "】"; WarnMsg = Name + "入库库位格式错误:二维码【" + message + "】库位【" + posId + "】";
LogUtil.error(LOGGER, "服务器反馈 入库库位格式错误:二维码【" + message + "】库位【" + posId + "】"); LogUtil.error(Name+ "服务器反馈 入库库位格式错误:二维码【" + message + "】库位【" + posId + "】");
LogUtil.info(LOGGER, "服务器反馈 入库库位格式错误:二维码【" + message + "】库位【" + posId + "】"); LogUtil.info( "服务器反馈 入库库位格式错误:二维码【" + message + "】库位【" + posId + "】");
return; return;
} }
...@@ -1147,8 +1018,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -1147,8 +1018,8 @@ namespace OnlineStore.DeviceLibrary
if (position == null) if (position == null)
{ //出入库没有找到服务器发送的库位,需要打印日志方便查询原因 { //出入库没有找到服务器发送的库位,需要打印日志方便查询原因
WarnMsg = "入库未找到库位:二维码【" + message + "】库位【" + posId + "】 "; WarnMsg = "入库未找到库位:二维码【" + message + "】库位【" + posId + "】 ";
LogUtil.error(LOGGER, "收到服务器入库命令:入库未找到库位:二维码【" + message + "】库位【" + posId + "】"); LogUtil.error(Name + "收到服务器入库命令:入库未找到库位:二维码【" + message + "】库位【" + posId + "】");
LogUtil.info(LOGGER, "收到服务器入库命令:入库未找到库位:二维码【" + message + "】库位【" + posId + "】"); LogUtil.info( "收到服务器入库命令:入库未找到库位:二维码【" + message + "】库位【" + posId + "】");
return; return;
} }
//TODO:判断BOX是否处于可以入库状态,如果调试或急停中,需要返回给服务器; //TODO:判断BOX是否处于可以入库状态,如果调试或急停中,需要返回给服务器;
...@@ -1157,11 +1028,11 @@ namespace OnlineStore.DeviceLibrary ...@@ -1157,11 +1028,11 @@ namespace OnlineStore.DeviceLibrary
InOutParam param = new InOutParam(message, posId, plateH, plateW); InOutParam param = new InOutParam(message, posId, plateH, plateW);
StartInStoreMove(param); StartInStoreMove(param);
//如果当前正在出入库中,需要记录下来,等待空闲时执行 //如果当前正在出入库中,需要记录下来,等待空闲时执行
LogUtil.info(LOGGER, Name + " 收到服务器入库命令:库位号【" + posId + "】二维码【" + message + "】 开始入库!"); LogInfo( " 收到服务器入库命令:库位号【" + posId + "】二维码【" + message + "】 开始入库!");
} }
else else
{ {
LogUtil.info(LOGGER, Name + " 收到服务器入库命令:库位号【" + posId + "】二维码【" + message + "】 正在忙碌中,无法入库!"); LogInfo( " 收到服务器入库命令:库位号【" + posId + "】二维码【" + message + "】 正在忙碌中,无法入库!");
} }
} }
...@@ -1170,17 +1041,17 @@ namespace OnlineStore.DeviceLibrary ...@@ -1170,17 +1041,17 @@ namespace OnlineStore.DeviceLibrary
public bool ReviceLineCheckInStoreCMD(string posId, string plateH, string plateW, string message) public bool ReviceLineCheckInStoreCMD(string posId, string plateH, string plateW, string message)
{ {
string logName = "入库库位验证【 " + message + "】【" + posId + "】:"; string logName =Name+ "入库库位验证【 " + message + "】【" + posId + "】:";
try try
{ {
if (storeRunStatus.Equals(StoreRunStatus.Wait)) if (storeRunStatus.Equals(StoreRunStatus.Wait))
{ {
LogUtil.info(LOGGER, logName+ " 设备未启动,验证失败"); LogUtil.info( logName+ " 设备未启动,验证失败");
return false; return false;
} }
// CodeMsg = "收到二维码【 " + message + "】,发送给服务器获取入库PosID"; // CodeMsg = "收到二维码【 " + message + "】,发送给服务器获取入库PosID";
LogUtil.debug(LOGGER, logName+"发送给服务器验证入库PosID"); LogUtil.debug( logName+"发送给服务器验证入库PosID");
//发送扫码内容到服务器进行入库操作 //发送扫码内容到服务器进行入库操作
Operation operation = getLineBoxStatus(); Operation operation = getLineBoxStatus();
operation.op = 1; operation.op = 1;
...@@ -1191,23 +1062,23 @@ namespace OnlineStore.DeviceLibrary ...@@ -1191,23 +1062,23 @@ namespace OnlineStore.DeviceLibrary
if (resultOperation == null) if (resultOperation == null)
{ {
// CodeMsg = "二维码【" + message + "】没有收到服务器反馈"; // CodeMsg = "二维码【" + message + "】没有收到服务器反馈";
LogUtil.info(LOGGER, logName + " 没有收到服务器反馈 "); LogUtil.info( logName + " 没有收到服务器反馈 ");
} }
else if (!string.IsNullOrEmpty(resultOperation.msg)) else if (!string.IsNullOrEmpty(resultOperation.msg))
{ {
//如果有提示消息,直接显示提示 //如果有提示消息,直接显示提示
LogUtil.info(LOGGER, logName + "服务器反馈 :" + resultOperation.msg); LogUtil.info( logName + "服务器反馈 :" + resultOperation.msg);
} }
else if (resultOperation.op.Equals(1)) else if (resultOperation.op.Equals(1))
{ {
LogUtil.info(LOGGER, logName + " 成功"); LogUtil.info( logName + " 成功");
return true; return true;
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.info(LOGGER, logName + " 出错:" + ex.ToString()); LogUtil.info( logName + " 出错:" + ex.ToString());
} }
return false; return false;
...@@ -1234,7 +1105,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -1234,7 +1105,7 @@ namespace OnlineStore.DeviceLibrary
{ //出入库没有找到服务器发送的库位,需要打印日志方便查询原因 { //出入库没有找到服务器发送的库位,需要打印日志方便查询原因
WarnMsg = "入库未找到库位:二维码【" + message + "】库位【" + posId + "】 "; WarnMsg = "入库未找到库位:二维码【" + message + "】库位【" + posId + "】 ";
LogUtil.error(logName + "未找到库位"); LogUtil.error(logName + "未找到库位");
// LogUtil.info(LOGGER, "收到流水线入库:入库未找到库位:二维码【" + message + "】库位【" + posId + "】"); // LogUtil.info( "收到流水线入库:入库未找到库位:二维码【" + message + "】库位【" + posId + "】");
return; return;
} }
//TODO:判断BOX是否处于可以入库状态,如果调试或急停中,需要返回给服务器; //TODO:判断BOX是否处于可以入库状态,如果调试或急停中,需要返回给服务器;
...@@ -1291,7 +1162,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -1291,7 +1162,7 @@ namespace OnlineStore.DeviceLibrary
{ {
humidity = param.Humidity; humidity = param.Humidity;
temp = param.Temperate; temp = param.Temperate;
currTempStr = ("当前湿度:" + humidity.ToString() + ",当前温度:" + temp); currTempStr =Name+ ("当前湿度:" + humidity.ToString() + ",当前温度:" + temp);
} }
//double currMaxHumidity = HumitureServer.GetMaxHumidity(Config.GetTempAddrList()); //double currMaxHumidity = HumitureServer.GetMaxHumidity(Config.GetTempAddrList());
double currMaxHumidity = param.Humidity; double currMaxHumidity = param.Humidity;
...@@ -1306,7 +1177,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -1306,7 +1177,7 @@ namespace OnlineStore.DeviceLibrary
TimeSpan span = DateTime.Now - LastEndBlowTime; TimeSpan span = DateTime.Now - LastEndBlowTime;
if (span.TotalMinutes > this.Config.BlowAir_Interval) if (span.TotalMinutes > this.Config.BlowAir_Interval)
{ {
LOGGER.Info("当前最大湿度:" + currMaxHumidity.ToString() + ",开始吹气湿度:" + startBlowHumidity + ",当前不在吹气中,且间隔超过" + Config.BlowAir_Interval + "分钟,开始吹气!"); LogUtil.info(Name + "当前最大湿度:" + currMaxHumidity.ToString() + ",开始吹气湿度:" + startBlowHumidity + ",当前不在吹气中,且间隔超过" + Config.BlowAir_Interval + "分钟,开始吹气!");
IsInBlowing = true; IsInBlowing = true;
//Thread.Sleep(100); //Thread.Sleep(100);
IOMove(IO_Type.StartOrStopBlow, IO_VALUE.HIGH); IOMove(IO_Type.StartOrStopBlow, IO_VALUE.HIGH);
...@@ -1317,7 +1188,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -1317,7 +1188,7 @@ namespace OnlineStore.DeviceLibrary
if (IsInBlowing && stopBlowHumidity > currMaxHumidity) if (IsInBlowing && stopBlowHumidity > currMaxHumidity)
{ {
LOGGER.Info("当前最大湿度:" + currMaxHumidity.ToString() + ",停止吹气湿度:" + stopBlowHumidity + ",停止吹气!"); LogUtil.info(Name + "当前最大湿度:" + currMaxHumidity.ToString() + ",停止吹气湿度:" + stopBlowHumidity + ",停止吹气!");
IsInBlowing = false; IsInBlowing = false;
IOMove(IO_Type.StartOrStopBlow, IO_VALUE.LOW); IOMove(IO_Type.StartOrStopBlow, IO_VALUE.LOW);
LastEndBlowTime = DateTime.Now; LastEndBlowTime = DateTime.Now;
...@@ -1328,7 +1199,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -1328,7 +1199,7 @@ namespace OnlineStore.DeviceLibrary
TimeSpan span = DateTime.Now - LastBeginBlowTime; TimeSpan span = DateTime.Now - LastBeginBlowTime;
if (span.TotalMinutes > this.Config.BlowAir_Time) if (span.TotalMinutes > this.Config.BlowAir_Time)
{ {
LOGGER.Info("已经吹气" + span.TotalMinutes + "分钟,超过配置的吹气时间" + Config.BlowAir_Time + "分钟,停止吹气!"); LogUtil.info(Name + "已经吹气" + span.TotalMinutes + "分钟,超过配置的吹气时间" + Config.BlowAir_Time + "分钟,停止吹气!");
IsInBlowing = false; IsInBlowing = false;
//Thread.Sleep(100); //Thread.Sleep(100);
IOMove(IO_Type.StartOrStopBlow, IO_VALUE.LOW); IOMove(IO_Type.StartOrStopBlow, IO_VALUE.LOW);
...@@ -1343,7 +1214,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -1343,7 +1214,7 @@ namespace OnlineStore.DeviceLibrary
} }
else if (temp > Max_Temperature && Max_Temperature > 0) else if (temp > Max_Temperature && Max_Temperature > 0)
{ {
LOGGER.Info("当前温度【" + param.Temperate + "】超过最高温度【" + Max_Temperature + "】,开始报警!"); LogUtil.info(Name + "当前温度【" + param.Temperate + "】超过最高温度【" + Max_Temperature + "】,开始报警!");
needAlarm = true; needAlarm = true;
//Thread.Sleep(100); //Thread.Sleep(100);
IOMove(IO_Type.StartOrStopBlow, IO_VALUE.LOW); IOMove(IO_Type.StartOrStopBlow, IO_VALUE.LOW);
...@@ -1352,7 +1223,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -1352,7 +1223,7 @@ namespace OnlineStore.DeviceLibrary
{ {
if (IsInBlowing.Equals(false) && TempOrHumidityIsAlarm) if (IsInBlowing.Equals(false) && TempOrHumidityIsAlarm)
{ {
LOGGER.Info("不在吹气中,且当前温度【" + param.Temperate + "】低于【" + Max_Temperature + "】,关闭报警!"); LogUtil.info(Name + "不在吹气中,且当前温度【" + param.Temperate + "】低于【" + Max_Temperature + "】,关闭报警!");
TempOrHumidityIsAlarm = false; TempOrHumidityIsAlarm = false;
//Thread.Sleep(100); //Thread.Sleep(100);
IOMove(IO_Type.StartOrStopBlow, IO_VALUE.LOW); IOMove(IO_Type.StartOrStopBlow, IO_VALUE.LOW);
...@@ -1370,7 +1241,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -1370,7 +1241,7 @@ namespace OnlineStore.DeviceLibrary
} }
catch (Exception ex) catch (Exception ex)
{ {
LOGGER.Error(Name + "HumidityProcess出错:" + ex.ToString()); LogUtil.error(Name + "HumidityProcess出错:" + ex.ToString());
} }
} }
private void HTAlarm() private void HTAlarm()
...@@ -1397,17 +1268,6 @@ namespace OnlineStore.DeviceLibrary ...@@ -1397,17 +1268,6 @@ namespace OnlineStore.DeviceLibrary
isInProcess = true; isInProcess = true;
try try
{ {
//if (LineConnect.IsConnect())
//{
// int hasTray = (int)IOValue(IO_Type.TrayCheck_Door);
// int ss = (int)storeStatus;
// if (IsDebug)
// {
// ss = (int)StoreStatus.Debugging;
// }
// StoreSendBean store=new StoreSendBean(Config.Id,Config.CID, (int)ss, (int)storeRunStatus, hasTray, (int)alarmType);
// LineConnect.SendHeart(store);
//}
if (StoreManager.IsConnectServer) if (StoreManager.IsConnectServer)
{ {
try try
...@@ -1416,16 +1276,15 @@ namespace OnlineStore.DeviceLibrary ...@@ -1416,16 +1276,15 @@ namespace OnlineStore.DeviceLibrary
} }
catch (Exception ex) catch (Exception ex)
{ {
LOGGER.Error("定时给服务器发送消息出错:", ex); LogUtil.error (Name + "定时给服务器发送消息出错:"+ ex.ToString());
} }
} }
HumitureController.QueryData(); HumitureController.QueryData();
HumidityProcess(); HumidityProcess();
LedProcess();
}catch(Exception ex) }catch(Exception ex)
{ {
LogUtil.error("server_connect_timer_Tick出错:"+ex.ToString()); LogUtil.error(Name + "server_connect_timer_Tick出错:" +ex.ToString());
} }
isInProcess = false; isInProcess = false;
} }
...@@ -1490,22 +1349,11 @@ namespace OnlineStore.DeviceLibrary ...@@ -1490,22 +1349,11 @@ namespace OnlineStore.DeviceLibrary
boxStatus.status = (int)lastPosIdStatus; boxStatus.status = (int)lastPosIdStatus;
if (lastPosId != "") if (lastPosId != "")
{ {
LogUtil.info(LOGGER, "给服务器发送出入库完成消息:" + Name + ",status【" + lastPosIdStatus + "】posId【" + lastPosId + "】"); LogUtil.info( "给服务器发送出入库完成消息:" + Name + ",status【" + lastPosIdStatus + "】posId【" + lastPosId + "】");
} }
lastPosId = ""; lastPosId = "";
} }
////如果在空闲中,且有入库未完成,直接发送入库执行中
//if (boxStatus.status.Equals((int)StoreStatus.StoreOnline))
//{
// List<string> list = new List<string>(LineConnect.WaitInStoreList);
// if (list.Count > 0 && (LineConnect.CanStartOut().Equals(false)))
// {
// boxStatus.status = (int)StoreStatus.InStoreExecute;
// }
//}
//温湿度 //温湿度
//ASTemperateParam param = HumitureServer.GetTemperateParam(Config.Temperate_Serveraddress); //ASTemperateParam param = HumitureServer.GetTemperateParam(Config.Temperate_Serveraddress);
ASTemperateParam param = HumitureController.LastData; ASTemperateParam param = HumitureController.LastData;
...@@ -1532,7 +1380,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -1532,7 +1380,7 @@ namespace OnlineStore.DeviceLibrary
if (Max_Humidity <= 0 || (Max_Temperature <= 0)) if (Max_Humidity <= 0 || (Max_Temperature <= 0))
{ {
lineOperation.op = 5; lineOperation.op = 5;
LogUtil.info(LOGGER, Name + "没有湿度预警范围,需要从服务器获取,发送OP=" + lineOperation.op); LogInfo( "没有湿度预警范围,需要从服务器获取,发送OP=" + lineOperation.op);
} }
string server = ConfigAppSettings.GetValue(Setting_Init.http_server); string server = ConfigAppSettings.GetValue(Setting_Init.http_server);
Operation resultOperation = HttpHelper.Post(StoreManager.GetPostApi(server), lineOperation, false); Operation resultOperation = HttpHelper.Post(StoreManager.GetPostApi(server), lineOperation, false);
...@@ -1572,13 +1420,13 @@ namespace OnlineStore.DeviceLibrary ...@@ -1572,13 +1420,13 @@ namespace OnlineStore.DeviceLibrary
{ {
string maxHumidity = data[ParamDefine.maxHumidity]; string maxHumidity = data[ParamDefine.maxHumidity];
string maxTemp = data[ParamDefine.maxTemperature]; string maxTemp = data[ParamDefine.maxTemperature];
LogUtil.info(LOGGER, "收到服务器温湿度预警值:maxHumidity=" + maxHumidity + ",maxTemperature=" + maxTemp); LogUtil.info( "收到服务器温湿度预警值:maxHumidity=" + maxHumidity + ",maxTemperature=" + maxTemp);
try try
{ {
this.Max_Humidity = (float)Convert.ToDouble(maxHumidity); this.Max_Humidity = (float)Convert.ToDouble(maxHumidity);
this.Max_Temperature = (float)Convert.ToDouble(maxTemp); this.Max_Temperature = (float)Convert.ToDouble(maxTemp);
LogUtil.info(LOGGER, "保存温湿度预警值:Max_Humidity=" + Max_Humidity + ",Max_Temperature=" + Max_Temperature); LogUtil.info( "保存温湿度预警值:Max_Humidity=" + Max_Humidity + ",Max_Temperature=" + Max_Temperature);
} }
catch (Exception ex) catch (Exception ex)
{ {
...@@ -1597,7 +1445,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -1597,7 +1445,7 @@ namespace OnlineStore.DeviceLibrary
string plateWStr = data[ParamDefine.plateW]; string plateWStr = data[ParamDefine.plateW];
string plateHStr = data[ParamDefine.plateH]; string plateHStr = data[ParamDefine.plateH];
LogUtil.info(LOGGER, "收到服务器出库消息:poaIs=" + posIdStr + ",platew=" + plateWStr + ",plateh=" + plateHStr); LogUtil.info( "收到服务器出库消息:poaIs=" + posIdStr + ",platew=" + plateWStr + ",plateh=" + plateHStr);
char splitChar = '|'; char splitChar = '|';
string[] posIdArray = posIdStr.Split(splitChar); string[] posIdArray = posIdStr.Split(splitChar);
string[] plateWArray = plateWStr.Split(splitChar); string[] plateWArray = plateWStr.Split(splitChar);
...@@ -1612,7 +1460,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -1612,7 +1460,7 @@ namespace OnlineStore.DeviceLibrary
if (posArray.Length != 2) if (posArray.Length != 2)
{ {
WarnMsg = Name + "出库格式错误:库位号【" + posId + "】"; WarnMsg = Name + "出库格式错误:库位号【" + posId + "】";
LogUtil.error(LOGGER, "收到服务器出库命令:库位号【" + posId + "】格式错误"); LogUtil.error(Name+ "收到服务器出库命令:库位号【" + posId + "】格式错误");
continue; continue;
} }
int storeId = int.Parse(posArray[0]); int storeId = int.Parse(posArray[0]);
...@@ -1623,7 +1471,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -1623,7 +1471,7 @@ namespace OnlineStore.DeviceLibrary
{ {
//出入库没有找到服务器发送的库位,需要打印日志方便查询原因 //出入库没有找到服务器发送的库位,需要打印日志方便查询原因
WarnMsg = Name + "出库未找库位:【" + posId + "】"; WarnMsg = Name + "出库未找库位:【" + posId + "】";
LogUtil.error(LOGGER, "收到服务器出库命令:未找到【" + posId + "】的库位信息"); LogUtil.error(Name+ "收到服务器出库命令:未找到【" + posId + "】的库位信息");
continue; continue;
} }
else else
...@@ -1635,7 +1483,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -1635,7 +1483,7 @@ namespace OnlineStore.DeviceLibrary
//判断是否接收过此库位的出库信息 //判断是否接收过此库位的出库信息
if (MoveInfo.MoveType.Equals(StoreMoveType.OutStore) && MoveInfo.MoveParam.PositionNum.Equals(posId)) if (MoveInfo.MoveType.Equals(StoreMoveType.OutStore) && MoveInfo.MoveParam.PositionNum.Equals(posId))
{ {
LogUtil.info(LOGGER, Name + " 收到出库【" + currInOutFixture.ToStr() + "】重复,当前已在【" + posId + "】出库中"); LogInfo( " 收到出库【" + currInOutFixture.ToStr() + "】重复,当前已在【" + posId + "】出库中");
continue; continue;
} }
else else
...@@ -1645,7 +1493,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -1645,7 +1493,7 @@ namespace OnlineStore.DeviceLibrary
reviceList = (from m in reviceList where m.PosId.Equals(posId) select m).ToList<FixtureCodeInfo>(); reviceList = (from m in reviceList where m.PosId.Equals(posId) select m).ToList<FixtureCodeInfo>();
if (reviceList.Count > 0) if (reviceList.Count > 0)
{ {
LogUtil.info(LOGGER, Name + " 收到出库【" + currInOutFixture.ToStr() + "】重复,排队列表中已存在【" + reviceList[0].ToStr() + "】"); LogInfo( " 收到出库【" + currInOutFixture.ToStr() + "】重复,排队列表中已存在【" + reviceList[0].ToStr() + "】");
continue; continue;
} }
} }
...@@ -1660,13 +1508,13 @@ namespace OnlineStore.DeviceLibrary ...@@ -1660,13 +1508,13 @@ namespace OnlineStore.DeviceLibrary
bool result = StartOutStoreMove(new InOutParam("", posId, plateW,plateH)); bool result = StartOutStoreMove(new InOutParam("", posId, plateW,plateH));
if (!result) if (!result)
{ {
LogUtil.info(LOGGER, Name + " 执行出库【" + currInOutFixture.ToStr() + "】失败,加入等待队列"); LogInfo( " 执行出库【" + currInOutFixture.ToStr() + "】失败,加入等待队列");
AddWaitOutInfo(currInOutFixture); AddWaitOutInfo(currInOutFixture);
} }
} }
else else
{ {
LogUtil.error(LOGGER, "执行出库【" + currInOutFixture.ToStr() + "】失败,当前在忙碌中,加入等待队列"); LogUtil.error(Name+ "执行出库【" + currInOutFixture.ToStr() + "】失败,当前在忙碌中,加入等待队列");
AddWaitOutInfo(currInOutFixture); AddWaitOutInfo(currInOutFixture);
} }
} }
......
...@@ -49,7 +49,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -49,7 +49,7 @@ namespace OnlineStore.DeviceLibrary
ACBoxPosition position = param.GetACPosition(); ACBoxPosition position = param.GetACPosition();
if (position == null) if (position == null)
{ {
LogUtil.error(LOGGER, Name + "出入库时发现param中取到的Position=null,没有库位不能执行出入库"); LogUtil.error(Name + "出入库时发现param中取到的Position=null,没有库位不能执行出入库");
return false; return false;
} }
...@@ -96,7 +96,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -96,7 +96,7 @@ namespace OnlineStore.DeviceLibrary
int errorCount = Math.Abs(outCount - InOut_P1); int errorCount = Math.Abs(outCount - InOut_P1);
if (errorCount <= Config.InOut_Axis.CanErrorCountMin) if (errorCount <= Config.InOut_Axis.CanErrorCountMin)
{ {
LogUtil.info("进出轴当前位置:" + outCount + ",已经在P1,不需要再回P1"); LogInfo("进出轴当前位置:" + outCount + ",已经在P1,不需要再回P1");
} }
else else
{ {
...@@ -151,7 +151,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -151,7 +151,7 @@ namespace OnlineStore.DeviceLibrary
{ {
wait.IsEnd = IOValue(wait.IoType).Equals(wait.IoValue); wait.IsEnd = IOValue(wait.IoType).Equals(wait.IoValue);
int timeOutMs = Config.IOSingle_TimerOut; int timeOutMs = Config.IOSingle_TimerOut;
if (MoveInfo.MoveStep .Equals( StoreMoveStep.SO_14_WaitTake)) if (MoveInfo.MoveStep.Equals(StoreMoveStep.SO_14_WaitTake))
{ {
timeOutMs = 650000; timeOutMs = 650000;
} }
...@@ -160,7 +160,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -160,7 +160,7 @@ namespace OnlineStore.DeviceLibrary
ConfigIO io = Config.getWaitIO(wait.IoType); ConfigIO io = Config.getWaitIO(wait.IoType);
WarnMsg = Name + " 等待信号" + io.DisplayStr + "=" + wait.IoValue + "超时!"; WarnMsg = Name + " 等待信号" + io.DisplayStr + "=" + wait.IoValue + "超时!";
Alarm(StoreAlarmType.IoSingleTimeOut, io.ElectricalDefinition, WarnMsg, MoveInfo.MoveType); Alarm(StoreAlarmType.IoSingleTimeOut, io.ElectricalDefinition, WarnMsg, MoveInfo.MoveType);
LogUtil.error(LOGGER, Name + wait.IoType + "等待信号(" + io.DisplayStr + "=" + wait.IoValue + ") 超时", 14); LogUtil.error(Name + wait.IoType + "等待信号(" + io.DisplayStr + "=" + wait.IoValue + ") 超时", 14);
isOk = false; isOk = false;
break; break;
} }
...@@ -198,7 +198,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -198,7 +198,7 @@ namespace OnlineStore.DeviceLibrary
} }
else else
{ {
if (!MoveInfo.OneWaitCanEndStep ) if (!MoveInfo.OneWaitCanEndStep)
{ {
isOk = false; isOk = false;
break; break;
...@@ -213,7 +213,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -213,7 +213,7 @@ namespace OnlineStore.DeviceLibrary
{ {
WarnMsg = Name + "【" + MoveInfo.MoveType + "】【" + MoveInfo.MoveStep + "】等待超时 [" + NotOkMsg WarnMsg = Name + "【" + MoveInfo.MoveType + "】【" + MoveInfo.MoveStep + "】等待超时 [" + NotOkMsg
+ "]已等待[" + Math.Round(span.TotalSeconds, 1) + "]秒"; + "]已等待[" + Math.Round(span.TotalSeconds, 1) + "]秒";
LogUtil.error(LOGGER, WarnMsg,100); LogUtil.error(WarnMsg, 100);
Alarm(StoreAlarmType.IoSingleTimeOut, "", WarnMsg, MoveInfo.MoveType); Alarm(StoreAlarmType.IoSingleTimeOut, "", WarnMsg, MoveInfo.MoveType);
} }
} }
...@@ -236,15 +236,15 @@ namespace OnlineStore.DeviceLibrary ...@@ -236,15 +236,15 @@ namespace OnlineStore.DeviceLibrary
{ {
if (!LoadParamPosition(param)) if (!LoadParamPosition(param))
{ {
LogUtil.error(LOGGER, Name + " 启动入库【" + posId + "】出错,找不到库位信息"); LogUtil.error(Name + " 启动入库【" + posId + "】出错,找不到库位信息");
return; return;
} }
if (IOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.HIGH)) if (IOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.HIGH))
{ {
LogUtil.error(LOGGER, Name + " 启动入库【" + posId + "】出错,叉子料盘检测有料"); LogUtil.error(Name + " 启动入库【" + posId + "】出错,叉子料盘检测有料");
return; return;
} }
LogUtil.info(LOGGER, Name + " 启动入库【" + posId + "】", storeMoveColor); LogInfo(" 启动入库【" + posId + "】");
storeRunStatus = StoreRunStatus.Busy; storeRunStatus = StoreRunStatus.Busy;
storeStatus = StoreStatus.InStoreExecute; storeStatus = StoreStatus.InStoreExecute;
MoveInfo.NewMove(StoreMoveType.InStore, param); MoveInfo.NewMove(StoreMoveType.InStore, param);
...@@ -264,7 +264,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -264,7 +264,7 @@ namespace OnlineStore.DeviceLibrary
} }
else else
{ {
LogUtil.error(LOGGER, Name + " 启动【" + posId + "】入库出错,当前状态,storeStatus=" + storeRunStatus); LogUtil.error(Name + " 启动【" + posId + "】入库出错,当前状态,storeStatus=" + storeRunStatus);
} }
} }
...@@ -314,7 +314,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -314,7 +314,7 @@ namespace OnlineStore.DeviceLibrary
{ {
InStoreLog("入库:SI_03 所有轴回到待机点,轴2、轴1 动作到P1,,轴4动作至P3"); InStoreLog("入库:SI_03 所有轴回到待机点,轴2、轴1 动作到P1,,轴4动作至P3");
MoveInfo.NextMoveStep(StoreMoveStep.SI_03_ReturnHome); MoveInfo.NextMoveStep(StoreMoveStep.SI_03_ReturnHome);
ComMoveToPosition(moveP.ComPress_P3,Config.CompAxis_P3_Speed); ComMoveToPosition(moveP.ComPress_P3, Config.CompAxis_P3_Speed);
ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P1, Config.UpDownAxis_P1_Speed); ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P1, Config.UpDownAxis_P1_Speed);
ACAxisMove(Config.Middle_Axis, moveP.Middle_P1, Config.MiddleAxis_P1_Speed); ACAxisMove(Config.Middle_Axis, moveP.Middle_P1, Config.MiddleAxis_P1_Speed);
} }
...@@ -323,7 +323,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -323,7 +323,7 @@ namespace OnlineStore.DeviceLibrary
InStoreLog("入库:SI_04_CompressWare 压紧物品(有压紧轴的才需要此步骤),压紧轴至P3(压紧前点) 开始"); InStoreLog("入库:SI_04_CompressWare 压紧物品(有压紧轴的才需要此步骤),压紧轴至P3(压紧前点) 开始");
MoveInfo.NextMoveStep(StoreMoveStep.SI_04_CompressWare); MoveInfo.NextMoveStep(StoreMoveStep.SI_04_CompressWare);
ComMoveToPosition(moveP.ComPress_P3,Config.CompAxis_P3_Speed); ComMoveToPosition(moveP.ComPress_P3, Config.CompAxis_P3_Speed);
} }
else if (MoveInfo.MoveStep == StoreMoveStep.SI_04_CompressWare) else if (MoveInfo.MoveStep == StoreMoveStep.SI_04_CompressWare)
...@@ -335,7 +335,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -335,7 +335,7 @@ namespace OnlineStore.DeviceLibrary
//NeedCheckSafetyLight = 0; //NeedCheckSafetyLight = 0;
InStoreLog("入库:SI_06 拿物品,压紧轴至P2(压紧点)) 升降轴至P7(进料口取料缓冲点) "); InStoreLog("入库:SI_06 拿物品,压紧轴至P2(压紧点)) 升降轴至P7(进料口取料缓冲点) ");
MoveInfo.NextMoveStep(StoreMoveStep.SI_06_DoorWarToDevice); MoveInfo.NextMoveStep(StoreMoveStep.SI_06_DoorWarToDevice);
ComMoveToPosition(moveP.ComPress_P2,Config.CompAxis_P2_Speed); ComMoveToPosition(moveP.ComPress_P2, Config.CompAxis_P2_Speed);
ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P7, Config.UpDownAxis_P7_Speed); ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P7, Config.UpDownAxis_P7_Speed);
} }
else if (MoveInfo.MoveStep == StoreMoveStep.SI_06_DoorWarToDevice) else if (MoveInfo.MoveStep == StoreMoveStep.SI_06_DoorWarToDevice)
...@@ -397,7 +397,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -397,7 +397,7 @@ namespace OnlineStore.DeviceLibrary
//SendLineStatus(StoreID, posId, StoreStatus.InStoreEnd); //SendLineStatus(StoreID, posId, StoreStatus.InStoreEnd);
MoveInfo.NextMoveStep(StoreMoveStep.SI_12_PutWareToBag); MoveInfo.NextMoveStep(StoreMoveStep.SI_12_PutWareToBag);
ComMoveToPosition(moveP.ComPress_P3,Config.CompAxis_P3_Speed); ComMoveToPosition(moveP.ComPress_P3, Config.CompAxis_P3_Speed);
ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P4, Config.UpDownAxis_P4_Speed); ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P4, Config.UpDownAxis_P4_Speed);
} }
...@@ -412,7 +412,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -412,7 +412,7 @@ namespace OnlineStore.DeviceLibrary
{ {
InStoreLog("入库:SI_14 返回待机点,轴2/轴1/轴4动作至P1(待机点)),检测门关闭"); InStoreLog("入库:SI_14 返回待机点,轴2/轴1/轴4动作至P1(待机点)),检测门关闭");
MoveInfo.NextMoveStep(StoreMoveStep.SI_14_GoBack); MoveInfo.NextMoveStep(StoreMoveStep.SI_14_GoBack);
ComMoveToPosition(moveP.ComPress_P1,Config.CompAxis_P1_Speed); ComMoveToPosition(moveP.ComPress_P1, Config.CompAxis_P1_Speed);
ACAxisMove(Config.Middle_Axis, moveP.Middle_P1, Config.MiddleAxis_P1_Speed); ACAxisMove(Config.Middle_Axis, moveP.Middle_P1, Config.MiddleAxis_P1_Speed);
ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P1, Config.UpDownAxis_P1_Speed); ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P1, Config.UpDownAxis_P1_Speed);
CloseDoor(); CloseDoor();
...@@ -421,7 +421,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -421,7 +421,7 @@ namespace OnlineStore.DeviceLibrary
{ {
TimeSpan span = DateTime.Now - startInStoreTime; TimeSpan span = DateTime.Now - startInStoreTime;
string posId = MoveInfo.MoveParam != null ? MoveInfo.MoveParam.PositionNum : ""; string posId = MoveInfo.MoveParam != null ? MoveInfo.MoveParam.PositionNum : "";
LogUtil.info(LOGGER, Name + " 【" + posId + "】 整个入库流程结束,耗时【" + FormUtil.GetSpanStr(span) + "】!", storeMoveColor); LogInfo(" 【" + posId + "】 整个入库流程结束,耗时【" + FormUtil.GetSpanStr(span) + "】!");
MoveInfo.EndMove(); MoveInfo.EndMove();
storeRunStatus = StoreRunStatus.Runing; storeRunStatus = StoreRunStatus.Runing;
//设备连接,入库后,BOX恢复原始状态 //设备连接,入库后,BOX恢复原始状态
...@@ -430,7 +430,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -430,7 +430,7 @@ namespace OnlineStore.DeviceLibrary
} }
else else
{ {
LogUtil.info(LOGGER, Name + " 入库,moveStatus=" + MoveInfo.MoveStep + ",没有对应的处理!"); LogInfo(" 入库,moveStatus=" + MoveInfo.MoveStep + ",没有对应的处理!");
} }
} }
...@@ -451,16 +451,16 @@ namespace OnlineStore.DeviceLibrary ...@@ -451,16 +451,16 @@ namespace OnlineStore.DeviceLibrary
{ {
if (!LoadParamPosition(param)) if (!LoadParamPosition(param))
{ {
LogUtil.error(LOGGER, Name + " 启动出库【" + posId + "】出错,找不到库位信息"); LogUtil.error(Name + " 启动出库【" + posId + "】出错,找不到库位信息");
return false ; return false;
} }
if (IOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.HIGH)) if (IOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.HIGH))
{ {
LogUtil.error(LOGGER, Name + " 启动出库【" + posId + "】出错,叉子料盘检测有料"); LogUtil.error(Name + " 启动出库【" + posId + "】出错,叉子料盘检测有料");
return false ; return false;
} }
storeStatus = StoreStatus.OutStoreExecute; storeStatus = StoreStatus.OutStoreExecute;
LogUtil.info(LOGGER, Name + "启动出库【" + posId + "】 ", storeMoveColor); LogInfo("启动出库【" + posId + "】 ");
storeRunStatus = StoreRunStatus.Busy; storeRunStatus = StoreRunStatus.Busy;
MoveInfo.NewMove(StoreMoveType.OutStore, param); MoveInfo.NewMove(StoreMoveType.OutStore, param);
...@@ -473,7 +473,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -473,7 +473,7 @@ namespace OnlineStore.DeviceLibrary
} }
else else
{ {
LogUtil.error(LOGGER, Name + " 启动出库出错,当前状态,storeStatus=" + storeRunStatus); LogUtil.error(Name + " 启动出库出错,当前状态,storeStatus=" + storeRunStatus);
} }
return false; return false;
} }
...@@ -498,7 +498,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -498,7 +498,7 @@ namespace OnlineStore.DeviceLibrary
{ {
MoveInfo.NextMoveStep(StoreMoveStep.SO_03_ToBagPosition); MoveInfo.NextMoveStep(StoreMoveStep.SO_03_ToBagPosition);
OutStoreLog("出库:SO_03 走到库位,压紧轴至P3(压紧前点) ,旋转轴至P2(库位点),升降轴至P5(库位出库前点)"); OutStoreLog("出库:SO_03 走到库位,压紧轴至P3(压紧前点) ,旋转轴至P2(库位点),升降轴至P5(库位出库前点)");
ComMoveToPosition(moveP.ComPress_P3,Config.CompAxis_P3_Speed); ComMoveToPosition(moveP.ComPress_P3, Config.CompAxis_P3_Speed);
ACAxisMove(Config.Middle_Axis, MoveInfo.MoveParam.MoveP.Middle_P2, Config.MiddleAxis_P2_Speed); ACAxisMove(Config.Middle_Axis, MoveInfo.MoveParam.MoveP.Middle_P2, Config.MiddleAxis_P2_Speed);
ACAxisMove(Config.UpDown_Axis, MoveInfo.MoveParam.MoveP.UpDown_P5, Config.UpDownAxis_P5_Speed); ACAxisMove(Config.UpDown_Axis, MoveInfo.MoveParam.MoveP.UpDown_P5, Config.UpDownAxis_P5_Speed);
} }
...@@ -513,7 +513,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -513,7 +513,7 @@ namespace OnlineStore.DeviceLibrary
OutStoreLog("出库:SO_05 拿起物品,升降轴至P6(库位出料缓冲点),压紧轴至P2(压紧点) "); OutStoreLog("出库:SO_05 拿起物品,升降轴至P6(库位出料缓冲点),压紧轴至P2(压紧点) ");
MoveInfo.NextMoveStep(StoreMoveStep.SO_05_BagWareToDevice); MoveInfo.NextMoveStep(StoreMoveStep.SO_05_BagWareToDevice);
ComMoveToPosition(moveP.ComPress_P2,Config.CompAxis_P2_Speed); ComMoveToPosition(moveP.ComPress_P2, Config.CompAxis_P2_Speed);
ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P6, Config.UpDownAxis_P6_Speed); ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P6, Config.UpDownAxis_P6_Speed);
} }
else if (MoveInfo.MoveStep == StoreMoveStep.SO_05_BagWareToDevice) else if (MoveInfo.MoveStep == StoreMoveStep.SO_05_BagWareToDevice)
...@@ -583,7 +583,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -583,7 +583,7 @@ namespace OnlineStore.DeviceLibrary
OutStoreLog("出库:SO_11 放下物品,升降轴至P8(进料口出料缓冲点) "); OutStoreLog("出库:SO_11 放下物品,升降轴至P8(进料口出料缓冲点) ");
MoveInfo.NextMoveStep(StoreMoveStep.SO_11_DevicePutWare); MoveInfo.NextMoveStep(StoreMoveStep.SO_11_DevicePutWare);
//NeedCheckSafetyLight = 0; //NeedCheckSafetyLight = 0;
ComMoveToPosition(moveP.ComPress_P1,Config.CompAxis_P1_Speed); ComMoveToPosition(moveP.ComPress_P1, Config.CompAxis_P1_Speed);
ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P8, Config.UpDownAxis_P8_Speed); ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P8, Config.UpDownAxis_P8_Speed);
} }
else if (MoveInfo.MoveStep == StoreMoveStep.SO_11_DevicePutWare) else if (MoveInfo.MoveStep == StoreMoveStep.SO_11_DevicePutWare)
...@@ -622,14 +622,14 @@ namespace OnlineStore.DeviceLibrary ...@@ -622,14 +622,14 @@ namespace OnlineStore.DeviceLibrary
string posId = MoveInfo.MoveParam != null ? MoveInfo.MoveParam.PositionNum : ""; string posId = MoveInfo.MoveParam != null ? MoveInfo.MoveParam.PositionNum : "";
storeStatus = StoreStatus.StoreOnline; storeStatus = StoreStatus.StoreOnline;
LogUtil.info(LOGGER, Name + " 【" + posId + "】 整个出库流程结束,耗时【" + FormUtil.GetSpanStr(span) + "】!", storeMoveColor); LogInfo(" 【" + posId + "】 整个出库流程结束,耗时【" + FormUtil.GetSpanStr(span) + "】!");
MoveInfo.EndMove(); MoveInfo.EndMove();
storeRunStatus = StoreRunStatus.Runing; storeRunStatus = StoreRunStatus.Runing;
InOutEndProcess(StoreMoveType.OutStore); InOutEndProcess(StoreMoveType.OutStore);
} }
else else
{ {
LogUtil.error(LOGGER, Name + " 出库处理,moveStatus=" + MoveInfo.MoveStep + ",没有对应的处理!"); LogUtil.error(Name + " 出库处理,moveStatus=" + MoveInfo.MoveStep + ",没有对应的处理!");
} }
} }
...@@ -700,13 +700,13 @@ namespace OnlineStore.DeviceLibrary ...@@ -700,13 +700,13 @@ namespace OnlineStore.DeviceLibrary
if (AutoStartIndex >= 0 && AutoStartIndex < PositionNumList.Count) if (AutoStartIndex >= 0 && AutoStartIndex < PositionNumList.Count)
{ {
newIndex = AutoStartIndex; newIndex = AutoStartIndex;
LogUtil.info(LOGGER, Name + "下一个索引不存在,重新开始自动出入库,索引【" + AutoStartIndex + "】"); LogInfo("下一个索引不存在,重新开始自动出入库,索引【" + AutoStartIndex + "】");
} }
else else
{ {
autoNext = false; autoNext = false;
autoMsg = "自动出入库结束!"; autoMsg = "自动出入库结束!";
LogUtil.info(LOGGER, Name + "下一个索引不存在,自动 出入库结束!"); LogInfo("下一个索引不存在,自动 出入库结束!");
} }
} }
else else
...@@ -717,21 +717,21 @@ namespace OnlineStore.DeviceLibrary ...@@ -717,21 +717,21 @@ namespace OnlineStore.DeviceLibrary
//判断是否需要重置 //判断是否需要重置
if (CurrInOutACount >= Config.Box_ResetACount) if (CurrInOutACount >= Config.Box_ResetACount)
{ {
LogUtil.info(LOGGER, Name + "自动进入下一个出库:posid=" + posid + ",当时已经出入库" + CurrInOutACount + "次,需要重置BOX,先把出库信息存入排队列表中"); LogInfo("自动进入下一个出库:posid=" + posid + ",当时已经出入库" + CurrInOutACount + "次,需要重置BOX,先把出库信息存入排队列表中");
Reset(false); Reset(false);
autoMsg = "自动出库:" + posid; autoMsg = "自动出库:" + posid;
AddWaitOutInfo(new FixtureCodeInfo(0, "", posid)); AddWaitOutInfo(new FixtureCodeInfo(0, "", posid));
} }
else if (CurrInOutCount >= Config.Box_ResetMCount) else if (CurrInOutCount >= Config.Box_ResetMCount)
{ {
LogUtil.info(LOGGER, Name + "自动进入下一个出库:posid=" + posid + ",当时已经出入库" + CurrInOutCount + "次,需要重置BOX旋转轴,先把出库信息存入排队列表中"); LogInfo("自动进入下一个出库:posid=" + posid + ",当时已经出入库" + CurrInOutCount + "次,需要重置BOX旋转轴,先把出库信息存入排队列表中");
//ResetMiddleAxis(false); //ResetMiddleAxis(false);
autoMsg = "自动出库:" + posid; autoMsg = "自动出库:" + posid;
AddWaitOutInfo(new FixtureCodeInfo(0, "", posid)); AddWaitOutInfo(new FixtureCodeInfo(0, "", posid));
} }
else else
{ {
LogUtil.info(LOGGER, Name + "自动进入下一个出库:posid=" + posid); LogInfo("自动进入下一个出库:posid=" + posid);
autoMsg = "自动出库:" + posid; autoMsg = "自动出库:" + posid;
StartOutStoreMove(new InOutParam("", posid)); StartOutStoreMove(new InOutParam("", posid));
} }
...@@ -745,13 +745,13 @@ namespace OnlineStore.DeviceLibrary ...@@ -745,13 +745,13 @@ namespace OnlineStore.DeviceLibrary
if (AutoStartIndex >= 0 && AutoStartIndex < PositionNumList.Count) if (AutoStartIndex >= 0 && AutoStartIndex < PositionNumList.Count)
{ {
newIndex = AutoStartIndex; newIndex = AutoStartIndex;
LogUtil.info(LOGGER, Name + "下一个索引不存在,重新开始自动出入库,索引【" + AutoStartIndex + "】"); LogInfo("下一个索引不存在,重新开始自动出入库,索引【" + AutoStartIndex + "】");
} }
else else
{ {
autoNext = false; autoNext = false;
autoMsg = "自动出入库结束!"; autoMsg = "自动出入库结束!";
LogUtil.info(LOGGER, Name + "下一个索引不存在,自动 出入库结束!"); LogInfo("下一个索引不存在,自动 出入库结束!");
} }
} }
else else
...@@ -760,21 +760,21 @@ namespace OnlineStore.DeviceLibrary ...@@ -760,21 +760,21 @@ namespace OnlineStore.DeviceLibrary
//判断是否需要重置 //判断是否需要重置
if (CurrInOutACount >= Config.Box_ResetACount) if (CurrInOutACount >= Config.Box_ResetACount)
{ {
LogUtil.info(LOGGER, Name + "自动进入下一个入库:posid=" + posid + ",当时已经出入库" + CurrInOutACount + "次,需要重置BOX,先把入库信息存入排队列表中"); LogInfo("自动进入下一个入库:posid=" + posid + ",当时已经出入库" + CurrInOutACount + "次,需要重置BOX,先把入库信息存入排队列表中");
Reset(false); Reset(false);
autoMsg = "自动入库:" + posid; autoMsg = "自动入库:" + posid;
AddWaitOutInfo(new FixtureCodeInfo(0, "AAAA", posid)); AddWaitOutInfo(new FixtureCodeInfo(0, "AAAA", posid));
} }
else if (CurrInOutCount >= Config.Box_ResetMCount) else if (CurrInOutCount >= Config.Box_ResetMCount)
{ {
LogUtil.info(LOGGER, Name + "自动进入下一个出库:posid=" + posid + ",当时已经出入库" + CurrInOutCount + "次,需要重置BOX旋转轴,先把出库信息存入排队列表中"); LogInfo("自动进入下一个出库:posid=" + posid + ",当时已经出入库" + CurrInOutCount + "次,需要重置BOX旋转轴,先把出库信息存入排队列表中");
//ResetMiddleAxis(false); //ResetMiddleAxis(false);
autoMsg = "自动入库:" + posid; autoMsg = "自动入库:" + posid;
AddWaitOutInfo(new FixtureCodeInfo(0, "AAAA", posid)); AddWaitOutInfo(new FixtureCodeInfo(0, "AAAA", posid));
} }
else else
{ {
LogUtil.info(LOGGER, Name + "自动进入下一个入库:posid=" + posid); LogInfo("自动进入下一个入库:posid=" + posid);
autoMsg = "自动入库:" + posid; autoMsg = "自动入库:" + posid;
StartInStoreMove(new InOutParam("AAAA", posid)); StartInStoreMove(new InOutParam("AAAA", posid));
} }
...@@ -783,19 +783,19 @@ namespace OnlineStore.DeviceLibrary ...@@ -783,19 +783,19 @@ namespace OnlineStore.DeviceLibrary
} }
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.error(LOGGER, ex.ToString()); LogUtil.error(Name + "InOutEndProcess ERROR:" + ex.ToString());
} }
} }
private void InStoreLog(string msg) private void InStoreLog(string msg)
{ {
string posId = MoveInfo.MoveParam != null ? MoveInfo.MoveParam.PositionNum : ""; string posId = MoveInfo.MoveParam != null ? MoveInfo.MoveParam.PositionNum : "";
LogUtil.info(LOGGER, "【" + posId + "】" + msg, storeMoveColor); LogInfo("【" + posId + "】" + msg);
} }
private void OutStoreLog(string msg) private void OutStoreLog(string msg)
{ {
string posId = MoveInfo.MoveParam != null ? MoveInfo.MoveParam.PositionNum : ""; string posId = MoveInfo.MoveParam != null ? MoveInfo.MoveParam.PositionNum : "";
LogUtil.info(LOGGER, "【" + posId + "】" + msg, storeMoveColor); LogInfo("【" + posId + "】" + msg);
} }
} }
} }
...@@ -23,16 +23,13 @@ namespace OnlineStore.DeviceLibrary ...@@ -23,16 +23,13 @@ namespace OnlineStore.DeviceLibrary
/// 灯闪烁定时器 /// 灯闪烁定时器
/// </summary> /// </summary>
private System.Timers.Timer ledProcessTimer = null; private System.Timers.Timer ledProcessTimer = null;
/// <summary>
/// 分出一个线程,专门处理急停,报警,气压检测,工单信号检测等处理
/// </summary>
private System.Timers.Timer IoCheckTimer = null;
public Dictionary<int, AC_BOX_Config> BoxConfigMap { get; set; } public Dictionary<int, AC_BOX_Config> BoxConfigMap { get; set; }
public Dictionary<int, AC_BOX_Bean> BoxMap = new Dictionary<int, AC_BOX_Bean>(); public Dictionary<int, AC_BOX_Bean> BoxMap = new Dictionary<int, AC_BOX_Bean>();
public Store_Config Config { get; set; } public Store_Config Config { get; set; }
public bool UseBuzzer = ConfigAppSettings.GetIntValue(Setting_Init.UseBuzzer).Equals(1);
#region 初始化 #region 初始化
private bool canStart = false; private bool canStart = false;
...@@ -80,7 +77,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -80,7 +77,7 @@ namespace OnlineStore.DeviceLibrary
IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.LOW); IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.LOW);
IOMove(IO_Type.RunSign_HddLed, IO_VALUE.LOW); IOMove(IO_Type.RunSign_HddLed, IO_VALUE.LOW);
mainTimer.Enabled = true; mainTimer.Enabled = true;
IoCheckTimer.Enabled = true;
canStart = true; canStart = true;
}); });
...@@ -106,11 +103,6 @@ namespace OnlineStore.DeviceLibrary ...@@ -106,11 +103,6 @@ namespace OnlineStore.DeviceLibrary
ledProcessTimer.AutoReset = true; ledProcessTimer.AutoReset = true;
ledProcessTimer.Enabled = false; ledProcessTimer.Enabled = false;
IoCheckTimer = new System.Timers.Timer();
IoCheckTimer.Interval = 200;
IoCheckTimer.Elapsed += IoCheckTimerProcess;
IoCheckTimer.AutoReset = true;
IoCheckTimer.Enabled = false;
} }
private void IoCheckTimerProcess(object sender, ElapsedEventArgs e) private void IoCheckTimerProcess(object sender, ElapsedEventArgs e)
...@@ -147,7 +139,6 @@ namespace OnlineStore.DeviceLibrary ...@@ -147,7 +139,6 @@ namespace OnlineStore.DeviceLibrary
StartTime = DateTime.Now; StartTime = DateTime.Now;
mainTimer.Enabled = false; mainTimer.Enabled = false;
IoCheckTimer.Enabled = false;
isInSuddenDown = false; isInSuddenDown = false;
isNoAirCheck = false; isNoAirCheck = false;
alarmType = StoreAlarmType.None; alarmType = StoreAlarmType.None;
...@@ -162,7 +153,6 @@ namespace OnlineStore.DeviceLibrary ...@@ -162,7 +153,6 @@ namespace OnlineStore.DeviceLibrary
} }
ledProcessTimer.Enabled = true; ledProcessTimer.Enabled = true;
IoCheckTimer.Enabled = true;
mainTimer.Enabled = true; mainTimer.Enabled = true;
return true; return true;
} }
...@@ -172,7 +162,6 @@ namespace OnlineStore.DeviceLibrary ...@@ -172,7 +162,6 @@ namespace OnlineStore.DeviceLibrary
public override void Reset(bool isNeedClearAuto = true) public override void Reset(bool isNeedClearAuto = true)
{ {
mainTimer.Enabled = false; mainTimer.Enabled = false;
IoCheckTimer.Enabled = false;
//停止运动 //停止运动
MoveInfo.EndMove(); MoveInfo.EndMove();
...@@ -180,7 +169,6 @@ namespace OnlineStore.DeviceLibrary ...@@ -180,7 +169,6 @@ namespace OnlineStore.DeviceLibrary
storeRunStatus = StoreRunStatus.Reset; storeRunStatus = StoreRunStatus.Reset;
mainTimer.Enabled = false; mainTimer.Enabled = false;
IoCheckTimer.Enabled = false;
isInSuddenDown = false; isInSuddenDown = false;
isNoAirCheck = false; isNoAirCheck = false;
alarmType = StoreAlarmType.None; alarmType = StoreAlarmType.None;
...@@ -203,207 +191,184 @@ namespace OnlineStore.DeviceLibrary ...@@ -203,207 +191,184 @@ namespace OnlineStore.DeviceLibrary
} }
} }
IoCheckTimer.Enabled = true;
mainTimer.Enabled = true; mainTimer.Enabled = true;
} }
public override void StopRun() public override void StopRun()
{ {
IoCheckTimer.Enabled = false;
mainTimer.Enabled = false; mainTimer.Enabled = false;
ledProcessTimer.Enabled = false; ledProcessTimer.Enabled = false;
//停止运行时,把阻挡气缸上升 //停止运行时,把阻挡气缸上升
StopMove(); StopMove();
foreach (AC_BOX_Bean equip in BoxMap.Values)
{
equip.StopRun();
}
storeRunStatus = StoreRunStatus.Wait; storeRunStatus = StoreRunStatus.Wait;
TimeSpan span = DateTime.Now - StartTime; TimeSpan span = DateTime.Now - StartTime;
LogUtil.info( Name + ",停止运行,总运行时间:" + span.ToString()); LogUtil.info( Name + ",停止运行,总运行时间:" + span.ToString());
} }
#region 灯光处理 #region 灯光处理
private void LedProcess(object sender, ElapsedEventArgs e) private void LedProcess(object sender, ElapsedEventArgs e)
{ {
//try try
//{ {
// DateTime time = DateTime.Now; DateTime time = DateTime.Now;
// //黄灯 bool isNeedAlarmLed = false;
// if ( storeRunStatus.Equals(StoreRunStatus.HomeMoving) || storeRunStatus.Equals(StoreRunStatus.Reset)) bool isInOut = false;
// { StoreRunStatus runs = StoreRunStatus.Wait;
// //开机执行中时黄灯闪烁
// if (IsDoValue(IO_Type.RunSign_HddLed, IO_VALUE.HIGH))
// {
// IOMove(IO_Type.RunSign_HddLed, IO_VALUE.LOW);
// }
// else
// {
// IOMove(IO_Type.RunSign_HddLed, IO_VALUE.HIGH);
// }
// }
// //休眠状态黄灯常亮
// else if (IsSleep)
// {
// if (IsDoValue(IO_Type.RunSign_HddLed, IO_VALUE.LOW))
// {
// IOMove(IO_Type.RunSign_HddLed, IO_VALUE.HIGH);
// }
// }
// else
// {
// if (IsDoValue(IO_Type.RunSign_HddLed, IO_VALUE.HIGH))
// {
// IOMove(IO_Type.RunSign_HddLed, IO_VALUE.LOW);
// }
// }
// bool isNeedAlarmLed = false;
// bool isInOut = false;
// if (alarmType.Equals(StoreAlarmType.None).Equals(false) || isNoAirCheck || isInSuddenDown || TrayManager.TrayErrorMsg != "")
// {
// isNeedAlarmLed = true;
// }
// foreach (AC_Packing_Box moveEquip in BoxConfigMap.Values)
// {
// if (!moveEquip.alarmType.Equals(StoreAlarmType.None))
// {
// isNeedAlarmLed = true;
// }
// if (moveEquip.MoveInfo.MoveType.Equals(LineMoveType.InStore) || moveEquip.MoveInfo.MoveType.Equals(LineMoveType.OutStore))
// {
// isInOut = true;
// }
// }
// //忙碌中,判断是否有移栽在出入库执行,绿灯闪烁
// if (isInOut)
// {
// if (IsDoValue(IO_Type.AutoRun_HddLed, IO_VALUE.LOW))
// {
// IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.HIGH);
// }
// else
// {
// IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.LOW);
// }
// }
// else if (IsDoValue(IO_Type.AutoRun_HddLed, IO_VALUE.HIGH))
// {
// IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.LOW);
// }
// //报警中 ,红灯闪烁 foreach (AC_BOX_Bean moveEquip in BoxMap.Values)
// if (isNeedAlarmLed) {
// { if (!moveEquip.alarmType.Equals(StoreAlarmType.None))
// if (IsDoValue(IO_Type.Alarm_HddLed, IO_VALUE.LOW)) {
// { isNeedAlarmLed = true;
// IOMove(IO_Type.Alarm_HddLed, IO_VALUE.HIGH); }
// } if (moveEquip.MoveInfo.MoveType.Equals(StoreMoveType.InStore) || moveEquip.MoveInfo.MoveType.Equals(StoreMoveType.OutStore))
// else {
// { isInOut = true;
// IOMove(IO_Type.Alarm_HddLed, IO_VALUE.LOW); }
// } if (moveEquip.storeRunStatus > runs)
// } {
// else if (IsDoValue(IO_Type.Alarm_HddLed, IO_VALUE.HIGH)) runs = moveEquip.storeRunStatus;
// { }
// IOMove(IO_Type.Alarm_HddLed, IO_VALUE.LOW);
// }
//}
//catch (Exception ex)
//{
// LogUtil.error(Name + "灯处理定时器出错:"+ ex.ToString());
//}
//Thread.Sleep(5);
} }
#endregion
/// <summary> //黄灯
/// 定时处理,监听信号,监听IO if (runs.Equals(StoreRunStatus.HomeMoving) || runs.Equals(StoreRunStatus.Reset))
/// </summary>
protected override void timersTimer_Elapsed(object sender, ElapsedEventArgs e)
{ {
try //开机执行中时黄灯闪烁
if (IsDoValue(IO_Type.RunSign_HddLed, IO_VALUE.HIGH))
{ {
DateTime time = DateTime.Now; IOMove(IO_Type.RunSign_HddLed, IO_VALUE.LOW);
if (storeRunStatus.Equals(StoreRunStatus.Wait)) }
else
{ {
//取新的Io状态 IOMove(IO_Type.RunSign_HddLed, IO_VALUE.HIGH);
IO_VALUE fuweiValue = IOValue(IO_Type.Reset_BTN); }
IO_VALUE lastFuwei = DILastValueMap[IO_Type.Reset_BTN]; }
addLastDI(IO_Type.Reset_BTN, fuweiValue);
bool isAutoStart = ConfigAppSettings.GetIntValue(Setting_Init.App_AutoRun) == 1;
//收到复位信号后启动 else
if (isAutoStart && fuweiValue.Equals(IO_VALUE.HIGH) && lastFuwei.Equals(IO_VALUE.LOW))
{ {
//没有启动时收到复位按钮,相当于启动按钮 if (IsDoValue(IO_Type.RunSign_HddLed, IO_VALUE.HIGH))
LogUtil.info( Name + "没有启动时收到复位按钮,相当于启动按钮,开始调用启动方法!");
bool isOk = StartRun();
if (!isOk)
{ {
LogUtil.error("启动失败,等待下次启动"); IOMove(IO_Type.RunSign_HddLed, IO_VALUE.LOW);
mainTimer.Enabled = true;
}
} }
return;
} }
//判断急停
else if (this.storeRunStatus >= StoreRunStatus.HomeMoving)
if (alarmType.Equals(StoreAlarmType.None).Equals(false) || isNoAirCheck || isInSuddenDown )
{ {
foreach (AC_BOX_Bean moveEquip in this.BoxMap.Values) isNeedAlarmLed = true;
}
//忙碌中,判断是否有移栽在出入库执行,绿灯闪烁
if (isInOut)
{ {
if (!moveEquip.IsDebug) if (IsDoValue(IO_Type.AutoRun_HddLed, IO_VALUE.LOW))
{ {
moveEquip.TimerProcess(); IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.HIGH);
} }
} else
}
}
catch (Exception ex)
{ {
LogUtil.error(Name + "主定时器出错:" + ex.ToString()); IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.LOW);
} }
Thread.Sleep(1);
} }
/// <summary> else if (IsDoValue(IO_Type.AutoRun_HddLed, IO_VALUE.HIGH))
/// 气压检测处理
/// </summary>
private IO_VALUE CheckAir(IO_VALUE airCheck, IO_VALUE lastAir)
{ {
IO_VALUE airValue = IO_VALUE.HIGH; IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.LOW);
if (airCheck == IO_VALUE.LOW && (!isInSuddenDown)) }
//报警中 ,红灯闪烁
if (isNeedAlarmLed)
{ {
//判断是否持续了3秒 if (IsDoValue(IO_Type.Alarm_HddLed, IO_VALUE.LOW))
if (lastAir == IO_VALUE.LOW)
{ {
if ((DateTime.Now - lastAirCloseTime).TotalSeconds > Config.AirCheckSeconds) IOMove(IO_Type.Alarm_HddLed, IO_VALUE.HIGH);
}
else
{ {
SetWarnMsg("持续"+Config.AirCheckSeconds+"秒未检测到气压信号"); IOMove(IO_Type.Alarm_HddLed, IO_VALUE.LOW);
//SendAlarmCode(0, LineAlarm.NoAirCheck);
airValue = IO_VALUE.LOW;
} }
} }
else else if (IsDoValue(IO_Type.Alarm_HddLed, IO_VALUE.HIGH))
{ {
lastAirCloseTime = DateTime.Now; IOMove(IO_Type.Alarm_HddLed, IO_VALUE.LOW);
isNoAirCheck = false;
} }
} }
else catch (Exception ex)
{ {
isNoAirCheck = false; LogUtil.error(Name + "灯处理定时器出错:" + ex.ToString());
} }
return airValue; Thread.Sleep(5);
} }
private bool IsDoValue(string ioType, IO_VALUE ioValue)
{
return IOValue(ioType).Equals(ioValue);
}
#endregion
/// <summary>
/// 定时处理,监听信号,监听IO
/// </summary>
protected override void timersTimer_Elapsed(object sender, ElapsedEventArgs e)
{
//try
//{
// DateTime time = DateTime.Now;
// if (storeRunStatus.Equals(StoreRunStatus.Wait))
// {
// //取新的Io状态
// IO_VALUE fuweiValue = IOValue(IO_Type.Reset_BTN);
// IO_VALUE lastFuwei = DILastValueMap[IO_Type.Reset_BTN];
// addLastDI(IO_Type.Reset_BTN, fuweiValue);
// bool isAutoStart = ConfigAppSettings.GetIntValue(Setting_Init.App_AutoRun) == 1;
// //收到复位信号后启动
// if (isAutoStart && fuweiValue.Equals(IO_VALUE.HIGH) && lastFuwei.Equals(IO_VALUE.LOW))
// {
// //没有启动时收到复位按钮,相当于启动按钮
// LogUtil.info( Name + "没有启动时收到复位按钮,相当于启动按钮,开始调用启动方法!");
// bool isOk = StartRun();
// if (!isOk)
// {
// LogUtil.error("启动失败,等待下次启动");
// mainTimer.Enabled = true;
// }
// }
// return;
// }
// //判断急停
// else if (this.storeRunStatus >= StoreRunStatus.HomeMoving)
// {
// foreach (AC_BOX_Bean moveEquip in this.BoxMap.Values)
// {
// if (!moveEquip.IsDebug)
// {
// moveEquip.TimerProcess();
// }
// }
// }
//}
//catch (Exception ex)
//{
// LogUtil.error(Name + "主定时器出错:" + ex.ToString());
//}
//Thread.Sleep(1);
BusyMoveProcess();
}
public override void StopMove() public override void StopMove()
...@@ -413,7 +378,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -413,7 +378,7 @@ namespace OnlineStore.DeviceLibrary
{ {
if (!equip.IsDebug) if (!equip.IsDebug)
{ {
equip.StopRun(); equip.StopMove();
} }
} }
MoveInfo.EndMove(); MoveInfo.EndMove();
...@@ -457,12 +422,12 @@ namespace OnlineStore.DeviceLibrary ...@@ -457,12 +422,12 @@ namespace OnlineStore.DeviceLibrary
public override void Alarm(StoreAlarmType alarmType, string alarmDetial, string alarmMsg, StoreMoveType storeMoveType) public override void Alarm(StoreAlarmType alarmType, string alarmDetial, string alarmMsg, StoreMoveType storeMoveType)
{ {
throw new NotImplementedException();
} }
protected override void ReturnHomeProcess() protected override void ReturnHomeProcess()
{ {
throw new NotImplementedException();
} }
} }
} }
\ No newline at end of file \ No newline at end of file
...@@ -39,6 +39,9 @@ ...@@ -39,6 +39,9 @@
<Reference Include="Asa.IOModule.AIOBOX"> <Reference Include="Asa.IOModule.AIOBOX">
<HintPath>..\..\dll\Asa.IOModule.AIOBOX.dll</HintPath> <HintPath>..\..\dll\Asa.IOModule.AIOBOX.dll</HintPath>
</Reference> </Reference>
<Reference Include="Asa.RFID">
<HintPath>..\..\dll\RFID\Asa.RFID.dll</HintPath>
</Reference>
<Reference Include="CodeLibrary"> <Reference Include="CodeLibrary">
<HintPath>..\..\..\RC32-SZBOSCH-ACSingleStore\dll\CodeLibrary.dll</HintPath> <HintPath>..\..\..\RC32-SZBOSCH-ACSingleStore\dll\CodeLibrary.dll</HintPath>
</Reference> </Reference>
...@@ -72,6 +75,7 @@ ...@@ -72,6 +75,7 @@
<Compile Include="device\PanasonicServo\ACCMDManager.cs" /> <Compile Include="device\PanasonicServo\ACCMDManager.cs" />
<Compile Include="device\PanasonicServo\ACServerManager.cs" /> <Compile Include="device\PanasonicServo\ACServerManager.cs" />
<Compile Include="device\PanasonicServo\ACServerManager_Partial.cs" /> <Compile Include="device\PanasonicServo\ACServerManager_Partial.cs" />
<Compile Include="device\RFID\RFIDManager.cs" />
<Compile Include="store\LineMoveP.cs" /> <Compile Include="store\LineMoveP.cs" />
<Compile Include="store\LineAlarm.cs"> <Compile Include="store\LineAlarm.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
......
...@@ -120,4 +120,5 @@ PRO,每次吹气的时间(分钟),BlowAir_Time,10,,,,,,, ...@@ -120,4 +120,5 @@ PRO,每次吹气的时间(分钟),BlowAir_Time,10,,,,,,,
PRO,两次吹气间隔(分钟),BlowAir_Interval,10,,,,,,, PRO,两次吹气间隔(分钟),BlowAir_Interval,10,,,,,,,
PRO,温湿度端口号,Humiture_Port,COM2,,,,,,, PRO,温湿度端口号,Humiture_Port,COM2,,,,,,,
PRO,扫码的相机名称(多个用#分隔),CameraNameList,Name1#Name1,,,,, PRO,扫码的相机名称(多个用#分隔),CameraNameList,Name1#Name1,,,,,
PRO,RFID读卡器IP,RFID_IP,192.168.200.11,,,,,,,
PRO,是否是调试状态,IsInDebug,1,,,,,,, PRO,是否是调试状态,IsInDebug,1,,,,,,,
...@@ -122,5 +122,6 @@ PRO,每次吹气的时间(分钟),BlowAir_Time,10,,,,,,, ...@@ -122,5 +122,6 @@ PRO,每次吹气的时间(分钟),BlowAir_Time,10,,,,,,,
PRO,两次吹气间隔(分钟),BlowAir_Interval,10,,,,,,, PRO,两次吹气间隔(分钟),BlowAir_Interval,10,,,,,,,
PRO,温湿度端口号,Humiture_Port,COM2,,,,,,, PRO,温湿度端口号,Humiture_Port,COM2,,,,,,,
PRO,扫码的相机名称(多个用#分隔),CameraNameList,Name1#Name1,,,,, PRO,扫码的相机名称(多个用#分隔),CameraNameList,Name1#Name1,,,,,
PRO,RFID读卡器IP,RFID_IP,192.168.200.11,,,,,,,
PRO,是否是调试状态,IsInDebug,1,,,,,,, PRO,是否是调试状态,IsInDebug,1,,,,,,,
using Asa.IOModule;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace OnlineStore.DeviceLibrary
{
public abstract class AIManager
{
public bool NeedShow = false;
public static AIManager Instance = null;
public static void Init()
{
bool isAIOBox = ConfigAppSettings.GetIntValue(Setting_Init.UseAIOBOX).Equals(1);
if (isAIOBox)
{
Instance = new AIOAIManager();
}
else
{
Instance = new KNDAIManager();
}
}
public static double ConvertAI(double aiValue, double defaultValue)
{
double xishu = (double)StoreManager.Config.AI_ConvertPosition;
double result = Math.Round((aiValue - defaultValue) / xishu, 2);
return result;
}
public abstract void StartConnect(params string[] ioIp);
public abstract void CloseConnect();
public abstract double GetAIValue(string ioiP,int index);
}
}
using Asa.IOModule;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
public class AIOAIManager:AIManager
{
private object AILock = "";
private List<int> AIValList = null;
private int AILength = 4;
private Asa.IOModule.AIOBOX AIBox = null;
private System.Timers.Timer conTimer = null;
private List<string> needConIp = new List<string>();
public override void StartConnect(params string[] ipList)
{
if (conTimer == null)
{
conTimer = new System.Timers.Timer();
conTimer.AutoReset = true;
conTimer.Interval = 60000;
conTimer.Elapsed += ConTimer_Elapsed;
}
conTimer.Enabled = false;
needConIp = new List<string>(ipList);
foreach (string ip in ipList)
{
bool result = ConnectionIP(ip);
}
if (needConIp.Count > 0)
{
//启动定时器,1一分钟重连一次
conTimer.Start();
}
}
private bool ConnectionIP(string ioIp)
{
int autoMS = 150;
try
{
AIValList = new List<int>();
AIBox = new Asa.IOModule.AIOBOX();
AIBox.IP = ioIp;
// bool rtn = AIBox.AutoIP(ioIp);
AIBox.SetInput(Asa.IOModule.Box_Type.AI, AILength);
AIBox.SetOutput(Asa.IOModule.Box_Type.DO, 0);
AIBox.AutoReadInput(true, autoMS);
AIBox.AI_Changed_Event += Box_AI_Changed_Event;
LogUtil.debug("开始连接AI模块[" + ioIp + "][" + autoMS + "],尝试重连三次");
for (int i = 1; i <= 3; i++)
{
bool result = AIBox.Connect();
if (result)
{
if (needConIp.Contains(ioIp))
{
needConIp.Remove(ioIp);
}
LogUtil.info("第【" + i + "】次连接IO模块[" + ioIp + "][" + autoMS + "]成功:" + AIBox.ErrInfo);
return true;
}
else
{
LogUtil.error("第【" + i + "】次连接IO模块[" + ioIp + "][" + autoMS + "]失败:" + AIBox.ErrInfo + "");
}
Thread.Sleep(10);
}
}
catch (Exception error)
{
LogUtil.error("连接IO模块[" + ioIp + "][" + autoMS + "]出错:" + error.ToString());
}
return false;
}
private void ConTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
try
{
List<string> list = new List<string>(needConIp);
if (list.Count > 0)
{
foreach (string ip in list)
{
LogUtil.info("重连AOI AI 模块 :" + ip);
ConnectionIP(ip);
}
}
}
catch (Exception ex)
{
LogUtil.error("AOI AI ConTimer_Elapsed 出错: " + ex.ToString());
}
}
public override void CloseConnect()
{
try
{
if (AIBox != null)
{
AIBox.Close();
}
}
catch (Exception ex)
{
LogUtil.error("断开AI连接出错:" + ex.ToString());
}
}
private void Box_AI_Changed_Event(AIOBOX box, int[] val)
{
try
{
if (val != null && val.Length >= AILength)
{
lock (AILock)
{
AIValList = new List<int>();
AIValList.AddRange(val);
}
}
}
catch (Exception ex)
{
LogUtil.error("Box_AI_Changed_Event出错:" + ex.ToString());
}
}
public override double GetAIValue(string ioiP,int index)
{
if (AIValList != null && AIValList.Count > index)
{
return AIValList[index];
}
return -1;
}
//public override double ConvertAI(double aiValue, double defaultValue)
//{
// double xishu = (double)ConfigAppSettings.GetNumValue(Setting_Init.AI_ConvertPosition);
// double result = Math.Round((aiValue - defaultValue) / xishu, 2);
// return result;
//}
}
}
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;
}
}
}
...@@ -27,6 +27,52 @@ namespace OnlineStore.DeviceLibrary ...@@ -27,6 +27,52 @@ namespace OnlineStore.DeviceLibrary
private object DILock = ""; private object DILock = "";
private object DOLock = ""; private object DOLock = "";
private List<string> IoIPLIst = new List<string>();
private System.Timers.Timer conTimer = null;
public override void ConnectionIOList(List<string> DIONameList)
{
if (conTimer == null)
{
conTimer = new System.Timers.Timer();
conTimer.AutoReset = true;
conTimer.Interval = 60000;
conTimer.Elapsed += ConTimer_Elapsed;
}
conTimer.Enabled = false;
IoIPLIst = new List<string>(DIONameList);
foreach (string ip in DIONameList)
{
ConnectionIP(ip);
}
if (IoIPLIst.Count > 0)
{
//启动定时器,1一分钟重连一次
conTimer.Start();
}
}
private void ConTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
try
{
List<string> list = new List<string>(IoIPLIst);
if (list.Count > 0)
{
foreach (string ip in list)
{
LogUtil.info("重连AOI :" + ip);
ConnectionIP(ip);
}
}
}
catch (Exception ex)
{
LogUtil.error("AOI ConTimer_Elapsed 出错: " + ex.ToString());
}
}
public void ConnectionIP(string ioIp) public void ConnectionIP(string ioIp)
{ {
AIOBOX aioBox = null; AIOBOX aioBox = null;
...@@ -49,11 +95,6 @@ namespace OnlineStore.DeviceLibrary ...@@ -49,11 +95,6 @@ namespace OnlineStore.DeviceLibrary
{ {
DOValueMap.Remove(ioIp); DOValueMap.Remove(ioIp);
} }
try
{
// Create new modbus master and add event functions
aioBox = new AIOBOX();
aioBox.IP = ioIp;
int DIMS = ConfigAppSettings.GetIntValue("DIMS"); int DIMS = ConfigAppSettings.GetIntValue("DIMS");
if (DIMS < 20) if (DIMS < 20)
{ {
...@@ -64,9 +105,17 @@ namespace OnlineStore.DeviceLibrary ...@@ -64,9 +105,17 @@ namespace OnlineStore.DeviceLibrary
{ {
DOMS = 200; DOMS = 200;
} }
// bool rtn = aioBox.AutoIP(ioIp);
int DILength = StoreManager.Config.GetDILength(ioIp); int DILength = StoreManager.Config.GetDILength(ioIp);
int DOLength = StoreManager.Config.GetDOLength(ioIp); int DOLength = StoreManager.Config.GetDOLength(ioIp);
string logName = "IO模块[" + ioIp + "] DI[" + DILength + "] DO[" + DOLength + "],[" + DIMS + "] [" + DOMS + "]";
try
{
// Create new modbus master and add event functions
aioBox = new AIOBOX();
aioBox.IP = ioIp;
// bool rtn = aioBox.AutoIP(ioIp);
aioBox.SetInput(Asa.IOModule.Box_Type.DI, DILength); aioBox.SetInput(Asa.IOModule.Box_Type.DI, DILength);
aioBox.SetOutput(Asa.IOModule.Box_Type.DO, DOLength); aioBox.SetOutput(Asa.IOModule.Box_Type.DO, DOLength);
aioBox.AutoReadInput(true, DIMS); aioBox.AutoReadInput(true, DIMS);
...@@ -78,29 +127,34 @@ namespace OnlineStore.DeviceLibrary ...@@ -78,29 +127,34 @@ namespace OnlineStore.DeviceLibrary
// aioBox.Log_Out_Event += AioBox_Log_Out_Event; // aioBox.Log_Out_Event += AioBox_Log_Out_Event;
//aioBox.Log_RxTx_Event += AioBox_Log_RxTx_Event; //aioBox.Log_RxTx_Event += AioBox_Log_RxTx_Event;
AIOMap.Add(ioIp, aioBox); AIOMap.Add(ioIp, aioBox);
LogUtil.info("开始连接IO模块[" + ioIp + "][" + DIMS + "][" + DOMS + "],尝试重连三次");
LogUtil.debug("开始连接" + logName + ",尝试重连5次");
for (int i = 1; i <= 3; i++) for (int i = 1; i <= 3; i++)
{ {
bool result = aioBox.Connect(); bool result = aioBox.Connect();
if (result) if (result)
{ {
LogUtil.info("第【" + i + "】次连接IO模块【" + ioIp + "】成功:" + aioBox.ErrInfo); LogUtil.info("第【" + i + "】次连接 " + logName + " 成功:" + aioBox.ErrInfo);
Thread.Sleep(10); Thread.Sleep(10);
//读取所有的DO //读取所有的DO
ReadAllDI(ioIp, 0); ReadAllDI(ioIp, 0);
if (IoIPLIst.Contains(ioIp))
{
IoIPLIst.Remove(ioIp);
}
break; break;
} }
else else
{ {
LogUtil.error("第【" + i + "】次连接IO模块【" + ioIp + "】失败:" + aioBox.ErrInfo + ""); LogUtil.error("第【" + i + "】次连接 " + logName + " 失败:" + aioBox.ErrInfo + "");
} }
Thread.Sleep(10); Thread.Sleep(2);
} }
} }
catch (Exception error) catch (Exception error)
{ {
LogUtil.error(LOGGER, "连接IO模块[" + ioIp + "]出错:" + error.ToString()); LogUtil.error(LOGGER, "连接IO模块 " + logName + " 出错:" + error.ToString());
} }
} }
...@@ -123,7 +177,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -123,7 +177,7 @@ namespace OnlineStore.DeviceLibrary
{ {
foreach (string str in s) foreach (string str in s)
{ {
LogUtil.AIOLog.Debug("[" + box.IP + "]" + str); // LogUtil.AIOLog.Debug("[" + box.IP + "]" + str);
} }
} }
...@@ -155,6 +209,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -155,6 +209,7 @@ namespace OnlineStore.DeviceLibrary
{ {
if (sta != null && sta.Length >= StoreManager.Config.GetDILength(ip)) if (sta != null && sta.Length >= StoreManager.Config.GetDILength(ip))
{ {
string updateDi = "[" + ip + "]:";
bool needUpdate = false; bool needUpdate = false;
List<Box_Sta> newList = new List<Box_Sta>(); List<Box_Sta> newList = new List<Box_Sta>();
newList.AddRange(sta); newList.AddRange(sta);
...@@ -166,6 +221,14 @@ namespace OnlineStore.DeviceLibrary ...@@ -166,6 +221,14 @@ namespace OnlineStore.DeviceLibrary
} }
else else
{ {
//foreach(Box_Sta s in sta)
//{
// updateDi += s.ToString() + ",";
//}
//if (ip.Equals("192.168.201.61"))
//{
// LogUtil.info(updateDi);
//}
for (int i = 0; i < newList.Count; i++) for (int i = 0; i < newList.Count; i++)
{ {
if (!(oldList[i].Equals(newList[i]))) if (!(oldList[i].Equals(newList[i])))
...@@ -245,13 +308,6 @@ namespace OnlineStore.DeviceLibrary ...@@ -245,13 +308,6 @@ namespace OnlineStore.DeviceLibrary
} }
public override void ConnectionIOList(List<string> DIONameList)
{
foreach (string ip in DIONameList)
{
ConnectionIP(ip);
}
}
//关闭所有的DO //关闭所有的DO
public override void CloseAllDO() public override void CloseAllDO()
...@@ -451,11 +507,11 @@ namespace OnlineStore.DeviceLibrary ...@@ -451,11 +507,11 @@ namespace OnlineStore.DeviceLibrary
{ {
if (configIO.ProType.Equals(ConfigItemType.DI)) if (configIO.ProType.Equals(ConfigItemType.DI))
{ {
return GetDIValue(configIO.IO_IP, configIO.SlaveID, configIO.GetIOAddr()); return GetDIValue(configIO.DeviceName, configIO.SlaveID, configIO.GetIOAddr());
} }
else if (configIO.ProType.Equals(ConfigItemType.DO)) else if (configIO.ProType.Equals(ConfigItemType.DO))
{ {
return GetDOValue(configIO.IO_IP, configIO.SlaveID, configIO.GetIOAddr()); return GetDOValue(configIO.DeviceName, configIO.SlaveID, configIO.GetIOAddr());
} }
} }
catch (Exception ex) catch (Exception ex)
......
/*
* @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 \ 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 \ 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 \ No newline at end of file
using System;
using System.Collections;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Diagnostics;
using log4net;
using System.Reflection;
using OnlineStore.Common;
namespace OnlineStore.DeviceLibrary
{
public class AITcpClient
{
public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
// ------------------------------------------------------------------------
// Constants for access
private const byte fctReadCoil = 1;
private const byte fctReadDiscreteInputs = 2;
private const byte fctReadHoldingRegister = 3;
private const byte fctReadInputRegister = 4;
private const byte fctWriteSingleCoil = 5;
private const byte fctWriteSingleRegister = 6;
private const byte fctWriteMultipleCoils = 15;
private const byte fctWriteMultipleRegister = 16;
private const byte fctReadWriteMultipleRegister = 23;
/// <summary>Constant for exception illegal function.</summary>
public const byte excIllegalFunction = 1;
/// <summary>Constant for exception illegal data address.</summary>
public const byte excIllegalDataAdr = 2;
/// <summary>Constant for exception illegal data value.</summary>
public const byte excIllegalDataVal = 3;
/// <summary>Constant for exception slave device failure.</summary>
public const byte excSlaveDeviceFailure = 4;
/// <summary>Constant for exception acknowledge.</summary>
public const byte excAck = 5;
/// <summary>Constant for exception slave is busy/booting up.</summary>
public const byte excSlaveIsBusy = 6;
/// <summary>Constant for exception gate path unavailable.</summary>
public const byte excGatePathUnavailable = 10;
/// <summary>Constant for exception not connected.</summary>
public const byte excExceptionNotConnected = 253;
/// <summary>Constant for exception connection lost.</summary>
public const byte excExceptionConnectionLost = 254;
/// <summary>Constant for exception response timeout.</summary>
public const byte excExceptionTimeout = 255;
/// <summary>Constant for exception wrong offset.</summary>
private const byte excExceptionOffset = 128;
/// <summary>Constant for exception send failt.</summary>
private const byte excSendFailt = 100;
// ------------------------------------------------------------------------
// Private declarations
private static ushort _timeout = 500;
private static ushort _refresh = 10;
private static bool _connected = false;
private static bool _autoConnectOfBreak = false;
private Socket socketClient;
private int M281_A_Len = 0;
private byte[] tcpSocketReviceBuffer = new byte[2048];
//private Socket tcpSynCl;
//private byte[] tcpSynClBuffer = new byte[2048];
// ------------------------------------------------------------------------
/// <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);
/// <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>
public delegate void ExceptionData(string ip, ushort id, byte function, byte exception, byte[] reviceData);
/// <summary>Exception data event. This event is called when the data is incorrect</summary>
public event ExceptionData OnException;
/// <summary>
/// autoConnectOfBreak
/// </summary>
public bool autoConnectOfBreak
{
get { return _autoConnectOfBreak; }
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 AITcpClient()
{
}
public string IP = "";
public int Port = 0;
public int TimeOutTime = 0;
public AITcpClient(string ip, ushort port)
{
TimeOutTime = 2000;
connect(ip, port);
}
private System.Timers.Timer reviceTimer = new System.Timers.Timer();
public void connect(string ip, ushort port)
{
try
{
this.IP = ip;
this.Port = port;
OnResponseData = null;
// Connect asynchronous client
socketClient = new Socket(IPAddress.Parse(ip).AddressFamily, SocketType.Stream, ProtocolType.Tcp);
if (TimeOutTime <= 0)
{
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);
}
else
{
socketClient.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, _timeout);
socketClient.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, _timeout);
socketClient.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, 1);
IAsyncResult connResult = socketClient.BeginConnect(ip, port, null, null);
connResult.AsyncWaitHandle.WaitOne(this.TimeOutTime, true); //等待2秒
if (!connResult.IsCompleted)
{
LogUtil.info(LOGGER, "Connect to " + ip + ":" + port + " fail!");
return;
}
else
{
_connected = true;
LogUtil.info(LOGGER, "Connect to " + ip + ":" + port + " success!");
}
}
//Thread threadReceive = new Thread(new ThreadStart(ReceiveHandle));
//threadReceive.Start();
reviceTimer.AutoReset = true;
reviceTimer.Elapsed += reviceTimer_Elapsed;
reviceTimer.Interval = 130;
reviceTimer.Enabled = true;
_connected = true;
}
catch (Exception error)
{
LogUtil.info(LOGGER, "Connect to " + ip + ":" + port + " fail!");
_connected = false;
}
}
public void WriteAIScope(ushort id, byte slaveId, string address, int value)
{
//0x000100000006FF0603EA0001
byte function = 0x06;
byte[] data = new byte[12];
byte[] _id = BitConverter.GetBytes((short)id);
data[0] = _id[0]; // Slave id high byte
data[1] = _id[1]; // Slave id low byte
data[2] = 0x00;
data[3] = 0x00;
data[4] = 0x00;
data[5] = 6; // Message size
data[6] = slaveId; // Slave address //必须设置为"1": 2012.04-24 覃发光;
data[7] = function; ; // Function code
byte[] _adr = AcSerialBean.StringToByte(address);
data[8] = _adr[0]; // Start address
data[9] = _adr[1]; // Start address
byte[] _length = BitConverter.GetBytes((short)1);
data[10] = _length[0]; // Number of data to read
data[11] = _length[1]; // Number of data to read
WriteAsyncData(data, id);
}
public void ReadAllAI(ushort id, string startAddress, int length, byte slaveId)
{
//0x 000100000006FF0302580010
byte function = 0x03;
byte[] data = CreateData(id, startAddress, (ushort)length, function, slaveId);
WriteAsyncData(data, id);
}
private byte[] CreateData(ushort id, string startAddress, ushort length, byte function, byte SlaveID)
{
byte[] data = new byte[12];
byte[] _id = BitConverter.GetBytes((short)id);
data[0] = _id[0]; // Slave id high byte
data[1] = _id[1]; // Slave id low byte
data[5] = 6; // Message size
data[6] = SlaveID; // Slave address //必须设置为"1": 2012.04-24 覃发光;
data[7] = function; // Function code
byte[] _adr = AcSerialBean.StringToByte(startAddress);
if (_adr.Length.Equals(2))
{
data[8] = _adr[0]; // Start address
data[9] = _adr[1]; // Start address
}
else if (_adr.Length.Equals(1))
{
data[8] = 0x00;
data[9] = _adr[0]; // Start address
}
else
{
data[8] = 0x00;
data[9] = 0x00;
}
byte[] _length = BitConverter.GetBytes((short)IPAddress.HostToNetworkOrder((short)length));
data[10] = _length[0]; // Number of data to read
data[11] = _length[1]; // Number of data to read
return data;
}
void reviceTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
try
{
ReviceDataProcess();
Thread.Sleep(10);
}
catch (Exception ex)
{
LOGGER.Error("出错:" + ex.ToString());
}
}
private void ReviceDataProcess()
{
byte[] rdata = Receive();
if (rdata == null)
{
return;
}
string str = "";
foreach (byte by in rdata)
{
str = str + " " + by;
}
int lengthIndex = 5;
//这里rdata就是接收到的数据,
IPEndPoint clientipe = (IPEndPoint)socketClient.RemoteEndPoint;
byte dataLength = rdata[lengthIndex];
int allLength = lengthIndex + 1 + dataLength;
if (rdata.Length <= allLength)
{
LogUtil.debug(LOGGER, clientipe.ToString() + "收到数据(无需分包):" + str);
ushort id = BitConverter.ToUInt16(rdata, 0);
byte function = rdata[7];
DataProcess(clientipe.ToString(), id, function, rdata);
return;
}
int currStartIndex = 0;
try
{
for (int i = 0; i < 100; i++)
{
if (rdata.Length < currStartIndex + lengthIndex)
{
LogUtil.error(clientipe.ToString() + "收到数据:" + str + "分包出错 [" + currStartIndex + "]");
break;
}
else
{
dataLength = rdata[currStartIndex + lengthIndex];
allLength = lengthIndex + 1 + dataLength;
byte[] thisData = new byte[allLength];
Array.Copy(rdata, currStartIndex, thisData, 0, allLength);
ushort id = BitConverter.ToUInt16(thisData, 0);
byte function = thisData[7];
DataProcess(clientipe.ToString(), id, function, thisData);
//剩余的数据处理
if (rdata.Length <= currStartIndex + allLength)
{
break;
}
currStartIndex = currStartIndex + allLength;
}
}
}
catch (Exception ex)
{
LogUtil.error(clientipe.ToString() + "收到数据:" + str + "分包出错 [" + currStartIndex + "]:" + ex.ToString());
}
}
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];
Array.Copy(rdata, 10, data, 0, 2);
}
// ------------------------------------------------------------
// Read response data
else
{
data = new byte[rdata[8]];
Array.Copy(rdata, 9, data, 0, rdata[8]);
}
// ------------------------------------------------------------
// Response data is slave exception
if (function > excExceptionOffset)
{
function -= excExceptionOffset;
CallException(id, function, rdata[8], rdata);
}
// ------------------------------------------------------------
// Response data is regular data
else if (OnResponseData != null)
{ //收到的数据打印出来
OnResponseData(clientIp, id, function, data, rdata);
}
}
private byte[] Receive()
{
try
{
if (socketClient == null || !socketClient.Connected || socketClient.Available < 1)
{
return null;
}
int size = socketClient.Available;
byte[] rData = new byte[size];
socketClient.Receive(rData, size, SocketFlags.None);
return rData;
}
catch (SocketException e)
{
if (socketClient != null)
{
socketClient.Close();
socketClient = null;
}
return null;
}
}
public void disconnect()
{
Dispose();
}
~AITcpClient()
{
Dispose();
}
public void Dispose()
{
reviceTimer.Enabled = false;
if (socketClient != null)
{
if (socketClient.Connected)
{
try { socketClient.Shutdown(SocketShutdown.Both); }
catch { }
socketClient.Close();
}
socketClient = null;
}
}
internal void CallException(ushort id, byte function, byte exception, byte[] rdata)
{
reviceTimer.Enabled = false;
if ((socketClient == null))
{
return;
}
if (exception == excExceptionConnectionLost)
{
//tcpSynCl = null;
socketClient = null;
return;
}
if (OnException != null)
{
OnException(socketClient.RemoteEndPoint.AddressFamily.ToString(), id, function, exception, rdata);
}
}
public void WriteAsyncData(byte[] write_data, ushort id)
{
try
{
if (socketClient == null)
{
LOGGER.Error("AITcpClient发送数据时发现socketClient=null");
return;
}
IPEndPoint clientipe = (IPEndPoint)socketClient.RemoteEndPoint;
if ((socketClient != null) && (socketClient.Connected))
{
try
{
//LogUtil.info( clientipe.ToString()+"发送数据:" + AcSerialBean.byteToHexStr(write_data));
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();
}
catch (SystemException error)
{
CallException(id, write_data[7], excExceptionConnectionLost, tcpSocketReviceBuffer);
}
}
else CallException(id, write_data[7], excExceptionConnectionLost, tcpSocketReviceBuffer);
}
catch (Exception ex)
{
LOGGER.Error("出错:" + ex.ToString());
}
}
// ------------------------------------------------------------------------
// Write asynchronous data acknowledge
private void OnSend(System.IAsyncResult result)
{
if (result.IsCompleted == false) CallException(0xFFFF, 0xFF, excSendFailt, tcpSocketReviceBuffer);
}
internal bool ISConnection()
{
if (socketClient == null)
{
return false;
}
if (socketClient.Connected == false)
{
return false;
}
return true;
}
}
}
using log4net;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
//using FuBaRobot.LoadCSVLibrary;
namespace OnlineStore.DeviceLibrary
{
/// <summary>
/// 康奈德IO控制模块
/// </summary>
public class KNDAIManager
{
public static ushort DefaultAILength = 8;
public static byte DefualtSlaveID = 255;
private static string AIStartAddress = "0258";
public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public static Dictionary<string, AITcpClient> mastMap = new Dictionary<string, AITcpClient>();
public static Dictionary<string, List<KNDAI>> AIValueMap = new Dictionary<string, List<KNDAI>>();
private static object AIMapLock = "";
public static System.Timers.Timer timer = null;
private static ushort port = 502;
//public static bool IsNeedReadAI = true;
public static void ConnectionIP(string ioIp)
{
if (timer == null)
{
timer = new System.Timers.Timer();
timer.Interval = 300;
timer.AutoReset = true;
timer.Elapsed += timer_Elapsed;
timer.Enabled = true;
}
AITcpClient MBmaster = null;
if (mastMap.ContainsKey(ioIp))
{
MBmaster = mastMap[ioIp];
if (null != MBmaster)
{
MBmaster.disconnect();
MBmaster.Dispose();
MBmaster = null;
lock (AIMapLock)
{
if (AIValueMap.ContainsKey(ioIp))
{
AIValueMap.Remove(ioIp);
}
}
}
mastMap.Remove(ioIp);
}
try
{
// Create new modbus master and add event functions
MBmaster = new AITcpClient(ioIp, port);
MBmaster.OnResponseData += new AITcpClient.ResponseData(MBmaster_OnResponseData);
MBmaster.OnException += new AITcpClient.ExceptionData(MBmaster_OnException);
MBmaster.autoConnectOfBreak = false;
mastMap.Add(ioIp, MBmaster);
LogUtil.info(LOGGER, "连接AI模块[" + ioIp + "]成功");
Thread.Sleep(10);
WriteAIScope(ioIp, 1);
Thread.Sleep(10);
ReadAll(ioIp);
}
catch (Exception error)
{
LogUtil.error(LOGGER, "连接AI模块[" + ioIp + "]出错:" + error.ToString());
}
}
private static void ReadAll(string ioIp)
{
//读取所有的DO
ReadMultipleAI(ioIp, DefualtSlaveID, AIStartAddress, DefaultAILength);
}
/// <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))
{
//判断是否连接,如果没有连接自动重连
AITcpClient clinet = mastMap[io];
if (clinet.ISConnection())
{
return true;
}
}
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "出错啦:" + ex.ToString());
}
return false;
}
private static DateTime PreCheckTime = DateTime.Now;
private static bool isProcess = false;
public static bool NeedShow = false;
private static void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (isProcess)
{
return;
}
try
{
isProcess = true;
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)
{
//判断是否连接,如果没有连接自动重连
AITcpClient clinet = mastMap[IP];
if (!IsNeedReadAI)
{
ClearAIData(IP);
continue;
}
if (clinet.ISConnection())
{
ReadAll(clinet.IP);
}
else if (span.TotalSeconds > 3)
{
LogUtil.error(LOGGER, "AI模块" + IP + "当前没有连上,重连" + IP);
ConnectionIP(IP);
PreCheckTime = DateTime.Now;
}
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "出错啦:" + ex.ToString());
}
Thread.Sleep(2);
isProcess = false;
}
private static void WriteAIScope(string ioIp, int value)
{
// 0 表示 0 - 10V, 1 表示 0 - 5V
WriteAIScope(ioIp, DefualtSlaveID, "03EA", value);
}
private static void WriteAIScope(string ioIp, byte slaveId, string Adress, int value)
{
// 写 AI 模块采样范围,可以往寄存器里面写入 0 或 1。 0 表示 0 - 10V, 1 表示 0 - 5V。默
//认 0,写 AI 模块采样范围为 0 - 5V
ushort ID = 1;
AITcpClient MBmaster = null;
if (mastMap.ContainsKey(ioIp))
{
MBmaster = mastMap[ioIp];
MBmaster.WriteAIScope(ID, slaveId, Adress, value);
}
else
{
LogUtil.error(LOGGER, "WriteAIScope出错没有连接AI模块:" + ioIp);
}
}
private static void ReadMultipleAI(string ioIp, byte slaveId, string StartAddress, int length)
{
ushort ID = 1;
AITcpClient MBmaster = null;
if (mastMap.ContainsKey(ioIp))
{
MBmaster = mastMap[ioIp];
MBmaster.ReadAllAI(ID, StartAddress, length * 2, slaveId);
}
else
{
LogUtil.error(LOGGER, "ReadMultipleAI出错没有连接AI模块:" + ioIp);
}
}
public static void CloseAllConnection()
{
List<AITcpClient> list = new List<AITcpClient>();
foreach (AITcpClient tcp in list)
{
tcp.disconnect();
}
mastMap.Clear();
}
public static double ConvertAI(double aiValue, double defaultValue)
{
double xishu = (double)ConfigAppSettings.GetNumValue(Setting_Init.AI_ConvertPosition);
double result = Math.Round((aiValue - defaultValue) / xishu, 2);
return result;
}
public static double GetAIValue(string ioiP, int index)
{
double aiValue = GetAIValue(ioiP, DefualtSlaveID, index - 1);
return Math.Round(aiValue, 2);
}
public static double GetAIValue(string ioIP, byte slaveId, int index)
{
double value = 0;
try
{
lock (AIMapLock)
{
if (AIValueMap.ContainsKey(ioIP))
{
List<KNDAI> allIo = new List<KNDAI>(AIValueMap[ioIP]);
List<KNDAI> list = (from m in allIo where m.SlaveId.Equals(slaveId) && m.AIIndex.Equals(index) select m).ToList<KNDAI>();
if (list.Count > 0)
{
value = list[0].AIValue;
}
}
}
}
catch (Exception ex)
{
LogUtil.error("GetAIValue 出错了 :ioIP[" + ioIP + "]index[" + index + "]:" + ex);
}
return value;
}
private static void ClearAIData(string ioIp)
{
byte[] datas = new byte[32];
for (int i = 0; i < datas.Length; i++)
{
datas[i] = 0;
}
SaveAIData(ioIp, 3, datas);
}
private static void SaveAIData(string ioIp, ushort ID, byte[] values)
{
try
{
if (values.Length.Equals(DefaultAILength * 4))
{
List<KNDAI> kndList = new List<KNDAI>();
string strFromat = "{0:X2}";
string msg = "";
for (int index = 0; index < DefaultAILength; index++)
{
string str1 = String.Format(strFromat, values[index * 4 + 2]) + String.Format(strFromat, values[index * 4 + 3])
+ String.Format(strFromat, values[index * 4 + 1]) + String.Format(strFromat, values[index * 4]);
double value = BitToFloat(str1);
KNDAI io = new KNDAI(ioIp, (byte)DefualtSlaveID, index, value);
if (value > 0)
{
Console.WriteLine(str1 + " float convert = {0}", value);
}
msg += "【" + index + "=" + value + "】";
kndList.Add(io);
}
//LogUtil.info(msg);
lock (AIMapLock)
{
if (AIValueMap.ContainsKey(ioIp))
{
AIValueMap.Remove(ioIp);
}
AIValueMap.Add(ioIp, kndList);
}
try
{
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)
{ //每次上传后验证下
int v1 = (int)GetAIValue(ioIp, StoreManager.Config.AIDI1_Addr);
int v2 = (int)GetAIValue(ioIp, StoreManager.Config.AIDI2_Addr);
if (v1.Equals(0) && v2.Equals(0))
{
LogUtil.info(msg);
string value = AcSerialBean.ByteToString(values);
LogUtil.error("收到【" + ioIp + "】的数据【" + value + "】,2个高度都为0");
// ConnectionIP(ioIp);
}
}
else if (StoreManager.Config.AIDI3_Addr > 0 && StoreManager.Config.AIDI4_Addr > 0)
{ //每次上传后验证下
int v1 = (int)GetAIValue(ioIp, StoreManager.Config.AIDI3_Addr);
int v2 = (int)GetAIValue(ioIp, StoreManager.Config.AIDI4_Addr);
if (v1.Equals(0) && v2.Equals(0))
{
LogUtil.info(msg);
string value = AcSerialBean.ByteToString(values);
LogUtil.error("收到【" + ioIp + "】的数据【" + value + "】,2个高度都为0");
// ConnectionIP(ioIp);
}
}
}
}
catch (Exception ex)
{
LogUtil.error("验证数据出错:" + ex.StackTrace);
}
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "SaveAIData出错:" + ex.ToString());
}
}
private static float BitToFloat(string hexString)
{
uint num = uint.Parse(hexString, System.Globalization.NumberStyles.AllowHexSpecifier);
byte[] floatVals = BitConverter.GetBytes(num);
float f = BitConverter.ToSingle(floatVals, 0);
return f;
}
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 strFromat = "{0:X2}";
string reviceMsg = "";
foreach (byte data in reviceData)
{
reviceMsg = reviceMsg + " " + String.Format(strFromat, data);
if (reviceMsg.Length > 200)
{
break;
}
}
// LOGGER.Info ("Read data:【" + reviceMsg + "】 ");
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 (function)
{
case 1:
//LOGGER.Info("Read coils end:【" + reviceMsg + "】 ");
break;
case 2:
//LOGGER.Info("Read discrete inputs end:【" + reviceMsg + "】 ");
//SaveAIData(ioIp, SlaveId, values);
break;
case 3:
SaveAIData(ioIp, ID, values);
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());
}
}
private static void MBmaster_OnException(string ioIp, ushort id, byte function, byte exception, byte[] reviceData)
{
string exc = "Modbus says error: ";
switch (exception)
{
case AITcpClient.excIllegalFunction: exc += "Illegal function!"; break;
case AITcpClient.excIllegalDataAdr: exc += "Illegal data adress!"; break;
case AITcpClient.excIllegalDataVal: exc += "Illegal data value!"; break;
case AITcpClient.excSlaveDeviceFailure: exc += "Slave device failure!"; break;
case AITcpClient.excAck: exc += "Acknoledge!"; break;
case AITcpClient.excSlaveIsBusy: exc += "Slave is busy!"; break;
case AITcpClient.excGatePathUnavailable: exc += "Gateway path unavailbale!"; break;
case AITcpClient.excExceptionTimeout: exc += "Slave timed out!"; break;
case AITcpClient.excExceptionConnectionLost: exc += "Connection is lost!"; break;
case AITcpClient.excExceptionNotConnected: exc += "Not connected!"; break;
default:
break;
}
LOGGER.Error("接收数据出错:" + exc);
}
}
public class KNDAI
{
public KNDAI(string ioIp, byte ID, int index, double value)
{
this.IoIP = ioIp;
this.SlaveId = ID;
this.AIIndex = index;
this.AIValue = value;
UpdateTime = DateTime.Now;
}
/// <summary>
/// AI模块IP
/// </summary>
public string IoIP { get; set; }
/// <summary>
/// 地址
/// </summary>
public byte SlaveId { get; set; }
/// <summary>
/// 第几个AI
/// </summary>
public int AIIndex { get; set; }
/// <summary>
/// 值
/// </summary>
public double AIValue { get; set; }
/// <summary>
/// 更新时间
/// </summary>
public DateTime UpdateTime { get; set; }
}
}
using Asa.RFID;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
public class RFIDManager
{
public static Dictionary<string, Reader> RFReaderMap = new Dictionary<string, Reader>();
private static List<string> RfIPList = new List<string>();
private static System.Timers.Timer conTimer = null;
internal static void ConnectRFIOList(List<string> rfioNameList)
{
try {
if (conTimer == null)
{
conTimer = new System.Timers.Timer();
conTimer.AutoReset = true;
conTimer.Interval = 60000;
conTimer.Elapsed += ConTimer_Elapsed;
}
conTimer.Enabled = false;
RfIPList = new List<string>(rfioNameList);
foreach (string ip in rfioNameList)
{
ConnectionIP(ip);
}
if (RfIPList.Count > 0)
{
conTimer.Start();
}
}catch(Exception ex)
{
LogUtil.error("ConnectRFIOList出错:" + ex.ToString());
}
}
private static bool isProcess = false;
private static DateTime lastTime = DateTime.Now;
private static void ConTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
TimeSpan span = DateTime.Now - lastTime;
if (span.TotalMinutes < RfIPList.Count && isProcess)
{
return;
}
isProcess = true;
lastTime = DateTime.Now;
try
{
List<string> list = new List<string>(RfIPList);
if (list.Count > 0)
{
LogUtil.info("开始重连RFIP模块 ------------");
foreach (string ip in list)
{
ConnectionIP(ip);
}
LogUtil.info("结束重连RFIP模块 ------------");
}
GC.Collect();
}
catch (Exception ex)
{
LogUtil.error("RFIP ConTimer_Elapsed 出错: " + ex.ToString());
}
isProcess = false;
}
internal static void ConnectionIP(string rfid)
{
Reader rfidReader = null;
if (RFReaderMap.ContainsKey(rfid))
{
rfidReader = RFReaderMap[rfid];
if (null != rfidReader)
{
rfidReader.Close();
rfidReader = null;
}
RFReaderMap.Remove(rfid);
}
string logName = "RFIP模块[" + rfid + "] ";
try
{
LogUtil.debug("开始连接" + logName + ",尝试重连3次");
for (int i = 1; i <= 3; i++)
{
rfidReader = new Reader();
// rfidReader.LocalIP = "192.168.100.101";
rfidReader.RemoteIP = rfid;
bool result = rfidReader.Connect();
if (result)
{
rfidReader.AutoScan(true);
LogUtil.info("第【" + i + "】次连接 " + logName + " 成功:");
Thread.Sleep(10);
RFReaderMap.Add(rfid, rfidReader);
if (RfIPList.Contains(rfid))
{
RfIPList.Remove(rfid);
}
break;
}
else
{
LogUtil.error("第【" + i + "】次连接 " + logName + " 失败:" + "");
}
Thread.Sleep(5);
}
}
catch (Exception error)
{
LogUtil.error("连接RFIP模块 " + logName + " 出错:" + error.ToString());
}
}
internal static void CloseAllConnection()
{
foreach (Reader reader in RFReaderMap.Values)
{
reader.Close();
}
}
public static bool WriteData(string IP, RFIDData obj)
{
byte[] sendData = obj.ToData();
return WriteData(IP, sendData, 3);
}
public static RFIDData ReadData(string IP)
{
byte[] reviceData = ReadData(IP, 3);
if (reviceData != null)
{
return new RFIDData(reviceData);
}
return null;
}
public static string SearchIP(string localIp)
{
string ip = "";
try
{
Reader rfReader = new Reader();
rfReader.LocalIP = localIp;
ip = rfReader.FindIP();
}
catch (Exception ex)
{
}
return ip;
}
public static bool FindRFID(string IP)
{
try
{
Reader rfReader = getRfReader(IP);
if (rfReader != null)
{
return rfReader.FindRFID();
}
}
catch (Exception ex)
{
LogUtil.error("RFIP FindRFID [" + IP + "] 出错 :" + ex.ToString());
}
return false;
}
public static byte[] ReadData(string IP, int reReadCount = 1,int startIndex=0,int readLength=8)
{
try
{
Reader rfReader = getRfReader(IP);
if (rfReader == null)
{
return null;
}
for (int i = 1; i <= reReadCount; i++)
{
byte[] reviceData = rfReader.Read(startIndex, readLength);
if (reviceData != null)
{
return reviceData;
}
LogUtil.error("RFIP ReadData [" + IP + "] 第" + i + "次失败 ");
}
}
catch (Exception ex)
{
LogUtil.error("RFIP ReadData [" + IP + "] 出错 :" + ex.ToString());
}
return null;
}
public static bool WriteData(string IP, byte[] data, int reWriteCount = 1)
{
try
{
Reader rfReader = getRfReader(IP);
if (rfReader == null)
{
return false;
}
for (int i = 1; i <= reWriteCount; i++)
{
bool result = rfReader.Write(data);
if (result)
{
return result;
}
LogUtil.error("RFIP WriteData [" + IP + "] 第" + i + "次失败:");
}
}
catch (Exception ex)
{
LogUtil.error("RFIP WriteData [" + IP + "] 出错 :" + ex.ToString());
}
return false;
}
private static Reader getRfReader(string IP)
{
Reader rfReader = null;
if (RFReaderMap.ContainsKey(IP))
{
rfReader = RFReaderMap[IP];
}
else
{
LogUtil.error("getRfReader 没有连接RFIP模块:" + IP);
}
return rfReader;
}
}
public class RFIDData
{
/// <summary>
/// RFID类型,区分是料架还是托盘,托盘=E
/// </summary>
public char RFType= 'E';
/// <summary>
/// 托盘编号,从1-32
/// </summary>
public int Num = 0;
public RFIDData (int num,char t='E')
{
this.RFType = t;
this.Num = num;
}
public RFIDData(byte[] data)
{
try
{
RFType =(char)data[1];
Num = Convert.ToInt32(data[2]);
}
catch (Exception ex)
{
LogUtil.error("RFIP 数据【" + data + "】 获取编码失败");
}
}
public byte[] ToData(int dataLength=10)
{
byte[] sendData = new byte[dataLength];
for (int i = 0; i < sendData.Length; i++)
{
sendData[i] = 0x00;
}
sendData[0] = (byte)RFType;
sendData[1] = (byte)Num;
return sendData;
}
public string ToStr()
{
return "Type=["+RFType+"],Num=["+Num+"]";
}
}
}
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;
namespace OnlineStore.DeviceLibrary
{
/// <summary>
/// 压紧机构计量检测信号处理
/// </summary>
public class MeteringSignal
{
public static int ComAxisChangeValue = ConfigAppSettings.GetIntValue(Setting_Init.ComAxisChangeValue);
/// <summary>
/// 信号变化次数
/// </summary>
public static int SignalChangeCount=0;
public static int TragetChangeCount = 0;
public static IO_VALUE PreSignalValue = IO_VALUE.LOW;
private static System.Timers.Timer timer = null;
public static void StartCheck(int targetPositon, int currPosition)
{
int chazhi = Math.Abs(targetPositon - currPosition);
int count = chazhi / ComAxisChangeValue;
if (count > 0 && chazhi > ComAxisChangeValue)
{
StartCheck(count);
}
}
private static void StartCheck(int targetCount)
{
TragetChangeCount = targetCount;
if (timer == null)
{
timer = new System.Timers.Timer();
timer.Interval = 50;
timer.AutoReset = true;
timer.Elapsed += Timer_Elapsed;
timer.Enabled = false;
}
LogUtil.debug("开始压紧轴计量检测,预计变化" + TragetChangeCount + "次");
IsInProcess = false;
PreSignalValue = IO_VALUE.LOW;
SignalChangeCount = 0;
timer.Start();
}
public static void StopCheck()
{
if(timer==null)
{ return; }
timer.Stop();
}
private static bool IsInProcess = false;
protected static void Timer_Elapsed(object sender, ElapsedEventArgs e)
{
if (IsInProcess) { return; }
IsInProcess = true;
IO_VALUE value = StoreManager.Store.KNDIOValue(IO_Type.CompressAxis_Check);
if (value.Equals(IO_VALUE.HIGH) && PreSignalValue.Equals(IO_VALUE.LOW))
{
SignalChangeCount++;
LogUtil.debug("检测到信号变化,已经变化" + SignalChangeCount + "次");
}
PreSignalValue = value;
if (TragetChangeCount <= SignalChangeCount)
{
timer.Stop();
}
IsInProcess = false;
}
}
}
using log4net;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading;
namespace OnlineStore.DeviceLibrary
{
/// <summary>
/// 硕科控制模块代码
/// </summary>
public class ShuoKeControls
{
public static readonly ILog LOGGER = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private static AcSerialBean bean = null;
public static bool isRun = false;
private static Dictionary<int, ShuoKeInfo> shuokeMap = new Dictionary<int, ShuoKeInfo>();
public static string PortName = "";
private static int SleepMS = 50;
private static int DReviceLength = 5;
#region 串口操作
public static bool ResertInitPort(string comPortName, int baudRate, int tparity, int dataBits, StopBits stopBits)
{
PortName = comPortName;
if (isRun)
{
ClosePort();
}
return InitPort(comPortName, baudRate, tparity, dataBits, stopBits);
}
public static bool InitPort(string comPortName, int baudRate, int tparity, int dataBits, StopBits stopBits)
{
if (isRun)
{
return true;
}
try
{
PortName = comPortName;
Parity parity = (Parity)tparity;
bean = new AcSerialBean(comPortName, baudRate, parity, 8, stopBits);
bool result = bean.openPort();
if (!result)
{
return false;
}
//bean.DataReceived += DataReceived;
isRun = true;
}
catch (Exception ex)
{
isRun = false;
LogUtil.error(LOGGER, "打开步进控制器串口失败:" + ex.ToString());
return false;
}
return true;
}
public static void ClosePort()
{
isRun = false;
if (bean == null)
{
return;
}
bean.closePort();
LogUtil.info(LOGGER, "关闭步进控制器串口完成");
}
/// <summary>
/// 发送数据并获取返回值
/// </summary>
/// <param name="data">发送的数据</param>
/// <param name="outTime">超时时间</param>
/// <returns>返回值的长度</returns>
public static byte[] SendCommand( byte[] data, int outTime, int reviceLength)
{
if (outTime <= 0)
{
outTime = 30;
}
if (outTime > 80)
{
outTime = 80;
}
byte[] returnData = null;
try
{
if (data == null)
{
return returnData;
}
string strSend = "";
for (int i = 0; i < data.Length; i++)
{
strSend += string.Format("{0:X2} ", data[i]);
}
if (strSend.Equals(""))
{
return returnData;
}
LogUtil.debug("串口" + PortName + " 写入数据:" + strSend + "");
if (bean == null)
{
LogUtil.debug(" 试图向未打开串口【" + PortName + "】写入数据:" + strSend + "。");
}
else
{
bean.SendCommand(data, ref returnData, outTime, reviceLength);
}
}
catch (Exception ex)
{
LogUtil.info(ex.ToString());
}
return returnData;
}
private static void DataReceived(string portName, object sender, SerialDataReceivedEventArgs e, byte[] bits)
{
string strSend = "";
for (int i = 0; i < bits.Length; i++)
{
strSend += string.Format("{0:X2} ", bits[i]);
}
if (strSend.Equals(""))
{
return;
}
//校验
ushort pChecksum = 0;
AcSerialBean.CalculateCRC(bits, bits.Length - 2, out pChecksum);
string checkStr = Convert.ToString(pChecksum, 16);
byte[] checkByte = AcSerialBean.StringToByte(checkStr);
if (checkByte.Length == 1)
{
if (!bits[bits.Length - 2].Equals(checkByte[0]))
{
bean.clearInBuffer();
LogUtil.info(LOGGER, " 【" + portName + "】 收到数据【" + strSend + "】,校验错误");
return;
}
}
else
{
if (!bits[bits.Length - 1].Equals(checkByte[0]) || (!bits[bits.Length - 2].Equals(checkByte[1])))
{
bean.clearInBuffer();
LogUtil.info(LOGGER, " 【" + portName + "】 收到数据【" + strSend + "】,校验错误");
return;
}
}
LogUtil.debug(LOGGER, " 【" + portName + "】 收到数据【" + strSend + "】");
int slvAddr = (int)bits[0];
byte cmd = bits[1];
//查询状态
if (cmd.Equals(ShuoKeCMD.SearchMoveStatus))
{
ShuoKeInfo info = DataToStatus(bits);
}
else if (cmd.Equals(ShuoKeCMD.GetAbsPosition))
{
int position = DataToPosition(bits);
}
}
private static bool CheckByte(byte[] bits)
{
string strSend = "";
if (bits == null)
{
return false;
}
for (int i = 0; i < bits.Length; i++)
{
strSend += string.Format("{0:X2} ", bits[i]);
}
//校验
ushort pChecksum = 0;
AcSerialBean.CalculateCRC(bits, bits.Length - 2, out pChecksum);
string checkStr = Convert.ToString(pChecksum, 16);
byte[] checkByte = AcSerialBean.StringToByte(checkStr);
if (checkByte.Length == 1)
{
if (!bits[bits.Length - 2].Equals(checkByte[0]))
{
bean.clearInBuffer();
LogUtil.info(LOGGER, "【" + PortName + "】收到数据【" + strSend + "】校验错误");
return false ;
}
}
else
{
if (!bits[bits.Length - 1].Equals(checkByte[0]) || (!bits[bits.Length - 2].Equals(checkByte[1])))
{
bean.clearInBuffer();
LogUtil.info(LOGGER, "【" + PortName + "】收到数据【" + strSend + "】校验错误");
return false ;
}
}return true;
}
private static int DataToPosition(byte[] bits)
{
int absValue = -1;
if (!CheckByte(bits))
{
return absValue;
}
if (bits.Length >= 7)
{
int slvAddr = (int)bits[0];
byte[] positionData = new byte[4];
Array.Copy(bits, 3, positionData, 0, 4);
string a = AcSerialBean.byteToHexStr(positionData);
absValue = Convert.ToInt32(a, 16);
LogUtil.debug(LOGGER, "收到驱动器【" + slvAddr + "】绝对位置【" + absValue + "】");
if (shuokeMap.ContainsKey(slvAddr))
{
shuokeMap[slvAddr].LastPosition = absValue;
}
else
{
ShuoKeInfo info = new ShuoKeInfo(slvAddr, absValue);
shuokeMap.Add(slvAddr, info);
}
}
return absValue;
}
private static ShuoKeInfo DataToStatus(byte[] bits)
{
ShuoKeInfo info = new ShuoKeInfo(-1, -1);
if (!CheckByte(bits))
{
return info;
}
if (bits.Length >= 8)
{
//[数据1]:1表示运动中,0表示停止
//[数据2]:LL-左限位IO状态 1表示有效 0表示无效
//[数据3]:O-原点IO状态 1表示有效 0表示无效,,=1表示原点灭,=0表示当前原点亮
// [数据4]:RL-右限位IO状态 1表示有效 0表示无效
//[数据5]:EN-使能IO状态 1表示有效 0表示无效
int slvAddr = (int)bits[0];
byte cmd = bits[1];
int isInMove = bits[3];
int isLLimit = bits[4];
int isOrg = bits[5];
int isRLimit = bits[6];
int isEn = bits[7];
info = new ShuoKeInfo(isInMove, slvAddr, isLLimit, isOrg, isRLimit, isEn);
try
{
if (shuokeMap.ContainsKey(slvAddr))
{
info.LastPosition = shuokeMap[slvAddr].LastPosition;
shuokeMap.Remove(slvAddr);
}
shuokeMap.Add(slvAddr, info);
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "记录状态出错:" + ex.ToString());
}
LogUtil.debug(LOGGER, "收到驱动器【" + slvAddr + "】运动状态:运动【" + isInMove + "】左限位【" + isLLimit + "】右限位【" + isRLimit + "】原点【" + isOrg + "】使能【" + isEn + "】");
}
return info;
}
public static int GetLastPosition(int slvAddr)
{
if (shuokeMap.ContainsKey(slvAddr))
{
ShuoKeInfo info = shuokeMap[slvAddr];
return info.LastPosition;
}
return -1;
}
#endregion
#region 逻辑判断
public static bool IsMoveEnd(int slvAddr, int targetPosition, DateTime time, out string msg)
{
ShuoKeInfo shuokeInfo = GetStatus(slvAddr);
msg = " IsInMove【" + shuokeInfo.IsInMove + "】 ";
if (shuokeInfo.IsInMove == 0 && shuokeInfo.UpdateTime > time)
{
int position = GetABSPosition(slvAddr);
msg += "位置【" + position + "】";
if (Math.Abs(position - targetPosition) < 10 || targetPosition.Equals(-2000))
{
return true;
}
else
{
LogUtil.info("【" + PortName + "】 目标位置【" + targetPosition + "】当前位置【" + position + "】,已经不再运动中");
}
}
return false;
}
//public static bool IsHomeMoveEnd(int slvAddr, DateTime time, out string msg)
//{
// ShuoKeInfo shuokeInfo = GetStatus(slvAddr);
// msg = " IsInMove【" + shuokeInfo.IsInMove + "】Org【" + shuokeInfo.Org + "】";
// if (shuokeInfo.IsInMove .Equals(0) && shuokeInfo.Org.Equals(0)&&shuokeInfo.UpdateTime>time)
// {
// return true;
// }
// //如果是运动结束状态,但原点未到达,直接重新开始运动
// else if (shuokeInfo.IsInMove.Equals(0) && shuokeInfo.Org.Equals(1) && shuokeInfo.UpdateTime > time)
// {
// TimeSpan span = DateTime.Now - lastRHomeTime;
// if (span.TotalSeconds > 3)
// {
// LogUtil.error("【" + PortName + "】已经停止运动但不在原点,重新回原点");
// lastRHomeTime = DateTime.Now;
// HomeMove(slvAddr);
// }
// }
// return false;
//}
#endregion
#region 驱动器操作方法
public static ShuoKeInfo GetStatus(int slvAddr)
{
byte[] reviceData = SendData(slvAddr, ShuoKeCMD.SearchMoveStatus, 0x00, 0,10);
return DataToStatus(reviceData);
}
public static void DStoop(int slvAddr)
{
byte[] reviceData = SendData(slvAddr, ShuoKeCMD.DStopMove, 0x00, 0,DReviceLength);
}
public static void SuddownStop(int slvAddr)
{
byte[] reviceData = SendData(slvAddr, ShuoKeCMD.SuddownStopMove, 0x00, 0, DReviceLength);
}
public static int GetABSPosition(int slvAddr)
{
byte[] reviceData = SendData(slvAddr, ShuoKeCMD.GetAbsPosition, 0x00, 0, 9);
return DataToPosition(reviceData);
}
// <param name="homeType">0=反方向,1=正方向</param>
public static void HomeMove(int slvAddr, byte homeType=1)
{
string fangx = homeType.Equals(0) ? "反方向" : "正方向";
LogUtil.info("压紧轴原点返回:" + fangx);
byte[] reviceData = SendData(slvAddr, ShuoKeCMD.HomeMove, 0x01, homeType, DReviceLength);
}
public static void SetConfigSpeed(AC_SA_Config Config)
{
ShuoKeControls.SetSpeed(Config.CompressAxis_Slv, ShuoKeCMD.SetAddSpeed, Config.CompressAxis_AddSpeed);
ShuoKeControls.SetSpeed(Config.CompressAxis_Slv, ShuoKeCMD.SetDelSpeed, Config.CompressAxis_DelSpeed);
ShuoKeControls.SetSpeed(Config.CompressAxis_Slv, ShuoKeCMD.SetEndSpeed, Config.CompressAxis_EndSpeed);
ShuoKeControls.SetSpeed(Config.CompressAxis_Slv, ShuoKeCMD.SetHomeSpeed, Config.CompressAxis_HomeSpeed);
ShuoKeControls.SetSpeed(Config.CompressAxis_Slv, ShuoKeCMD.SetMaxSpeed, Config.CompressAxis_MaxSpeed);
ShuoKeControls.SetSpeed(Config.CompressAxis_Slv, ShuoKeCMD.SetStartSpeed, Config.CompressAxis_StartSpeed);
}
public static void VolMove(int slvAddr, int speed)
{
byte[] reviceData = SendData(slvAddr, ShuoKeCMD.VolMove, 0x04, speed, DReviceLength);
}
public static void AbsMove(int slvAddr, int TargetPosition)
{
// 47、设置绝对位置并开始运动:不支持广播(开环的32位脉冲统计长度)
//正负数表示绝对位置,如果已经到位置,则不做运动。(M4505S特有命令)
//发送: 应答:
//[设备地址] 0x01 [设备地址] 0x01
//[命令] 0x50 [命令] 0x50
//[数据长度] 4 [数据长度] 0
//[数据] xxxxxxxx [数据] 无
//[CRC校验1] 0xnn [CRC校验1] 0xnn
//[CRC校验2] 0xnn [CRC校验2] 0xnn
//数据:4BYTE,(支持32位有符号脉冲位置)
byte[] reviceData = SendData(slvAddr, ShuoKeCMD.AbsMove, 0x04, TargetPosition, DReviceLength);
}
public static void RelativeMove(int slvAddr, int position)
{
//1是正方向
byte fangxiang = 0x01;
if (position < 0)
{
fangxiang = 0x00;
position = Math.Abs(position);
}
byte dataLength = 0x04;
byte[] sendData = new byte[5 + dataLength];
sendData[0] = (byte)slvAddr;
sendData[1] = ShuoKeCMD.RelativeMove;
sendData[2] = dataLength;
sendData[3] = 0x00;
sendData[4] = 0x00;
sendData[5] = 0x00;
sendData[6] = 0x00;
string speed = Convert.ToString(position, 16);
byte[] speedByte = AcSerialBean.StringToByte(speed);
for (int i = 0; i < speedByte.Length; i++)
{
if (i >= 4)
{
break;
}
sendData[6 - (speedByte.Length - 1 - i)] = speedByte[i];
}
sendData[3] = fangxiang;
sendData = buildCheckData(sendData, 3 + dataLength);
byte[] reviceData = SendCommand(sendData,SleepMS,DReviceLength);
Thread.Sleep(SleepMS);
}
public static void PositionClear(int slvAddr, byte setCMD)
{
byte[] reviceData = SendData(slvAddr, setCMD, 0x00, 0, DReviceLength);
}
/// <summary>
/// 设置电机的速度
/// </summary>
/// <param name="slvAddr">电机地址</param>
/// <param name="setCMD">设置速度的命令号</param>
/// <param name="speedValue">速度值</param>
public static void SetSpeed(int slvAddr, byte setCMD, int speedValue)
{
byte[] reviceData = SendData(slvAddr, setCMD, 0x04, speedValue, DReviceLength);
Thread.Sleep(10);
}
private static byte[] SendData(int slvAddr, byte cmd, byte dataLength, int dataValue, int reviceDataLength)
{
byte[] sendData = new byte[5 + dataLength];
sendData[0] = (byte)slvAddr;
sendData[1] = cmd;
sendData[2] = dataLength;
if (dataLength.Equals(0x00))
{
}
else if (dataLength.Equals(0x01))
{
sendData[3] = (byte)dataValue;
}
else if (dataLength.Equals(0x04))
{
sendData[3] = 0x00;
sendData[4] = 0x00;
sendData[5] = 0x00;
sendData[6] = 0x00;
string speed = Convert.ToString(dataValue, 16);
byte[] speedByte = AcSerialBean.StringToByte(speed);
for (int i = 0; i < speedByte.Length; i++)
{
if (i >= 4)
{
break;
}
sendData[6 - (speedByte.Length - 1 - i)] = speedByte[i];
}
}
sendData = buildCheckData(sendData, 3 + dataLength);
byte[] reviceData = SendCommand(sendData, SleepMS, reviceDataLength);
Thread.Sleep(SleepMS);
return reviceData;
}
private static byte[] buildCheckData(byte[] sendData, int length)
{
ushort pChecksum = 0;
AcSerialBean.CalculateCRC(sendData, length, out pChecksum);
string checkStr = Convert.ToString(pChecksum, 16);
byte[] checkByte = AcSerialBean.StringToByte(checkStr);
if (checkByte.Length == 1)
{
sendData[length] = checkByte[0];
sendData[length + 1] = 0x00;
}
else
{
sendData[length + 1] = checkByte[0];
sendData[length] = checkByte[1];
}
return sendData;
}
#endregion
}
public class ShuoKeCMD
{
/// <summary>
/// 设置运动初速度://SndHex:01 25 04 00 00 00 64 FC DE
/// </summary>
public static byte SetStartSpeed = 0x25;
/// <summary>
/// 设置运动最大速度://SndHex:01 27 04 00 00 27 10 E6 EB
/// </summary>
public static byte SetMaxSpeed = 0x27;
/// <summary>
/// 设置运动末速度://SndHex:01 29 04 00 00 03 E8 FD 47
/// </summary>
public static byte SetEndSpeed = 0x29;
/// <summary>
/// 设置运动加速度://SndHex:01 2B 04 00 00 13 88 F1 4D
/// </summary>
public static byte SetAddSpeed = 0x2B;
/// <summary>
/// 设置运动减速度://SndHex:01 2D 04 00 00 03 E8 FC C3
/// </summary>
public static byte SetDelSpeed = 0x2D;
/// <summary>
/// 设置归零运动速度://SndHex:01 2F 04 00 00 27 10 E7 A3
/// </summary>
public static byte SetHomeSpeed = 0x2F;
/// <summary>
/// //查找原点命令:
//SndHex:01 3E 01 00 61 84
/// </summary>
public static byte HomeMove = 0x3E;
/// <summary>
/// 绝对位置运动//SndHex:01 50 04 FF FF D8 F0 AC 30
/// </summary>
public static byte AbsMove = 0x50;
/// <summary>
/// 急停命令://SndHex:01 3C 00 31 00
/// </summary>
public static byte SuddownStopMove = 0x3C;
/// <summary>
/// 减速停止命令://SndHex:01 3D 00 30 90
/// </summary>
public static byte DStopMove = 0x3D;
/// <summary>
/// 绝对位置清零: //SndHex:01 38 00 33 C0
/// </summary>
public static byte AbsPositionClear = 0x38;
/// <summary>
/// 相对位置清零: //SndHex:01 3A 00 32 A0
/// </summary>
public static byte RelPositionClear = 0x3A;
/// <summary>
/// 查询运动状态://SndHex:01 3B 00 33 30
/// </summary>
public static byte SearchMoveStatus = 0x3B;
/// <summary>
//查询设备地址://SndHex:00 21 00 69 90
/// </summary>
public static byte SearchSlvAddr = 0x21;
/// <summary>
/// 设置32位运动速度,并恒速运动:SndHex:01 33 04 00 00 27 10 E5 FF
/// </summary>
public static byte VolMove = 0x33;
/// <summary>
/// 查询绝对位置
/// </summary>
public static byte GetAbsPosition = 0x37;
/// <summary>
/// 相对位置运动
/// </summary>
public static byte RelativeMove = 0x32;
}
public class ShuoKeInfo
{
public ShuoKeInfo(int slv, int position)
{
this.IsInMove = -1;
this.SlvAddr = slv;
this.LLimit = -1;
this.RLimit = -1;
this.Org = -1;
this.En = -1;
UpdateTime = DateTime.Now;
LastPosition = position;
}
public ShuoKeInfo(int ismove, int slv, int ll, int org, int rl, int en)
{
this.IsInMove = ismove;
this.SlvAddr = slv;
this.LLimit = ll;
this.RLimit = rl;
this.Org = org;
this.En = en;
UpdateTime = DateTime.Now;
LastPosition = 0;
}
public int LastPosition { get; set; }
/// <summary>
/// 驱动器地址
/// </summary>
public int SlvAddr { get; set; }
/// <summary>
/// 是否在运动中
/// </summary>
public int IsInMove { get; set; }
/// <summary>
/// 左极限
/// </summary>
public int LLimit { get; set; }
/// <summary>
/// 右极限
/// </summary>
public int RLimit { get; set; }
/// <summary>
/// 原点信号是否有效
/// </summary>
public int Org { get; set; }
/// <summary>
/// 使能是否有效
/// </summary>
public int En { get; set; }
public DateTime UpdateTime { get; set; }
public string ToShowStr()
{
return "运动[" + IsInMove + "]左限位[" + LLimit + "]右限位[" + RLimit + "]原点[" + Org + "]使能[" + En + "][" + UpdateTime.ToShortTimeString() + "]";
}
}
}
...@@ -31,7 +31,6 @@ namespace OnlineStore.DeviceLibrary ...@@ -31,7 +31,6 @@ namespace OnlineStore.DeviceLibrary
/// 日志颜色 /// 日志颜色
/// </summary> /// </summary>
protected static Color storeMoveColor = Color.Blue; protected static Color storeMoveColor = Color.Blue;
protected static readonly ILog LOGGER = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public string Name { get; set; } public string Name { get; set; }
public int DeviceID { get; set; } public int DeviceID { get; set; }
public BaseConfig baseConfig = null; public BaseConfig baseConfig = null;
...@@ -99,7 +98,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -99,7 +98,7 @@ namespace OnlineStore.DeviceLibrary
} }
catch (Exception ex) catch (Exception ex)
{ {
LOGGER.Error(ex.ToString()); LogUtil.error(ex.ToString());
} }
} }
...@@ -238,7 +237,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -238,7 +237,7 @@ namespace OnlineStore.DeviceLibrary
protected void ACAxisHomeMove(ConfigMoveAxis moveAxis) protected void ACAxisHomeMove(ConfigMoveAxis moveAxis)
{ {
moveAxis.TargetPosition = 0; moveAxis.TargetPosition = 0;
LogUtil.info(LOGGER, moveAxis.DisplayStr + "speed[" + moveAxis.TargetSpeed + "]开始原点返回"); LogUtil.info(Name+ moveAxis.DisplayStr + "speed[" + moveAxis.TargetSpeed + "]开始原点返回");
MoveInfo.WaitList.Add(WaitResultInfo.WaitAxis(moveAxis, true)); MoveInfo.WaitList.Add(WaitResultInfo.WaitAxis(moveAxis, true));
ACServerManager.HomeMove(moveAxis.DeviceName, (short)moveAxis.GetAxisValue(), moveAxis.HomeHighSpeed); ACServerManager.HomeMove(moveAxis.DeviceName, (short)moveAxis.GetAxisValue(), moveAxis.HomeHighSpeed);
} }
...@@ -274,7 +273,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -274,7 +273,7 @@ namespace OnlineStore.DeviceLibrary
//判断是否需要重新运动 //判断是否需要重新运动
if (MoveInfo.CanWhileCount > 0) if (MoveInfo.CanWhileCount > 0)
{ {
LogUtil.error(LOGGER, moveAxis.DisplayStr + "目标位置[" + targetPosition + "]当前位置[" + outCount + LogUtil.error(Name+ moveAxis.DisplayStr + "目标位置[" + targetPosition + "]当前位置[" + outCount +
"],误差过大,重新开始运动,剩余[" + MoveInfo.CanWhileCount + "]次"); "],误差过大,重新开始运动,剩余[" + MoveInfo.CanWhileCount + "]次");
ACServerManager.AbsMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), targetPosition, targetSpeed); ACServerManager.AbsMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), targetPosition, targetSpeed);
MoveInfo.CanWhileCount--; MoveInfo.CanWhileCount--;
...@@ -283,7 +282,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -283,7 +282,7 @@ namespace OnlineStore.DeviceLibrary
{ {
msg = Name + " storeMoveStep=" + MoveInfo.MoveStep + moveAxis.DisplayStr + "目标位置[" + targetPosition + "]当前位置[" + outCount msg = Name + " storeMoveStep=" + MoveInfo.MoveStep + moveAxis.DisplayStr + "目标位置[" + targetPosition + "]当前位置[" + outCount
+ "],误差过大,需要报警"; + "],误差过大,需要报警";
LogUtil.error(LOGGER, msg); LogUtil.error(Name+ msg);
} }
} }
return false; return false;
...@@ -303,7 +302,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -303,7 +302,7 @@ namespace OnlineStore.DeviceLibrary
//判断是否需要重新运动 //判断是否需要重新运动
if (MoveInfo.CanWhileCount > 0) if (MoveInfo.CanWhileCount > 0)
{ {
LogUtil.error(LOGGER, moveAxis.DisplayStr + "收到原点完成信号,当前位置[" + outCount + "],重新回原点,剩余[" + MoveInfo.CanWhileCount + "]次"); LogUtil.error(Name+ moveAxis.DisplayStr + "收到原点完成信号,当前位置[" + outCount + "],重新回原点,剩余[" + MoveInfo.CanWhileCount + "]次");
//LogUtil.error(LOGGER, StoreName + moveAxis.DisplayStr + "重新回原点"); //LogUtil.error(LOGGER, StoreName + moveAxis.DisplayStr + "重新回原点");
ACServerManager.HomeMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), moveAxis.HomeHighSpeed); ACServerManager.HomeMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), moveAxis.HomeHighSpeed);
MoveInfo.CanWhileCount--; MoveInfo.CanWhileCount--;
...@@ -311,7 +310,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -311,7 +310,7 @@ namespace OnlineStore.DeviceLibrary
else else
{ {
msg = Name + " storeMoveStep=" + MoveInfo.MoveStep + moveAxis.DisplayStr + "收到原点完成信号,当前位置[" + outCount + "],误差过大,需要报警"; msg = Name + " storeMoveStep=" + MoveInfo.MoveStep + moveAxis.DisplayStr + "收到原点完成信号,当前位置[" + outCount + "],误差过大,需要报警";
LogUtil.error(LOGGER, msg); LogUtil.error(Name+ msg);
} }
} }
return false; return false;
...@@ -477,6 +476,29 @@ namespace OnlineStore.DeviceLibrary ...@@ -477,6 +476,29 @@ namespace OnlineStore.DeviceLibrary
{ {
LogUtil.info(Name + logInfo); LogUtil.info(Name + logInfo);
} }
protected int GetAlarmCodeByAxis(ConfigMoveAxis axis)
{
int alarmCode = LineAlarm.InOutAxisAlarm;
int axisType = axis.GetAxisValue() % 4;
if (axisType == 1)
{
alarmCode = LineAlarm.MiddleAxisAlarm;
}
else if (axisType == 2)
{
alarmCode = LineAlarm.UpDownAxisAlarm;
}
else if (axisType == 3)
{
alarmCode = LineAlarm.InOutAxisAlarm;
}
else
{
alarmCode = LineAlarm.CompressAxisAlarm;
}
return alarmCode;
}
} }
} }
...@@ -441,7 +441,11 @@ namespace OnlineStore.LoadCSVLibrary ...@@ -441,7 +441,11 @@ namespace OnlineStore.LoadCSVLibrary
[ConfigProAttribute("CameraNameList")] [ConfigProAttribute("CameraNameList")]
public string CameraNameList { get; set; } public string CameraNameList { get; set; }
/// <summary>
/// PRO,RFID读卡器IP,RFID_IP,192.168.200.11,,,,,,,
/// </summary>
[ConfigProAttribute("RFID_IP")]
public string RFID_IP { get; set; }
/// <summary> /// <summary>
/// PRO,是否是调试状态,IsInDebug,1,,,,,,, /// PRO,是否是调试状态,IsInDebug,1,,,,,,,
/// </summary> /// </summary>
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!