领胜LDS 键盘AOI检测项目
1. gocator添加重试和清理缓存操作
2. gts板卡调整监听频率
3. 记录产品数据使用filsstream避免程序崩溃影响
11个文件已修改
219 ■■■■ 已修改文件
src/Bro.Common.Device/Base/DeviceBase.cs 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.Device.GTSCard/GTSCardDriver.cs 23 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.Device.GTSCard/Properties/AssemblyInfo.cs 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.Device.Gocator/GocatorDriver.cs 56 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.Device.Gocator/Properties/AssemblyInfo.cs 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M071.Process/M071Process.cs 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M071.Process/UI/M071_MainForm.cs 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.UI.Config/MenuForms/FrmStatistic.Designer.cs 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.UI.Config/MenuForms/FrmStatistic.cs 97 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.UI.Config/MenuForms/FrmStatistic.resx 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.UI.Config/Properties/AssemblyInfo.cs 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.Common.Device/Base/DeviceBase.cs
@@ -70,6 +70,7 @@
            }
            set
            {
                LogAsync(DateTime.Now, $"设备状态切换:{_currentState.ToString()}->{value.ToString()}", "");
                _currentState = value;
                if (value != EnumHelper.DeviceState.TBD)
src/Bro.Device.GTSCard/GTSCardDriver.cs
@@ -312,7 +312,6 @@
            }
        }
        public override bool AllAxisOn()
        {
            List<Task<bool>> taskList = new List<Task<bool>>(); ;
@@ -387,7 +386,7 @@
                responseMessage.Result = resultList.All(u => u == true);
                if (!responseMessage.Result)
                {
                    responseMessage.Message = $"点位运动异常";
                    responseMessage.Message = $"点位运动异常,运动结果:{string.Join(" ", resultList.Select(u => u ? "1" : "0"))}";
                }
            }
            return responseMessage;
@@ -770,7 +769,14 @@
                    repeatTime--;
                }
                return (ret == (short)GTSRetCode.GRCRunOK) && isStop;
                if (repeatTime <= 0)
                {
                    LogAsync(DateTime.Now, "轴" + optionPara.AxisIndex + "APS_absolute_move未停止", "");
                    return false;
                }
                //return (ret == (short)GTSRetCode.GRCRunOK) && isStop;
                return true;
            }
            catch (Exception ex)
            {
@@ -1056,6 +1062,10 @@
                OnExceptionOccured?.Invoke(DateTime.Now, ex);
                return false;
            }
            finally
            {
            }
        }
        /// <summary>
@@ -1235,7 +1245,9 @@
                            }
                        });
                        _positionWait.SpinOnce();
                        Task.Delay(100).Wait();
                        //_positionWait.SpinOnce();
                    }
                    catch (Exception ex)
                    {
@@ -1272,7 +1284,8 @@
                            }
                        });
                        _statusWait.SpinOnce();
                        Thread.Sleep(10);
                        //Task.Delay(10).Wait();
                    }
                    catch (Exception ex)
                    {
src/Bro.Device.GTSCard/Properties/AssemblyInfo.cs
@@ -32,5 +32,5 @@
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]
src/Bro.Device.Gocator/GocatorDriver.cs
@@ -13,6 +13,7 @@
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
@@ -218,6 +219,7 @@
            }
        }
        [MethodImpl(MethodImplOptions.Synchronized)]
        public override IImageSet Snapshot(IOperationConfig config)
        {
            GocatorOperationConfig opConfig = config as GocatorOperationConfig;
@@ -234,7 +236,8 @@
                    {
                        try
                        {
                            system.Start();
                            sensor.Start();
                            LogAsync(DateTime.Now, $"传感器状态:{sensor.State.ToString()}", "");
                            if (sensor.State != GoState.Running)
                            {
                                Thread.Sleep(100);
@@ -247,6 +250,7 @@
                        catch (Exception ex)
                        {
                            LogAsync(DateTime.Now, $"开启异常:{ex.GetExceptionMessage()}", "");
                            Thread.Sleep(100);
                        }
                    } while (true);
@@ -284,17 +288,27 @@
                    return null;
                }
                try
                int reTryTime = 3;
                do
                {
                    dataSet = system.ReceiveData(IIConfig.SnapshotTimeout);
                }
                catch (Exception ex)
                {
                    LogAsync(DateTime.Now, $"{Name}获取图像异常", ex.GetExceptionMessage());
                    imgSet.HImage = null;
                    dataSet = null;
                    //return imgSet;
                }
                    try
                    {
                        dataSet = system.ReceiveData(IIConfig.SnapshotTimeout);
                        reTryTime = 0;
                    }
                    catch (Exception ex)
                    {
                        reTryTime--;
                        LogAsync(DateTime.Now, $"{Name}获取图像异常", ex.GetExceptionMessage());
                        if (reTryTime <= 0)
                        {
                            imgSet.HImage = null;
                            dataSet = null;
                            system.ClearData();
                        }
                    }
                } while (reTryTime > 0);
            }
            if (!IIConfig.IsAsyncMode)
@@ -310,8 +324,9 @@
                    {
                        try
                        {
                            system.Stop();
                            sensor.Stop();
                            LogAsync(DateTime.Now, $"传感器状态:{sensor.State.ToString()}", "");
                            if (sensor.State != GoState.Ready)
                            {
                                Thread.Sleep(100);
@@ -324,6 +339,7 @@
                        catch (Exception ex)
                        {
                            LogAsync(DateTime.Now, $"关闭异常:{ex.GetExceptionMessage()}", "");
                            Thread.Sleep(100);
                        }
                    } while (true);
@@ -442,10 +458,22 @@
        {
            base.Start();
            //system.Start();
            if (sensor.State != GoState.Ready)
            {
                system.Start();
            }
            if (IIConfig.IsAsyncMode)
                system.Start();
            {
                sensor.Start();
            }
            else
            {
                //if (sensor.State == GoState.Ready)
                {
                    sensor.Stop();
                }
            }
        }
        protected override void Stop()
src/Bro.Device.Gocator/Properties/AssemblyInfo.cs
@@ -32,5 +32,5 @@
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyVersion("1.0.2.0")]
[assembly: AssemblyFileVersion("1.0.2.0")]
src/Bro.M071.Process/M071Process.cs
@@ -19,6 +19,7 @@
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@@ -197,6 +198,7 @@
        List<ProductionMeasurement> productionList = new List<ProductionMeasurement>();
        [ProcessMethod("", "StartJob", "开始扫描", InvokeType.TestInvoke)]
        [MethodImpl(MethodImplOptions.Synchronized)]
        public ProcessResponse StartJob(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
        {
            if (!IsAllowedWork)
src/Bro.M071.Process/UI/M071_MainForm.cs
@@ -7,8 +7,10 @@
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using static Bro.Common.Helper.EnumHelper;
src/Bro.UI.Config/MenuForms/FrmStatistic.Designer.cs
@@ -28,9 +28,12 @@
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
            this.plStatistic = new System.Windows.Forms.Panel();
            this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
            this.ctmsClearQty = new System.Windows.Forms.ContextMenuStrip(this.components);
            this.tsmiClearQty = new System.Windows.Forms.ToolStripMenuItem();
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
@@ -71,6 +74,7 @@
            this.flowLayoutPanel1.SuspendLayout();
            this.plStatistic.SuspendLayout();
            this.tableLayoutPanel1.SuspendLayout();
            this.ctmsClearQty.SuspendLayout();
            this.plCT.SuspendLayout();
            this.tableLayoutPanel2.SuspendLayout();
            this.plOEE.SuspendLayout();
@@ -104,6 +108,7 @@
            this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 30F));
            this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 35F));
            this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 35F));
            this.tableLayoutPanel1.ContextMenuStrip = this.ctmsClearQty;
            this.tableLayoutPanel1.Controls.Add(this.label1, 0, 0);
            this.tableLayoutPanel1.Controls.Add(this.label2, 0, 1);
            this.tableLayoutPanel1.Controls.Add(this.label3, 0, 2);
@@ -122,6 +127,20 @@
            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 33F));
            this.tableLayoutPanel1.Size = new System.Drawing.Size(215, 100);
            this.tableLayoutPanel1.TabIndex = 0;
            //
            // ctmsClearQty
            //
            this.ctmsClearQty.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.tsmiClearQty});
            this.ctmsClearQty.Name = "ctmsClearQty";
            this.ctmsClearQty.Size = new System.Drawing.Size(125, 26);
            //
            // tsmiClearQty
            //
            this.tsmiClearQty.Name = "tsmiClearQty";
            this.tsmiClearQty.Size = new System.Drawing.Size(124, 22);
            this.tsmiClearQty.Text = "计数清零";
            this.tsmiClearQty.Click += new System.EventHandler(this.tsmiClearQty_Click);
            // 
            // label1
            // 
@@ -226,6 +245,7 @@
            this.btnClearStatistic.TabIndex = 8;
            this.btnClearStatistic.Text = "清  零";
            this.btnClearStatistic.UseVisualStyleBackColor = true;
            this.btnClearStatistic.Visible = false;
            this.btnClearStatistic.Click += new System.EventHandler(this.btnClearStatistic_Click);
            // 
            // plCT
@@ -588,6 +608,7 @@
            this.plStatistic.ResumeLayout(false);
            this.tableLayoutPanel1.ResumeLayout(false);
            this.tableLayoutPanel1.PerformLayout();
            this.ctmsClearQty.ResumeLayout(false);
            this.plCT.ResumeLayout(false);
            this.tableLayoutPanel2.ResumeLayout(false);
            this.tableLayoutPanel2.PerformLayout();
@@ -641,5 +662,7 @@
        private System.Windows.Forms.Button btnRefreshOEE;
        private System.Windows.Forms.Label lblCT;
        private System.Windows.Forms.Label lblUPH;
        private System.Windows.Forms.ContextMenuStrip ctmsClearQty;
        private System.Windows.Forms.ToolStripMenuItem tsmiClearQty;
    }
}
src/Bro.UI.Config/MenuForms/FrmStatistic.cs
@@ -5,7 +5,9 @@
using System;
using System.Configuration;
using System.IO;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using static Bro.Common.Helper.EnumHelper;
@@ -403,10 +405,10 @@
                CurrentState = RunState.Stop;
            }
            if (state == EnumHelper.DeviceState.DSClose)
            {
                SaveNumRecord();
            }
            //if (state == EnumHelper.DeviceState.DSClose)
            //{
            //    SaveNumRecord();
            //}
        }
        private void CheckIdle(object state)
@@ -436,7 +438,7 @@
            Task.Run(() =>
            {
                SaveNumRecord();
                SaveNumRecord(Qty_OK, Qty_NG);
            });
        }
@@ -505,22 +507,52 @@
            AvailableTime = AvailableTime.Add(new TimeSpan(0, 0, 1));
        }
        private void OnClearQty()
        {
            Qty_OK = Qty_NG = 0;
        }
        //private void OnClearQty()
        //{
        //    Qty_OK = Qty_NG = 0;
        //}
        string numRecordFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Statistic.json");
        static object numLock = new object();
        private void SaveNumRecord()
        [MethodImpl(MethodImplOptions.Synchronized)]
        private void SaveNumRecord(int okNum, int ngNum)
        {
            lock (numLock)
            {
                using (StreamWriter writer = new StreamWriter(numRecordFile, false, System.Text.Encoding.UTF8))
                try
                {
                    string dataStr = JsonConvert.SerializeObject(new { Qty_OK, Qty_NG });
                    writer.Write(dataStr);
                    writer.Flush();
                    //using (StreamWriter writer = new StreamWriter(numRecordFile, false, System.Text.Encoding.UTF8))
                    //{
                    //    if (okNum % 5 == 0)
                    //    {
                    //        Application.Exit();
                    //        throw new AccessViolationException();
                    //    }
                    //    string dataStr = JsonConvert.SerializeObject(new StatisticModel() { Qty_OK = okNum, Qty_NG = ngNum });
                    //    if (!string.IsNullOrWhiteSpace(dataStr))
                    //    {
                    //        writer.Write(dataStr);
                    //        writer.Flush();
                    //    }
                    //}
                    using (FileStream fs = new FileStream(numRecordFile, FileMode.OpenOrCreate, FileAccess.Write))
                    {
                        fs.Seek(0, SeekOrigin.Begin);
                        string dataStr = JsonConvert.SerializeObject(new StatisticModel() { Qty_OK = okNum, Qty_NG = ngNum });
                        byte[] dataBuf = System.Text.Encoding.UTF8.GetBytes(dataStr);
                        fs.Write(dataBuf, 0, dataBuf.Length);
                        fs.SetLength(dataBuf.Length);
                        fs.Flush();
                        fs.Close();
                    }
                }
                catch (Exception ex)
                {
                    LogAsync(DateTime.Now, $"保存统计数据异常,{ex.GetExceptionMessage()}");
                }
            }
        }
@@ -535,21 +567,50 @@
                    {
                        string dataStr = reader.ReadToEnd();
                        JObject data = JsonConvert.DeserializeObject<JObject>(dataStr);
                        //JObject data = JsonConvert.DeserializeObject<JObject>(dataStr);
                        if (data != null)
                        //if (data != null)
                        //{
                        //    Qty_OK = data.Value<int>("Qty_OK");
                        //    Qty_NG = data.Value<int>("Qty_NG");
                        //}
                        StatisticModel model = JsonConvert.DeserializeObject<StatisticModel>(dataStr);
                        if (model != null)
                        {
                            Qty_OK = data.Value<int>("Qty_OK");
                            Qty_NG = data.Value<int>("Qty_NG");
                            Qty_OK = model.Qty_OK;
                            Qty_NG = model.Qty_NG;
                        }
                        else
                        {
                            //LogAsync(DateTime.Now, $"载入统计数据错误", "");
                            MessageBox.Show($"载入统计数据错误");
                        }
                    }
                }
            }
            else
            {
                //LogAsync(DateTime.Now, $"统计数据文件不存在", "");
                MessageBox.Show($"统计数据文件不存在");
            }
        }
        private void btnClearStatistic_Click(object sender, EventArgs e)
        {
            //Qty_OK = Qty_NG = 0;
        }
        private void tsmiClearQty_Click(object sender, EventArgs e)
        {
            Qty_OK = Qty_NG = 0;
        }
    }
    public class StatisticModel
    {
        public int Qty_OK { get; set; }
        public int Qty_NG { get; set; }
    }
}
src/Bro.UI.Config/MenuForms/FrmStatistic.resx
@@ -117,4 +117,7 @@
  <resheader name="writer">
    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
  </resheader>
  <metadata name="ctmsClearQty.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
    <value>17, 17</value>
  </metadata>
</root>
src/Bro.UI.Config/Properties/AssemblyInfo.cs
@@ -31,5 +31,5 @@
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
// 方法是按如下所示使用“*”: :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]