Exemple #1
0
    //

    private void DoDiTask(int id)
    {
        if (DiChValStp >= 99)
        {
            ResStr01 = "Failed";
            FailCnt++;
            DiChValStp = 0;
            mainTaskStp++;
        }
        else if (DiChValStp > 5 && DiChValStp < 99)
        {
            //ResStr01 = "Passed";
            mainTaskStp++;
            Thread.Sleep(50);
            DiChValStp = 0;
        }
        //else if (DiChValStp == 7)
        //{
        //    if (ReadMdsGCLflg() == 0) mainTaskStp++;
        //    else DiChValStp = 99;
        //}
        //else if (DiChValStp == 6)
        //{
        //    WriteGCLflg(0);
        //    DiChValStp++;
        //}
        else if (DiChValStp == 5) //判斷modus inter flg 4x305 =-1(65535) (FFFF)
        {
            //if (ReadMdsGCLflg() == 65535)
            //mainTaskStp++;
            //else
            //{
            //    FailCnt++;
            //    mainTaskStp++;
            //}
            //timer1.Stop();
        }
        else if (DiChValStp == 4)//Write DO to AllFalse, check 5040
        {
            //OutData03 = OutputDO(SetAllTrue.ToArray());
            GetStr04 = ADAM6KReqService.SendCmd(CmdStr04);
            string tmp1 = GetStr04.Substring(0, 3);
            //bool[] tmpApaxDi = APAX5070Service.ReadCoils(_apaxDIslot_idx, Device.DiTotal);
            bool[] tmpApaxDi = APAX5070Service.ReadCoils(65, Device.DoTotal);
            if (tmp1 == ">01")
            {
                bool[] AdamAllFalse = new bool[Device.DoTotal];
                bool   bEqual       = false;
                //比較陣列元素
                if (AdamAllFalse.Length == tmpApaxDi.Length)
                {
                    int i = 0;
                    while ((i < AdamAllFalse.Length) && AdamAllFalse[i] == tmpApaxDi[i])
                    {
                        i += 1;
                    }
                    if (i == AdamAllFalse.ToArray().Length)
                    {
                        bEqual = true;
                    }
                }
                if (bEqual)
                {
                    ResStr04 = "Passed";
                }
                else
                {
                    ResStr04 = "Failed"; FailCnt++;
                }
            }
            else
            {
                ResStr04 = "Failed"; FailCnt++;
            }
            Thread.Sleep(100);
            DiChValStp++;
            timer1.Stop();
        }
        else if (DiChValStp == 3)//Write DO to AllTrue, check 5040
        {
            //OutData03 = OutputDO(SetAllTrue.ToArray());
            GetStr03 = ADAM6KReqService.SendCmd(CmdStr03);
            string tmp1 = GetStr03.Substring(0, 3);
            //bool[] tmpApaxDi = APAX5070Service.ReadCoils(_apaxDIslot_idx, Device.DiTotal);
            bool[] tmpApaxDi = APAX5070Service.ReadCoils(65, Device.DoTotal);

            //byte[] byteArray = System.Text.Encoding.ASCII.GetBytes ( str );
            //string str = System.Text.Encoding.Default.GetString ( tmpApaxDi );
            string st = "";
            foreach (bool t in tmpApaxDi)
            {
                st += Convert.ToByte(t).ToString();
            }
            int intNum = Convert.ToInt32(st, 2);
            OutData03 = intNum;
            //string strHex = Convert.ToString(intNum, 16);
            //OutData03 = Convert.ToInt32(strHex);
            if (tmp1 == ">01")
            {
                List <bool> AdamAllTrue = new List <bool>();
                for (int i = 0; i < Device.DoTotal; i++)
                {
                    AdamAllTrue.Add(true);
                }
                bool bEqual = false;
                //比較陣列元素
                if (AdamAllTrue.ToArray().Length == tmpApaxDi.Length)
                {
                    int i = 0;
                    while ((i < AdamAllTrue.ToArray().Length) && AdamAllTrue.ToArray()[i] == tmpApaxDi[i])
                    {
                        i += 1;
                    }
                    if (i == AdamAllTrue.ToArray().Length)
                    {
                        bEqual = true;
                    }
                }
                if (bEqual)
                {
                    ResStr03 = "Passed";
                }
                else
                {
                    ResStr03 = "Failed"; FailCnt++;
                }
            }
            else
            {
                ResStr03 = "Failed"; FailCnt++;
            }
            Thread.Sleep(100);
            DiChValStp++;
            //timer1.Stop();
        }

        else if (DiChValStp == 2)//SendCmd("$01F"); //Read DI value when setAllTrue
        {
            List <bool> SetAllTrue = new List <bool>();
            for (int i = 0; i < Device.DiTotal; i++)
            {
                SetAllTrue.Add(true);
            }
            //OutData02 = OutputDO(SetAllTrue.ToArray());
            GetStr02 = ADAM6KReqService.SendCmd(CmdStr02);
            string tmp1 = GetStr02.Substring(0, 3);
            string tmp2 = GetStr02.Substring(4, 4);
            switch (Device.ModuleType)
            {
            case "Adam6050":
                if (tmp1 == "!01" && tmp2 == "0FFF")
                {
                    ResStr02 = "Passed";
                }
                else
                {
                    ResStr02 = "Failed"; FailCnt++;
                }
                break;

            case "Adam6051":
                if (tmp1 == "!01" && tmp2 == "0FFF")
                {
                    ResStr02 = "Passed";
                }
                else
                {
                    ResStr02 = "Failed"; FailCnt++;
                }
                break;

            case "Adam6052":
                if (tmp1 == "!01" && tmp2 == "00FF")
                {
                    ResStr02 = "Passed";
                }
                else
                {
                    ResStr02 = "Failed"; FailCnt++;
                }
                break;

            case "Adam6060":
                if (tmp1 == "!01" && tmp2 == "003F")
                {
                    ResStr02 = "Passed";
                }
                else
                {
                    ResStr02 = "Failed"; FailCnt++;
                }
                break;

            case "Adam6066":
                if (tmp1 == "!01" && tmp2 == "003F")
                {
                    ResStr02 = "Passed";
                }
                else
                {
                    ResStr02 = "Failed"; FailCnt++;
                }
                break;
            }
            Thread.Sleep(100);
            bool[] tmp = new bool[Device.DiTotal];
            OutputDO(tmp); // set 5046 Do to all false
            DiChValStp++;
        }

        else if (DiChValStp == 1)//CmdStr01 = "$016"; //Read DI value when setAllFalse
        {
            OutData01 = 0;
            GetStr01  = ADAM6KReqService.SendCmd(CmdStr01);
            string tmp1 = GetStr01.Substring(0, 3);
            string tmp2 = GetStr01.Substring(4, 4);
            if (tmp1 == "!01" && tmp2 == "0000")
            {
                ResStr01 = "Passed";
            }
            else
            {
                ResStr01 = "Failed"; FailCnt++;
            }
            //string[] tmpStr = GetStr01.Split(new char[2] { '!', '\r' });
            Thread.Sleep(100);
            DiChValStp++;
        }
        else if (DiChValStp == 0)//initial
        {
            bool[] SetAllFalse = new bool[Device.DiTotal];
            ResStr01 = ResStr01 = ResStr02 = ResStr03 = "";
            //set to DI-mode and invser enable
            ADAM6KReqService.SetDIO_DefaultMod(); //atuo refresh
            OutputDO(SetAllFalse);                //initail APAX Do out 0
            DiChValStp++;
        }
    }
Exemple #2
0
    //

    private void DoDiTask(int id)
    {
        if (DiChValStp >= 99)
        {
            ResStr01 = "Failed";
            FailCnt++;
            DiChValStp = 0;
            mainTaskStp++;
        }
        else if (DiChValStp > 5 && DiChValStp < 99)
        {
            //ResStr01 = "Passed";
            mainTaskStp++;
            Thread.Sleep(50);
            DiChValStp = 0;
        }
        //else if (DiChValStp == 7)
        //{
        //    if (ReadMdsGCLflg() == 0) mainTaskStp++;
        //    else DiChValStp = 99;
        //}
        //else if (DiChValStp == 6)
        //{
        //    WriteGCLflg(0);
        //    DiChValStp++;
        //}
        else if (DiChValStp == 5) //判斷modus inter flg 4x305 =-1(65535) (FFFF)
        {
            if (ReadMdsGCLflg() == 65535)
            {
                mainTaskStp++;
            }
            else
            {
                FailCnt++;
                mainTaskStp++;
            }
            //timer1.Stop();
        }
        else if (DiChValStp == 4)//Check $01Vd 的值是正確的
        {
            GetStr04 = ADAM6KReqService.SendCmd(CmdStr04);
            if (GetStr04 == ExStr04)
            {
                ResStr04 = "Passed";
            }
            else
            {
                ResStr04 = "Failed"; FailCnt++;
            }
            Thread.Sleep(100);
            DiChValStp++;
            //timer1.Stop();
        }
        else if (DiChValStp == 3)//This command sets all GCL internal flags values.
        {
            GetStr03 = ADAM6KReqService.SendCmd(CmdStr03);
            string[] tmpStr = GetStr03.Split(new char[1] {
                ' '
            });
            if (tmpStr[0] == ">01\r")
            {
                ResStr03 = "Passed";
            }
            else
            {
                ResStr03 = "Failed"; FailCnt++;
            }
            Thread.Sleep(100);
            DiChValStp++;
        }

        else if (DiChValStp == 2)//SendCmd("$01F"); //Read Firmware Version
        {
            GetStr02 = ADAM6KReqService.SendCmd(CmdStr02);
            string[] tmpStr = GetStr02.Split(new char[2] {
                ' ', '.'
            });
            if (tmpStr[0] == "!01" || tmpStr[1] == "5")
            {
                ResStr02 = "Passed";
            }
            else
            {
                ResStr02 = "Failed"; FailCnt++;
            }
            Thread.Sleep(100);

            DiChValStp++;
        }
        else if (DiChValStp == 1)//CmdStr01= "$01M"; //Read Module Name
        {
            GetStr01 = ADAM6KReqService.SendCmd(CmdStr01);
            if (GetStr01 == ExStr01)
            {
                ResStr01 = "Passed";
            }
            else
            {
                ResStr04 = "Failed"; FailCnt++;
            }
            Thread.Sleep(100);
            DiChValStp++;
        }
        else if (DiChValStp == 0)//initial
        {
            ResStr01 = ResStr01 = ResStr02 = ResStr03 = "";
            Thread.Sleep(50);
            //OutData01 = OutputDO(0); //initail APAX Do out 0
            DiChValStp++;
        }
    }