public App() { System.Diagnostics.Process[] pses = System.Diagnostics.Process.GetProcessesByName("ioex-cs"); if (pses.Length > 0) { // System.Diagnostics.Process.GetCurrentProcess().Kill(); // return; } if (Environment.CommandLine.IndexOf("/debug") > 0) NodeAgent.IsDebug = true; StringResource.SetLanguage(); //app_cfg = new XmlConfig(ProdNum.baseDir +"\\app_config.xml"); app_cfg = new SqlConfig("app"); app_cfg.LoadConfigFromFile(); curr_cfg = app_cfg.Current; agent = new NodeAgent(); packers = new List<UIPacker>(); for (int i = 0; i < Int32.Parse(curr_cfg.Element("machine_number").Value); i++) { UIPacker p = new UIPacker(i, agent); p.agent = agent; p.InitConfig(); packers.Add(p); } singlewnd = new SingleMode(Int32.Parse(curr_cfg.Element("node_number").Value)); runwnd = new RunMode(Int32.Parse(curr_cfg.Element("node_number").Value)); histwnd = new ProdHistory(); helpwnd = new Help(); kbdwnd = new kbd(); bottomwnd = new BottomWnd(); alertwnd = new AlertWnd(); alertwnd.UpdateUI(); //load alert configuration which is in app_config.xml too pwdwnd = new PwdWnd(); engwnd = new EngConfigWnd(); configwnd = new ConfigMenuWnd(); prodwnd = new ProdWnd(); prodnum = new ProdNum(); }
//load all the configuration and update the UI, //packer and sub node will share the same configuration name public void LoadPackConfig(string cfgname,bool init) { if (status == PackerStatus.RUNNING) return; pkg_confs.LoadConfig(cfgname); _curr_cfg.FromElement(pkg_confs.Current); foreach (byte n in weight_nodes) { if(init) { nodes_config[n] = new SqlConfig("node" + n);//new XmlConfig(ProdNum.baseDir + "\\node_" + n + ".xml"); nodes_config[n].LoadConfigFromFile(); } nodes_config[n].LoadConfig(cfgname); } if (!nodes_config.ContainsKey(vib_addr)) { if (init) { nodes_config[vib_addr] = new SqlConfig("node" + vib_addr);//new XmlConfig(ProdNum.baseDir + "\\node_" + vib_addr + ".xml"); nodes_config[vib_addr].LoadConfigFromFile(); } nodes_config[vib_addr].LoadConfig(cfgname); } if (!nodes_config.ContainsKey(bot_addr)) { if (init) { nodes_config[bot_addr] = new SqlConfig("node" + bot_addr);//new XmlConfig(ProdNum.baseDir + "\\node_" + bot_addr + ".xml"); nodes_config[bot_addr].LoadConfigFromFile(); } nodes_config[bot_addr].LoadConfig(cfgname); } //download the configuration of node settings foreach (string reg in new string[] { "magnet_freq", "magnet_amp", "magnet_time", "target_weight", "cs_filter" }) { try { agent.SetNodeReg(vib_addr, reg, UInt32.Parse(nodes_config[vib_addr].Current.Element(reg).Value)); }catch{ } } if (bot_addr != vib_addr) { foreach (string reg in new string[] { "magnet_freq", "magnet_amp", "magnet_time", "target_weight", "cs_filter" }) { try { agent.SetNodeReg(bot_addr, reg, UInt32.Parse(nodes_config[bot_addr].Current.Element(reg).Value)); } catch { } } } foreach (byte n in weight_nodes) { foreach (string reg in new string[] { "magnet_freq", "magnet_amp", "magnet_time", "motor_speed", "cs_filter", "cs_gain_wordrate", "delay_f", "delay_w", "delay_s", "open_s", "open_w", "target_weight"}) { try { agent.SetNodeReg(n, reg, UInt32.Parse(nodes_config[n].Current.Element(reg).Value)); }catch{ } } } }
public UIPacker(int pack_id,NodeAgent nagent) { agent = nagent; vib_addr = 0xff; bot_addr = 0xff; _pack_id = pack_id; status = PackerStatus.IDLE; weight_nodes = new List<byte>(); nodes_config = new Dictionary<byte, SqlConfig>(); pkg_confs = new SqlConfig("pack" + pack_id.ToString()); pkg_confs.LoadConfigFromFile(); _curr_cfg = new PackerConfig(); packhist = new Queue<onepack>(); }
private void LoadConfiguration() { //load current configuration //XmlConfig app_cfg = new XmlConfig(ProdNum.baseDir + "\\app_config.xml"); SqlConfig app_cfg = new SqlConfig("app"); app_cfg.LoadConfigFromFile(); XElement def_cfg = app_cfg.Current; Int32 baudrate = Int32.Parse(def_cfg.Element("baudrate").Value); string parity = def_cfg.Element("parity").Value.ToLower(); string[] ser_ports = def_cfg.Element("totalports").Value.ToString().Split(new char[] { ',' }); string[] node_addrs = def_cfg.Element("totalnodes").Value.ToString().Split(new char[] { ',' }); VAR_RANGE = Double.Parse(def_cfg.Element("var_range").Value); LASTCOMB_NUM = UInt32.Parse(def_cfg.Element("lastcomb_num").Value); MSDELAY = UInt32.Parse(def_cfg.Element("msdelay").Value); //create all serial ports foreach (string port in ser_ports) { if (parity == "even") allports.Add(new SPort(port, baudrate, Parity.Even, 8, StopBits.One)); else if (parity == "odd") allports.Add(new SPort(port, baudrate, Parity.Odd, 8, StopBits.One)); else allports.Add(new SPort(port, baudrate, Parity.None, 8, StopBits.One)); } foreach (SPort sp in allports) { if (!sp.Open()) { MessageBox.Show("Failed to open the port"); throw new Exception("Failed to open the port"); } } //create all nodes foreach (string node in node_addrs) { string type = def_cfg.Element("node_type" + node).Value; string com = def_cfg.Element("node_com" + node).Value; if (type == "weight") { nodemap[byte.Parse(node)] = new WeighNode(allports[byte.Parse(com)], byte.Parse(node)); lastrelease[byte.Parse(node)] = DateTime.Now; weight_nodes.Add(nodemap[byte.Parse(node)] as WeighNode); } if (type == "vibrate") { nodemap[byte.Parse(node)] = new VibrateNode(allports[byte.Parse(com)], byte.Parse(node)); } } missingnode = new WeighNode(allports[0], byte.Parse(def_cfg.Element("def_addr").Value)); //36 is the default address of unassigned address board }
static Password() { //load password.xml and fill in the username list //pwds = new XmlConfig("password.xml"); pwds = new SqlConfig("password"); pwds.LoadConfigFromFile(); //string a = MD5Value("0106C2255SJ 8GB", true); //"0106C2255SJ 8GB" //"" }