예제 #1
0
파일: BJDAO.cs 프로젝트: jume2003/SK800
 public bool SaveBJ(IList <VBJ> BJList)
 {
     if (BJList == null || BJList.Count == 0)
     {
         return(true);
     }
     mapper.BeginTransaction();
     try
     {
         foreach (var item in BJList)
         {
             if (item.ID == 0)
             {
                 InsertBJ(item);
             }
             else
             {
                 UpdateBJ(item);
             }
         }
         mapper.CommitTransaction();
         return(true);
     }
     catch (Exception ex)
     {
         Tool.AppLogError(ex);
         mapper.RollBackTransaction();
         return(false);
     }
 }
예제 #2
0
        public void Connect()
        {
            IPEndPoint ie = new IPEndPoint(IPAddress.Parse(ipAddr), port);

            socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            socket.ReceiveTimeout = 10000;

            //将套接字与远程服务器地址相连
            try
            {
                socket.Connect(ie);
                Connected         = socket.Connected;
                this.ErrorMessage = "OK";
            }
            catch (SocketException e)
            {
                //Console.Out.WriteLine("连接服务器失败  " + e.Message);
                Tool.AppLogError($"连接【{ipAddr}】失败!");
                Tool.AppLogError(e);
                this.ErrorMessage = "设备联机失败";
                return;
            }

            /*
             * ThreadStart myThreaddelegate = new ThreadStart(ReceiveMsg);
             * var myThread = new Thread(myThreaddelegate);
             * myThread.Start();
             */
        }
예제 #3
0
        public void Stop()
        {
            try
            {
                //发送停采命令
                if (null != m_objIGXFeatureControl)
                {
                    m_objIGXFeatureControl.GetCommandFeature("AcquisitionStop").Execute();
                }

                //关闭采集流通道
                if (null != m_objIGXStream)
                {
                    m_objIGXStream.StopGrab();
                    //注销采集回调函数
                    m_objIGXStream.UnregisterCaptureCallback();
                }

                m_bIsSnap = false;
            }
            catch (Exception ex)
            {
                Tool.AppLogError(ex);
                MessageBox.Show(ex.Message);
            }
        }
예제 #4
0
        public bool SaveT_Result(T_Result result)
        {
            bool res = false;

            if (result.ID == 0)
            {
                Mapper.BeginTransaction();
                try
                {
                    if (result.Picture != null)
                    {
                        Mapper.Insert("InsertT_Picture", result.Picture);
                        result.PictureID = result.Picture.ID;
                    }
                    Mapper.Insert("InsertT_Result", result);
                    Mapper.CommitTransaction();
                    res = true;
                }
                catch (Exception ex)
                {
                    Tool.AppLogError(ex);
                    Mapper.RollBackTransaction();
                }
            }
            return(res);
        }
예제 #5
0
파일: GELDAO.cs 프로젝트: jume2003/SK800
        public bool InserOrUpdateGEL(T_Gel t_Gel)
        {
            if (t_Gel.ID == 0)
            {
                var session = mapper.BeginTransaction();
                try
                {
                    mapper.Insert("InsertT_Gel", t_Gel);
                    if (t_Gel.ResultMaps != null)
                    {
                        InserOrUpdateCollect(t_Gel.ResultMaps, "T_ResultMap", new KeyValuePair <String, Object>("GelID", t_Gel.ID));
                    }
                    if (t_Gel.GelSteps != null)
                    {
                        InserOrUpdateCollect(t_Gel.GelSteps, "T_GelStep", new KeyValuePair <String, Object>("GelID", t_Gel.ID));
                    }
                    mapper.CommitTransaction();
                    return(t_Gel.ID > 0);
                }
                catch (Exception ex)
                {
                    Tool.AppLogError(ex);
                    mapper.RollBackTransaction();
                    return(false);
                }
            }
            else
            {
                var result  = false;
                var session = mapper.BeginTransaction();
                try
                {
                    result = mapper.Update("UpdateT_Gel", t_Gel) > 0;
                    if (t_Gel.ResultMaps != null)
                    {
                        InserOrUpdateCollect(t_Gel.ResultMaps, "T_ResultMap", new KeyValuePair <String, Object>("GelID", t_Gel.ID));
                    }
                    if (t_Gel.GelSteps != null)
                    {
                        InserOrUpdateCollect(t_Gel.GelSteps, "T_GelStep", new KeyValuePair <String, Object>("GelID", t_Gel.ID));
                    }
                    mapper.CommitTransaction();
                    result = true;
                }
                catch (Exception ex)
                {
                    Tool.AppLogError(ex);
                    result = false;
                    mapper.RollBackTransaction();
                }

                return(result);
            }
        }
예제 #6
0
 /// <summary>
 /// 回调函数,用于获取图像信息和显示图像
 /// </summary>
 /// <param name="obj">用户自定义传入参数</param>
 /// <param name="objIFrameData">图像信息对象</param>
 private void __CaptureCallbackPro(object objUserParam, IFrameData objIFrameData)
 {
     try
     {
         if (BitmapGot != null)
         {
             var bm = m_objGxBitmap.GetBitmap(objIFrameData);
             BitmapGot(this, new BitmapGotEventArgs(bm));
         }
     }
     catch (Exception ex)
     {
         Tool.AppLogError("取图失败", ex);
     }
 }
예제 #7
0
파일: LogicDAO.cs 프로젝트: jume2003/SK800
        bool ILogicDAO.SaveT_LogicTest(T_LogicTest logicTest)
        {
            bool result = false;

            mapper.BeginTransaction();
            try
            {
                if (logicTest.ID == 0)
                {
                    mapper.Insert("InsertT_LogicTest", logicTest);
                }
                else
                {
                    mapper.Update("UpdateT_LogicTest", logicTest);
                }
                if (logicTest.ID > 0)
                {
                    if (logicTest.LogicSteps != null && logicTest.LogicSteps.Count > 0)
                    {
                        foreach (var item in logicTest.LogicSteps)
                        {
                            item.ProgramID = logicTest.ID;
                            if (item.ID == 0)
                            {
                                mapper.Insert("InsertT_LogicStep", item);
                            }
                            else
                            {
                                mapper.Update("UpdateT_LogicStep", item);
                            }
                        }
                    }
                    mapper.CommitTransaction();
                    result = true;
                }
                else
                {
                    mapper.RollBackTransaction();
                }
            }catch (Exception ex)
            {
                mapper.RollBackTransaction();
                Tool.AppLogError(ex);
            }
            return(result);
        }
예제 #8
0
파일: LogicDAO.cs 프로젝트: jume2003/SK800
        public bool DeleteT_LogicTest(int id)
        {
            var result = false;

            mapper.BeginTransaction();
            try
            {
                DeleteT_LogicStepByProgramId(id);
                result = mapper.Delete("DeleteT_LogicTest", id) > 0;
                mapper.CommitTransaction();
            }catch (Exception ex)
            {
                Tool.AppLogError(ex);
                mapper.RollBackTransaction();
            }

            return(result);
        }
예제 #9
0
 /// <summary>
 /// 查询线圈当前状态
 /// </summary>
 /// <param name="coilAddr"></param>
 /// <returns></returns>
 public bool this[String coilAddr]
 {
     get
     {
         if (String.IsNullOrEmpty(coilAddr))
         {
             return(false);
         }
         int start = ScanStartIndex;
         int end   = int.Parse(coilAddr.Substring(1));
         try
         {
             if (end >= start)
             {
                 return(this.RunResult[end - start]);
             }
         }
         catch (Exception ex)
         {
             Tool.AppLogError(ex);
         }
         return(false);
     }
     set
     {
         if (String.IsNullOrEmpty(coilAddr))
         {
             return;
         }
         int start = int.Parse(Constants.OutputStartAddr.Substring(1));
         int end   = int.Parse(coilAddr.Substring(1));
         try
         {
             if (end >= start)
             {
                 this.RunResult[end - start] = value;
             }
         }
         catch (Exception ex)
         {
             Tool.AppLogDebug(ex);
         }
     }
 }
예제 #10
0
파일: GELDAO.cs 프로젝트: jume2003/SK800
        public bool DeleteGel(T_Gel Gel)
        {
            bool result  = false;
            var  session = mapper.BeginTransaction();

            try
            {
                if (Gel.GelSteps != null)
                {
                    String Ids = "";
                    foreach (var item in Gel.GelSteps)
                    {
                        Ids += (Ids == "" ? "" : ",") + item.ID.ToString();
                    }
                    if (Ids != "")
                    {
                        mapper.Delete("DeleteT_GelStepByIDs", Ids);
                    }
                }
                if (Gel.ResultMaps != null)
                {
                    String Ids = "";
                    foreach (var item in Gel.ResultMaps)
                    {
                        Ids += (Ids == "" ? "" : ",") + item.ID.ToString();
                    }
                    if (Ids != "")
                    {
                        mapper.Delete("DeleteT_ResultMapByIDs", Ids);
                    }
                }
                mapper.Delete("DeleteT_Gel", Gel);
                mapper.CommitTransaction();
                result = true;
            }
            catch (Exception ex)
            {
                Tool.AppLogError(ex);
                result = false;
                mapper.RollBackTransaction();
            }
            return(result);
        }
예제 #11
0
        /// <summary>
        /// 打开串口
        /// </summary>
        /// <param name="portName"></param>
        /// <param name="baudRate"></param>
        /// <returns></returns>
        public bool Open(String portName)
        {
            if (serialPort.IsOpen)
            {
                return(true);
            }
            //串口名
            serialPort.PortName = portName;
            //波特率
            serialPort.BaudRate = baudRate;
            //数据位
            serialPort.DataBits = dataBits;    //8
            //1个停止位
            serialPort.StopBits = stopBits;
            //无奇偶校验位
            serialPort.Parity      = parity;//None
            serialPort.ReadTimeout = 30000;

            this.serialPort.NewLine = NewLine;

            if (serialPort.IsOpen)
            {
                Close();
            }
            try
            {
                serialPort.Open();
                if (serialPort.IsOpen)
                {
                    serialPort.DataReceived += SerialPort_DataReceived;
                    return(true);
                }
                else
                {
                    return(false);
                }
            }catch (Exception ex)
            {
                Tool.AppLogError(ex);
                return(false);
            }
        }
예제 #12
0
        public Bitmap GetBitmap()
        {
            try
            {
                IImageData objIImageData = null;
                uint       nTimeout      = 500;


                //每次发送触发命令之前清空采集输出队列
                //防止库内部缓存帧,造成本次GXGetImage得到的图像是上次发送触发得到的图
                if (null != m_objIGXStream)
                {
                    m_objIGXStream.FlushQueue();
                }

                //发送软触发命令
                if (null != m_objIGXFeatureControl)
                {
                    m_objIGXFeatureControl.GetCommandFeature("TriggerSoftware").Execute();
                }

                //获取图像
                if (null != m_objIGXStream)
                {
                    objIImageData = m_objIGXStream.GetImage(nTimeout);
                }
                var bm = m_objGxBitmap.GetBitmap(objIImageData);
                if (null != objIImageData)
                {
                    //用完之后释放资源
                    objIImageData.Destroy();
                }
                return((Bitmap)bm.Clone());
            }
            catch (Exception ex)
            {
                Tool.AppLogError(ex);
                //MessageBox.Show(ex.Message);
            };
            return(null);
        }
예제 #13
0
        public bool UpdateT_Result(T_Result result)
        {
            bool res = false;

            Mapper.BeginTransaction();
            try
            {
                if (result.Picture != null)
                {
                    Mapper.Update("UpdateT_Picture", result.Picture);
                }
                Mapper.Update("UpdateT_Result", result);
                Mapper.CommitTransaction();
                res = true;
            }
            catch (Exception ex)
            {
                Tool.AppLogError(ex);
                Mapper.RollBackTransaction();
            }
            return(res);
        }
예제 #14
0
        /// <summary>
        /// 保存参数设置
        /// </summary>
        public void SaveInjector()
        {
            var    ents = this.injectorDevice.Injector.Entercloses;
            String msg  = null;

            if (ents.Length > 0)
            {
                int maxIndex = ents.Max(et => et.Index);
                int minIndex = ents.Min(et => et.Index);
                if (maxIndex - minIndex + 1 != ents.Length)
                {
                    msg = "禁用通道不连续,请重新设置";
                }
                else if (maxIndex != Constants.EntercloseCount - 1 && minIndex != 0)
                {
                    msg = "不能单独禁用中间的通道,请重新设置";
                }
            }
            if (!String.IsNullOrEmpty(msg))
            {
                windowManager.ShowMessageBox(msg, "系统提示");
                return;
            }
            if (Keyboard.FocusedElement is UIElement ele)
            {
                ele.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
                ele.MoveFocus(new TraversalRequest(FocusNavigationDirection.Previous));
            }
            try
            {
                var result      = BjParamService.SaveAsJson <Injector>(this.injector);
                var newInjector = this.BjParamService.LoadFromJson <Injector>();
                var iocInj      = IoC.Get <InjectorDevice>().Injector;
                newInjector.XMotor.IsBack          = iocInj.XMotor.IsBack;
                newInjector.XMotor.CurrentDistance = iocInj.XMotor.CurrentDistance;

                newInjector.TMotor.IsBack          = iocInj.TMotor.IsBack;
                newInjector.TMotor.CurrentDistance = iocInj.TMotor.CurrentDistance;

                for (byte i = 0; i < Constants.EntercloseCount; i++)
                {
                    newInjector.Entercloses[i].Selected = iocInj.Entercloses[i].Selected;

                    newInjector.Entercloses[i].YMotor.IsBack          = iocInj.Entercloses[i].YMotor.IsBack;
                    newInjector.Entercloses[i].YMotor.CurrentDistance = iocInj.Entercloses[i].YMotor.CurrentDistance;

                    newInjector.Entercloses[i].ZMotor.IsBack          = iocInj.Entercloses[i].ZMotor.IsBack;
                    newInjector.Entercloses[i].ZMotor.CurrentDistance = iocInj.Entercloses[i].ZMotor.CurrentDistance;

                    newInjector.Entercloses[i].PumpMotor.IsBack          = iocInj.Entercloses[i].PumpMotor.IsBack;
                    newInjector.Entercloses[i].PumpMotor.CurrentDistance = iocInj.Entercloses[i].PumpMotor.CurrentDistance;
                }
                IoC.Get <InjectorDevice>().Injector = newInjector;

                this.View.ShowHint(new MessageWin(result?"保存成功":"保存失败"));
            }
            catch (Exception ex)
            {
                Tool.AppLogError(ex);
                this.View.ShowHint(new MessageWin(ex.Message));
            }
        }