ソースを参照

添加串口标识,界面获取串口数据

章政 7 年 前
コミット
f766304ff6

+ 36 - 0
UAS-出货标签管理(吉利通)/CustomControl/SerialPortWithTag.Designer.cs

@@ -0,0 +1,36 @@
+namespace UAS_LabelMachine.CustomControl
+{
+    partial class SerialPortWithTag
+    {
+        /// <summary> 
+        /// 必需的设计器变量。
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary> 
+        /// 清理所有正在使用的资源。
+        /// </summary>
+        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region 组件设计器生成的代码
+
+        /// <summary> 
+        /// 设计器支持所需的方法 - 不要修改
+        /// 使用代码编辑器修改此方法的内容。
+        /// </summary>
+        private void InitializeComponent()
+        {
+            components = new System.ComponentModel.Container();
+        }
+
+        #endregion
+    }
+}

+ 36 - 0
UAS-出货标签管理(吉利通)/CustomControl/SerialPortWithTag.cs

@@ -0,0 +1,36 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Drawing;
+using System.Data;
+using System.Linq;
+using System.Text;
+using System.Windows.Forms;
+using System.IO.Ports;
+
+namespace UAS_LabelMachine.CustomControl
+{
+    public partial class SerialPortWithTag : SerialPort
+    {
+
+        private string tag;
+
+        public SerialPortWithTag()
+        {
+            InitializeComponent();
+        }
+
+        public string Tag
+        {
+            get
+            {
+                return tag;
+            }
+
+            set
+            {
+                tag = value;
+            }
+        }
+    }
+}

+ 5 - 0
UAS-出货标签管理(吉利通)/ParamSetting.Designer.cs

@@ -189,6 +189,7 @@
             this.COM5.Str1 = null;
             this.COM5.Str2 = null;
             this.COM5.TabIndex = 6;
+            this.COM5.Tag = "ManBackendCheck";
             // 
             // label13
             // 
@@ -277,6 +278,7 @@
             this.COM4.Str1 = null;
             this.COM4.Str2 = null;
             this.COM4.TabIndex = 6;
+            this.COM4.Tag = "BackendCheck";
             // 
             // label17
             // 
@@ -374,6 +376,7 @@
             this.COM3.Str1 = null;
             this.COM3.Str2 = null;
             this.COM3.TabIndex = 5;
+            this.COM3.Tag = "FrontendCheck";
             // 
             // label16
             // 
@@ -458,6 +461,7 @@
             this.COM2.Str1 = null;
             this.COM2.Str2 = null;
             this.COM2.TabIndex = 4;
+            this.COM2.Tag = "PLC2";
             // 
             // label4
             // 
@@ -533,6 +537,7 @@
             this.COM1.Str1 = null;
             this.COM1.Str2 = null;
             this.COM1.TabIndex = 3;
+            this.COM1.Tag = "PLC1";
             // 
             // label3
             // 

+ 1 - 0
UAS-出货标签管理(吉利通)/ParamSetting.cs

@@ -80,6 +80,7 @@ namespace UAS_LabelMachine
             for (int i = 1; i < 6; i++)
             {
                 COMINFO.Rows[i - 1]["COM"] =  Controls["GP"].Controls["GP" + i].Controls["COM" + i].Text;
+                COMINFO.Rows[i - 1]["COMTYPE"] = Controls["GP"].Controls["GP" + i].Controls["COM" + i].Tag.ToString();
                 COMINFO.Rows[i - 1]["BaudRate"]= Controls["GP"].Controls["GP" + i].Controls["BaudRate" + i].Text ;
                 COMINFO.Rows[i - 1]["Datawait"]=Controls["GP"].Controls["GP" + i].Controls["Datawait" + i].Text  ;
                 if (Controls["GP"].Controls["GP" + i].Controls["OutTime" + i] != null)

+ 147 - 0
UAS-出货标签管理(吉利通)/PublicMethod/DataGridViewVirtualModel.cs

@@ -0,0 +1,147 @@
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Linq;
+using System.Text;
+
+namespace UAS_LabelMachine.PublicMethod
+{
+    class DataGridViewVirtualModel
+    {
+        public interface IDataPageRetriever
+        {
+            DataTable ApplyPageOfData(int lowPageBoundary, int rowsPerPage);
+        }
+
+        internal class DataRetriever : IDataPageRetriever
+        {
+
+            private DataColumnCollection columns;
+
+            private string commaSeparatedColumnNames;
+
+            public DataTable ApplyPageOfData(int lowPageBoundary, int rowsPerPage)
+            {
+                return new DataTable();
+            }
+
+            #region IDataPageRetriver 
+            #endregion
+        }
+
+        internal class Cache
+        {
+            private struct DataPage
+            {
+                public DataTable table;
+                private int lowIndex;
+                private int highIndex;
+
+                public DataPage(DataTable table, int rowIndex)
+                {
+                    this.table = table;
+                    this.lowIndex = MapLowerBoundary(rowIndex);
+                    this.highIndex = MapUpperBoundary(rowIndex);
+                }
+                public int LowIndex
+                {
+                    get { return this.lowIndex; }
+                }
+                public int HighIndex
+                {
+                    get { return this.highIndex; }
+                }
+
+                public static int MapLowerBoundary(int rowIndex)
+                {
+                    return (rowIndex / RowPerPage) * RowPerPage;
+                }
+                public static int MapUpperBoundary(int rowIndex)
+                {
+                    return MapLowerBoundary(rowIndex) + RowPerPage - 1;
+                }
+            }
+            IDataPageRetriever dataSupply;
+            static int RowPerPage;
+            DataPage[] catchPages = new DataPage[2];
+
+            public Cache(IDataPageRetriever dataSupplier, int rowsPerPage)
+            {
+                this.dataSupply = dataSupplier;
+                RowPerPage = rowsPerPage;
+                PreLoadDataPages();
+            }
+            private void PreLoadDataPages()
+            {
+                catchPages[0] = new DataPage(dataSupply.ApplyPageOfData(0, RowPerPage), 0);
+                catchPages[1] = new DataPage(dataSupply.ApplyPageOfData(RowPerPage, RowPerPage), RowPerPage);
+            }
+            public string RetrieveElement(int rowIndex, int colIndex)
+            {
+                string element = "";
+                if (IfPageCatched_TheSetElement(rowIndex, colIndex, ref element))
+                {
+                    return element;
+                }
+                else
+                {
+                    element = RetrieveData_CatchIt_ReturnElement(rowIndex, colIndex);
+                }
+                return element;
+            }
+
+            private bool IfPageCatched_TheSetElement(int rowIndex, int colIndex, ref string element)
+            {
+                if (IsRowCatchedInPage(0, rowIndex))
+                {
+                    element = catchPages[0].table.Rows[rowIndex % RowPerPage][colIndex].ToString();
+                    return true;
+                }
+                else if (IsRowCatchedInPage(1, rowIndex))
+                {
+                    element = catchPages[1].table.Rows[rowIndex % RowPerPage][colIndex].ToString();
+                    return true;
+                }
+                return false;
+            }
+
+            private string RetrieveData_CatchIt_ReturnElement(int rowIndex, int colIndex)
+            {
+
+                DataPage newPage = new DataPage(dataSupply.ApplyPageOfData(DataPage.MapLowerBoundary(rowIndex), RowPerPage), rowIndex);
+
+                //which old datapage should be replaced?
+                catchPages[GetIndexOfReplacedPage(rowIndex)] = newPage;
+
+                return RetrieveElement(rowIndex, colIndex);
+            }
+
+            private bool IsRowCatchedInPage(int pageNum, int rowIndex)
+            {
+                return catchPages[pageNum].LowIndex <= rowIndex &&
+                    catchPages[pageNum].HighIndex >= rowIndex;
+            }
+
+            private int GetIndexOfReplacedPage(int rowIndex)
+            {
+                if (catchPages[0].HighIndex < rowIndex && catchPages[1].HighIndex < rowIndex)
+                {
+                    int offsetFromPage0 = rowIndex - catchPages[0].HighIndex;
+                    int offsetFromPage1 = rowIndex - catchPages[1].HighIndex;
+                    if (offsetFromPage0 < offsetFromPage1)
+                        return 1;
+                    else
+                        return 0;
+                }
+                else
+                {
+                    int offsetFromPage0 = catchPages[0].LowIndex - rowIndex;
+                    int offsetFromPage1 = catchPages[1].LowIndex - rowIndex;
+                    if (offsetFromPage0 < offsetFromPage1)
+                        return 1;
+                    return 0;
+                }
+            }
+        }
+    }
+}

+ 1 - 2
UAS-出货标签管理(吉利通)/PublicMethod/DataHelper.cs

@@ -813,7 +813,6 @@ namespace UAS_LabelMachine
         {
             object result = null;
             command = new OracleCommand(SQL, connection);
-            Console.WriteLine(SQL);
             //用来拼接参数的
             if (names.Length > 0)
             {
@@ -967,7 +966,7 @@ namespace UAS_LabelMachine
                         command.Parameters.Add(new OracleParameter(names[0][i - 1].ToString(), OracleDbType.Date, time, ParameterDirection.Input));
                     }
                     catch (Exception)
-                    {
+                    {   
                         command.Parameters.Add(new OracleParameter(names[0][i - 1].ToString(), OracleDbType.Varchar2, names[i], ParameterDirection.Input));
                     }
                 }

+ 7 - 0
UAS-出货标签管理(吉利通)/UAS-出货标签管理(吉利通).csproj

@@ -214,6 +214,12 @@
     <Compile Include="CustomControl\SearchTextBox.Designer.cs">
       <DependentUpon>SearchTextBox.cs</DependentUpon>
     </Compile>
+    <Compile Include="CustomControl\SerialPortWithTag.cs">
+      <SubType>Component</SubType>
+    </Compile>
+    <Compile Include="CustomControl\SerialPortWithTag.Designer.cs">
+      <DependentUpon>SerialPortWithTag.cs</DependentUpon>
+    </Compile>
     <Compile Include="DbFind.cs">
       <SubType>Form</SubType>
     </Compile>
@@ -249,6 +255,7 @@
     <Compile Include="PublicMethod\ArrayList.cs" />
     <Compile Include="PublicMethod\AutoSizeFormClass.cs" />
     <Compile Include="PublicMethod\BaseUtil.cs" />
+    <Compile Include="PublicMethod\DataGridViewVirtualModel.cs" />
     <Compile Include="PublicMethod\DataHelper.cs" />
     <Compile Include="PublicMethod\ExcelHandler.cs" />
     <Compile Include="PublicMethod\ftpOperater.cs" />

+ 4 - 0
UAS-出货标签管理(吉利通)/UAS_出货标签管理.Designer.cs

@@ -93,6 +93,7 @@
             this.CleanBarCode = new System.Windows.Forms.Button();
             this.ListButtonMenu = new System.Windows.Forms.ListBox();
             this.ButtonSetting = new System.Windows.Forms.Button();
+            this.FrontendCheck = new CustomControl.SerialPortWithTag();
             this.groupBoxWithBorder1 = new UAS_LabelMachine.CustomControl.GroupBoxWithBorder.GroupBoxWithBorder();
             this.ExportData = new System.Windows.Forms.Button();
             this.label18 = new System.Windows.Forms.Label();
@@ -174,6 +175,7 @@
             this.OutBoxLabelPrint = new System.Windows.Forms.Button();
             this.OutBoxLabelAutoPrint = new System.Windows.Forms.CheckBox();
             this.OutBoxCombox = new System.Windows.Forms.ComboBox();
+            this.BackendCheck = new CustomControl.SerialPortWithTag();
             ((System.ComponentModel.ISupportInitialize)(this.Si_ItemDGV)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.MidSource)).BeginInit();
             this.groupBoxWithBorder1.SuspendLayout();
@@ -1893,5 +1895,7 @@
         private System.Windows.Forms.DataGridViewTextBoxColumn pr_spec;
         private System.Windows.Forms.DataGridViewTextBoxColumn pib_outboxcode1;
         private System.Windows.Forms.DataGridViewTextBoxColumn pib_outboxcode2;
+        private CustomControl.SerialPortWithTag FrontendCheck;
+        private CustomControl.SerialPortWithTag BackendCheck;
     }
 }

+ 49 - 0
UAS-出货标签管理(吉利通)/UAS_出货标签管理.cs

@@ -15,6 +15,8 @@ using UAS_LabelMachine.PublicForm;
 using System.Threading;
 using System.IO;
 using System.Globalization;
+using System.IO.Ports;
+using UAS_LabelMachine.CustomControl;
 
 namespace UAS_LabelMachine
 {
@@ -205,6 +207,53 @@ namespace UAS_LabelMachine
             }
             RefreshDBConnect.Interval = 60000;
             RefreshDBConnect.Start();
+
+            DataTable dt = (DataTable)adh.ExecuteSql("select * from cominfo", "select");
+            DataRow[] dr = dt.Select("comtype='FrontendCheck'");
+            if (dr.Length > 0)
+            {
+                FrontendCheck.PortName = dr[0]["COM"].ToString();
+                FrontendCheck.Tag = "FrontendCheck";
+                FrontendCheck.BaudRate = int.Parse(dr[0]["BaudRate"].ToString());
+                FrontendCheck.DataReceived += Serial_DataReceived;
+                FrontendCheck.Open();
+            }
+            dr = dt.Select("comtype='BackendCheck'");
+            if (dr.Length > 0)
+            {
+                BackendCheck.PortName = dr[0]["COM"].ToString();
+                BackendCheck.Tag = "BackendCheck";
+                BackendCheck.BaudRate = int.Parse(dr[0]["BaudRate"].ToString());
+                BackendCheck.DataReceived += Serial_DataReceived;
+                BackendCheck.Open();
+            }
+        }
+
+        //获取串口数据
+        private void Serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
+        {
+            try
+            {
+                SerialPortWithTag port = sender as SerialPortWithTag;
+                int len = port.BytesToRead;
+                byte[] readBuffer = new byte[len];
+                port.Read(readBuffer, 0, len); //将数据读入缓存
+                string msg = Encoding.ASCII.GetString(readBuffer, 0, len); //获取出入库产品编号
+                switch (port.Tag)
+                {
+                    case "FrontendCheck":
+                        break;
+                    case "BackendCheck":
+                        break;
+                    default:
+                        break;
+                }
+                Console.WriteLine(msg);
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show("提示信息", "接收返回消息异常!具体原因:" + ex.Message);
+            }
         }
 
         private void Sg_code_DbChange(object sender, EventArgs e)

+ 63 - 0
UAS-出货标签管理(吉利通)/UAS_出货标签管理.resx

@@ -141,6 +141,30 @@
   <metadata name="si_expressionitem.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     <value>True</value>
   </metadata>
+  <metadata name="si_detno.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="si_index.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="si_kind.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="si_indexstring.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="si_length.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="si_expression.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="si_item.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="si_expressionitem.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
   <metadata name="RefreshDBConnect.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     <value>17, 17</value>
   </metadata>
@@ -150,6 +174,9 @@
   <metadata name="ExportFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     <value>294, 17</value>
   </metadata>
+  <metadata name="FrontendCheck.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>442, 17</value>
+  </metadata>
   <metadata name="pib_ifmodify.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     <value>True</value>
   </metadata>
@@ -183,6 +210,42 @@
   <metadata name="pr_spec.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     <value>True</value>
   </metadata>
+  <metadata name="pib_ifmodify.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="pib_ifupload.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="pib_madein.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="pr_zxbzs.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="pr_unit.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="pib_ifrecheck.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="pib_datecode1.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="pib_custbarcode.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="pd_custprodcode.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="pd_custprodspec.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="pr_spec.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="BackendCheck.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>584, 18</value>
+  </metadata>
   <assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
   <data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
     <value>