//Захват сигнала public void CaptureSignal(string fileName = "") { FindRedRat3(); redRat3.LearningSignalIn += SignalDataHandler; //Ввод сигнала в RedRat3 осуществляется в течении 10с redRat3.GetModulatedSignal(10000); haveSignal = false; while (!haveSignal) { Thread.Sleep(100); } if (modSignal != null) { #region old //if (IsXmlFile(fileName) ) //{ // //Создаем объект AV-устройства, чтобы мы могли хранить данные сигнала в файле XML. // var avDeviceDB = new AVDeviceDB(); // var avDevice = new AVDevice("Sample Device", AVDevice.AVDeviceType.SET_TOP_BOX); // avDeviceDB.AddAVDevice(avDevice); // irPacket.Name = "New Signal"; // //Добавить сигналы в «Sample Device». // avDevice.AddSignal(irPacket, false); // //Храните это как файл XML... // var ser = new XmlSerializer(typeof(AVDeviceDB) ); // TextWriter writer = new StreamWriter( (new FileInfo(fileName) ).FullName); // ser.Serialize(writer, avDeviceDB); // writer.Close(); // MessageBox.Show("ИК-данные c ПДУ сохранены в формате XML в файл:\n" + fileName); //} //else //{ // RRUtil.SerializePacketToBinary(fileName, irPacket); // MessageBox.Show("Saved in binary format to file: " + fileName); //} //xmlDoc.WriteEndDocument(); //xmlDoc.Close(); #endregion } else { logger.Info("Сигнал не был получен."); return; } }
// Захват сигнала public void CaptureSignal(string fileName = "") { OpenFileDialog OFD = new OpenFileDialog(); OFD.InitialDirectory = Form1.pathClick; SearchRedRat SRR = new SearchRedRat(); if (SRR.FindRedRat() != null) { RedRat3 = SRR.FindRedRat(); RedRat3.LearningSignalIn += SignalDataHandler; RedRat3.GetModulatedSignal(10000);//Ввод сигнала в RedRat3 осуществляется в течении 10с haveSignal = false; while (!haveSignal) { Thread.Sleep(100); } if (modSignal != null) { var mes = MessageBox.Show("OK - cохранить XML" + Environment.NewLine + "CANCEL - cохранить BIN", "Вариант сохранения файла", MessageBoxButtons.OKCancel); if (mes == DialogResult.OK) { inputName IN = new inputName(); IN.ShowDialog(); RRUtil.SerializePacketToXML(Form1.pathClick + "\\" + IN.name + ".xml", modSignal); tempMessage = "XML файл \"" + IN.name + "\" сохранен."; } else { inputName IN = new inputName(); IN.ShowDialog(); RRUtil.SerializePacketToBinary(Form1.pathClick + "\\" + IN.name + ".bin", modSignal);//SerializePacketToXML //var m = MessageBox.Show("Файл \"" + IN.name + "\" сохранен.", "Прием сигнала", MessageBoxButtons.OK); tempMessage = "BIN файл \"" + IN.name + "\" сохранен."; } } else { MessageBox.Show("Сигнал не был получен. Прием окончен.", "Прием сигнала", MessageBoxButtons.OK); } } }
/// <summary> /// Capture/learn a remote control signal. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void learnIRButton_Click(object sender, System.EventArgs e) { IRedRat3 rr3 = parent.RedRat3; if (rr3 == null) { return; } SignalInputDialog signalInputDialog = null; // == Right, this is probably the most complicated bit of interaction == // == with the RR3 in this program - but its not too bad really. == try { // 1. Tell the RR3 we want to input a demodulated signal (learn) rr3.GetModulatedSignal(0); // 2. Create modal dialog that allows us to cancel the operation if required. signalInputDialog = new SignalInputDialog(rr3); // 3. The dialog box has to handle the input signal event from the RR3. rr3.LearningSignalIn += new EventHandler(signalInputDialog.SignalDataIn); // 4. Popup dialog.... signalInputDialog.ShowDialog(this); // 5. Once finished, get the event object SignalEventArgs siea = signalInputDialog.SignalInEvent; // Have input data of some kind... if (siea.Action == SignalEventAction.MODULATED_SIGNAL) { irPacket = siea.IRPacket; changed = true; } // We have had some error from the comms with the USB device, so read exception and throw it. else if (siea.Action == SignalEventAction.EXCEPTION) { throw siea.Exception; } // The user has pressed cancel else if (siea.Action == SignalEventAction.INPUT_CANCELLED) { // Don't need to do anything here. } } catch (Exception ex) { string msg = ex.Message; if (ex.InnerException != null) { msg += ": " + ex.InnerException.Message; } MessageBox.Show(msg, "Communication Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } finally { // Remove listener... if (signalInputDialog != null) { rr3.LearningSignalIn -= new EventHandler(signalInputDialog.SignalDataIn); } signalInputDialog.Close(); } }
//Захват сигнала public void CaptureSignal(string fileName) { if (fileName == "") { MessageBox.Show("Имя файла отсутствует.", "Ошибка", MessageBoxButtons.OK); return; } else { FindRedRat3(); redRat3.LearningSignalIn += SignalDataHandler; //Ввод сигнала в RedRat3 осуществляется в течении 10с redRat3.GetModulatedSignal(10000); haveSignal = false; while (!haveSignal) { Thread.Sleep(10); } if (irPacket != null) { //Создает новый файл XML для irPacket //XmlTextWriter xmlDoc = new XmlTextWriter("C:\\RedRat3_signalDB\\BD - irPacket.xml", Encoding.UTF8); //xmlDoc.WriteStartDocument(); //var fileName = "C:\\RedRat3\\XMLsignal\\XMLsignal.xml"; //var fileName = argParser.GetArgOption(ArgumentParser.CaptureArg); if (IsXmlFile(fileName)) { //RRUtil.SerializePacketToXML(fileName, irPacket); //Создаем объект AV-устройства, чтобы мы могли хранить данные сигнала в файле XML. var avDeviceDB = new AVDeviceDB(); var avDevice = new AVDevice("Sample Device", AVDevice.AVDeviceType.SET_TOP_BOX); avDeviceDB.AddAVDevice(avDevice); irPacket.Name = "New Signal"; //Добавить сигналы в «Sample Device». avDevice.AddSignal(irPacket, false); //Храните это как файл XML... var ser = new XmlSerializer(typeof(AVDeviceDB)); TextWriter writer = new StreamWriter((new FileInfo(fileName)).FullName); ser.Serialize(writer, avDeviceDB); writer.Close(); MessageBox.Show("ИК-данные c ПДУ сохранены в формате XML в файл:\n" + fileName); } else { RRUtil.SerializePacketToBinary(fileName, irPacket); MessageBox.Show("Saved in binary format to file: " + fileName); } //xmlDoc.WriteEndDocument(); //xmlDoc.Close(); } else { MessageBox.Show("Сигнал пуст."); return; } } }