/// <summary> /// 创建LED设备 /// </summary> /// <param name="type"></param> /// <returns></returns> public static ILedDevice CreateLedDevice(LedDeviceTypeEnum type) { ILedDevice device = null; switch (type) { case LedDeviceTypeEnum.LX: device = new LXDevice(); break; case LedDeviceTypeEnum.TW103: device = new YXTW103Device(); break; case LedDeviceTypeEnum.TdNew: device = new YXTDNew(); break; case LedDeviceTypeEnum.Unknow: case LedDeviceTypeEnum.TWBI2: default: break; } return(device); }
private void Display() { CommunicateDevice.FindAllWithCache().ForEach(com => { com.ShowDevices.ForEach(showDevice => { var cardType = showDevice.ShowDeviceType; var ledType = LedDeviceFactory.GetLedDeviceType(cardType.Name); ILedDevice ledDevice = LedDeviceFactory.CreateLedDevice(ledType); if (ledDevice != null) { try { var host = com.Args1; var args = Convert.ToInt32(com.Args2); ledDevice.Init(host, args); var maxPosition = 0; var messageList = showDevice.ShowDatas.ToList() .Select(sd => { var dev = sd.SensorDeviceUnit; var position = sd.Position; var info = dev.ShowValue; if (info == "负无穷大") { info = ""; } if (dev.Sensor.Name.Contains("雨雪")) { info = dev.ProcessedValue == 1M ? "有" : "无"; } if (dev.Sensor.Name.Contains("风向")) { info = JudgWindDirection(dev.ProcessedValue); dev.Sensor.Unit = ""; //发送到屏幕上去除风向的单位 } if (position > maxPosition) { maxPosition = position; } return(new Tuple <int, string>(position, string.Format("{0}:{1}{2}", dev.Name, info, dev.Sensor.Unit))); }).ToList(); if (!Setting.Current.LedAttactInfo.IsNullOrWhiteSpace()) { messageList.Add(new Tuple <int, string>(maxPosition + 1, Setting.Current.LedAttactInfo)); } ledDevice.Display(messageList); ServiceLogger.Current.WriteDebugLog("LED发送成功,{0}:{1}", com.Args1, com.Args2); } catch (Exception ex) { ServiceLogger.Current.WriteError("发送LED失败," + ex.Message); ServiceLogger.Current.WriteException(ex); } } }); }); }