Browse Source

添加电子秤重量读取

callm 3 years ago
parent
commit
924261355a

+ 44 - 41
UAS_MES_PW/FunctionCode/Make/Make_ColorBoxWeigh.cs

@@ -73,7 +73,7 @@ namespace UAS_MES_NEW.Make
             ma_code.SetValueField = new string[] { "ma_code", "pr_code", "pr_spec" };
             ma_code.Condition = "ma_statuscode='STARTED'";
             ma_code.DbChange += Ma_code_DbChange;
-            //StartWeight.PerformClick();
+            StartWeight.PerformClick();
             dh = SystemInf.dh;
             StepCount.StepCode = User.CurrentStepCode;
             StepCount.Source = User.UserSourceCode;
@@ -283,7 +283,6 @@ namespace UAS_MES_NEW.Make
             BaseUtil.ClosePrint(lbl);
             StopWeight.PerformClick();
             InitPrint.Abort();
-            socConnection.Close();
             if (serialPort1.IsOpen)
             {
                 GetData = false;
@@ -346,52 +345,56 @@ namespace UAS_MES_NEW.Make
             socConnection = socketWatch.Accept();
             while (socConnection.Connected)  //持续不断监听客户端发来的请求
             {
-                Thread.Sleep(100);
-                byte[] data = new byte[1024];
-                socConnection.Receive(data);
-                List<byte> arr = new List<byte>();
-                byte[] byteTemp = new byte[4];
-                byteTemp[3] = Convert.ToByte("00", 16);
-                byteTemp[2] = Convert.ToByte("00", 16);
-                byteTemp[1] = Convert.ToByte("00", 16);
-                byteTemp[0] = Convert.ToByte("00", 16);
-                for (int i = 0; i < 10; i++)
+                try
                 {
-                    if (data[i].ToString() == "0")
-                        continue;
-                    arr.Add(data[i]);
-                }
-                for (int i = 0; i < arr.Count; i++)
-                {
-                    switch (i)
+                    Thread.Sleep(100);
+                    byte[] data = new byte[1024];
+                    socConnection.Receive(data);
+                    List<byte> arr = new List<byte>();
+                    byte[] byteTemp = new byte[4];
+                    byteTemp[3] = Convert.ToByte("00", 16);
+                    byteTemp[2] = Convert.ToByte("00", 16);
+                    byteTemp[1] = Convert.ToByte("00", 16);
+                    byteTemp[0] = Convert.ToByte("00", 16);
+                    for (int i = 0; i < 10; i++)
                     {
-                        case 0:
-                            byteTemp[3] = arr.ToArray()[0];
-                            break;
-                        case 1:
-                            byteTemp[2] = arr.ToArray()[1];
-                            break;
-                        case 2:
-                            byteTemp[1] = arr.ToArray()[2];
-                            break;
-                        case 3:
-                            byteTemp[0] = arr.ToArray()[3];
-                            break;
-                        default:
-                            break;
+                        if (data[i].ToString() == "0")
+                            continue;
+                        arr.Add(data[i]);
                     }
+                    for (int i = 0; i < arr.Count; i++)
+                    {
+                        switch (i)
+                        {
+                            case 0:
+                                byteTemp[3] = arr.ToArray()[0];
+                                break;
+                            case 1:
+                                byteTemp[2] = arr.ToArray()[1];
+                                break;
+                            case 2:
+                                byteTemp[1] = arr.ToArray()[2];
+                                break;
+                            case 3:
+                                byteTemp[0] = arr.ToArray()[3];
+                                break;
+                            default:
+                                break;
+                        }
+                    }
+                    float fTemp = BitConverter.ToSingle(byteTemp, 0);
+                    if (fTemp.ToString().Length > 5)
+                        weight.Text = fTemp.ToString().Substring(0, 5);
+                    else
+                        weight.Text = fTemp.ToString();
+                }
+                catch (Exception)
+                {
+
                 }
-                float fTemp = BitConverter.ToSingle(byteTemp, 0);
-                if (fTemp.ToString().Length > 5)
-                    weight.Text = fTemp.ToString().Substring(0, 5);
-                else
-                    weight.Text = fTemp.ToString();
             }
         }
 
-
-
-
         private void StopWeight_Click(object sender, EventArgs e)
         {
             socketWatch.Close();

+ 9 - 0
UAS_MES_PW/UAS_MES_PW.csproj

@@ -125,11 +125,19 @@
       <SpecificVersion>False</SpecificVersion>
       <HintPath>Tool\ExcelHelper.dll</HintPath>
     </Reference>
+    <Reference Include="HslCommunication, Version=9.7.0.0, Culture=neutral, PublicKeyToken=cdb2261fa039ed67, processorArchitecture=MSIL">
+      <HintPath>..\packages\HslCommunication.9.7.0\lib\net35\HslCommunication.dll</HintPath>
+      <Private>True</Private>
+    </Reference>
     <Reference Include="Interop.SpeechLib, Version=5.4.0.0, Culture=neutral, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
       <EmbedInteropTypes>False</EmbedInteropTypes>
       <HintPath>Tool\Interop.SpeechLib.dll</HintPath>
     </Reference>
+    <Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+      <HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net40\Newtonsoft.Json.dll</HintPath>
+      <Private>True</Private>
+    </Reference>
     <Reference Include="NPOI, Version=1.2.5.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
       <HintPath>Tool\NPOI.dll</HintPath>
@@ -1605,6 +1613,7 @@
     <None Include="App.config">
       <SubType>Designer</SubType>
     </None>
+    <None Include="packages.config" />
     <None Include="Properties\Settings.settings">
       <Generator>SettingsSingleFileGenerator</Generator>
       <LastGenOutput>Settings.Designer.cs</LastGenOutput>

+ 5 - 0
UAS_MES_PW/packages.config

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+  <package id="HslCommunication" version="9.7.0" targetFramework="net40" />
+  <package id="Newtonsoft.Json" version="12.0.3" targetFramework="net40" />
+</packages>