/// <summary>
        /// 根据Task生成一个Mirror
        /// </summary>
        private Mirror GetNewMirror(SPFTask task)
        {
            Mirror mirror = new Mirror();

            mirror.Block      = SourcePosition.CurrentSelectedDisk.CurrentSelectedItem;
            mirror.Source     = task.Device;
            mirror.Target     = TargetPosition.DirPath;
            mirror.TargetFile = DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss") + ".bin";
            EnumDeviceType deviceType = task.Device.DeviceType;

            if (deviceType == EnumDeviceType.Chip)
            {
                mirror.Type = EnumMirror.Chip;
            }
            else if (deviceType == EnumDeviceType.SIM)
            {
                mirror.Type = EnumMirror.SIM;
            }
            else if (deviceType == EnumDeviceType.SDCard)
            {
                mirror.Type = EnumMirror.SDCard;
            }
            else
            {
                mirror.Type = EnumMirror.Device;
            }
            mirror.MirrorFlag = MirrorFlag.NewMirror;
            return(mirror);
        }
Beispiel #2
0
 public Device(string name, EnumDeviceType typeDevice)
 {
     this.name       = name;
     this.typeDevice = typeDevice;
     ready           = false;
     this.driver     = new Driver(name, typeDevice, 0);
 }
Beispiel #3
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("未定义");
     }
 }
Beispiel #4
0
 public Device(string name, EnumDeviceType typeDevice, Driver driver) : this(name, typeDevice)
 {
     if (isCompatible(driver))
     {
         this.driver = driver;
     }
     ready       = isReady();
     this.driver = new Driver(name, typeDevice, 0);
 }
Beispiel #5
0
 public Driver(string name, EnumDeviceType deviceType, int version)
 {
     this.name       = name;
     this.version    = version;
     this.deviceType = deviceType;
     supportingOS    = new HashSet <string>();
     supportingOS.Add("os1");
     supportingOS.Add("os2");
 }
Beispiel #6
0
        /// <summary>
        /// 根据返回结果 转化JSON
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public override string BuildResultDataJson(byte[] data, EnumDeviceType enumDeviceType)
        {
            string str = "无此类型设备";

            if (enumDeviceType == EnumDeviceType.电表)
            {
                Result63ReadAmmeter res = new Result63ReadAmmeter(DeviceNum, data);
                str = JsonConvert.SerializeObject(res);
            }
            else if (enumDeviceType == EnumDeviceType.阀门)
            {
                Result63ReadValve res = new Result63ReadValve(DeviceNum, data);
                str = JsonConvert.SerializeObject(res);
            }
            else if (enumDeviceType == EnumDeviceType.灯控)
            {
                Result63ReadLight res = new Result63ReadLight(DeviceNum, data);
                str = JsonConvert.SerializeObject(res);
            }
            else if (enumDeviceType == EnumDeviceType.水表)
            {
                Result63ReadWatermeter res = new Result63ReadWatermeter(DeviceNum, data);
                str = JsonConvert.SerializeObject(res);
            }
            else if (enumDeviceType == EnumDeviceType.温度)
            {
                Result63ReadTemperature res = new Result63ReadTemperature(DeviceNum, data);
                str = JsonConvert.SerializeObject(res);
            }
            else if (enumDeviceType == EnumDeviceType.湿度)
            {
                Result63ReadHumidity res = new Result63ReadHumidity(DeviceNum, data);
                str = JsonConvert.SerializeObject(res);
            }
            else if (enumDeviceType == EnumDeviceType.光感度)
            {
                Result63ReadOptical res = new Result63ReadOptical(DeviceNum, data);
                str = JsonConvert.SerializeObject(res);
            }
            else if (enumDeviceType == EnumDeviceType.水浸)
            {
                Result63ReadWatermeter res = new Result63ReadWatermeter(DeviceNum, data);
                str = JsonConvert.SerializeObject(res);
            }



            return(str);
        }
Beispiel #7
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));
        }
Beispiel #8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="data">返回结果</param>
 /// <returns>JSON</returns>
 public virtual string BuildResultDataJson(byte[] data, EnumDeviceType enumDeviceType)
 {
     throw new Exception("基类方法不允许直接调用!");
 }
Beispiel #9
0
 public Command50Set(EnumHandleType enumHandleType, EnumDeviceType enumDeviceType)
 {
     EnumDeviceType = enumDeviceType;
     EnumHandleType = enumHandleType;
 }
Beispiel #10
0
        /// <summary>
        /// 根据返回结果 转化JSON
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public override string BuildResultDataJson(byte[] data, EnumDeviceType enumDeviceType)
        {
            string str = "无此类型设备";

            Result63ReadBase result63ReadBase = null;

            if (enumDeviceType == EnumDeviceType.电表)
            {
                Result63ReadAmmeter res = new Result63ReadAmmeter(DeviceNum, data);
                result63ReadBase = res;
                //PLCDeviceCacheObject.Instance[res.Num.ToString()] = res;
                str = JsonConvert.SerializeObject(res);
            }
            else if (enumDeviceType == EnumDeviceType.水表)
            {
                Result63ReadWatermeter res = new Result63ReadWatermeter(DeviceNum, data);
                //PLCDeviceCacheObject.Instance[res.Num.ToString()] = res;
                result63ReadBase = res;
                str = JsonConvert.SerializeObject(res);
            }
            else if (enumDeviceType == EnumDeviceType.阀门)
            {
                Result63ReadValve res = new Result63ReadValve(DeviceNum, data);
                //PLCDeviceCacheObject.Instance[res.Num.ToString()] = res;
                result63ReadBase = res;
                str = JsonConvert.SerializeObject(res);
            }
            else if (enumDeviceType == EnumDeviceType.温度)
            {
                Result63ReadTemperature res = new Result63ReadTemperature(DeviceNum, data);
                //PLCDeviceCacheObject.Instance[res.Num.ToString()] = res;
                result63ReadBase = res;
                str = JsonConvert.SerializeObject(res);
            }
            else if (enumDeviceType == EnumDeviceType.湿度)
            {
                Result63ReadHumidity res = new Result63ReadHumidity(DeviceNum, data);
                //PLCDeviceCacheObject.Instance[res.Num.ToString()] = res;
                result63ReadBase = res;
                str = JsonConvert.SerializeObject(res);
            }
            else if (enumDeviceType == EnumDeviceType.灯控)
            {
                Result63ReadLight res = new Result63ReadLight(DeviceNum, data);
                //PLCDeviceCacheObject.Instance[res.Num.ToString()] = res;
                result63ReadBase = res;
                str = JsonConvert.SerializeObject(res);
            }
            else if (enumDeviceType == EnumDeviceType.光感度)
            {
                Result63ReadOptical res = new Result63ReadOptical(DeviceNum, data);
                //PLCDeviceCacheObject.Instance[res.Num.ToString()] = res;
                result63ReadBase = res;
                str = JsonConvert.SerializeObject(res);
            }
            else if (enumDeviceType == EnumDeviceType.水浸)
            {
                Result63ReadWater res = new Result63ReadWater(DeviceNum, data);
                //PLCDeviceCacheObject.Instance[res.Num.ToString()] = res;
                result63ReadBase = res;
                str = JsonConvert.SerializeObject(res);
            }

            if (result63ReadBase != null)
            {
                PLCDeviceCacheObject.Instance.AddDeviceData(result63ReadBase);
            }



            return(str);
        }
Beispiel #11
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);
        }
Beispiel #12
0
 public Driver(string name, EnumDeviceType deviceType, int version, HashSet <string> supportingOS)
     : this(name, deviceType, version)
 {
     this.supportingOS.Concat(supportingOS);
 }