/// <summary> /// AlarmEditPage constructor. /// </summary> /// <param name="alarmRecordData">AlarmRecord</param> public AlarmEditPage(AlarmRecord alarmRecordData) { InitializeComponent(); TimeSelector.BindingContext = this; _alarmSaving = false; SelectedDateTime = alarmRecordData.ScheduledDateTime; }
public void Alarm(AlarmRecord alarmRecord) { SaveFlag = true; SendGPIOSignal(); SendAlarmInfo(alarmRecord); SaveAlarmImage(alarmRecord); }
/// <summary> /// This method launches another tone setting app and set proper type based on selection. /// </summary> /// <param name="alarmRecord">AlarmRecord object</param> public void LaunchAlarmToneAppControl(AlarmRecord alarmRecord) { try { /// Sets app id Native.AppControl appControl = new Native.AppControl() { ApplicationId = "org.tizen.setting-ringtone" }; /// Sets operation for app control appControl.Operation = "http://tizen.org/appcontrol/operation/pick"; /// Adds selection mode appControl.ExtraData.Add("http://tizen.org/appcontrol/data/selection_mode", "single"); /// Prepares tone resources List <string> toneResources = new List <string>() { Native.Application.Current.DirectoryInfo.SharedResource + "ringtones/alarm.mp3", Native.Application.Current.DirectoryInfo.SharedResource + "ringtones", }; /// Sets launch mode appControl.LaunchMode = Native.AppControlLaunchMode.Group; /// Sets tone resource collections appControl.ExtraData.Add("http://tizen.org/appcontrol/data/path", toneResources); /// Sets alarm record to update based on app control result _bindableRecord = alarmRecord; /// Requests launch Native.AppControl.SendLaunchRequest(appControl, ReplyAfterLaunching); } catch (Exception e) { Debug.WriteLine("[LaunchAlarmToneAppControl] Exception - Message:{0}", e.Message); } }
private void ShowAlarmPic(AlarmRecord alarmRecord) { //建立新的系统进程 System.Diagnostics.Process process = new System.Diagnostics.Process(); //设置图片的真实路径和文件名 DateTime createdTime = alarmRecord.CreatedTime; int x = alarmRecord.XPos; int y = alarmRecord.YPic; string picName = x + "_" + y + "_" + createdTime.ToString("hh_mm_ss.fff"); string imageFolder = "C:\\Alarm_Pic\\pic_" + createdTime.ToString("yyyy_MM_dd") + "\\下位机_" + mainWindowViewModel.Biz.DetectParam.CameraNo.ToString() + "_报警截图\\"; var images = Directory.GetFiles(imageFolder); string picPath = Path.Combine(imageFolder, picName); var image = images.SingleOrDefault(i => i.StartsWith(picPath)); if (image == null || !File.Exists(image)) { return; } try { process.StartInfo.FileName = image; process.StartInfo.Arguments = "rundl132.exe C://WINDOWS//system32//shimgvw.dll,ImageView_Fullscreen"; process.StartInfo.UseShellExecute = true; process.Start(); } catch (Exception ex) { App.Current?.Dispatcher.Invoke(() => { MessageBox.Show(ex.Message, "提示", MessageBoxButton.OK); }); } }
public int Delete(AlarmRecord item) { lock (locker) { return(database.Delete <AlarmRecord>(item.DateCreated)); } }
public int Update(AlarmRecord item) { lock (locker) { return(database.Update(item)); } }
public int Insert(AlarmRecord item) { lock (locker) { return(database.Insert(item)); } }
private void SaveAlarmVideo() { AlarmRecord alarmRecord = new AlarmRecord() { CreatedTime = DateTime.Now, LatestOccurTime = DateTime.Now, }; string picName = alarmRecord.XPos + "_" + alarmRecord.YPic + "_"; string destFolder = "C:\\Alarm_Video\\pic_" + alarmRecord.CreatedTime.ToString("yyyy_MM_dd") + "\\下位机_" + DetectParam.CameraNo + "_报警截图\\" + picName + alarmRecord.CreatedTime.ToString("hh_mm_ss.fff") + "_AlarmPic\\"; if (!Directory.Exists(destFolder)) { Directory.CreateDirectory(destFolder); } int num = random.Next(); ConcurrentDictionary <AlarmPos, DetectResultStatistic> temp = new ConcurrentDictionary <AlarmPos, DetectResultStatistic>(detectResultStatistics); Task.Run(() => { foreach (var detectResultStatistic in temp.Values) { foreach (var image in detectResultStatistic.ImageStore) { string destFileName = DateTime.Now.ToString("hh_mm_ss.fff") + num++ + ".bmp"; string destFile = destFolder + destFileName; //image.Draw(new Rectangle(alarmRecord.XPos - 32, alarmRecord.YPic - 32, 64, 64), new Bgr(Color.Red), 3); image.Bitmap.Save(destFile); } } }); }
/// <summary> /// Launch AlarmEdit page /// </summary> private Task CreateNewAlarm() { /// Creates default alarm record AlarmRecord defaultAlarmRecord = new AlarmRecord(); defaultAlarmRecord.SetDefault(); return(Navigation.PushAsync(AlarmPageController.GetInstance(AlarmPages.EditPage, defaultAlarmRecord))); }
private void HistoryHurts_MouseDoubleClick(object sender, MouseButtonEventArgs e) { if (HistoryHurts.SelectedItems.Count > 0) { AlarmRecord alarmRecord = HistoryHurts.SelectedItem as AlarmRecord; ShowAlarmPic(alarmRecord); } }
/// <summary> /// Launch AlarmEdit page /// </summary> async void CreateNewAlarm() { /// Creates default alarm record AlarmRecord defaultAlarmRecord = new AlarmRecord(); defaultAlarmRecord.SetDefault(); await Navigation.PushAsync(AlarmPageController.GetInstance(AlarmPages.EditPage, defaultAlarmRecord)); }
/// <summary> /// SavePopupPage constructor /// </summary> /// <param name="record">AlarmRecord</param> public SavePopupPage(AlarmRecord record) { InitializeComponent(); NavigationPage.SetHasNavigationBar(this, false); _record = record; SetPopupLabel(); ClosePopup(); }
/// <summary> /// Creates a system alarm of AlarmRecord /// </summary> /// <param name="binableAlarmRecord">AlarmRecord object to create a system alarm based on</param> /// <seealso cref="AlarmRecord"> /// <returns> Returns native alarm object </returns> public static int CreateAlarm(AlarmRecord record) { Native.AppControl appControl = new Native.AppControl() { ApplicationId = Native.Application.Current.ApplicationInfo.ApplicationId }; appControl.ExtraData.Add("AlarmRecord.UniqueIdentifier", record.GetUniqueIdentifier()); //temporary set AllDays , After implement select day of week. additional implementation should be add. Native.Alarm nativeAlarm = Native.AlarmManager.CreateAlarm(record.ScheduledDateTime, Native.AlarmWeekFlag.AllDays, appControl); Console.WriteLine("@@ [Alarm.CreateAlarm] UID : " + record.GetUniqueIdentifier() + ", ScheduledDateTime : " + record.ScheduledDateTime + " NativeAlarmID : " + nativeAlarm.AlarmId); return(nativeAlarm.AlarmId); }
public RingPage(RingType type, AlarmRecord alarmRecord) { try { NavigationPage.SetHasNavigationBar(this, false); _alarmRecord = alarmRecord; SnoozeOn = _alarmRecord.Snooze; Content = CreateRingPage(type); } catch (Exception EX) { System.Diagnostics.Debug.WriteLine("RingPage() exception : " + EX.Message + " , " + EX.Source + ", " + EX.StackTrace); } }
/// <summary> /// Cancel a system alarm of AlarmRecord /// </summary> /// <param name="binableAlarmRecord">AlarmRecord object relevant to a system alarm to cancel</param> /// <seealso cref="AlarmRecord"> public static void DeleteAlarm(AlarmRecord record) { var allAlarms = Native.AlarmManager.GetAllScheduledAlarms(); foreach (Native.Alarm item in allAlarms) { if (item.AlarmId == record.NativeAlarmID) { Console.WriteLine("@@ [Alarm.DeleteAlarm] Cancel NativeAlarmID:" + record.NativeAlarmID + ", UID:" + record.GetUniqueIdentifier()); item.Cancel(); record.NativeAlarmID = 0; break; } } }
/// <summary> /// ListItem tapped event handler /// </summary> /// <param name="sender">object</param> /// <param name="e">SelectedItemChangedEventArgs</param> void OnItemTapped(object sender, SelectedItemChangedEventArgs e) { /// skips for no selected item case if (e.SelectedItem == null) { return; } /// checks selected item AlarmRecord alarm = e.SelectedItem as AlarmRecord; /// Deselects first ((ListView)sender).SelectedItem = null; // de-select the row EditAlarm(alarm); }
/// <summary> /// SavePopupPage constructor /// </summary> /// <param name="record">AlarmRecord</param> public SavePopupPage(AlarmRecord record) { InitializeComponent(); NavigationPage.SetHasNavigationBar(this, false); _record = record; SetPopupLabel(); Appearing += async(s, e) => { // Close the pop-up after 2 seconds. await Task.Delay(2000); await Navigation.PopToRootAsync(); }; }
private void SaveAlarmImage(AlarmRecord alarmRecord) { string picName = alarmRecord.XPos + "_" + alarmRecord.YPic + "_"; string destFolder = "C:\\Alarm_Pic\\pic_" + alarmRecord.CreatedTime.ToString("yyyy_MM_dd") + "\\下位机_" + DetectParam.CameraNo + "_报警截图\\"; if (!Directory.Exists(destFolder)) { Directory.CreateDirectory(destFolder); } string destFileName = picName + alarmRecord.CreatedTime.ToString("hh_mm_ss.fff") + "_AlarmPic.bmp"; string destFile = destFolder + destFileName; var image = Image.Clone(); image.Draw(new Rectangle(alarmRecord.XPos - 32, alarmRecord.YPic - 32, 64, 64), new Bgr(Color.Red), 3); image.Bitmap.Save(destFolder + destFileName); }
/// <summary> /// Creates a system alarm of AlarmRecord /// </summary> /// <param name="binableAlarmRecord">AlarmRecord object to create a system alarm based on</param> /// <seealso cref="AlarmRecord"> /// <returns> Returns native alarm object </returns> public int CreateAlarm(AlarmRecord record) { Native.AppControl appControl = new Native.AppControl() { ApplicationId = Native.Application.Current.ApplicationInfo.ApplicationId }; appControl.ExtraData.Add("AlarmRecord.UniqueIdentifier", record.GetUniqueIdentifier()); appControl.ExtraData.Add("RingType", RingType.RING_TYPE_ALARM.ToString()); Native.AlarmWeekFlag nativeFlag = Convert(record.WeekFlag); Native.Alarm nativeAlarm = Native.AlarmManager.CreateAlarm(record.ScheduledDateTime, nativeFlag, appControl); #if ALARM_DEBUG System.Diagnostics.Debug.WriteLine("@@ [Alarm.CreateAlarm] UID : " + record.GetUniqueIdentifier() + ", ScheduledDateTime : " + record.ScheduledDateTime + " nativeFlag : " + nativeFlag); System.Diagnostics.Debug.WriteLine(" --> Done Native UID : " + nativeAlarm.AlarmId + ", ScheduledDate : " + nativeAlarm.ScheduledDate + " nativeFlag : " + nativeAlarm.WeekFlag); #endif return(nativeAlarm.AlarmId); }
public AlarmRecord Find(DateTime dt) { AlarmRecord ret = null; lock (locker) { var alarmRecordList = database.Table <AlarmRecord>().ToList(); foreach (var ar in alarmRecordList) { if (ar.ScheduledDateTime.Hour == dt.Hour && ar.ScheduledDateTime.Minute == dt.Minute) { ret = ar; break; } } } return(ret); }
/// <summary> /// Cancel a system alarm of AlarmReco /// </summary> /// <param name="binableAlarmRecord">AlarmRecord object relevant to a system alarm to cancel</param> /// <seealso cref="AlarmRecord"> public void DeleteAlarm(AlarmRecord record) { var allAlarms = Native.AlarmManager.GetAllScheduledAlarms(); foreach (Native.Alarm item in allAlarms) { if (item.AlarmId == record.NativeAlarmID) { #if ALARM_DEBUG System.Diagnostics.Debug.WriteLine("@@ [Alarm.DeleteAlarm] Cancel NativeUID:" + record.NativeAlarmID + ", UID:" + record.GetUniqueIdentifier()); #endif item.Cancel(); break; } } #if ALARM_DEBUG Toast.DisplayText("@@ [Alarm.DeleteAlarm] Native Alarm is not found. NativeUID:" + record.NativeAlarmID + ", UID:" + record.GetUniqueIdentifier()); System.Diagnostics.Debug.WriteLine("@@ [Alarm.DeleteAlarm] Native Alarm is not found. NativeUID:" + record.NativeAlarmID + ", UID:" + record.GetUniqueIdentifier()); #endif }
public void ExtractNumAlarms_Test() { var Mock_SystemInfo = new Mock_SystemInfo(); NodeType dbtype = new NodeType(Symbol.Intern("DatabaseManager"), false, false, new List <PropertyDefinition>()); Mock_SystemInfo.mock_addNodeDefinition(dbtype, "DatabaseManager", null, new NodeID(1)); var Mock_NodeController = new Mock_INodeController(); var mockSystemInterface = new Mock_SystemInterface(Mock_SystemInfo, Mock_NodeController); var station = new Stations(); var alarmList = new List <AlarmRecord>(); var alarmTime1 = DateTime.Now; var alarmRecord1 = new AlarmRecord(new NodeID(0, 1), Symbol.Intern("TestAlarm1"), alarmTime1, true); alarmList.Add(alarmRecord1); station.ExtractNumAlarms(QueryResult.Valid, alarmList, 1, mockSystemInterface); }
public bool AddOneAlarmRecord(AlarmRecord alarmRecord) { string sql = "insert into record_alarmrecord(TempMeasure_Index,Rule_Index,Rule_Type,AlarmType,AlarmRecordTime,RelMeaVal,RefPreAlarmVal,RefAlarmVal,RefSuperAlarmVal,Readed) " + "values(@TempMeasure_Index,@Rule_Index,@Rule_Type,@AlarmType,@AlarmRecordTime,@RelMeaVal,@RefPreAlarmVal,@RefAlarmVal,@RefSuperAlarmVal,@Readed)"; List <MySqlParameter> parmList = new List <MySqlParameter>(); parmList.Add(new MySqlParameter("@TempMeasure_Index", alarmRecord.TempMeasure_Index)); parmList.Add(new MySqlParameter("@Rule_Index", alarmRecord.Rule_Index)); parmList.Add(new MySqlParameter("@Rule_Type", alarmRecord.Rule_Type)); parmList.Add(new MySqlParameter("@AlarmType", alarmRecord.AlarmType)); parmList.Add(new MySqlParameter("@AlarmRecordTime", alarmRecord.AlarmRecordTime)); parmList.Add(new MySqlParameter("@RelMeaVal", alarmRecord.RelMeaVal)); parmList.Add(new MySqlParameter("@RefPreAlarmVal", alarmRecord.RefPreAlarmVal)); parmList.Add(new MySqlParameter("@RefAlarmVal", alarmRecord.RefAlarmVal)); parmList.Add(new MySqlParameter("@RefSuperAlarmVal", alarmRecord.RefSuperAlarmVal)); parmList.Add(new MySqlParameter("@Readed", alarmRecord.Readed)); MySqlConnection conn = SqlHelper.GetConnection(ip, port, username, password, databaseName); return(SqlHelper.AddData(conn, sql, parmList.ToArray())); }
private void AddAlarmToStatistics(int avgX, int yPic, float length, DetectResultStatistic detectResultStatistic) { int xPos = avgX; int yPos = serialComm.LoopCount % AlarmRecord.TotalLoopCount; AlarmRecord alarmRecord = new AlarmRecord { XPos = xPos, YPos = yPos, YPic = yPic, LatestOccurTime = DateTime.Now, CreatedTime = DateTime.Now, Length = length }; App.Current?.Dispatcher.Invoke(() => { if (Alarms.Contains(alarmRecord)) { int index = Alarms.IndexOf(alarmRecord); var alarm = Alarms[index]; //alarm.XPos = alarmRecord.XPos; if (AlarmHeadFlag) { if (firstAlarmRecord == null) { firstAlarmRecord = alarmRecord; } if (firstAlarmRecord == alarmRecord) { LoopOffset = alarmRecord.YPos - alarm.YPos; } alarm.YPos = alarmRecord.YPos; AlarmHeadFlag = false; } alarm.Length = alarmRecord.Length; alarm.LatestOccurTime = alarmRecord.LatestOccurTime; } else { Alarms.Add(alarmRecord); Alarm(alarmRecord); } SelectedAlarmIndex = Alarms.IndexOf(alarmRecord); AsyncSaveObject("Alarms", Alarms); }); }
internal AlarmRecordViewModelEnum SaveToDb() { AlarmRecord existingRecord = SQLiteDBAccessor.Instance.Find(_alarmRecord.ScheduledDateTime); if (_alarmRecord.NativeAlarmId == null) { if (existingRecord != null) { return(AlarmRecordViewModelEnum.FailureNew); } //IAlarm iAlarm = DependencyService.Get<IAlarm>(); _alarmRecord.NativeAlarmId = AlarmRecord.SaveAlarm(_alarmRecord); SQLiteDBAccessor.Instance.Insert(_alarmRecord); return(AlarmRecordViewModelEnum.SuccessNew); } else { if (existingRecord != null) { if (existingRecord.DateCreated != _alarmRecord.DateCreated) { // TODO: Critical!! Need to delete existingRecord's AlarmRecordViewModel from SQLiteDBAccessor.Instance.Update(_alarmRecord); return(AlarmRecordViewModelEnum.SuccessCancelAndUpdateExisting); } else { SQLiteDBAccessor.Instance.Update(_alarmRecord); return(AlarmRecordViewModelEnum.SuccessUpdateExceptTime); } // TODO: Update native alarm if week flag changed } else { // TODO: Update native alarm since time has changed SQLiteDBAccessor.Instance.Update(_alarmRecord); return(AlarmRecordViewModelEnum.SuccessUpdateNonexisting); } } }
/// <summary> /// Draws alarm list /// </summary> /// <returns>Returns RelativeLayout</returns> protected virtual StackLayout Draw() { /// Need to get bindable context to assign list value AlarmRecord alarmData = (AlarmRecord)BindingContext; /// If binding context is null, can't proceed further action if (alarmData == null) { return(null); } /// Alarm item layout should be set if null if (alarmItemLayout == null) { // The layout of item cell alarmItemLayout = new StackLayout { HeightRequest = 120, Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand }; // Time Label timeLabel = new Label() { WidthRequest = 280, FontSize = 12, TextColor = Color.White, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center, }; timeLabel.SetBinding(Label.TextProperty, new Binding("ScheduledDateTime", BindingMode.Default, new ScheduledDateTimeToTextConverter())); alarmItemLayout.Children.Add(timeLabel); switchObj = new Check { HeightRequest = 80, WidthRequest = 80, DisplayStyle = CheckDisplayStyle.Default, IsToggled = alarmData.AlarmState == AlarmStates.Inactive ? false : true, HorizontalOptions = LayoutOptions.End, VerticalOptions = LayoutOptions.Center, }; alarmItemLayout.Children.Add(switchObj); /// Adds an event switchObj.Toggled += (s, e) => { AlarmRecord am = (AlarmRecord)BindingContext; if (am != null) { /// Modify state and re-draw it. Redraw must be called to redraw if (e.Value) { AlarmModel.ReactivatelAlarm(am); } else { AlarmModel.DeactivatelAlarm(am); } } }; } return(alarmItemLayout); }
/// <summary> /// Request to save alarm event. /// </summary> /// <param name="sender">object</param> /// <param name="args">EventArgs</param> async void OnSaveButtonClicked(object sender, EventArgs args) { Console.WriteLine("OnSaveButtonClicked"); if (_alarmSaving) { return; } _alarmSaving = true; //substract second from selectedTime. SelectedDateTime = SelectedDateTime.AddSeconds(-SelectedDateTime.Second); Console.WriteLine($"SelectedDateTime :{SelectedDateTime}"); AlarmModel.BindableAlarmRecord.ScheduledDateTime = SelectedDateTime; AlarmRecord duplicate = new AlarmRecord(); bool existSameAlarm = AlarmModel.CheckAlarmExist(ref duplicate); if (existSameAlarm) { // Use alarm created date for unique identifier for an alarm record string alarmUID = AlarmModel.BindableAlarmRecord.GetUniqueIdentifier(); if (!AlarmModel.BindableAlarmRecord.IsSerialized) { // in case that AlarmEditPage is shown by clicking at add alarm // when trying to create a system alarm and save it, find the same alarm // expected behavior : update the previous one and do not create a new alarm AlarmModel.BindableAlarmRecord.IsSerialized = true; duplicate.DeepCopy(AlarmModel.BindableAlarmRecord, false); // Update the existing alarm(duplicate) Console.WriteLine("exist same alarm! update previous alarm, not create new alarm:" + AlarmModel.BindableAlarmRecord.ToString()); AlarmModel.UpdateAlarm(duplicate); } else if (alarmUID.Equals(duplicate.GetUniqueIdentifier())) { // in case that AlarmEditPage is shown by selecting an item of ListView in AlarmListPage // At saving time, just update itself. (It doesn't affect other alarms) Console.WriteLine("exist same alarm! update current alarm:" + AlarmModel.BindableAlarmRecord.ToString()); AlarmModel.UpdateAlarm(AlarmModel.BindableAlarmRecord); } else { // in case that AlarmEditPage is shown by selecting an item of ListView in AlarmListPage // At saving time, the same alarm is found. // In case that this alarm is not new, the existing alarm(duplicate) will be deleted and it will be updated. // 1. delete duplicate alarm Console.WriteLine("exist same alarm! delete duplicate alarm and update current alarm:" + AlarmModel.BindableAlarmRecord.ToString()); AlarmModel.DeleteAlarm(duplicate); // 2. update bindableAlarmRecord AlarmModel.UpdateAlarm(AlarmModel.BindableAlarmRecord); } } else { if (!AlarmModel.BindableAlarmRecord.IsSerialized) { // In case that AlarmEditPage is shown by clicking FloatingButton // There's no same alarm. So, just create a new alarm and add to list and dictionary. AlarmModel.BindableAlarmRecord.IsSerialized = true; Console.WriteLine("new Alarm create:" + AlarmModel.BindableAlarmRecord.ToString()); AlarmModel.CreateAlarm(); } else { // in case that AlarmEditPage is shown by selecting an item of ListView in AlarmListPage // There's no same alarm. So, just update itself. Console.WriteLine("update current alarm:" + AlarmModel.BindableAlarmRecord.ToString()); AlarmModel.UpdateAlarm(AlarmModel.BindableAlarmRecord); } } //Create SavePopupPage, and then close current EditPage. Navigation.InsertPageBefore(new SavePopupPage(AlarmModel.BindableAlarmRecord), this); await Navigation.PopAsync(); _alarmSaving = false; }
/// <summary> /// Update SelectedDateTime with alarmRecordData time. /// </summary> /// <param name="alarmRecordData">Alarm record data to set SelectedDateTime</param> internal void Update(AlarmRecord alarmRecordData) { Console.WriteLine("Update" + alarmRecordData.ToString()); SelectedDateTime = alarmRecordData.ScheduledDateTime; _alarmSaving = false; }
/// <summary> /// AlertPageModel constructor with AlarmRecord /// </summary> /// <param name="record">Record to be shown</param> public AlertPageModel(AlarmRecord record = null) { Record = record; }
/// <summary> /// 返回记录数据 /// </summary> /// <param name="lstDataDomain">数据域数组</param> /// <returns></returns> //public object GetDataValue(List<byte> lstDataDomain) public object GetDataValue(List <byte> lstReciveByte) { //如果返回不是正常应答帧 返回空 //if (!serialPortHelper.IsNormalFrame) //{ // return null; //} //lstClone.AddRange(lstDataDomain); //isNormalFrame = false; returnType = 0; lstDataDomain.Clear(); lstRead.Clear(); int revLength = lstReciveByte.Count; if (revLength >= 8) { if (lstReciveByte[0] == 0x10 && lstReciveByte[1] == 0xFF && lstReciveByte[2] == 0xFE) //识别帧 { int dataLength = lstReciveByte[4] * 256 + lstReciveByte[3]; int frameLen = dataLength + 5; if (revLength >= frameLen) { List <byte> checkList = lstReciveByte.GetRange(3, dataLength); byte[] bytCheck = GetDataCheck(checkList); if (bytCheck[1] == lstReciveByte[frameLen - 1] && bytCheck[0] == lstReciveByte[frameLen - 2]) //校验和 { lstRead.AddRange(lstReciveByte.GetRange(0, frameLen)); lstDataDomain.AddRange(lstReciveByte.GetRange(5, dataLength - 2)); returnType = lstDataDomain[0]; isNormalFrame = true; Application.DoEvents(); //System.Threading.Thread.Sleep(50); //lstReciveByte.Clear(); } //else //{ // byte a = lstReciveByte[frameLen - 1]; // byte b = lstReciveByte[frameLen - 2]; // isNormalFrame = true; // returnType = 0x20; // lstDataDomain.AddRange(lstReciveByte.GetRange(5, dataLength - 2)); // lstRead.AddRange(lstReciveByte.GetRange(0, frameLen)); //} lstReciveByte.RemoveRange(0, frameLen); } } } if (!isNormalFrame) { return(null); } //创建一个新集合 克隆数据域数据 List <byte> lstClone = new List <byte>(); lstClone.AddRange(lstDataDomain); object obj = null; if (lstClone.Count > 1) { switch (lstClone[0]) { case 0x01: //设置单板时间 case 0x04: //系统参数设置 case 0x06: //设置CH1参数 case 0x08: //设置CH2参数 case 0x0A: //设置CH3参数 case 0x0C: //保存参数 case 0x11: //关闭信号强度显示 case 0x14: //退出上传通道信号 case 0x15: //设置调试相位 case 0x60: case 0x61: case 0x62: case 0x63: case 0x64: case 0x65: case 0x0D: if (lstClone[1] == 0) { obj = "操作成功"; // MessageBox.Show("操作成功"); } else if (lstClone[1] == 1) { obj = "参数错误"; //MessageBox.Show("参数错误"); } else { obj = "无效"; //MessageBox.Show("无效"); } break; case 0x68: if (lstClone.Count == 5) { CheckCode checkCode = new CheckCode(); checkCode.Data1 = lstClone[1]; checkCode.Data2 = lstClone[2]; checkCode.Data3 = lstClone[3]; checkCode.Data4 = lstClone[4]; obj = checkCode; } break; case 0x6E: if (lstClone.Count == 2) { RandomModel randomModel = new RandomModel(); randomModel.ModelType = lstClone[1]; obj = randomModel; } break; case 0x69: if (lstClone.Count == 2) { MiduParam param = new MiduParam(); param.Data = lstClone[1]; obj = param; } break; case 0x6A: if (lstClone.Count == 2) { TongbuParam param = new TongbuParam(); param.Data = lstClone[1]; obj = param; } break; case 0x6B: if (lstClone.Count == 2) { NoiseParam param = new NoiseParam(); param.Data = lstClone[1]; obj = param; } break; case 0x6C: if (lstClone.Count == 2) { XinhaoParam param = new XinhaoParam(); param.Data = lstClone[1]; obj = param; } break; case 0x6D: if (lstClone.Count == 2) { InterverParam param = new InterverParam(); param.Data = lstClone[1]; obj = param; } break; case 0x0E: if (lstClone.Count == 2) { GongpinParam param = new GongpinParam(); param.Data = lstClone[1]; obj = param; } break; case 0x02: //查询单板时间 if (lstClone.Count == 8) { SystemDT systemDT = new SystemDT(); systemDT.Year = lstClone[2] * 256 + lstClone[1]; systemDT.Month = lstClone[3]; systemDT.Day = lstClone[4]; systemDT.Hour = lstClone[5]; systemDT.Minute = lstClone[6]; systemDT.Second = lstClone[7]; obj = systemDT; } break; case 0x03: //查询单板版本信息 if (lstClone.Count == 12) { VersionInfo versionInfo = new VersionInfo(); versionInfo.SoftVersion = lstClone[1] + "." + lstClone[2] + "." + lstClone[3] + "." + lstClone[4]; versionInfo.CompileDT = new SystemDT(); versionInfo.CompileDT.Year = lstClone[6] * 256 + lstClone[5]; versionInfo.CompileDT.Month = lstClone[7]; versionInfo.CompileDT.Day = lstClone[8]; versionInfo.CompileDT.Hour = lstClone[9]; versionInfo.CompileDT.Minute = lstClone[10]; versionInfo.CompileDT.Second = lstClone[11]; obj = versionInfo; } break; case 0x05: //查询系统参数 if (lstClone.Count == 14) { SystemParam systemParam = new SystemParam(); //byte[] phase = lstClone.GetRange(1, 4).ToArray(); //phase = phase.Reverse().ToArray(); systemParam.Phase = lstClone[2] * 256 + lstClone[1]; systemParam.Frequency = lstClone[3]; systemParam.SendInterval = lstClone[4]; systemParam.SendStrength = lstClone[5]; systemParam.RevDelay = lstClone[6]; systemParam.ChannelMode = lstClone[7]; systemParam.InterferenceDetection = lstClone[8]; systemParam.SignDetection = lstClone[9]; systemParam.DecodingFilterA = lstClone[10]; systemParam.DecodingFilterB = lstClone[11]; systemParam.DecodingFilterC = lstClone[12]; systemParam.DecodingFilterD = lstClone[13]; obj = systemParam; } break; case 0x07: //查询CH1参数 case 0x09: //查询CH2参数 case 0x0B: //查询CH3参数 if (lstClone.Count == 5) { ChannelParam channelParam = new ChannelParam(); channelParam.AlarmThreshold = lstClone[1]; //channelParam.Sign1 = lstClone[2] & 0x01; //channelParam.Sign2 = (lstClone[2] >> 1) & 0x01; //channelParam.Sign3 = (lstClone[2] >> 2) & 0x01; channelParam.TX = lstClone[2] & 0x01; channelParam.RX = (lstClone[2] >> 1) & 0x01; channelParam.Buzzer = lstClone[3]; channelParam.ChannelGain = lstClone[4]; obj = channelParam; } break; case 0x10: //显示通道信号强度 if (lstClone.Count == 7) { ChannelSignStrength channelSignStrength = new ChannelSignStrength(); channelSignStrength.Ch1Noise = lstClone[1]; channelSignStrength.Ch1Sign = lstClone[2]; channelSignStrength.Ch2Noise = lstClone[3]; channelSignStrength.Ch2Sign = lstClone[4]; channelSignStrength.Ch3Noise = lstClone[5]; channelSignStrength.Ch3Sign = lstClone[6]; obj = channelSignStrength; } break; case 0x12: //检测周围相位 if (lstClone.Count == 33) { List <string> phaseList = new List <string>(); for (int i = 0; i < 16; i++) { int temp = lstClone[i * 2 + 2] * 256 + lstClone[i * 2 + 1]; if (temp == 65535) { phaseList.Add("无"); } else { double fTemp = temp * 0.1; phaseList.Add(fTemp.ToString("0.0")); } } obj = phaseList; } break; case 0x13: //上传通道信号 //if (lstClone.Count == 601) { int number = (lstClone.Count - 1) / 2; UploadChannelSign ucs = new UploadChannelSign(); ucs.Bit15List = new List <int>(); ucs.Bit0_14List = new List <int>(); for (int i = 0; i < number; i++) { if ((lstClone[i * 2 + 2] >> 7) == 1) { ucs.Bit15List.Add(1600); } else { ucs.Bit15List.Add(0); } // ucs.Bit15List.Add((lstClone[i * 2 + 2] >> 15) & 0x80); ucs.Bit0_14List.Add((lstClone[i * 2 + 2] & 0x7F) * 256 + lstClone[i * 2 + 1]); } obj = ucs; } break; case 0x20: //上传单板报警记录 List <AlarmRecord> arList = new List <AlarmRecord>(); int count = (lstClone.Count - 1) / 16; for (int i = 0; i < count; i++) { AlarmRecord ar = new AlarmRecord(); ar.index = i + 1; ar.Number = lstClone[i * 16 + 1]; ar.Code = lstClone[i * 16 + 2]; ar.RecordDT = new SystemDT(); ar.RecordDT.Year = 2000 + lstClone[i * 16 + 3]; ar.RecordDT.Month = lstClone[i * 16 + 4]; ar.RecordDT.Day = lstClone[i * 16 + 5]; ar.RecordDT.Hour = lstClone[i * 16 + 6]; ar.RecordDT.Minute = lstClone[i * 16 + 7]; ar.RecordDT.Second = lstClone[i * 16 + 8]; StringBuilder sb = new StringBuilder(); for (int j = 9; j <= 16; j++) { if (sb.Length > 0) { sb.Append(" "); } sb.Append(lstClone[i * 16 + j].ToString("X2")); } ar.Data = sb.ToString(); arList.Add(ar); } obj = arList; break; } } return(obj); }