Bladeren bron

Merge branch 'master' of ssh://10.10.100.21/source/mes-client

Hcsy 7 jaren geleden
bovenliggende
commit
f0addde6c4

+ 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;
     }
 }

+ 8 - 16
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)";
@@ -503,8 +502,6 @@ namespace UAS_PLCDataReader
                     ModBusTCPClient modclient = new ModBusTCPClient(DNC.Rows[0]["dnc_ip"].ToString(), int.Parse(DNC.Rows[0]["dnc_port"].ToString()));
                     client.Add(DpcID, modclient);
                 }
-                //发送指令
-                //mbt.Send(IP, SendCoding, ReceiveCoding, Command);
                 //如果不包含该项数据则在键值对中添加
                 if (!ReturnData.ContainsKey(Decode))
                 {
@@ -877,7 +874,7 @@ namespace UAS_PLCDataReader
                 ShowDeviceStatus();
             }
         }
-        
+
         private void PanelDeviceStatus_SizeChanged(object sender, EventArgs e)
         {
             if (PageDeviceStatus.PageVisible)
@@ -887,10 +884,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);
             }
         }
     }

+ 0 - 120
TestProject/Form2.resx

@@ -1,120 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<root>
-  <!-- 
-    Microsoft ResX Schema 
-    
-    Version 2.0
-    
-    The primary goals of this format is to allow a simple XML format 
-    that is mostly human readable. The generation and parsing of the 
-    various data types are done through the TypeConverter classes 
-    associated with the data types.
-    
-    Example:
-    
-    ... ado.net/XML headers & schema ...
-    <resheader name="resmimetype">text/microsoft-resx</resheader>
-    <resheader name="version">2.0</resheader>
-    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
-    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
-    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
-    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
-    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
-        <value>[base64 mime encoded serialized .NET Framework object]</value>
-    </data>
-    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
-        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
-        <comment>This is a comment</comment>
-    </data>
-                
-    There are any number of "resheader" rows that contain simple 
-    name/value pairs.
-    
-    Each data row contains a name, and value. The row also contains a 
-    type or mimetype. Type corresponds to a .NET class that support 
-    text/value conversion through the TypeConverter architecture. 
-    Classes that don't support this are serialized and stored with the 
-    mimetype set.
-    
-    The mimetype is used for serialized objects, and tells the 
-    ResXResourceReader how to depersist the object. This is currently not 
-    extensible. For a given mimetype the value must be set accordingly:
-    
-    Note - application/x-microsoft.net.object.binary.base64 is the format 
-    that the ResXResourceWriter will generate, however the reader can 
-    read any of the formats listed below.
-    
-    mimetype: application/x-microsoft.net.object.binary.base64
-    value   : The object must be serialized with 
-            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
-            : and then encoded with base64 encoding.
-    
-    mimetype: application/x-microsoft.net.object.soap.base64
-    value   : The object must be serialized with 
-            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
-            : and then encoded with base64 encoding.
-
-    mimetype: application/x-microsoft.net.object.bytearray.base64
-    value   : The object must be serialized into a byte array 
-            : using a System.ComponentModel.TypeConverter
-            : and then encoded with base64 encoding.
-    -->
-  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
-    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
-    <xsd:element name="root" msdata:IsDataSet="true">
-      <xsd:complexType>
-        <xsd:choice maxOccurs="unbounded">
-          <xsd:element name="metadata">
-            <xsd:complexType>
-              <xsd:sequence>
-                <xsd:element name="value" type="xsd:string" minOccurs="0" />
-              </xsd:sequence>
-              <xsd:attribute name="name" use="required" type="xsd:string" />
-              <xsd:attribute name="type" type="xsd:string" />
-              <xsd:attribute name="mimetype" type="xsd:string" />
-              <xsd:attribute ref="xml:space" />
-            </xsd:complexType>
-          </xsd:element>
-          <xsd:element name="assembly">
-            <xsd:complexType>
-              <xsd:attribute name="alias" type="xsd:string" />
-              <xsd:attribute name="name" type="xsd:string" />
-            </xsd:complexType>
-          </xsd:element>
-          <xsd:element name="data">
-            <xsd:complexType>
-              <xsd:sequence>
-                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
-                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
-              </xsd:sequence>
-              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
-              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
-              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
-              <xsd:attribute ref="xml:space" />
-            </xsd:complexType>
-          </xsd:element>
-          <xsd:element name="resheader">
-            <xsd:complexType>
-              <xsd:sequence>
-                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
-              </xsd:sequence>
-              <xsd:attribute name="name" type="xsd:string" use="required" />
-            </xsd:complexType>
-          </xsd:element>
-        </xsd:choice>
-      </xsd:complexType>
-    </xsd:element>
-  </xsd:schema>
-  <resheader name="resmimetype">
-    <value>text/microsoft-resx</value>
-  </resheader>
-  <resheader name="version">
-    <value>2.0</value>
-  </resheader>
-  <resheader name="reader">
-    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
-  </resheader>
-  <resheader name="writer">
-    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
-  </resheader>
-</root>