Exemplo n.º 1
0
        public bool Connect(short nDevNo, short nIP1, short nIP2, short nIP3, int num)
        {
            bool flag = false;

            TdWatchDIO = new Thread(new ThreadStart(DoWatch));

            short nRet;

            try
            {
                nRet = NMF.nmf_PingCheck(nDevNo, nIP1, nIP2, nIP3, 200);
                if (nRet != 0)
                {
                    return(flag);
                }

                nRet = NMF.nmf_Connect(nDevNo, nIP1, nIP2, nIP3);
                if (nRet == 0)
                {
                    m_bDevConnect = true;
                    switch (TdWatchDIO.ThreadState)
                    {
                    case ThreadState.Stopped:
                        TdWatchDIO = new Thread(new ThreadStart(DoWatch));
                        break;

                    case ThreadState.Unstarted:
                        break;

                    default:
                        TdWatchDIO.Abort();
                        // TdWatchSensor.Join();
                        while (TdWatchDIO.ThreadState != ThreadState.Stopped)
                        {
                        }
                        break;
                    }
                    TdWatchDIO.Start();
                    flag = true;
                }
            }
            catch (Exception ex)
            {
            }
            return(flag);
        }