예제 #1
0
        /// <summary>
        /// 获取控制器状态
        /// </summary>
        private int 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)
                {
                    //写日志
                    MonitorLog monitorLog = MonitorLog.NewMonitorLog();
                    monitorLog.LOGNAME     = "设备初始化";
                    monitorLog.LOGINFO     = "电子标签串口路由ID:" + GWID[i] + " 连接成功, 状态 :" + ret;
                    monitorLog.LOGLOCATION = "设备";
                    monitorLog.LOGTYPE     = 0;
                    monitorLog.Save();
                    return(1);
                }
                else
                {
                    MessageBox.Show("电子标签串口路由ID:" + GWID[i] + " 连接失败, 状态 :" + ret);
                    //写日志
                    MonitorLog monitorLog = MonitorLog.NewMonitorLog();
                    monitorLog.LOGNAME     = "设备初始化";
                    monitorLog.LOGINFO     = "电子标签串口路由ID:" + GWID[i] + " 连接失败, 状态 :" + ret;
                    monitorLog.LOGLOCATION = "设备";
                    monitorLog.LOGTYPE     = 0;
                    monitorLog.Save();
                }
            }
            return(0);
        }
예제 #2
0
        /// <summary>
        /// 控制器打开
        /// </summary>
        /// <returns></returns>
        private int Dap_Open()
        {
            int posspace, postab, pos;

            //txAddrList.Clear();

            GWCount = 0;
            if (!System.IO.File.Exists("IPINDEX"))
            {
                MessageBox.Show("串口路由地址文件不存在!");
                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("串口路由地址文件格式错误!");
                            return(-1);
                        }

                        //txAddrList.AppendText(line + "\r\n");

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

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


            //写日志
            MonitorLog monitorLog = MonitorLog.NewMonitorLog();

            monitorLog.LOGNAME     = "设备初始化";
            monitorLog.LOGINFO     = "初始化串口API成功";
            monitorLog.LOGLOCATION = "设备";
            monitorLog.LOGTYPE     = 0;
            monitorLog.Save();

            //ShowMsg("API Open Success!");

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

            return(1);
        }