コード例 #1
0
        /// <summary>
        /// 获取控制器状态
        /// </summary>
        private void GetGWStatus()
        {
            bool bGoOn;
            int  ret, timeStart;

            for (int i = 0; i < GWCount; i++)
            {
                Dapapi.AB_GW_Open(GWID[i]);
                ret = Dapapi.AB_GW_Status(GWID[i]);

                if (ret != 7)
                {
                    bGoOn     = true;
                    timeStart = System.Environment.TickCount;
                    while (bGoOn)
                    {
                        ret = Dapapi.AB_GW_Status(GWID[i]);
                        if (ret == 7)
                        {
                            bGoOn = false;
                        }
                        else if (System.Environment.TickCount - timeStart > 3000)
                        {
                            bGoOn = false;
                        }
                    }
                }

                if (ret == 7)
                {
                    this.tb_msg.Text += "\r\n Gateway ID:" + GWID[i] + " success connected, status return :" + ret;
                }
                else
                {
                    this.tb_msg.Text += "\r\n Gateway ID:" + GWID[i] + " failed to connected, status return :" + ret;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// 控制器打开
        /// </summary>
        /// <returns></returns>
        private int Dap_Open(string name, string IP)
        {
            int posspace, postab, pos;

            tb_Addrlist.Clear();

            GWCount = 0;
            if (!System.IO.File.Exists(name))
            {
                MessageBox.Show("JSON文件不存在!");
                return(-1);
            }
            try
            {
                using (System.IO.StreamReader sr = new System.IO.StreamReader(name))
                {
                    String line;
                    // Read and display lines from the file until the end of
                    // the file is reached.
                    //StreamReader file = File.OpenText("IPindex.json");
                    //JsonTextReader reader = new JsonTextReader(file);
                    //JObject jsonObject = (JObject)JToken.ReadFrom(reader);
                    //line = (string)jsonObject["IP"];
                    //file.Close();
                    line = IP;

                    //while ((line = sr.ReadLine()) != null)
                    if (line != null)
                    {
                        GWCount++;
                        posspace = line.IndexOf(" ");     //find space
                        postab   = line.IndexOf((char)9); //find tab

                        if (posspace <= 0)
                        {
                            posspace = postab;
                        }
                        if (postab <= 0)
                        {
                            postab = posspace;
                        }
                        pos = System.Math.Min(posspace, postab);
                        if (pos <= 0)
                        {
                            MessageBox.Show("JSON格式错误!");
                            return(-1);
                        }

                        tb_Addrlist.AppendText(line + "\r\n");

                        GWID[GWCount - 1] = int.Parse(line.Substring(0, pos));
                        diagnosis[GWCount - 1].Init(2);
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("读取文件JSON失败!" + e.Message);
                return(-1);
            }

            if (APIOpen() < 0)
            {
                MessageBox.Show("初始化API失败!");
                return(-1);
            }

            MessageBox.Show("API Open Success!");

            for (int i = 0; i < GWCount; i++)
            {
                if (Dapapi.AB_GW_Open(GWID[i]) < 0)
                {
                    MessageBox.Show("控制器'" + GWID[i] + "'打开失败!");
                }
            }

            return(1);
        }
コード例 #3
0
        /// <summary>
        /// 控制器打开
        /// </summary>
        /// <returns></returns>
        private int Dap_Open()
        {
            int posspace, postab, pos;

            tb_Addrlist.Clear();

            GWCount = 0;
            if (!System.IO.File.Exists("IPINDEX"))
            {
                MessageBox.Show("文件IPINDEX不存在!");
                return(-1);
            }
            try
            {
                using (System.IO.StreamReader sr = new System.IO.StreamReader("IPINDEX"))
                {
                    String line;
                    // Read and display lines from the file until the end of
                    // the file is reached.
                    while ((line = sr.ReadLine()) != null)
                    {
                        GWCount++;
                        posspace = line.IndexOf(" ");     //find space
                        postab   = line.IndexOf((char)9); //find tab

                        if (posspace <= 0)
                        {
                            posspace = postab;
                        }
                        if (postab <= 0)
                        {
                            postab = posspace;
                        }
                        pos = System.Math.Min(posspace, postab);
                        if (pos <= 0)
                        {
                            MessageBox.Show("IPINDEX格式错误!");
                            return(-1);
                        }

                        tb_Addrlist.AppendText(line + "\r\n");

                        GWID[GWCount - 1] = int.Parse(line.Substring(0, pos));
                        diagnosis[GWCount - 1].Init(2);
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("读取文件IPINDEX失败!" + e.Message);
                return(-1);
            }

            if (APIOpen() < 0)
            {
                MessageBox.Show("初始化API失败!");
                return(-1);
            }

            MessageBox.Show("API Open Success!");

            for (int i = 0; i < GWCount; i++)
            {
                if (Dapapi.AB_GW_Open(GWID[i]) < 0)
                {
                    MessageBox.Show("控制器'" + GWID[i] + "'打开失败!");
                }
            }

            return(1);
        }