private bool Connect1751() { try { //присваивание объектам классов InstantDi(о)Ctrl параметров платы, имеющей ID = DeviceNumber PCI_1751.SelectedDevice = new DeviceInformation(Find1751()); PCI_1751.Write(5, 0xFF); //SW-POW (PC14) off //настройка портов на выход/вход PortDirection[] portDirs = PCI_1751.PortDirection; portDirs[5].Direction = DioPortDir.LinHout; //PC10 - input (ZPR), PC14 - output (SW-POW) portDirs[0].Direction = DioPortDir.Input; //Data_0-7 portDirs[1].Direction = DioPortDir.Input; //Data_8-15 portDirs[2].Direction = DioPortDir.LinHout; //PC00 - input (ZPR), PC04 - INIT, PC05 - WA, PC06 - RD, PC07 - WD } catch (Exception) { FormConsole.AppendText("Не удалось сконфигурировать PCI-1751! Проверьте подключение!\n"); FormConsole.ScrollToCaret(); return(false); } return(true); }
public Work_Form(SystemInfoClass sysInfo) { InitializeComponent(); SysInfo = sysInfo; PrepareForm(); if (!Connect1751()) { return; } if (ConnectMOXA()) { START_button.Enabled = true; STOP_button.Enabled = false; FormConsole.AppendText("МПИ подключен.\n"); FormConsole.ScrollToCaret(); } else { START_button.Enabled = false; STOP_button.Enabled = false; FormConsole.AppendText("Проверьте подключение МПИ!\n"); FormConsole.ScrollToCaret(); } }
private void ConsoleWriter(string text, Color color = default(Color)) { FormConsole.Invoke((MethodInvoker) delegate { FormConsole.AppendText(text + "\n"); FormConsole.ScrollToCaret(); if (color == default(Color)) { return; } FormConsole.Select(FormConsole.Text.Length - text.Length - 1, text.Length); FormConsole.SelectionColor = color; FormConsole.Select(FormConsole.Text.Length - 1, 1); FormConsole.ScrollToCaret(); }); }
//загрузка Format Data из файла private Tuple <PatternsType, KeysType, AnswersType> FormatLoad(string filePath) { string message = "Данные загружены из "; message += filePath + "\r\n"; PatternsType patts = new PatternsType(); KeysType keys = new KeysType(); AnswersType answs = new AnswersType(); #region Read Answers int posLastSlesh = filePath.LastIndexOf('\\'); string answersPath = filePath.Substring(0, posLastSlesh); answersPath += "\\answers.txt"; answs = LoadVec.LoadFloatVecWithKey(answersPath); #endregion #region Read Patterns string[] readText = File.ReadAllLines(filePath); foreach (string s in readText) { if (s.Trim() != "") { string[] elemsStr = s.Split(new char[] { ',' }); List <float> vec = new List <float>(elemsStr.Length - 1); string key = elemsStr[0]; for (int i = 1; i < elemsStr.Length; i++) { float floatEl; bool ok = float.TryParse(elemsStr[i], out floatEl); if (ok) { vec.Add(floatEl); } else { FormConsole.PrintlnAndScroll("error try parse"); return(new Tuple <PatternsType, KeysType, AnswersType>(null, null, null)); } } patts.Add(vec); keys.Add(key); } } #endregion FormConsole.PrintlnAndScroll(message); return(new Tuple <PatternsType, KeysType, AnswersType>(patts, keys, answs)); }
// this.RequireUIThread(() => // { // // }); /// <summary> /// 获取帮助数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Login(object sender, Chromium.Remote.Event.CfrV8HandlerExecuteEventArgs e) { //DeleteDir(Directory.GetCurrentDirectory() + @"\Cache"); if (e.Arguments.Length > 0) { var a1 = e.Arguments[0].ToString(); var cookie = e.Arguments[1].ToString(); UserInfo.Cookie = cookie; SetUserContext(cookie); } parentForm.DialogResult = System.Windows.Forms.DialogResult.OK; parentForm.Hide(); var form2 = new FormConsole(); form2.SetParentForm(parentForm); form2.Show(); }
//вывод в консоль выхода НН по входу public static void consoleRunNN(bool isPrintIn = true) { if (Information.inputSignals.Count == Information.inputSize + (Information.NN.IsBiasNeuron ? 1 : 0)) { List <float> outputSignals = Information.NN.Run(Information.inputSignals, Information.NN.IsBiasNeuron); FormConsole.AppendText("Run Result:\r\n"); int i = 1; if (isPrintIn) { FormConsole.AppendText("input: "); foreach (float signal in Information.inputSignals) { FormConsole.AppendText(i + ") " + signal.ToString() + " "); i++; } FormConsole.AppendText("\r\n"); } i = 1; FormConsole.AppendText("output: "); float max = float.MinValue; int maxInd = -1; foreach (float signal in outputSignals) { if (max < signal) { max = signal; maxInd = i - 1; } FormConsole.AppendText(i + ") " + Math.Round(signal, 4).ToString() + " "); i++; } FormConsole.AppendText("\r\n"); FormConsole.AppendText("Answer Pattern = " + maxInd); FormConsole.AppendText("\r\n"); FormConsole.Scroll(); } else { FormConsole.PrintlnAndScroll("Some Error In Run NN\r\n"); } }
public BO_serie(SousMarin cs_parent, int cs_baudrate, int cs_nbBits, string cs_parite, string cs_stopBits, int cs_readBufferSize, int cs_writeBufferSize, int cs_readTimeOut, int cs_writeTimeOut)//, ref bool flag_A) { parent = cs_parent; Console = new FormConsole(parent); dataSerie = new String("".ToCharArray()); baudrate = cs_baudrate; nbBits = cs_nbBits; parite = cs_parite; stopBits = cs_stopBits; readBufferSize = cs_readBufferSize; readTimeOut = cs_readTimeOut; writeBufferSize = cs_writeBufferSize; writeTimeOut = cs_writeTimeOut; serialPort = new SerialPort(); tableau_de_donnee = new BO_tableau(); DemandePortCom = new FormPortCom(this); DemandePortCom.ShowDialog(); }
private void STOP_button_Click(object sender, EventArgs e) { MPIReset(); FormConsole.Clear(); long endFilePos; using (BinaryReader dataFile = new BinaryReader(File.OpenRead(BinPath))) { endFilePos = dataFile.BaseStream.Length; } if (endFilePos == 0) { File.Delete(BinPath); ConvertToCSV_Button.Enabled = false; } else { ConvertToCSV_Button.Enabled = true; } }
//Начать учить НН private async void startLearnNN(object sender, EventArgs e) { int MaxEp; if (int.TryParse(textBoxLearnRate.Text, out MaxEp)) { Information.NN.MaxEp = MaxEp; } int DistPrint; if (int.TryParse(textBoxMoment.Text, out DistPrint)) { Information.NN.DistPrint = DistPrint; } if (Information.pattNames.Count == Information.answNames.Count && Information.pattNames.Count != 0) { string[] fileNames1 = Information.pattNames.ToArray(); LoadFromFile lF1 = new LoadFromFile(fileNames1); string[] fileNames2 = Information.answNames.ToArray(); LoadFromFile lF2 = new LoadFromFile(fileNames2); List <List <float> > pattList = lF1.ConvertIntoList(); List <List <float> > answList = lF2.ConvertIntoList(); Information.NN.Learning(pattList.Count, pattList, answList); } else if (Information.isMnistLearn && Information.answNames.Count == 10) { ReadMnist readMnist = new ReadMnist(true, false); //File.WriteAllLines("mnist_data.txt", Information.mnistStrs); string[] fileNames2 = Information.answNames.ToArray(); LoadFromFile lF2 = new LoadFromFile(fileNames2); List <List <float> > answList = lF2.ConvertIntoList(); Information.NN.LearningMnist(readMnist, answList); } else if (Information.isFormatLearn) { if (Information.NN != null) { openFileDialog1.FileName = "Выбор файла NN"; openFileDialog1.Filter = "*(*.txt)|*.txt"; openFileDialog1.InitialDirectory = Directory.GetCurrentDirectory() + @"\formatData"; if (openFileDialog1.ShowDialog() == DialogResult.OK) { string filePath = openFileDialog1.FileName; Information.FormatFilePath = filePath; Tuple <PatternsType, KeysType, AnswersType> data = FormatLoad(filePath); PatternsType pattList = data.Item1; KeysType keys = data.Item2; AnswersType answList = data.Item3; await Information.NN.LearningFormat(pattList, keys, answList); } else { FormConsole.PrintlnAndScroll("erroe open file dialog"); } } else { FormConsole.PrintlnAndScroll("erroe NN is not define"); } } else { printErrorMessage("Неверно заданы образцы и ответы"); } }
private void START_button_Click(object sender, EventArgs e) { DisplayClear(); FormConsole.Clear(); AllMPIbuttonsOFF(); BrokenPackages = 0; string DirectoryPath = Application.StartupPath + "\\data\\"; if (!Directory.Exists(DirectoryPath)) { Directory.CreateDirectory(DirectoryPath); } BinPath = Path.Combine(DirectoryPath, "temporary.bin"); using (new BinaryWriter(File.Create(BinPath))) { } ZeroSignalDisplayed = false; GIBgotov = false; LastData_TempWords = new int[SysInfo.TempWords * 2]; LastData_OtherWords = new int[SysInfo.OtherWords]; RS422_Port.DiscardInBuffer(); RS422_Port.DiscardOutBuffer(); byte[] Command = { 0x4D, 0x4B, (byte)SysInfo.OtherWords, (byte)SysInfo.TempWords, 0xFF }; RS422_Port.Write(Command, 0, Command.Length); byte[] answer = new byte[2]; RS422_Port.Read(answer, 0, 2); if ((answer[0] == 0x59) && (answer[1] == 0x00)) { AllMPIbuttonsON(); START_button.Enabled = false; STOP_button.Enabled = true; Back_button.Enabled = false; ConvertToCSV_Button.Enabled = false; if (VKGroupIsEnable) { VKGroup.Enabled = true; } if (SysInfo.RKVuse) { if (SysInfo.YCXuse) { YCXtext.BackColor = Color.GreenYellow; //масштаб УСХ } if (SysInfo.YCYuse) { YCYtext.BackColor = Color.GreenYellow; //масштаб УСY } if (SysInfo.YCZuse) { YCZtext.BackColor = Color.GreenYellow; //масштаб УСZ } } ConsoleWriter("Для прекращения работы нажмите \"СТОП\""); RS422_Port.Write(SysInfo.UsingAdressess, 0, SysInfo.UsingAdressess.Length); RS422_Port.DiscardInBuffer(); RS422_Port.DataReceived += DataReceivedHandler; if (SysInfo.WordsInPack != 0) { timer1.Start(); } } else { MPIError(answer[0], answer[1]); } }