Browse Source

主机断线后自动重新连接

章政 7 years ago
parent
commit
f9f068ce62

+ 41 - 7
PLCDataReader/Device/Information/DeviceStatusInfo.Designer.cs

@@ -55,6 +55,9 @@ namespace UAS_PLCDataReader.Device.Infomation
             this.dpg_receivedatasize = new UAS_PLCDataReader.CustomerControl.ValueLabel.ValueLabel();
             this.dpg_senddatasize = new UAS_PLCDataReader.CustomerControl.ValueLabel.ValueLabel();
             this.dpg_starttime = new UAS_PLCDataReader.CustomerControl.ValueLabel.ValueLabel();
+            this.labelControl13 = new DevExpress.XtraEditors.LabelControl();
+            this.INQTY = new UAS_PLCDataReader.CustomerControl.ValueLabel.ValueLabel();
+            this.OUTQTY = new UAS_PLCDataReader.CustomerControl.ValueLabel.ValueLabel();
             ((System.ComponentModel.ISupportInitialize)(this.groupControl1)).BeginInit();
             this.groupControl1.SuspendLayout();
             ((System.ComponentModel.ISupportInitialize)(this.groupControl2)).BeginInit();
@@ -149,29 +152,32 @@ namespace UAS_PLCDataReader.Device.Infomation
             // 
             // groupControl2
             // 
+            this.groupControl2.Controls.Add(this.OUTQTY);
+            this.groupControl2.Controls.Add(this.INQTY);
+            this.groupControl2.Controls.Add(this.labelControl13);
             this.groupControl2.Controls.Add(this.labelControl5);
             this.groupControl2.Controls.Add(this.labelControl6);
             this.groupControl2.Controls.Add(this.labelControl8);
             this.groupControl2.Controls.Add(this.labelControl7);
             this.groupControl2.Location = new System.Drawing.Point(12, 202);
             this.groupControl2.Name = "groupControl2";
-            this.groupControl2.Size = new System.Drawing.Size(187, 159);
+            this.groupControl2.Size = new System.Drawing.Size(187, 182);
             this.groupControl2.TabIndex = 1;
             this.groupControl2.Text = "生产信息";
             // 
             // labelControl5
             // 
             this.labelControl5.Appearance.Font = new System.Drawing.Font("黑体", 12F);
-            this.labelControl5.Location = new System.Drawing.Point(13, 128);
+            this.labelControl5.Location = new System.Drawing.Point(13, 127);
             this.labelControl5.Name = "labelControl5";
             this.labelControl5.Size = new System.Drawing.Size(32, 16);
             this.labelControl5.TabIndex = 10;
-            this.labelControl5.Text = "数量";
+            this.labelControl5.Text = "投入";
             // 
             // labelControl6
             // 
             this.labelControl6.Appearance.Font = new System.Drawing.Font("黑体", 12F);
-            this.labelControl6.Location = new System.Drawing.Point(13, 97);
+            this.labelControl6.Location = new System.Drawing.Point(13, 95);
             this.labelControl6.Name = "labelControl6";
             this.labelControl6.Size = new System.Drawing.Size(32, 16);
             this.labelControl6.TabIndex = 9;
@@ -189,7 +195,7 @@ namespace UAS_PLCDataReader.Device.Infomation
             // labelControl7
             // 
             this.labelControl7.Appearance.Font = new System.Drawing.Font("黑体", 12F);
-            this.labelControl7.Location = new System.Drawing.Point(13, 65);
+            this.labelControl7.Location = new System.Drawing.Point(13, 64);
             this.labelControl7.Name = "labelControl7";
             this.labelControl7.Size = new System.Drawing.Size(32, 16);
             this.labelControl7.TabIndex = 8;
@@ -254,7 +260,7 @@ namespace UAS_PLCDataReader.Device.Infomation
             this.groupControl3.Controls.Add(this.labelControl11);
             this.groupControl3.Location = new System.Drawing.Point(216, 12);
             this.groupControl3.Name = "groupControl3";
-            this.groupControl3.Size = new System.Drawing.Size(328, 349);
+            this.groupControl3.Size = new System.Drawing.Size(328, 372);
             this.groupControl3.TabIndex = 2;
             this.groupControl3.Text = "运行信息";
             // 
@@ -298,11 +304,36 @@ namespace UAS_PLCDataReader.Device.Infomation
             this.dpg_starttime.Size = new System.Drawing.Size(0, 16);
             this.dpg_starttime.TabIndex = 0;
             // 
+            // labelControl13
+            // 
+            this.labelControl13.Appearance.Font = new System.Drawing.Font("黑体", 12F);
+            this.labelControl13.Location = new System.Drawing.Point(13, 156);
+            this.labelControl13.Name = "labelControl13";
+            this.labelControl13.Size = new System.Drawing.Size(32, 16);
+            this.labelControl13.TabIndex = 11;
+            this.labelControl13.Text = "产出";
+            // 
+            // INQTY
+            // 
+            this.INQTY.Appearance.Font = new System.Drawing.Font("黑体", 12F);
+            this.INQTY.Location = new System.Drawing.Point(69, 128);
+            this.INQTY.Name = "INQTY";
+            this.INQTY.Size = new System.Drawing.Size(0, 16);
+            this.INQTY.TabIndex = 20;
+            // 
+            // OUTQTY
+            // 
+            this.OUTQTY.Appearance.Font = new System.Drawing.Font("黑体", 12F);
+            this.OUTQTY.Location = new System.Drawing.Point(69, 156);
+            this.OUTQTY.Name = "OUTQTY";
+            this.OUTQTY.Size = new System.Drawing.Size(0, 16);
+            this.OUTQTY.TabIndex = 21;
+            // 
             // DeviceStatusInfo
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 14F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(556, 373);
+            this.ClientSize = new System.Drawing.Size(556, 396);
             this.Controls.Add(this.groupControl3);
             this.Controls.Add(this.groupControl2);
             this.Controls.Add(this.groupControl1);
@@ -354,5 +385,8 @@ namespace UAS_PLCDataReader.Device.Infomation
         private ValueLabel de_wccode;
         private ValueLabel de_name;
         private ValueLabel dpg_runtime;
+        private DevExpress.XtraEditors.LabelControl labelControl13;
+        private ValueLabel OUTQTY;
+        private ValueLabel INQTY;
     }
 }

+ 18 - 0
PLCDataReader/Device/Information/DeviceStatusInfo.cs

@@ -6,6 +6,7 @@ using System.Data;
 using System.Text;
 using UAS_PLCDataReader.PublicMethod;
 using System.Windows.Forms;
+using System.Collections.Generic;
 
 namespace UAS_PLCDataReader.Device.Infomation
 {
@@ -47,6 +48,23 @@ namespace UAS_PLCDataReader.Device.Infomation
                 dpg_starttime.Text = Main.ReturnData[de_code].StartTime.ToString("yyyy-MM-dd HH:mm:ss");
                 dpg_senddatasize.Text = Main.ReturnData[de_code].SendDataSize.ToString();
                 dpg_receivedatasize.Text = Main.ReturnData[de_code].ReceiveDataSize.ToString();
+                Dictionary<string, string> ItemData = Main.ReturnData[de_code].ItemData;
+                foreach (var item in ItemData)
+                {
+                    switch (item.Key)
+                    {
+                        case "INQTY":
+                            INQTY.Text = item.Value;
+                            break;
+                        case "OUTQTY":
+                            OUTQTY.Text = item.Value;
+                            break;
+                        case "TEMPERATURE":
+                            break;
+                        default:
+                            break;
+                    }
+                }
             }
             //dt = (DataTable)dh.ExecuteSql("select dpg_count,round((sysdate-dpg_starttime)*1440)||'分钟' dpg_runtime,dpg_starttime,dpg_senddatasize,dpg_receivedatasize from DEVICEPOLLINGLOG where dpg_id=(select max(dpg_id) from DEVICEPOLLINGLOG where dpg_decode='" + de_code + "') and dpg_status='Running'", "select");
             //if (dt.Rows.Count > 0)

+ 13 - 4
PLCDataReader/Main.Designer.cs

@@ -97,6 +97,7 @@ namespace UAS_PLCDataReader
             this.dc_code = new DevExpress.XtraGrid.Columns.GridColumn();
             this.dc_name = new DevExpress.XtraGrid.Columns.GridColumn();
             this.dc_type = new DevExpress.XtraGrid.Columns.GridColumn();
+            this.dc_typename = new DevExpress.XtraGrid.Columns.GridColumn();
             this.dc_dataindex = new DevExpress.XtraGrid.Columns.GridColumn();
             this.dc_value = new DevExpress.XtraGrid.Columns.GridColumn();
             this.dc_sendcoding = new DevExpress.XtraGrid.Columns.GridColumn();
@@ -236,7 +237,6 @@ namespace UAS_PLCDataReader
             this.DeviceInf,
             this.DeviceCommandSetting});
             this.RibbonNav.Size = new System.Drawing.Size(1033, 128);
-            this.RibbonNav.Click += new System.EventHandler(this.RibbonNav_Click);
             // 
             // ButtonDeviceList
             // 
@@ -825,6 +825,7 @@ namespace UAS_PLCDataReader
             this.dc_code,
             this.dc_name,
             this.dc_type,
+            this.dc_typename,
             this.dc_dataindex,
             this.dc_value,
             this.dc_sendcoding,
@@ -880,12 +881,19 @@ namespace UAS_PLCDataReader
             // 
             // dc_type
             // 
-            this.dc_type.Caption = "指令类型";
+            this.dc_type.Caption = "指令";
             this.dc_type.FieldName = "DC_TYPE";
             this.dc_type.Name = "dc_type";
             this.dc_type.Visible = true;
             this.dc_type.VisibleIndex = 3;
-            this.dc_type.Width = 57;
+            // 
+            // dc_typename
+            // 
+            this.dc_typename.Caption = "指令类型";
+            this.dc_typename.ColumnEdit = this.DataItemRepositoryItemComboBox1;
+            this.dc_typename.FieldName = "DC_TYPENAME";
+            this.dc_typename.Name = "dc_typename";
+            this.dc_typename.Width = 57;
             // 
             // dc_dataindex
             // 
@@ -1864,7 +1872,7 @@ namespace UAS_PLCDataReader
         private DevExpress.XtraGrid.Columns.GridColumn em_name;
         private DevExpress.XtraGrid.Columns.GridColumn de_inman;
         private DevExpress.XtraGrid.Columns.GridColumn de_linecode;
-        private DevExpress.XtraGrid.Columns.GridColumn dc_type;
+        private DevExpress.XtraGrid.Columns.GridColumn dc_typename;
         private DevExpress.XtraGrid.Columns.GridColumn db_name;
         private DevExpress.XtraGrid.Columns.GridColumn dpc_man;
         private DevExpress.XtraGrid.Columns.GridColumn em_name1;
@@ -1885,5 +1893,6 @@ namespace UAS_PLCDataReader
         private DevExpress.XtraGrid.Columns.GridColumn de_item2;
         private DevExpress.XtraGrid.Columns.GridColumn de_item3;
         private DevExpress.XtraEditors.Repository.RepositoryItemComboBox DataItemRepositoryItemComboBox1;
+        private DevExpress.XtraGrid.Columns.GridColumn dc_type;
     }
 }

+ 7 - 13
PLCDataReader/Main.cs

@@ -63,13 +63,13 @@ namespace UAS_PLCDataReader
             CommandSetRepositoryItemComboBox1.Items.Add(cbd2);
 
             ComboBoxData cbd3 = new ComboBoxData();
-            cbd3.Text = "INQTY";
+            cbd3.Text = "投入";
             cbd3.Value = "INQTY";
             ComboBoxData cbd4 = new ComboBoxData();
-            cbd4.Text = "OUTQTY";
+            cbd4.Text = "产出";
             cbd4.Value = "OUTQTY";
             ComboBoxData cbd5 = new ComboBoxData();
-            cbd5.Text = "TEMPERATURE";
+            cbd5.Text = "温度";
             cbd5.Value = "TEMPERATURE";
             DataItemRepositoryItemComboBox1.Items.Add(cbd3);
             DataItemRepositoryItemComboBox1.Items.Add(cbd4);
@@ -86,11 +86,10 @@ namespace UAS_PLCDataReader
                 item = (ComboBoxData)(sender as ComboBoxEdit).SelectedItem;
                 string text = item.Text.ToString();
                 string value = item.Value;
-                GridView myView = (GridDeviceList.MainView as GridView);
+                GridView myView = (GridCommandSetting.MainView as GridView);
                 int dataIndex = myView.GetDataSourceRowIndex(myView.FocusedRowHandle);
-                DataTable dt = (DataTable)GridDeviceList.DataSource;
-                dt.Rows[dataIndex]["de_item1"] = value;
-                GridDeviceList.DataSource = dt;
+                DataTable dt = (DataTable)GridCommandSetting.DataSource;
+                dt.Rows[dataIndex]["dc_type"] = value;
             }
             catch (Exception ex)
             {
@@ -147,7 +146,7 @@ namespace UAS_PLCDataReader
             ButtonDeleteCommandSet.Grid = GridPollingSetting;
 
             //指令设置界面
-            GridCommandSetting.GetDataSQL = "select 0 CHECKEDCOLUMN,dc_id,dc_code,dc_name,dc_type,dc_value,dc_dataindex,dc_sendcoding,dc_receivecoding,db_name,dc_man,dc_date from devicecommand left join devicebrand on db_code=dc_debrand".ToUpper();
+            GridCommandSetting.GetDataSQL = "select 0 CHECKEDCOLUMN,dc_id,dc_code,dc_name,dc_type,case when dc_type='INQTY' then '投入' when dc_type='OUTQTY' then '产出' when dc_type='TEMPERATURE' then '温度' end dc_typename,dc_value,dc_dataindex,dc_sendcoding,dc_receivecoding,db_name,dc_man,dc_date from devicecommand left join devicebrand on db_code=dc_debrand".ToUpper();
             GridCommandSetting.TableName = "devicecommand";
             GridCommandSetting.ID = "dc_id";
             GridCommandSetting.InsertSQL = "insert into devicecommand(dc_id,dc_code,dc_name,dc_value,dc_debrand,dc_sendcoding,dc_receivecoding,dc_man,dc_date,dc_dataindex) values(devicecommand_seq.nextval,:dc_code,:dc_name,:dc_value,'" + BaseUtil.GetComboxEditValue(Brand) + "',:dc_sendcoding,:dc_receivecoding,'" + User.UserName + "',sysdate,:dc_dataindex)";
@@ -887,10 +886,5 @@ namespace UAS_PLCDataReader
             }
         }
         #endregion
-
-        private void RibbonNav_Click(object sender, EventArgs e)
-        {
-
-        }
     }
 }

+ 6 - 1
PLCDataReader/PublicMethod/LogicHandler.cs

@@ -49,7 +49,12 @@ namespace UAS_PLCDataReader.PublicMethod
             dh.ExecuteSql(sql.ToString(), "insert");
         }
 
-        public static void UpdateDeviceData(string Decode,Dictionary<string,string> ItemData)
+        /// <summary>
+        /// 更新设备数据
+        /// </summary>
+        /// <param name="Decode"></param>
+        /// <param name="ItemData"></param>
+        public static void UpdateDeviceData(string Decode, Dictionary<string, string> ItemData)
         {
             string INQTY = "";
             string OUTQTY = "";

+ 22 - 10
PLCDataReader/PublicMethod/ModBusTCPClient.cs

@@ -104,19 +104,31 @@ namespace UAS_PLCDataReader.PublicMethod
 
         public void Send(string Command)
         {
-            Command = Command.Replace(" ", "");
-            byte[] arr = new byte[Command.Length / 2];
-            for (int i = 0; i < Command.Length / 2; i++)
+            try
             {
-                arr[i] = (byte)Convert.ToInt32(Command.Substring(i * 2, 2), 16);
+                if (!socket.Connected)
+                {
+                    socket.Close();
+                    socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
+                    socket.Connect(serverFullAddr);
+                }
+                Command = Command.Replace(" ", "");
+                byte[] arr = new byte[Command.Length / 2];
+                for (int i = 0; i < Command.Length / 2; i++)
+                {
+                    arr[i] = (byte)Convert.ToInt32(Command.Substring(i * 2, 2), 16);
+                }
+                socket.Send(arr);
+                byte[] receive = new byte[1024 * 1024];
+                int length = socket.Receive(receive);
+                if (!returnvalue.ContainsKey(socket.RemoteEndPoint.ToString()))
+                {
+                    returnvalue.Add(socket.RemoteEndPoint.ToString(), BaseUtil.ByteToHexadecimalString(receive, length));
+                }
             }
-            socket.Send(arr);
-            byte[] receive = new byte[1024 * 1024];
-            int length = socket.Receive(receive);
-            Console.WriteLine(BaseUtil.ByteToHexadecimalString(receive, length));
-            if (!returnvalue.ContainsKey(socket.RemoteEndPoint.ToString()))
+            catch (Exception e)
             {
-                returnvalue.Add(socket.RemoteEndPoint.ToString(), BaseUtil.ByteToHexadecimalString(receive, length));
+                Console.WriteLine(e.Message);
             }
         }
     }