public ActionResult SearchBuildingAllRoomNormalEquipmentInfo() { try { string allClassEquipmentInfoKey = AppSettingUtils.GetValue("allClassEquipmentInfo"); List <Buildings> list = Cache.GetCache <List <Buildings> >(allClassEquipmentInfoKey); List <Buildings> _list = new List <Buildings>(); foreach (var building in list) { building.Floors = building.Floors.Where(u => u.AbnormalEquipment == false).ToList(); _list.Add(building); } EResult.AppendData = _list; EResult.Status = true; EResult.Message = "查询成功"; EResult.ResultCode = ResultCode.Ok; } catch (Exception exception) { EResult.AppendData = exception.Message; EResult.Status = true; EResult.Message = "查询失败"; EResult.ResultCode = ResultCode.Ok; } return(Json(EResult)); }
public ActionResult SearchTest(QueryParams queryParams) { EquipmentResult result = new EquipmentResult(); Z_Room room = ZRoomService.GetEntity(u => u.F_RoomNo == queryParams.classroom).FirstOrDefault(); //获取该教室所有的设备 var zeList = ZEquipmentService.GetEntity(u => u.F_RoomId == room.F_Id).ToList(); byte fun = (byte)Convert.ToInt32(AppSettingUtils.GetValue("Search")); ClassRoom classRoom = PortService.GetReturnDataTest(queryParams.classroom); if (classRoom != null) { classRoom.Name = room?.F_FullName; classRoom.ClassNo = room.F_EnCode; //教室编码 classRoom.Id = room.F_RoomNo; var list = classRoom.SonserList; classRoom.AbnormalSonserList = classRoom.SonserList.Where(u => u.Online == StateType.Offline).ToList(); classRoom.NormalSonserList = classRoom.SonserList.Where(u => u.Online == StateType.Online).ToList(); result.Count = zeList.Count; result.ExceptionCount = classRoom.AbnormalSonserList.Count; result.NormalCount = classRoom.NormalSonserList.Count; result.AppendData = classRoom; } else { result.Message = "查询设备信息失败!请重试"; } return(Json(result)); }
/// <summary> /// 开关灯 /// </summary> /// <param name="classroom"></param> /// <param name="nodeAdd"></param> /// <param name="onoff"></param> /// <returns></returns> public void SetLamp(string classroom, string nodeAdd, string onoff) { byte fun = (byte)Convert.ToInt32(AppSettingUtils.GetValue("Lamp")); byte b; // byte fun = 0x01; b = (byte)(onoff == StateType.OPEN ? 0x01 : 0x00); PortService.SendConvertCmd(fun, classroom, nodeAdd, b); }
public ActionResult SetProjectionScreen(ControlParams controlParams) { byte fun = (byte)Convert.ToInt32(AppSettingUtils.GetValue("ProjectionScreen")); byte b = (byte)(controlParams.onoff == StateType.OPEN ? 0x01 : 0x00); EResult = PortService.SendConvertCmd(fun, controlParams.classroom, controlParams.nodeAdd, b); EResult.Message = EResult.Status ? "设置投影屏成功" : "设置投影屏失败"; return(Json(EResult)); }
public ActionResult SetCurtain(ControlParams controlParams) { byte fun = (byte)Convert.ToInt32(AppSettingUtils.GetValue("Curtain")); byte b = (byte)(controlParams.onoff == StateType.OPEN ? 0x04 : (controlParams.onoff == StateType.STOP ? 0x05 : 0x00)); EResult = PortService.SendConvertCmd(fun, controlParams.classroom, controlParams.nodeAdd, b); EResult.Message = EResult.Status ? "设置窗帘成功" : "设置窗帘失败"; return(Json(EResult)); }
/// <summary> /// 设置风机 /// </summary> /// <param name="classroom">教室地址</param> /// <param name="nodeAdd">节点地址</param> /// <param name="onoff">开关</param> /// <returns></returns> public ActionResult SetFan(ControlParams controlParams) { byte fun = (byte)Convert.ToInt32(AppSettingUtils.GetValue("Fan")); byte b = (byte)(controlParams.onoff == StateType.OPEN ? 0x01 : 0x00); EResult = PortService.SendConvertCmd(fun, controlParams.classroom, controlParams.nodeAdd, b); EResult.Message = EResult.Status ? "设置风机成功" : "设置风机失败"; return(Json(EResult, JsonRequestBehavior.AllowGet)); }
public ActionResult SearchBuildingAllRoomEquipmentInfo(string buildingName, string layerName) { try { string allClassEquipmentInfoKey = AppSettingUtils.GetValue("allClassEquipmentInfo"); List <Buildings> list = Cache.GetCache <List <Buildings> >(allClassEquipmentInfoKey); foreach (var item in list) { EResult.ExceptionCount += item.ExceptionCount; } if (string.IsNullOrEmpty(buildingName) && string.IsNullOrEmpty(layerName)) //两个都为null 表示查询所有楼栋的教室设备信息 { EResult.AppendData = list; EResult.Status = true; EResult.Message = "查询成功"; EResult.ResultCode = ResultCode.Ok; return(Json(EResult)); } if (string.IsNullOrEmpty(layerName)) //楼层为null,表示查询整个楼栋教室设备的信息 { Buildings building = list.FirstOrDefault(u => u.Name == buildingName); EResult.AppendData = building; EResult.Status = true; EResult.Message = "查询成功"; EResult.ResultCode = ResultCode.Ok; return(Json(EResult)); } else //楼栋,楼层都不为null,表示查询楼栋中,某层的教室设备信息 { Buildings building = list.FirstOrDefault(u => u.Name == buildingName); if (building != null) { building.Floors = building.Floors.Where(u => u.Name == layerName).ToList(); EResult.AppendData = building; } EResult.Message = "查询成功"; EResult.Status = true; EResult.ResultCode = ResultCode.Ok; return(Json(EResult)); } } catch (Exception exception) { EResult.ErrorData = exception.Message; EResult.Message = "查询失败,请重试"; EResult.ResultCode = ResultCode.Error; EResult.Status = false; return(Json(EResult)); } }
public ActionResult SetElectronicClock(string classroom, string nodeAdd) { EquipmentResult oa = new EquipmentResult(); try { byte fun = (byte)Convert.ToInt32(AppSettingUtils.GetValue("Clock")); byte[] classAddr = classroom.StrToHexByte(); byte[] nodeAddr = nodeAdd.StrToHexByte(); //获取当前时间 DateTime currentTime = Convert.ToDateTime(DatetimeExtened.GetNetDateTime()); //转换时间格式 string year = (currentTime.Year % 100).ToString(); string month = currentTime.Month < 10 ? "0" + currentTime.Month : currentTime.Month.ToString(); string day = currentTime.Day < 10 ? "0" + currentTime.Day : currentTime.Day.ToString(); string hour = currentTime.Hour < 10 ? "0" + currentTime.Hour : currentTime.Hour.ToString(); string minute = currentTime.Minute < 10 ? "0" + currentTime.Minute : currentTime.Minute.ToString(); string second = currentTime.Second < 10 ? "0" + currentTime.Second : currentTime.Second.ToString(); string date = $"{year} {month} {day}"; //日期部分 byte[] yMd = date.StrToHexByte(); //将日期部分转为byte[]类型 string time = $"{hour} {minute} {second}"; //时间部分 byte[] hms = time.StrToHexByte(); //将时间部分转为byte[]类型 byte week = (byte)(Convert.ToInt32(currentTime.DayOfWeek.ToString("d"))); byte[] cmd = { 0x55, 0x02, 0, 0, fun, 0, 0x0D, 0, 0, 0, week, 0, 0, 0, 0x23, 0, 0, 0x70, 0, 0 }; classAddr.CopyTo(cmd, 2); nodeAddr.CopyTo(cmd, 5); yMd.CopyTo(cmd, 7); hms.CopyTo(cmd, 11); cmd = cmd.ActuatorCommand(); PortService.SendCmd(cmd); oa.Status = true; oa.Message = "时间同步成功"; oa.ResultCode = ResultCode.Ok; } catch (Exception exception) { ExceptionHelper.AddException(exception); oa.Status = false; oa.ResultCode = ResultCode.Error; oa.Message = "时间同步失败"; oa.ErrorData = exception.Message; } return(Json(oa)); }
public ActionResult SetAirConditioning(AirControlParams airControlParams) { byte height = (byte)(airControlParams.onoff == StateType.OPEN ? 1 << 7 : 0 << 7); Int16 m = Convert.ToInt16(airControlParams.model); height |= (byte)(m << 4); Int16 s = Convert.ToInt16(airControlParams.speed); height |= (byte)(s << 2); height |= (byte)(Convert.ToInt16(airControlParams.SweepWind) << 1); byte low = (byte)Convert.ToInt16(airControlParams.wd); byte fun = (byte)Convert.ToInt32(AppSettingUtils.GetValue("Air")); EResult = PortService.SendConvertCmd(fun, airControlParams.classroom, airControlParams.nodeAdd, height: height, low: low); EResult.Message = EResult.Status ? "设置空调成功" : "设置空调失败"; return(Json(EResult)); }
/// <summary> /// 设置灯 /// </summary> /// <param name="controlParams"></param> /// <returns></returns> public ActionResult SetLamp(ControlParams controlParams) { byte fun = (byte)Convert.ToInt32(AppSettingUtils.GetValue("Lamp")); int res = controlParams.nodeAdd.IndexOf('_'); if (res != -1) //表示一个灯节点控制多个灯 { int state = Cache.GetCache <int>(controlParams.classroom); string[] node = controlParams.nodeAdd.Split('_'); //下滑线后面表示控制第几个灯 if (node[1] == "1") //控制第1个灯 { if (controlParams.onoff == StateType.CLOSE) { state &= ~0x02; } else { state |= 0x02; } } else if (node[1] == "0") //控制第0个灯 { if (controlParams.onoff == StateType.CLOSE) { state &= ~0x01; } else { state |= 0x01; } } state = state | 1 << 7; Cache.SetCache(controlParams.classroom, state); EResult = PortService.SendConvertCmd(fun, controlParams.classroom, node[0], (byte)state); } else //表示一个灯节点控制一个灯 { byte b = (byte)(controlParams.onoff == StateType.OPEN ? 0x01 : 0x00); EResult = PortService.SendConvertCmd(fun, controlParams.classroom, controlParams.nodeAdd, b); } EResult.Message = EResult.Status ? "设置灯成功" : "设置灯失败"; return(Json(EResult)); }
public void Execute(IJobExecutionContext context) { Thread.CurrentThread.IsBackground = true; try { List <Buildings> allBuilding = new List <Buildings>(); var rooms = ZRoomService.GetEntity(u => u.F_RoomType == "Building").ToList(); foreach (var room in rooms) { Buildings building = SearchBuildingAllRoomEquipmentInfo1(room.F_FullName, room); allBuilding.Add(building); } string allClassEquipmentInfoKey = AppSettingUtils.GetValue("allClassEquipmentInfo"); Cache.SetCache(allClassEquipmentInfoKey, allBuilding, DateTime.Now.AddDays(7)); } catch (Exception exception) { ExceptionHelper.AddException(exception); } }
/// <summary> /// 查询的教室设备节点信息 /// </summary> /// <param name="classroom">教室</param> /// <param name="result">记录结果</param> /// <returns>返回记录结果</returns> public ClassRoom Search(Z_Room room, ref EquipmentResult result) { //获取该教室所有的设备 var zeList = ZEquipmentService.GetEntity(u => u.F_RoomId == room.F_Id).ToList(); byte fun = (byte)Convert.ToInt32(AppSettingUtils.GetValue("Search")); //向串口发送查询指令 result = SendConvertSearchCmd(fun, room.F_RoomNo); ClassRoom classRoom = GetReturnData(room.F_RoomNo); if (classRoom == null) //没有数据就重新发一次 { Thread.Sleep(300); //向串口发送指令 result = SendConvertSearchCmd(fun, room.F_RoomNo); classRoom = GetReturnData(room.F_RoomNo); } if (classRoom != null) { classRoom.Name = room.F_FullName; classRoom.ClassNo = room.F_EnCode; //教室编码 classRoom.Id = room.F_RoomNo; classRoom.AbnormalSonserList = classRoom.SonserList.Where(u => u.Online == StateType.Offline).ToList(); classRoom.NormalSonserList = classRoom.SonserList.Where(u => u.Online == StateType.Online).ToList(); result.Count = zeList.Count; result.ExceptionCount = zeList.Count - classRoom.NormalSonserList.Count; result.NormalCount = classRoom.NormalSonserList.Count; result.Message = "查询设备信息成功"; } else { result.Status = false; result.ResultCode = ResultCode.Error; result.Message = "查询设备信息失败!请重试"; } return(classRoom); }
private void Process(string classroom, string nodeAdd) { try { byte fun = (byte)Convert.ToInt32(AppSettingUtils.GetValue("Clock")); byte[] classAddr = classroom.StrToHexByte(); byte[] nodeAddr = nodeAdd.StrToHexByte(); //获取当前时间 DateTime currentTime = Convert.ToDateTime(DatetimeExtened.GetNetDateTime()); //转换时间格式 string year = (currentTime.Year % 100).ToString(); string month = currentTime.Month < 10 ? "0" + currentTime.Month : currentTime.Month.ToString(); string day = currentTime.Day < 10 ? "0" + currentTime.Day : currentTime.Day.ToString(); string hour = currentTime.Hour < 10 ? "0" + currentTime.Hour : currentTime.Hour.ToString(); string minute = currentTime.Minute < 10 ? "0" + currentTime.Minute : currentTime.Minute.ToString(); string second = currentTime.Second < 10 ? "0" + currentTime.Second : currentTime.Second.ToString(); string date = $"{year} {month} {day}"; //日期部分 byte[] yMd = date.StrToHexByte(); //将日期部分转为byte[]类型 string time = $"{hour} {minute} {second}"; //时间部分 byte[] hms = time.StrToHexByte(); //将时间部分转为byte[]类型 byte week = (byte)(Convert.ToInt32(currentTime.DayOfWeek.ToString("d"))); byte[] cmd = { 0x55, 0x02, 0, 0, fun, 0, 0x0D, 0, 0, 0, week, 0, 0, 0, 0x23, 0, 0, 0x70, 0, 0 }; classAddr.CopyTo(cmd, 2); nodeAddr.CopyTo(cmd, 5); yMd.CopyTo(cmd, 7); hms.CopyTo(cmd, 11); cmd = cmd.ActuatorCommand(); PortService.SendCmd(cmd); } catch (Exception exception) { ExceptionHelper.AddException(exception); } }