Esempio n. 1
0
 public void AddNode(SubNode node)
 {
     if (node is WeighNode)
     {
         weight_node.Add(node as WeighNode);
     }
     if (node is VibrateNode)
     {
         vib_node = node as VibrateNode;
     }
     if (node is BottomPackNode)
     {
         pack_node = node as BottomPackNode;
     }
 }
Esempio n. 2
0
        public void KbdData(string param, string data)
        {
            App      p   = Application.Current as App;
            XElement cfg = p.curr_cfg;

            if (param == "entersys")
            {
                if (Password.compare_pwd("admin", data))
                {
                    Process app = new Process();
                    app.StartInfo.FileName  = "Explorer.exe";
                    app.StartInfo.Arguments = "";
                    app.Start();
                    Thread.Sleep(2000);
                    Type   shellType   = Type.GetTypeFromProgID("Shell.Application");
                    object shellObject = System.Activator.CreateInstance(shellType);
                    shellType.InvokeMember("ToggleDesktop", System.Reflection.BindingFlags.InvokeMethod, null, shellObject, null);
                }
                return;
            }
            if (param == "quitlock")
            {
                if (Password.compare_pwd("lock", data))
                {
                    b_lockon = false;
                    Password.set_pwd("lock", "0");
                    b_lockon = false;
                    (Application.Current as App).runwnd.Disable(Visibility.Visible);
                    (Application.Current as App).singlewnd.Disable(Visibility.Visible);
                    UpdateDisplay(true);
                }
            }
            if (param == "enterlock")
            {
                //App should expire after desired packer number reached , data is the actual packer count
                Password.set_pwd("lock_on", data);
                DeleteRegist("lock_on");
                WTRegedit("lock_on", data);
                Password.set_pwd("lock", data);
                p.SaveAppConfig();
                b_lockon = true;
                UpdateDisplay(false);
            }
            if (param.IndexOf("reg_") == 0)
            {
                Button  btn;
                SubNode n = null;
                if (curr_sel == -1)
                {
                    return;
                }
                Byte i = Convert.ToByte(curr_sel);

                if (i < 17)
                {
                    btn = IdToButton(i.ToString());
                    n   = p.agent[i];
                }
                else
                {
                    btn = IdToButton("36");
                    n   = p.agent.missingnode;
                }
                if (n["addr"] != null)
                {
                    param    = param.Remove(0, 4);
                    n[param] = UInt32.Parse(data);
                    Thread.Sleep(1000);


                    btn_refreshreg_Click(null, null);
                }
            }
            if (param.IndexOf("chgnd_") == 0)
            {
                Byte oldaddr = Byte.Parse(param.Remove(0, 6));
                Byte newaddr = Byte.Parse(data);

                Button btn = IdToButton(newaddr.ToString());
                if (btn != null && newaddr < 36) //valid new address
                {
                    if (btn.Visibility != Visibility.Visible)
                    {
                        SubNode oldn;
                        SubNode newn;
                        if (oldaddr == 36)
                        {
                            oldn = p.agent.missingnode;
                        }
                        else
                        {
                            oldn = p.agent[oldaddr];
                        }
                        newn                   = p.agent[newaddr];
                        newaddr               += 0xC0;
                        newn.status            = NodeStatus.ST_IDLE;
                        oldn["test_mode_reg2"] = newaddr;

                        Thread.Sleep(500);
                        newn.status  = NodeStatus.ST_IDLE;
                        newn["addr"] = null;
                        oldn.status  = NodeStatus.ST_LOST;
                        Thread.Sleep(100);
                        if (newn["addr"].HasValue)
                        {
                            MessageBox.Show(StringResource.str("change_addr_success"));
                            return;
                        }
                    }
                }

                MessageBox.Show(StringResource.str("change_addr_fail"));
            }
            if (param != "cali0" && (param.IndexOf("cali") == 0)) //cali1 to cali10
            {
                string msg = StringResource.str("put_poise") + "(" + data + StringResource.str("gram") + ")";

                if (MessageBox.Show(msg, "", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
                {
                    return;
                }
                NodeAgent n = p.agent;
                int       i = RunMode.StringToId(param) - 1;
                if (curr_sel >= 0)
                {
                    n.ClearNodeReg((byte)curr_sel, "cs_mtrl");
                    string cs_mtrl_val = n.GetNodeReg((byte)curr_sel, "cs_mtrl");
                    UInt32 val;
                    if (UInt32.TryParse(cs_mtrl_val, out val))
                    {
                        if (val <= WeighNode.MAX_VALID_WEIGHT)
                        {
                            if (i < 5)
                            {
                                n.SetNodeReg((byte)curr_sel, "poise_weight_gram" + i.ToString(), UInt32.Parse(cs_mtrl_val));
                            }
                            else
                            {
                                n.SetNodeReg((byte)curr_sel, "cs_poise" + (i - 5).ToString(), UInt32.Parse(cs_mtrl_val));
                            }
                            n.Action((byte)curr_sel, "flash");
                            MessageBox.Show(StringResource.str("calidone"));
                            label3_MouseLeftButtonUp(null, null);
                            return;
                        }
                    }
                    MessageBox.Show(StringResource.str("tryagain"));
                }
                return;
            }
        }
Esempio n. 3
0
 public bootloader(SubNode n)
 {
     node = n;
 }
Esempio n. 4
0
        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

            
        }
Esempio n. 5
0
        //called only by single command action ,such as trigger packer or release
        public bool WaitUntilFlagSent(SubNode n)
        {
            if (IsDebug)
                return true;
            string reg = "flag_cnt";
            Thread.Sleep(5);
            n[reg] = null;
            WaitForIdleQuick(n,8);
            if (n[reg].HasValue)
            {
                 uint lw_lb = n[reg].Value % 256;
                 if ((lw_lb) != n.flag_cnt)
                 {
                    n.flag_cnt = lw_lb;
                    return true;
                 }
            }
            Debug.Write("lost" + n.node_id);
//          n.status = NodeStatus.ST_LOST;
            return false;
        }
Esempio n. 6
0
 private bool WaitForIdleQuick(SubNode n, int to)
 {
     int i = 2;
     //int j = 0;
     while (n.status == NodeStatus.ST_BUSY)
     {
         Thread.Sleep(2);
         //i = i + (i + 1) / 2; //8,12,18,28,42,64,96,
         if (i++ > to*5)
         {
             return false;
         }
     }
     return true;
 }
Esempio n. 7
0
 private bool WaitForIdleSlow(SubNode n)
 {
     int i = 2;
     //int j = 0;
     while (n.status == NodeStatus.ST_BUSY)
     {
         Thread.Sleep(10);
         //i = i + (i + 1) / 2; //8,12,18,28,42,64,96,
         if (i++ > 30)
         {
             return false;
         }
     }
     return true;
 }
Esempio n. 8
0
 /*
  * wait until the read command is responded
  */
 private bool WaitForIdle(SubNode n)
 {
     int i = 2;
     //int j = 0;
     while (n.status == NodeStatus.ST_BUSY)
     {
         Thread.Sleep(5);
         //i = i + (i+1)/2;
         if (i++ > 190)
         {
                 return false;
         }else
         {
             if(i % 60 == 59)
                 n.ResendCommand();
         }
     }
     return true;
 }
Esempio n. 9
0
        //called only by programming and calibration
        public bool WaitUntilGetValue(SubNode n, string regname, UInt32 val) //until means if timeout happens, node will be set to lost
        {
            int i = 5;
            int j = 0;

            if (n.status == NodeStatus.ST_LOST)
                return false;

            if (n.status == NodeStatus.ST_DISABLED)
                return false;

            n[regname] = null;
            Thread.Sleep(12);

            
            while (WaitForIdleQuick(n,8))
            {
                if (n[regname].HasValue && n[regname].Value == val)
                {
                    return true;
                }
                Thread.Sleep(10);
                i = i * 2;
                j = j + 1;
                if (j > 240)
                {
                    n.status = NodeStatus.ST_LOST;
                    return false;
                }
                if(j % 40 == 39)
                    n[regname] = null; //ask for value again
            }
            return false;
        }
Esempio n. 10
0
        private void DoRelease(SubNode[] addrs, double weight)
        {
            foreach (SubNode n in addrs)
            {
                n.Action("release",false);
            }
            //todo update the display;

            onepack o = new onepack();
            o.bucket = new byte[5];
            o.bucket[1] = o.bucket[2] = o.bucket[3] = o.bucket[4] = o.bucket[0] = (byte)0;
            int i = 0;
            foreach (SubNode n in addrs)
            {
                o.bucket[i++] = (byte)n["addr"].Value;
                o.time = DateTime.Now;
            }

            o.weight = weight;
            ProdHistory.AddNewPack(o,(Application.Current as App).bSimulate);
            
        }
Esempio n. 11
0
 public bootloader(SubNode n)
 {
     node = n;
 }