private void Btn_Go(object sender, RoutedEventArgs e) { if (combo.SelectedItem == null) { return; } Globals.StopReadingHIstoryFile = true; //if (speed.SelectedIndex == 0) CAN_Common.HistoryReadRefreshSpeed = 0.25f; //else if (speed.SelectedIndex == 1) CAN_Common.HistoryReadRefreshSpeed = 0.5f; //else CAN_Common.HistoryReadRefreshSpeed = speed.SelectedIndex-1; Thread.Sleep(50); CAN_Common.CloseAllConnections(); Thread.Sleep(100); //CAN_Common.Instance.CmdCloseConnection.Execute(null); // vm_sciChartOsciloscope.prepareDataReceiver(); vm_sciChartOsciloscope.CmdClear.Execute(null); Thread.Sleep(100); string fileName = combo.SelectedItem.ToString(); Task.Factory.StartNew( action: () => SaveToDisk.Restore(fileName, vm_sciChartOsciloscope));//, vm_sciChartOsciloscope)); Close(); }
private void SetCommand_for_OC_Cmds(string cmdId, int idx, string description = null) { int key = Utils.MakeKey(cmdId, idx); if (description == null) { description = cmdId; } UIItem uiItem = new UIItem(cmdId, idx, true) { Description = description, CmdSend = new RelayCommand(e => { byte[] packageSet = Utils.makePacket(NodeId, cmdId, idx, false, true, dicSignals[key].ValueFloatSet.ToString()); byte[] packageGet = Utils.makePacket(NodeId, cmdId, idx, true, true, "0"); //Console.WriteLine("out:"+BitConverter.ToString(packageSet)+" key: "+key); //if(CAN_Common.Instance.CANHandle==-1)CAN_Common.Instance.CmdCANInit.Execute(null); CAN_Common.Write(packageSet); CAN_Common.Write(packageGet); }) }; dicSignals[key] = uiItem; OC_Cmds.Add(uiItem); setFloatListener(key); _keepRefreshed.Add(makeGetFloatPacket(cmdId, idx)); }
public void RefreshAll() { foreach (var entry in dicSignals) { CAN_Common.Write(entry.Value.PacketRefresh); } }
private void Set_OC_Activate_Current_Reference() { UIItemActivateCurrentReference LPF = new UIItemActivateCurrentReference("AF", -1) { Description = "LPF" }; UIItemActivateCurrentReference BSF1 = new UIItemActivateCurrentReference("AG", 1) { Description = "BSF1", myOC = OC_Activate_Current_Reference, Index = 1 }; UIItemActivateCurrentReference BSF2 = new UIItemActivateCurrentReference("AG", 2) { Description = "BSF2", myOC = OC_Activate_Current_Reference, Index = 2 }; UIItemActivateCurrentReference BSF3 = new UIItemActivateCurrentReference("AG", 3) { Description = "BSF3", myOC = OC_Activate_Current_Reference, Index = 3 }; UIItemActivateCurrentReference BSF4 = new UIItemActivateCurrentReference("AG", 4) { Description = "BSF4", myOC = OC_Activate_Current_Reference, Index = 4 }; UIItemActivateCurrentReference BSF5 = new UIItemActivateCurrentReference("AG", 5) { Description = "BSF5", myOC = OC_Activate_Current_Reference, Index = 5 }; UIItemActivateCurrentReference BSF6 = new UIItemActivateCurrentReference("AG", 6) { Description = "BSF6", myOC = OC_Activate_Current_Reference, Index = 6 }; LPF.CmdSend = new RelayCommand(e => { CAN_Common.Write(Utils.makePacket(NodeId, "AF", LPF.ValueBool ? 1 : 0, false, true, LPF.ValueFloat.ToString())); }); RelayCommand BSFCmd = new RelayCommand(e => { CAN_Common.Write(Utils.makePacket(NodeId, "AG", BSF1.ValueBool ? 1 : 0, false, true, BSF1.ValueFloat.ToString())); }); OC_Activate_Current_Reference.Add(LPF); OC_Activate_Current_Reference.Add(BSF1); OC_Activate_Current_Reference.Add(BSF2); OC_Activate_Current_Reference.Add(BSF3); OC_Activate_Current_Reference.Add(BSF4); OC_Activate_Current_Reference.Add(BSF5); OC_Activate_Current_Reference.Add(BSF6); for (int i = 1; i < 7; i++) { OC_Activate_Current_Reference[i].CmdSend = BSFCmd; } }
private void InitObservers() { Task.Factory.StartNew(action: () => { Thread.Sleep(100); AddEventHandler(Utils.MakeKey("AI", 0), s => CANStatus = RoundBoolLed.PASSED); int choice = 0; while (Active) { Thread.Sleep(100); if (CAN_Common.Instance.IsCheckingConnection) { Write("AI", 0, true, false); //Debug.WriteLine("Can Statyus {0}", _can_status); switch (_can_status) { case RoundBoolLed.IDLE: _can_status = RoundBoolLed.PASSED; continue; case RoundBoolLed.PASSED: _can_status = RoundBoolLed.DISABLED; continue; case RoundBoolLed.RUNNING: _can_status = RoundBoolLed.DISABLED; continue; case RoundBoolLed.FAILED: Thread.Sleep(200); if (_can_status == RoundBoolLed.FAILED) { CANStatus = RoundBoolLed.IDLE; CAN_Common.CloseConnection(NodeId); } continue; case RoundBoolLed.DISABLED: Write("AI", 0, true, false); Thread.Sleep(500); if (_can_status == RoundBoolLed.DISABLED) { CANStatus = RoundBoolLed.FAILED; } continue; default: continue; } } } }); }
public void AddNode(int nodeId, bool isCANInterface = true){ UC_Main uc_main; if (isCANInterface) { if (CAN_Common.Instance.dic_CanChanels.ContainsKey(nodeId)) return; uc_main = new UC_Main(nodeId) { Visibility = Visibility.Collapsed }; CAN_Common.OpenAllConnections(); } else{ CAN_Common._instance = new CAN_Common(activeInterface:Common.Consts.INTERFACE_RS232); uc_main = new UC_Main(nodeId) { Visibility = Visibility.Collapsed }; } var tb = makeButton(nodeId, uc_main); gridPresenter.Children.Add(uc_main); }
public void SetCalibration(int key, bool value) { int mask = 0; foreach (var uiItem in OC_Calibration) { if (uiItem.Key == key && value) { mask += value ? key : 0; } else { mask += uiItem.ValueBool ? uiItem.Key : 0; } } CAN_Common.Write(Utils.makePacket(NodeId, "CN", 0, false, false, mask.ToString())); }
public static void SendCCComand(int ccValue = 60, VM_SciChartOsciloscope vm_sci = null) { FrequencyManager.ccValue = (byte)ccValue; List <Tuple <VM_SciChartOsciloscope, uint> > restore = Globals.Vm_scis .Select(w => new Tuple <VM_SciChartOsciloscope, uint>(w, w.PlotTime)) .ToList(); Frequency = 1 / ((6.0 / ccValue)); foreach (var tuple in restore) { tuple.Item1.PlotTime = tuple.Item2; tuple.Item1.SynchronizeFrequency(vm_sci); } CAN_Common.WriteToAll("CC", 0, false, false, (ccValue * 3).ToString()); }
private void Btn_Open_Clicked(object sender, RoutedEventArgs e) { int nodeId = 0; try{ nodeId = Convert.ToInt32(txt_NodeId.Text.Trim()); } catch { MessageBox.Show("Not a valid number"); return; } bool sucess = false; Task.Factory.StartNew(() => { sucess = CAN_Common.OpenChannel(nodeId); }).Wait(); roundBool_openedSuccess.CurrStatus = sucess ? RoundBoolLed.PASSED : RoundBoolLed.FAILED; }
private void keepRefreshed() { Set_IO_keepRefreshed(); dicSignals.Add(MotorOnUIItem.Key, MotorOnUIItem); dicSignals.Add(TorqueRefSource.Key, TorqueRefSource); Task.Factory.StartNew(action: () => { //while (true){ // if (Active && !JustGraph){ // foreach (byte[] packet in _keepRefreshed){ // CAN_Common.Write(packet); // } // CAN_Common.Write(Utils.makePacket(NodeId, "CN", 0, true, false)); // CAN_Common.Write(Utils.makePacket(NodeId, "MO",0,true,false)); // CAN_Common.Write(Utils.makePacket(NodeId, "ZZ", 0, true, false)); // } // Thread.Sleep(REFRESH_RATE); //} while (true) { if (Active && !JustGraph) { foreach (var entry in dicSignals.Where(entry => entry.Value.AutoRefreshes)) { CAN_Common.Write(entry.Value.PacketRefresh); } } Disk_KeepRefreshed.GetKeepRefreshed(dicSignals); flagRefresh_Mcurr = true; Thread.Sleep(REFRESH_RATE); //scan keeprefreshed file for changes } }); }
public void Dispose() { CAN_Common.RemoveEventHandler(Utils.MakeKey("FT", 1), dataReceivedFT1); Globals.Vm_scis.Remove(this); OnExampleExit(); }
private VM_SciChartOsciloscope(VM_UC_Main.VM_UC_Main uc_main, int NodeId = 127) { //Create an instance of a ini file parser var parser = new FileIniDataParser(); string pathString = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Redler"; if (!System.IO.File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Redler\\Charts\\")) { // Create the subfolder. You can verify in File Explorer that you have this // structure in the C: drive. // Local Disk (C:) // Top-Level Folder // SubFolder System.IO.Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Redler\\Charts\\"); } IniData data; try { if (!System.IO.File.Exists(pathString + "\\MotorController.ini")) { // Create the subfolder. You can verify in File Explorer that you have this // structure in the C: drive. // Local Disk (C:) // Top-Level Folder // SubFolder System.IO.Directory.CreateDirectory(pathString); StreamWriter sw = System.IO.File.CreateText(pathString + "\\MotorController.ini"); pathString += "\\MotorController.ini"; // This load the INI file, reads the data contained in the fail, // and parses that data //data = parser.ReadFile("C:\\Users\\Joseph\\Documents\\Redler\\MotorController.ini"); sw.WriteLine("[GraphAdvanced]"); sw.WriteLine("Multiply = 1"); sw.WriteLine("Multiply2 = 1"); sw.WriteLine("UnderSample = 1"); sw.WriteLine("RefreshTime = 1"); sw.Close(); _multiply = 1; _multiply2 = 1; _under_sample = 1; _refreshTime = 50; INIFilePath = pathString; } } catch { } try { data = parser.ReadFile(pathString + "\\MotorController.ini"); _multiply = float.Parse(data["GraphAdvanced"]["Multiply"]); _multiply2 = float.Parse(data["GraphAdvanced"]["Multiply2"]); _under_sample = int.Parse(data["GraphAdvanced"]["UnderSample"]); if (_under_sample < 1) { _under_sample = 1; } _refreshTime = int.Parse(data["GraphAdvanced"]["RefreshTime"]); INIFilePath = pathString + "\\MotorController.ini"; } catch { } VM_UC_Main = uc_main; //RefreshTime = 55; // For chart data setup, see OnExampleEnter(), which is called by the SciChart Examples Suite CAN_Common.AddEventHandler( new Tuple <int, int>(Utils.MakeKey("AD", 0), NodeId), pck => { //int temp = Utils.getPacketInt(pck); //Multiply = temp; Multiply = _multiply; // pck.getPacketFloat(); }); //Multiply = 189; // _multiply = PersistFloat.GetValue(Consts.PERSIST_VARIABLES.MULTIPLY); //prepareDataReceiver(); OnExampleEnter(); CAN_Common.AddEventHandler(new Tuple <int, int>(Utils.MakeKey("FT", 1), NodeId), dataReceivedFT1); PlotTime = 1000; Thread.Sleep(100); PlotTime *= 2; init_DATA_RUNTIME(); }
private void Write(string Cmd, int idx, bool isGet, bool isFloat, string data = "0") { var pckt = Utils.makePacket(NodeId, Cmd, idx, isGet, isFloat, data); CAN_Common.Write(pckt); }
private void AddEventHandler(int key, Action <byte[]> action) { Tuple <int, int> tup = new Tuple <int, int>(key, NodeId); CAN_Common.AddEventHandler(tup, action); }