public HubReadWriterResultModel DoWork(HubReadWriterModel hubRead)
        {
            Type   handlerType = default;
            object handler     = default;

            try
            {
                handlerType = Type.GetType($"MMK.SmartSystem.CNC.Core.DeviceInOut.{hubRead.ProxyName}");
                handler     = iocManager.Resolve(handlerType);
                var connMethod = handlerType.GetMethod("BuildConnect");
                var connRes    = (bool)connMethod.Invoke(handler, null);
                if (!connRes)
                {
                    return(new HubReadWriterResultModel()
                    {
                        Action = hubRead.Action,
                        ConnectId = hubRead.ConnectId,
                        Error = "CNC建立连接失败",
                        ProxyName = hubRead.ProxyName,
                        Result = new object(),
                        Success = false,
                        Id = hubRead.Id
                    });
                }
                var methodInfo = handlerType.GetMethod(hubRead.Action);
                var res        = methodInfo.Invoke(handler, new object[] { hubRead }) as HubReadWriterResultModel ?? new HubReadWriterResultModel();
                res.Action    = hubRead.Action;
                res.ConnectId = hubRead.ConnectId;
                res.Id        = hubRead.Id;
                res.ProxyName = hubRead.ProxyName;
                return(res);
            }
            catch (Exception ex)
            {
                return(new HubReadWriterResultModel()
                {
                    Action = hubRead.Action,
                    ConnectId = hubRead.ConnectId,
                    Error = ex.Message + ex.InnerException?.Message,
                    ProxyName = hubRead.ProxyName,
                    Result = new object(),
                    Success = false,
                    Id = hubRead.Id
                });
            }
            finally
            {
                var closeConnect = handlerType.GetMethod("CloseConnect");
                if (closeConnect != null && handler != null)
                {
                    try
                    {
                        closeConnect.Invoke(handler, null);
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }
Esempio n. 2
0
        public string SendReadWriter(HubReadWriterModel model)
        {
            var hubClient = service.GetService(typeof(IHubContext <CncClientHub>)) as IHubContext <CncClientHub>;

            if (hubClient != null)
            {
                model.ConnectId = Context.ConnectionId;
                hubClient.Clients.All.SendAsync(CncClientHub.ClientReadWriter, model);
            }
            return("True");
        }
Esempio n. 3
0
 public async void SendReaderWriter(HubReadWriterModel readWriterModel)
 {
     try
     {
         await signalrProxyClient.SendAction <string>(SinglarCNCHubConsts.CNCReaderWriterAction, readWriterModel);
     }
     catch (Exception ex)
     {
         SignalrProxyClient_CncErrorEvent(ex.Message);
     }
 }
        public HubReadWriterResultModel MainProgramToCNC(HubReadWriterModel hubRead)
        {
            var res = new ProgramListHelper().SelectMainProgram(flib, hubRead.Data[0].ToString());

            return(new HubReadWriterResultModel()
            {
                Result = hubRead.Data[0].ToString(),
                Error = res.Item2,
                Success = res.Item1 == 0,
                SuccessTip = hubRead.SuccessTip,
                ErrorTip = hubRead.ErrorTip
            });
        }
        /// <summary>
        /// 删除CNC程序
        /// </summary>
        /// <param name="hubRead"></param>
        /// <returns></returns>
        public HubReadWriterResultModel DeleteProgram(HubReadWriterModel hubRead)
        {
            var res = new ProgramTransferHelper().DeleteProgramInCnc(flib, hubRead.Data[0].ToString());

            return(new HubReadWriterResultModel()
            {
                Result = res,
                Error = res,
                Success = string.IsNullOrEmpty(res),
                SuccessTip = hubRead.SuccessTip,
                ErrorTip = hubRead.ErrorTip
            });
        }
        public HubReadWriterResultModel ReadProgramInfo(HubReadWriterModel hubRead)
        {
            ReadProgramInfoResultModel readProgramInfo = new ReadProgramInfoResultModel();
            var res = new ProgramInfoHelper().ReadProgramInfo(flib, ref readProgramInfo);

            return(new HubReadWriterResultModel()
            {
                Result = readProgramInfo,
                Error = res.Item2,
                Success = res.Item1 == 0,
                SuccessTip = hubRead.SuccessTip,
                ErrorTip = hubRead.ErrorTip
            });
        }
        public HubReadWriterResultModel DownloadProgram(HubReadWriterModel hubRead)
        {
            string name = "";
            var    res  = new ProgramTransferHelper().LocalUploadProgramFromCncToPc(flib, hubRead.Data[0].ToString(), hubRead.Data[1].ToString(), 0);

            return(new HubReadWriterResultModel()
            {
                Result = name,
                Error = res,
                Success = string.IsNullOrEmpty(res),
                SuccessTip = hubRead.SuccessTip,
                ErrorTip = hubRead.ErrorTip
            });
        }
Esempio n. 8
0
        public HubReadWriterResultModel Reader(HubReadWriterModel hubRead)
        {
            List <ReadProgramListItemResultModel> data = new List <ReadProgramListItemResultModel>();
            var res = new ProgramListHelper().ReadProgramList(flib, hubRead.Data[0].ToString(), ref data);

            return(new HubReadWriterResultModel()
            {
                Result = data,
                Error = res.Item2,
                Success = res.Item1 == 0,
                SuccessTip = hubRead.SuccessTip,
                ErrorTip = hubRead.ErrorTip
            });
        }
Esempio n. 9
0
        public HubReadWriterResultModel Reversal(HubReadWriterModel hubRead)
        {
            short  adrType = (short)Convert.ToInt32(hubRead.Data[0].ToString());
            ushort adr     = (ushort)Convert.ToInt32(hubRead.Data[1].ToString());
            ushort bit     = (ushort)Convert.ToInt32(hubRead.Data[2].ToString());

            var res = new PmcHelper().ReversalPmcBit(flib, adrType, adr, bit);

            return(new HubReadWriterResultModel()
            {
                Result = res,
                Error = res,
                Success = string.IsNullOrEmpty(res),
                SuccessTip = hubRead.SuccessTip,
                ErrorTip = hubRead.ErrorTip
            });
        }
Esempio n. 10
0
        public HubReadWriterResultModel Reader(HubReadWriterModel hubRead)
        {
            ReadProgramFolderItemModel data = new ReadProgramFolderItemModel();

            data.Folder = hubRead.Data[0].ToString();
            data.RegNum = 0;
            var res = new ProgramFolderHelper().ReadProgramFolder(flib, ref data);

            return(new HubReadWriterResultModel()
            {
                Result = data,
                Error = res.Item2,
                Success = res.Item1 == 0,
                SuccessTip = hubRead.SuccessTip,
                ErrorTip = hubRead.ErrorTip
            });
        }
 private void RealReadWriterEvent(HubReadWriterModel obj)
 {
     obj.ConnectId = CurrentConnectId;
     SendReaderWriter(obj);
 }