Example #1
0
 public static PLCCommandBase GetPLCCommander(EnumHandleType enumHandleType, EnumDeviceType enumDeviceType)
 {
     if (enumHandleType == EnumHandleType.抄录)
     {
         return(new Jingjia.Command63Read());
     }
     else if (enumHandleType == EnumHandleType.通电Or全开)
     {
         return(new Jingjia.Command50Set(enumHandleType, enumDeviceType));
     }
     else if (enumHandleType == EnumHandleType.断电Or关三分之二)
     {
         return(new Jingjia.Command50Set(enumHandleType, enumDeviceType));
     }
     else if (enumHandleType == EnumHandleType.告警Or全关)
     {
         return(new Jingjia.Command50Set(enumHandleType, enumDeviceType));
     }
     else if (enumHandleType == EnumHandleType.关告警Or关三分之一)
     {
         return(new Jingjia.Command50Set(enumHandleType, enumDeviceType));
     }
     else
     {
         throw new Exception("未定义");
     }
 }
Example #2
0
        public void ProcessRequest(HttpContext context)
        {
            int deviceNum  = 0;
            int handleType = 0;
            int deviceType = 0;

            if (!int.TryParse(context.Request.Params[0], out deviceNum))
            {
                context.Response.Write(Common.ResultJsonStringNew(1, "设备ID参数错误", null));
                return;
            }
            if (!int.TryParse(context.Request.Params[1], out handleType))
            {
                context.Response.Write(Common.ResultJsonStringNew(1, "命令类型参数错误", null));
                return;
            }

            if (!int.TryParse(context.Request.Params[2], out deviceType))
            {
                context.Response.Write(Common.ResultJsonStringNew(1, "设备类型参数错误", null));
                return;
            }

            //命令类型枚举
            EnumHandleType enumHandleType = (EnumHandleType)handleType;

            //设备类型枚举
            EnumDeviceType enumDeviceType = (EnumDeviceType)Enum.ToObject(typeof(EnumDeviceType), deviceType);

            context.Response.ContentType = "text/plain";


            if (enumHandleType == EnumHandleType.打开任务调度器)
            {
                Jingjia.Task.Class1 class1 = new Jingjia.Task.Class1();
                class1.Star();
                context.Response.Write("任务调度器已打开");
                return;
            }

            string data = JingJia.PLCDriver.CommandQueueDriver.ExecuteCommand(deviceNum, enumHandleType, enumDeviceType);

            context.Response.Write(Common.ResultJsonStringNew(deviceNum, "ok", data));
        }
Example #3
0
 public Command50Set(EnumHandleType enumHandleType, EnumDeviceType enumDeviceType)
 {
     EnumDeviceType = enumDeviceType;
     EnumHandleType = enumHandleType;
 }
Example #4
0
        /// <summary>
        /// 执行单个命令
        /// </summary>
        /// <param name="num">设备编号</param>
        /// <param name="handleType">执行类型</param>
        /// <returns>返回执行结果</returns>
        public static string ExecuteCommand(int num, EnumHandleType handleType, EnumDeviceType enumDeviceType)
        {
            if (handleType == EnumHandleType.获取所有设备缓存)
            {
                _pLCDeviceCache = PLCDeviceCacheObject.Instance;
                Dictionary <int, Result63ReadBase> _dataDic = _pLCDeviceCache.GetResult63ReadBases();

                //List<Result63ReadBase> ress = new List<Result63ReadBase>();

                //foreach (Result63ReadBase item in _dataDic.Values)
                //{
                //    ress.Add(item);
                //}

                string str = JsonConvert.SerializeObject(_dataDic);

                return(str);
            }

            // if (handleType == EnumHandleType.打开任务调度器) {

            //    Class1 class1 = new Class1();
            //    class1.Star();

            //    return "已经打开";
            //}



            GR10 gr10 = DriveFactory.GetPLCInstence();

            //打开串口
            //gr10.Open("COM4");

            //命令对象工厂
            PLCCommandBase pLCCommandBase = DriveFactory.GetPLCCommander(handleType, enumDeviceType);

            //获取命令码
            byte[] sendData = pLCCommandBase.BuildCommandByte(num);

            byte[] resData;

            string json;

            try
            {
                resData = gr10.SendData("COM4", sendData);

                if (resData == null)
                {
                    json = "返回数据超时";
                }
                else
                {
                    json = pLCCommandBase.BuildResultDataJson(resData, enumDeviceType);
                }
            }
            catch (Exception ex)
            {
                json = ex.Message;
            }

            return(json);
        }
Example #5
0
 public static void AddCommand(int num, EnumHandleType handleType)
 {
     throw new NotImplementedException();
 }