5 Commits 829e27191a ... 11d3ceadbd

Author SHA1 Message Date
  mengshunguo 11d3ceadbd 完善日志信息打印,条码去除多余字符 1 month ago
  mengshunguo 682ad2475b 完善条码日志打印 1 month ago
  mengshunguo 084a2f06e4 提交 1 month ago
  mengshunguo 8505313aad 提交 1 month ago
  mengshunguo 5080aada0d 提交 1 month ago
2 changed files with 57 additions and 25 deletions
  1. 14 7
      SCADA_DAQ/Customer/UctFrmMain.xaml
  2. 43 18
      SCADA_DAQ/Customer/UctFrmMain.xaml.cs

+ 14 - 7
SCADA_DAQ/Customer/UctFrmMain.xaml

@@ -19,19 +19,26 @@
             <Grid.RowDefinitions>
                 <RowDefinition Height="2*"/>
                 <RowDefinition Height="1*"/>
+                <RowDefinition Height="1*"/>
             </Grid.RowDefinitions>
             <GroupBox Header="扫码信息">
                 <StackPanel Orientation="Vertical" HorizontalAlignment="Center">
-                    <TextBlock x:Name="TextContentTime" Text="扫码时间" VerticalAlignment="Bottom" HorizontalAlignment="Center" FontSize="30" Foreground="Black" FontStretch="Normal"/>
-                    <TextBlock Text="" HorizontalAlignment="Center" VerticalAlignment="Top" FontSize="50" Foreground="Black" FontStretch="Normal"/>
+                    <TextBlock x:Name="TextContentTime" Text="扫码时间" VerticalAlignment="Bottom" HorizontalAlignment="Center" FontSize="40" Foreground="Black" FontStretch="Normal"/>
+                    <TextBlock HorizontalAlignment="Center" VerticalAlignment="Top" FontSize="50" Foreground="Black" FontStretch="Normal"/>
                     <TextBlock x:Name="TextContent" Text="扫码内容" HorizontalAlignment="Center" VerticalAlignment="Top" 
-                    FontSize="30" Foreground="White" FontStretch="Normal" FontWeight="Black" Background="Black"/>
+                    FontSize="40" Foreground="White" FontStretch="Normal" FontWeight="Black" Background="Black"/>
                 </StackPanel>
             </GroupBox>
-            <GroupBox Grid.Row="1" Header="ASCII码信息">
-                <StackPanel Orientation="Vertical" HorizontalAlignment="Center">
-                    <TextBlock x:Name="ASCIICode" Text="ASCII码" HorizontalAlignment="Center" VerticalAlignment="Top" 
-                     FontSize="30" Foreground="White" FontStretch="Normal" FontWeight="Black" Background="Black"/>
+            <GroupBox Grid.Row="1" Header="长宽信息">
+                <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
+                    <TextBlock x:Name="LongAndWide" Text="长宽信息" HorizontalAlignment="Center" VerticalAlignment="Center" 
+          FontSize="40" Foreground="White" FontStretch="Normal" FontWeight="Black" Background="Black"/>
+                </StackPanel>
+            </GroupBox>
+            <GroupBox Grid.Row="2" Header="ASCII码信息">
+                <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
+                    <TextBlock x:Name="ASCIICode" Text="ASCII码" HorizontalAlignment="Center" VerticalAlignment="Center" 
+                     FontSize="40" Foreground="White" FontStretch="Normal" FontWeight="Black" Background="Black"/>
                 </StackPanel>
             </GroupBox>
         </Grid>

+ 43 - 18
SCADA_DAQ/Customer/UctFrmMain.xaml.cs

@@ -57,20 +57,21 @@ namespace SCADA_DAQ.Customer
         /// <summary>
         /// 条形码的索引
         /// </summary>
-        int Barcode;
+        int BarcodeIndx;
 
         /// <summary>
         /// 长的索引
         /// </summary>
-        int Long;
+        int LongIndx;
 
         /// <summary>
         /// 宽的索引
         /// </summary>
-        int Wide;
+        int WideIndx;
         /// <summary>
-        /// /
+        /// /条码
         /// </summary>
+        string Barcode;
         public UctFrmMain()
         {
             InitializeComponent();
@@ -79,30 +80,53 @@ namespace SCADA_DAQ.Customer
             if (BarcodeReader1 != null)
             {
                 BarcodeReader1.BarCodeReceived += BarcodeReader1_BarCodeReceived;
+                Log.Info("获取到读码器实例");
             }
         }
 
         private void BarcodeReader1_BarCodeReceived(object sender, SCADA.BarcodeReader.BarcodeReceivedEventArgs e)
         {
-            if (e.Barcode == null || e.Barcode == "" || e.Barcode == "NoRead")
+            string barCode = null;
+            if (e.Barcode.Substring(0, 6) == "QRCode")
             {
+                barCode = e.Barcode.Substring(6, e.Barcode.Length - 6).Trim(); 
+                Log.Info($"收到条码{barCode}");
+            }
+            else
+            {
+                barCode = e.Barcode.Trim();
+                Log.Info($"收到条码{barCode}");
+            }
+            if (barCode == null || barCode == "" || barCode == "NoRead" || barCode == this.Barcode
+                || BarcodeInfo.Count == 0 || !BarcodeInfo.ContainsKey(barCode))
+            {
+                if(barCode == this.Barcode)
+                {
+                    Log.Info($"重复读码{barCode}");
+                }
+                else if(!BarcodeInfo.ContainsKey(barCode))
+                {
+                    Log.Info($"Ecexl表中无此条码{barCode}信息");
+                }
                 return;
             }
-            var _long = BarcodeInfo[e.Barcode]?.Long;
-            var _wide = BarcodeInfo[e.Barcode]?.Wide;
+            var _long = BarcodeInfo[barCode].Long;
+            var _wide = BarcodeInfo[barCode].Wide;
             if (_long == null || _wide == null)
             {
+                Log.Info($"Excel表中此条码{Barcode}的长宽信息不完善");
                 return;
             }
             var _string = $"{_long}#{_wide}";
-            Log.Info(_string);
+            Log.Info($"收到条码信息{barCode},发送长宽信息{_string}");
             var _byte = ASCIIEncoding.ASCII.GetBytes(_string);
             Dispatcher.Invoke(() =>
             {
-                TextContent.Text = e.Barcode;
+                TextContent.Text = barCode;
                 TextContentTime.Text = e.TimeStamp.ToLongTimeString();
                 //ASCIICode.Text = Encoding.UTF8.GetString(_byte);
-                ASCIICode.Text = string.Join(" ",Encoding.UTF8.GetString(_byte));
+                LongAndWide.Text = string.Join("", ASCIIEncoding.ASCII.GetString(_byte));
+                ASCIICode.Text = string.Join(" ", _byte);
             });
             using (var serialcomm = new SerialPort()
             {
@@ -119,6 +143,7 @@ namespace SCADA_DAQ.Customer
                 {
                     serialcomm.Open();
                     serialcomm.Write(_byte, 0, _byte.Count());
+                    this.Barcode = barCode;
                 }
                 catch
                 {
@@ -165,15 +190,15 @@ namespace SCADA_DAQ.Customer
                         ExcelData.Columns.Add(col);
                         if (cellValue == "条形码")
                         {
-                            Barcode = i;
+                            BarcodeIndx = i;
                         }
-                        if (cellValue == "长")
+                        if (cellValue == "开料长")
                         {
-                            Long = i;
+                            LongIndx = i;
                         }
-                        if (cellValue == "宽")
+                        if (cellValue == "开料宽")
                         {
-                            Wide = i;
+                            WideIndx = i;
                         }
                     }
                     else
@@ -199,19 +224,19 @@ namespace SCADA_DAQ.Customer
                     if (row.GetCell(j) != null)
                     {
                         dr[j] = row.GetCell(j).ToString();
-                        if (j == Barcode)
+                        if (j == BarcodeIndx)
                         {
                             var barcode = row.GetCell(j).ToString();
                             barcodeInfo.Barcode = barcode;
                             key = barcode;
                             BarcodeInfo.Add(key, new BarcodeInformation() { Barcode = barcode });
                         }
-                        if (j == Long)
+                        if (j == LongIndx)
                         {
                             barcodeInfo.Long = row.GetCell(j).ToString();
                             BarcodeInfo[key].Long = row.GetCell(j).ToString();
                         }
-                        if (j == Wide)
+                        if (j == WideIndx)
                         {
                             barcodeInfo.Wide = row.GetCell(j).ToString();
                             BarcodeInfo[key].Wide = row.GetCell(j).ToString();