예제 #1
0
        private int Send(byte[] dat, int len, byte[] rev, int revlen)
        {
            HiPerfTimer ht = new HiPerfTimer();
            double sdTime = 0.3125 * len - 0.255;
            ht.Start();
            SP.Write(wrBuf, 0, len);
            while (ht.DurationInMs < sdTime) ;

            RevStatus = true;

            ht.Start();
            if (revlen > 0)
            {
                Boolean flag = true;
                while (SP.BytesToRead < revlen && flag)
                {
                    if (ht.DurationInMs > SPData.timeOut) flag = false;
                }
                int num = SP.BytesToRead;
                int m = SP.Read(rev, 0, num);
                RevStatus = false;
                return m;
            }
            else
            {
                RevStatus = false;
                return 0;
            }
        }
예제 #2
0
        //private
        private void PowerOn()
        {
            HiPerfTimer ht = new HiPerfTimer();
            double tt;
            double xx;
            InitPort();
            if (SP.IsOpen) SP.Close();
            SP.Open();

            RevStatus = true;
            int num = 5;
            for (int i = 0; i < num; i++)
            {
                  Boolean fb = false;
                  DataForceZero = fb;
                  RevStatus = !fb;
                  ht.Start();
                  tt = SPData.wave[i].time;
                  string ss = "Output ";
                  ss += (SPData.wave[i].VS == 0) ? "Low" : "High";
                  ss += " Time:" + SPData.wave[i].time.ToString() + "mS";
                  xx = ht.DurationInMs;
                  while (xx < tt) { xx = ht.DurationInMs; }
            }

            DataForceZero = false;
            RevStatus = false;
            wrBuf[0] = 0x53;
            wrBuf[1] = 0xAC;
            wrBuf[2] = 0x00;
            ht.Start();
            int dNum = Send(wrBuf, 2, rdBuf, 4);
            while (ht.DurationInMs < SPData.poSegTime) ;

            for (int i = 0; i < 5; i++)
            {
                wrBuf[0] = 0x4a;
                wrBuf[1] = 0xC0;
                wrBuf[2] = 0x00;
                wrBuf[3] = 0x00;
                wrBuf[4] = 0x00;
                wrBuf[5] = GetJYZ(wrBuf, 5);
                ht.Start();
                dNum = Send(wrBuf, 6, rdBuf, 7);
                while (ht.DurationInMs < SPData.segTime) ;
            }

            while (isRun)
            {
                wrBuf[0] = 0x4a;
                byte kk = KeyStatus;
                wrBuf[1] = kk;
                wrBuf[2] = 0x00;
                if (kk != 0x00)
                {
                    wrBuf[3] = 0x00;
                    wrBuf[4] = 0x00;
                }
                else
                {
                    wrBuf[3] = ForBackSpeed;
                    wrBuf[4] = LeftRightSpeed;
                }

                wrBuf[5] = GetJYZ(wrBuf, 5);
                ht.Start();
                dNum = Send(wrBuf, 6, rdBuf, 7);
                GetStatus(rdBuf, 6, dNum);
                while (ht.DurationInMs < SPData.segTime) ;
            }
            SP.Close();
        }