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; } }
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())); }
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 } }); }
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); }