From 9c22986e4dec6ccf57a88dfdf508363658180c54 Mon Sep 17 00:00:00 2001 From: yibo <361071264@qq.com> Date: Thu, 29 Apr 2021 17:26:34 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9C=80=E6=B1=82=E5=8D=95No.156433=E2=80=9C?= =?UTF-8?q?=E6=89=AB=E7=A0=81=E5=85=A5=E5=BA=93=E2=80=9D=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E7=AB=AF=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=96=91=E9=A9=ACDS2278=20?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ButcherFactory.Form.csproj | 13 ++++ .../SegmentInStore_/SegmentInStoreForm.cs | 66 +++++++++++-------- 2 files changed, 50 insertions(+), 29 deletions(-) diff --git a/ButcherFactory.Form/ButcherFactory.Form.csproj b/ButcherFactory.Form/ButcherFactory.Form.csproj index 7293c7b..2297bcd 100644 --- a/ButcherFactory.Form/ButcherFactory.Form.csproj +++ b/ButcherFactory.Form/ButcherFactory.Form.csproj @@ -52,6 +52,10 @@ + + False + ..\..\..\tsref\Debug\websocket-sharp.dll + @@ -211,6 +215,12 @@ InStoreSummaryView.cs + + Form + + + SegmentInStoreForm.cs + @@ -402,6 +412,9 @@ InStoreSummaryView.cs + + SegmentInStoreForm.cs + SegmentPickUpForm.cs diff --git a/ButcherFactory.Form/SegmentInStore_/SegmentInStoreForm.cs b/ButcherFactory.Form/SegmentInStore_/SegmentInStoreForm.cs index a495bf6..a273285 100644 --- a/ButcherFactory.Form/SegmentInStore_/SegmentInStoreForm.cs +++ b/ButcherFactory.Form/SegmentInStore_/SegmentInStoreForm.cs @@ -13,9 +13,9 @@ using System.Threading.Tasks; using System.Windows.Forms; using ButcherFactory.Utils; using ButcherFactory.BO.LocalBL; -using ButcherFactory.Controls; -using HidLibrary.Honeywell1902Series; - +using ButcherFactory.Controls; +using WebSocketSharp; + namespace ButcherFactory.SegmentInStore_ { public partial class SegmentInStoreForm : Form, IWithRoleForm @@ -38,10 +38,9 @@ namespace ButcherFactory.SegmentInStore_ BindingList unInstoreList; BindingList exceptionList; BindingList backStoreList; - private static Scanner1902 _scanner; long? storeID; bool isBack = false; - + WebSocket ws; public SegmentInStoreForm() { @@ -53,11 +52,8 @@ namespace ButcherFactory.SegmentInStore_ uploadData.Abort(); if (checkHasData != null && checkHasData.IsAlive) checkHasData.Abort(); - if (_scanner != null) - { - _scanner.StopListen(); - _scanner.Dispose(); - } + if (ws != null) + ws.Close(); }; storeSelect.SelectedIndexChanged += delegate @@ -68,8 +64,21 @@ namespace ButcherFactory.SegmentInStore_ storeID = (long)storeSelect.SelectedValue; XmlUtil.SerializerObjToFile(new SegmentInStoreFormConfig { StoreID = storeID }); }; - } - + this.Load += SegmentInStoreForm_Load; + } + + private void SegmentInStoreForm_Load(object sender, EventArgs e) + { + ws = new WebSocket("ws://127.0.0.1:12346"); + ws.OnMessage += (s, l) => + { + ScannerDataRecieved(l.Data); + }; + ws.Connect(); + if (ws.ReadyState != WebSocketState.Open) + throw new Exception("扫码服务异常,请检查"); + } + protected override void OnLoad(EventArgs e) { base.OnLoad(e); @@ -77,21 +86,20 @@ namespace ButcherFactory.SegmentInStore_ var initTask = new Thread(LoadBind); initTask.Start(); uploadData = new Thread(UpLoadLocalData); - uploadData.Start(); - - - var vid = Int32.Parse("0C2E", System.Globalization.NumberStyles.HexNumber); - var pid = Int32.Parse("0927", System.Globalization.NumberStyles.HexNumber); - _scanner = Scanner1902.Enumerate(vid, pid).FirstOrDefault(); - if (_scanner != null) - { - _scanner.DataRecieved += ScannerDataRecieved; - _scanner.StartListen(); - } - else - { - MessageBox.Show("请连接扫码枪后重新启动程序!"); - } + uploadData.Start(); + + //var vid = Int32.Parse("0C2E", System.Globalization.NumberStyles.HexNumber); + //var pid = Int32.Parse("0927", System.Globalization.NumberStyles.HexNumber); + //_scanner = Scanner1902.Enumerate(vid, pid).FirstOrDefault(); + //if (_scanner != null) + //{ + // _scanner.DataRecieved += ScannerDataRecieved; + // _scanner.StartListen(); + //} + //else + //{ + // MessageBox.Show("请连接扫码枪后重新启动程序!"); + //} } private void LoadBind() @@ -164,9 +172,9 @@ namespace ButcherFactory.SegmentInStore_ } } - private void ScannerDataRecieved(byte[] data) + private void ScannerDataRecieved(string data) { - var code = ControlsUtil.ParseCode(Encoding.ASCII.GetString(data)); + var code = ControlsUtil.ParseCode(data); if (string.IsNullOrEmpty(code)) return; this.Invoke(new Action(() =>