private void button11_Click_1(object sender, EventArgs e)
 {
     try
     {
         iscangetstatus           = false;
         Settings.Default.canmove = false;
         if (backgroundWorker.IsBusy)
         {
             backgroundWorker.CancelAsync();
         }
         btnFuckStart.Enabled = true;
         //button10.Enabled = false;
         button5.Enabled              = false;
         button11.Enabled             = false;
         fuckType.Enabled             = true;
         button4.Enabled              = true;
         button9.Enabled              = true;
         tbSavePath.Enabled           = true;
         btnFuckDetectThisPcb.Enabled = false;
         Camera.CameraStop();
         Thread.Sleep(1000);
         testDevice.StylusReset();
         testDevice.Close();
     }
     catch (Exception ex)
     {
         Loghelper.WriteLog("停止失败", ex);
     }
 }
 //backgroudwork
 private void getstauts(object sender, System.ComponentModel.DoWorkEventArgs e)
 {
     try
     {
         while (iscangetstatus)
         {
             if (this.testDevice.StylusStatue() && ismoveative == false)
             {
                 if (thiscard)
                 {
                     Settings.Default.num--;
                     this.ismoveative = getevent();
                     if (!isBabyYiNing)
                     {
                         Checkpicture checkpicture = new Checkpicture(tbSavePath.Text, Settings.Default.num + xYrulescs.Name, true, numericUpDown1.Value);
                         checkpicture.ShowDialog();
                     }
                     thiscard = false;
                     Settings.Default.num++;
                 }
                 else
                 {
                     this.ismoveative = getevent();
                     Settings.Default.num++;
                 }
             }
             Thread.Sleep(200);
         }
         e.Cancel = true;
     }
     catch (Exception ex)
     {
         Loghelper.WriteLog("获取箱体按钮状态失败", ex);
     }
 }
        private void button5_Click(object sender, EventArgs e)
        {
            try
            {
                if (button5.Text == "暂停")
                {
                    Settings.Default.canmove = false;
                    //button5.Enabled = false;
                    button5.Text = "继续";
                }
                else if (button5.Text == "继续")
                {
                    Settings.Default.canmove = true;
                    //button5.Enabled = false;
                    button5.Text = "暂停";
                }
            }
            catch (Exception ex)
            {
                Loghelper.WriteLog("暂停失败", ex);
            }


            //button10.Enabled = true;
        }
 private void button6_Click_1()
 {
     try
     {
         if (testDevice == null)
         {
             testDevice            = new TestBoxDriver(Settings.Default.comname);
             device                = testDevice.Driver as MotorDriver;
             testDevice.IsReset    = false;
             testDevice.DebugMode  = false;
             device.RequestTimeout = 30 * 1000;
         }
         if (testDevice.IsOpen)
         {
             testDevice.Close();
         }
         else
         {
             testDevice.LeftUpPoint    = new Point(0, 0);
             testDevice.RigntDownPoint = new Point(0, 0);
             testDevice.Open();
         }
     }
     catch (Exception e)
     {
         Loghelper.WriteLog("连接移动电机失败", e);
     }
 }
 public Form1()
 {
     InitializeComponent();
     #region 初始化委托
     onStitchCallBack = new StitchCallBack(doStitchCallBack);
     #endregion
     comboxgetrules();
     Camera = cameraDevice;
     tbSavePath.ForeColor = ColorTranslator.FromHtml("#999999");
     Camera.CameraName    = Settings.Default.cameraname;
     //获取状态初始化
     backgroundWorker = new BackgroundWorker
     {
         WorkerReportsProgress      = true,
         WorkerSupportsCancellation = true
     };
     backgroundWorker.DoWork += new DoWorkEventHandler(getstauts);
     Loghelper.WriteLog("初始化获取箱体按钮状态成功");
     //存照片线程初始化
     newbackgroundWorker = new BackgroundWorker
     {
         WorkerReportsProgress      = true,
         WorkerSupportsCancellation = true
     };
     newbackgroundWorker.DoWork += new DoWorkEventHandler(picevent);
     Loghelper.WriteLog("初始化保存图片线程成功");
     Camera.ScreenEvent += ScreenEvent;
     //button10.Enabled = false;
     button5.Enabled  = false;
     button11.Enabled = false;
     this.pictureBox1.Load(@"qtsj.jpg");
     sdkin();
 }
예제 #6
0
 private void getstauts(object sender, System.ComponentModel.DoWorkEventArgs e)
 {
     try
     {
         while (cancheck)
         {
             for (int i = 0; i < dataGridView1.RowCount; i++)
             {
                 if (needcheck)
                 {
                     if (dataGridView1["Column3", i].Value == null)
                     {
                         Bitmap bitmap = new Bitmap(dataGridView1["Column2", i].Value.ToString());
                         newbitmap = new Bitmap(bitmap.Width, bitmap.Height, PixelFormat.Format24bppRgb);
                         Graphics draw = Graphics.FromImage(newbitmap);
                         draw.DrawImage(bitmap, 0, 0);
                         draw.Dispose();
                         bitmap.Dispose();//释放bmp文件资源
                         //bool ng = true;
                         bool ng = savepic(newbitmap, dataGridView1["Column2", i].Value.ToString());
                         if (ng)
                         {
                             dataGridView1["Column3", i].Value = "NG";
                             dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Red;
                             dataGridView1["Column2", i].Value = picpath + "\\NG\\" + dataGridView1["Column1", i].Value.ToString();
                             bitmap.Dispose();
                             movepic(dataGridView1["Column1", i].Value.ToString(), picpath, true);
                         }
                         else
                         {
                             dataGridView1["Column3", i].Value = "OK";
                             dataGridView1["Column2", i].Value = picpath + "\\OK\\" + dataGridView1["Column1", i].Value.ToString();
                             movepic(dataGridView1["Column1", i].Value.ToString(), picpath, false);
                         }
                         Thread.Sleep(20);
                     }
                     else
                     {
                         continue;
                     }
                 }
                 else
                 {
                     return;
                 }
             }
             cancheck = false;
             write(picpath, card);
             button1.Text = "开始";
         }
         e.Cancel = true;
     }
     catch (Exception ex)
     {
         Loghelper.WriteLog("移动图片失败", ex);
     }
 }
 private void button3_Click(object sender, EventArgs e)
 {
     try
     {
         Camera.CameraClose();
         pictureBox1.Image = null;
     }
     catch (Exception ex)
     {
         Loghelper.WriteLog("连接相机失败", ex);
     }
 }
예제 #8
0
 private void Checkpicture_FormClosing(object sender, FormClosingEventArgs e)
 {
     try
     {
         if (showpic != null || !showpic.IsDisposed)
         {
             showpic.Close();
         }
     }
     catch (Exception ex) {
         Loghelper.WriteLog("失败", ex);
     }
 }
 private void button9_Click_1(object sender, EventArgs e)
 {
     try
     {
         conncamera();
         button6_Click_1();
         needsave = false;
         this.Camera.ContinueShot();
         Iboxcontroller iboxcontroller = new Iboxcontroller(this.testDevice, this.Camera);
         iboxcontroller.ShowDialog();
         if (iboxcontroller.DialogResult == DialogResult.OK)
         {
             string      name      = iboxcontroller.Xyname;
             string      xmove     = iboxcontroller.Xmove;
             string      ymove     = iboxcontroller.Ymove;
             string      firstpont = iboxcontroller.Firstpoint.X.ToString() + "," + iboxcontroller.Firstpoint.Y.ToString();
             string      endponit  = iboxcontroller.Endpoint.X.ToString() + "," + iboxcontroller.Endpoint.Y.ToString();
             XmlDocument doc       = new XmlDocument();
             doc.Load(@"xyrule.xml");
             //XmlNodeList no = doc.SelectSingleNode("//Rules").ChildNodes;
             XmlNode    xmlElementpark  = doc.SelectSingleNode("//Rules");
             XmlElement xmlElementall   = doc.CreateElement("rule");
             XmlElement xmlElement_name = doc.CreateElement("name");
             xmlElement_name.InnerText = name;
             xmlElementall.AppendChild(xmlElement_name);
             XmlElement xmlElement_cardnum = doc.CreateElement("leftup");
             xmlElement_cardnum.InnerText = firstpont;
             xmlElementall.AppendChild(xmlElement_cardnum);
             XmlElement xmlElement_kname = doc.CreateElement("rightdown");
             xmlElement_kname.InnerText = endponit;
             xmlElementall.AppendChild(xmlElement_kname);
             XmlElement xmlElement_khangbie = doc.CreateElement("xmove");
             xmlElement_khangbie.InnerText = xmove;
             xmlElementall.AppendChild(xmlElement_khangbie);
             XmlElement xmlElement_kainame = doc.CreateElement("ymove");
             xmlElement_kainame.InnerText = ymove;
             xmlElementall.AppendChild(xmlElement_kainame);
             xmlElementpark.AppendChild(xmlElementall);
             doc.Save(@"xyrule.xml");
         }
         comboxgetrules();
         Camera.CameraStop();
         testDevice.StylusReset();
         this.testDevice.Close();
     }
     catch (Exception ex)
     {
         Loghelper.WriteLog("创建运行规则失败", ex);
     }
 }
 private void conncamera()
 {
     try
     {
         Camera.InitExpourseTime = Settings.Default.InitExpourseTime;
         int number = Camera.GetCameraCount;
         if (Camera.m_hCamera >= 0)
         {
             Camera.ConnectCamera(0);
         }
     }
     catch (Exception e)
     {
         Loghelper.WriteLog("连接相机失败", e);
     }
 }
        private void ScreenEvent(BitmapInfo bitmapInfo)
        {
            lock (obj)
            {
                if (this.InvokeRequired)
                {
                    BeginInvoke(new ImageReadyEventScreen(ScreenEvent), bitmapInfo);
                    return;
                }
                else
                {
                    try
                    {
                        bitmap = bitmapInfo.m_Bitmap;

                        bitmap.RotateFlip(RotateFlipType.Rotate180FlipNone);  //指定不进行翻转的 180 度旋转  (垂直翻转+水平翻转)
                        nowPcb.FrontPcb.bitmaps.Enqueue(new OneStitchSidePcb.BitmapInfo()
                        {
                            bitmap = BitmapScaleHelper.ScaleToSize(bitmap, (float)0.5), name = "/F" + fuckDetectNum + ".jpg"
                        });
                        fuckDetectNum++;

                        //Aoi.StitchMain(nowPcb.FrontPcb, onStitchCallBack);
                        MySmartThreadPool.Instance().QueueWorkItem(() =>
                        {
                            lock (nowPcb.FrontPcb)
                            {
                                Aoi.StitchMain(nowPcb.FrontPcb, onStitchCallBack);
                            }
                        });
                        bitmap.Save(nowPcb.FrontPcb.savePath + "/F" + fuckDetectNum + ".jpg");
                        //this.pictureBox1.Image = bitmap;
                        //if (needsave)
                        //{

                        //    bitmaps.Enqueue(bitmap);
                        //}
                    }
                    catch (Exception e)
                    {
                        Loghelper.WriteLog("获取照片失败", e);
                        throw e;
                    }
                }
            }
        }
예제 #12
0
        //检测错误保存文件
        public bool savepic(Bitmap bitmap, String path)
        {
            bbox_t_container boxlist = new bbox_t_container();
            bool             ng;

            byte[] byteImg = Bitmap2Byte(bitmap);
            long   intime  = DateTimeUtil.DateTimeToLongTimeStamp(DateTime.Now);
            int    n       = AITestSDK.detect_opencv_mat(byteImg, byteImg.Length, ref boxlist, (float)typenum);
            long   endtime = DateTimeUtil.DateTimeToLongTimeStamp(DateTime.Now);
            long   gettime = endtime - intime;

            Console.WriteLine(gettime);
            int j = 0;

            if (n == -1)
            {
                Loghelper.WriteLog("调用失败,请检测目录是否包含opencv的dll");
            }

            for (int i = 0; i < boxlist.bboxlist.Length; i++)
            {
                if (boxlist.bboxlist[i].h == 0)
                {
                    break;
                }
                else
                {
                    DrawRectangleInPicture(bitmap, (int)boxlist.bboxlist[i].x,
                                           (int)boxlist.bboxlist[i].y,
                                           (int)boxlist.bboxlist[i].w,
                                           (int)boxlist.bboxlist[i].h, Color.Red, 2, DashStyle.Solid);
                    j++;
                }
            }
            if (j > 0)
            {
                ng = true;
            }
            else
            {
                ng = false;
            }
            bitmap.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg);
            return(ng);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                for (int j = 0; j < this.dataGridView1.Rows.Count; j++)
                {
                    if (dataGridView1.Rows[j].Selected == true)
                    {
                        this.dataGridView1.Rows.RemoveAt(j);
                    }
                }
                update();

                readxml();
            }
            catch (Exception ex) {
                Loghelper.WriteLog("修改界面删除规则失败", ex);
            }
        }
 void server_ErrorEvent(string msg)
 {
     if (!this.Visible)
     {
         return;
     }
     try
     {
         if (this.InvokeRequired)
         {
             this.BeginInvoke(new TcpServer.ErrorHandler(server_ErrorEvent), msg);
             return;
         }
         MessageBox.Show(this, msg, Config.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     catch (Exception ex)
     {
         Loghelper.WriteLog("", ex);
     }
 }
        private void Bw_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker bw = sender as BackgroundWorker;

            while (true)
            {
                if (bw.CancellationPending)
                {
                    break;
                }
                Thread.Sleep(5);

                //如果没有指令,继续等待
                if (CommandsQueue.Count == 0)
                {
                    Thread.Sleep(50);
                    continue;
                }

                //从队列中将指令取出
                CommandInfo info  = CommandsQueue.Dequeue() as CommandInfo;
                string      value = info.Command.Trim('\0');
                //SetValue(value, info.Client.Client);

                //如果设备未连接,通知客户端
                if (testDevice == null || !testDevice.IsOpen)
                {
                    ServerResultMessage _ServerResultMessage = new ServerResultMessage()
                    {
                        CommandType = CommandType.None,
                        ResultCode  = ResultCode.fail,
                        Data        = "device is disconnect.",
                    };
                    SendData(info, JsonConvert.SerializeObject(_ServerResultMessage));
                    Thread.Sleep(1000);
                    continue;
                }

                ResetType result = ResetType.None;
Start:
                try
                {
                    Command(value, info);
                }
                catch (MotorException ex)
                {
                    Loghelper.WriteLog("发送指令:", ex);
                    switch (result)
                    {
                    case ResetType.None:
                        lock (deviceLock)
                            result = device.ResetComUSB();
                        if (result == ResetType.USBSuccess || result == ResetType.Success)
                        {
                            goto Start;
                        }
                        break;

                    case ResetType.USBSuccess:
                        lock (deviceLock)
                            result = device.ResetCom();
                        if (result == ResetType.Success)
                        {
                            goto Start;
                        }
                        break;

                    case ResetType.Error:
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Loghelper.WriteLog("下发错误", ex);
                    ServerResultMessage _ServerResultMessage = new ServerResultMessage()
                    {
                        CommandType = CommandType.None,
                        ResultCode  = ResultCode.fail,
                        Data        = ex.Message,
                    };
                    SendData(info, JsonConvert.SerializeObject(_ServerResultMessage));
                }
                //SetValue(string.Format("队列还剩【{0}】条指令未下发", CommandsQueue.Count), null);
            }
        }