Пример #1
0
        public static void Opening_Check(ref Dictionary <string, object> SendMessage, ref Dictionary <string, object> MainResultArray, ref string SendString, string GroupName, ref int ExcelStepCounter, ref int TotalStepCount, ref ISheet sheet, ref int SocketDataCheck, ref string halfSocketRemark)
        {
            FuncClass.IdsStatus();
            SendMessage.Add("SavePath", dll_PublicFuntion.Folder.ToolPath + "IDSNowImage.png");
            try { SendString = dll_PublicFuntion.Other.DictionaryToXml(SendMessage); } catch { }
            FuncClass.IDS_Check(SendMessage, ref MainResultArray, false);

            if (!File.Exists((string)SendMessage["SavePath"]))
            {
                MainResultArray[Parameters.Status] = "Fail";
                MainResultArray[Parameters.Remark] = "IDS connect error.";
            }
            // Parameter => IconName / PicturePath
            Dictionary <string, object> FDic = new Dictionary <string, object>();

            try { FDic = dll_PublicFuntion.Other.XmlToDictionary(SendMessage[Parameters.Parameter].ToString()); } catch { }

            // Picture comparison
            if (File.Exists((string)SendMessage["SavePath"]))
            {
                Image FullScreen = FuncClass.OperateImage((string)SendMessage["SavePath"]);

                Image SmallPic = FuncClass.OperateImage((string)FDic["PicturePath"]);

                dll_opencv.OpenCV openCV = new dll_opencv.OpenCV();
                openCV.SourceLoadImage(FullScreen);
                openCV.SourceToGray();
                openCV.MatchLoadImage(SmallPic);
                openCV.MatchToGray();
                dll_opencv.OpenCV.MatchDataList matchDataList = openCV.GetMatchPos(Parameters.Confidential, false);

                double resultConfident = matchDataList.MaxConfidencevalue;
                Thread.Sleep(50);
                // Delete NowImage in case of wrong time
                FuncClass.FileDelete(dll_PublicFuntion.Folder.ToolPath + "IDSNowImage.png");
                if (resultConfident < Parameters.Confidential)
                {
                    MainResultArray[Parameters.Status] = "Pass";
                    MainResultArray[Parameters.Remark] = "Didn't find the title icon.";
                }
                else
                {
                    bool socketResult = false;
                    MainResultArray[Parameters.Status] = "Pass";
                    do
                    {
                        SendMessage[Parameters.Behavior] = Behavior.Send_Enter;
                        // Send to server
                        main.ConnectNet(dll_PublicFuntion.Other.DictionaryToXml(SendMessage), TotalStepCount, sheet, GroupName, ExcelStepCounter, ref socketResult, Behavior.Send_Enter);
                        dll_PublicFuntion.Other.Wait(1.5);
                    } while (SocketDataCheck == 1);

                    if (socketResult == false)
                    {
                        MainResultArray[Parameters.Status] = "Fail";
                        MainResultArray[Parameters.Remark] = halfSocketRemark;
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// LED 燈色檢查
        /// </summary>
        /// <param name="SendMessage"></param>
        /// <param name="MainResultArray"></param>
        /// <param name="SendString"></param>
        public static void LED_Check(ref Dictionary <string, object> SendMessage, ref Dictionary <string, object> MainResultArray, ref string SendString)
        {
            string   str     = Application.StartupPath + @"\IDSData\LedData";
            DateTime timeNow = DateTime.Now;

            if (!Directory.Exists(str))
            {
                Directory.CreateDirectory(str);
            }

            FuncClass.IdsStatus();
            SendMessage.Add("SavePath", dll_PublicFuntion.Folder.ToolPath + "IDSNowImage.png");
            try { SendString = dll_PublicFuntion.Other.DictionaryToXml(SendMessage); } catch { }
            FuncClass.IDS_Check(SendMessage, ref MainResultArray, false);

            if (!File.Exists((string)SendMessage["SavePath"]))
            {
                MainResultArray[Parameters.Status] = "Fail";
                MainResultArray[Parameters.Remark] = "IDS connect error.";
            }

            if ((string)MainResultArray[Parameters.Status] == "Pass")
            {
                Dictionary <string, object> FDic = new Dictionary <string, object>();
                try { FDic = dll_PublicFuntion.Other.XmlToDictionary(SendMessage[Parameters.Parameter].ToString()); } catch { }

                try
                {
                    // 創一個取樣大小的bitmap
                    Bitmap newRec     = new Bitmap((int.Parse((string)FDic["ImgWidth"])), int.Parse((string)FDic["ImgHeight"]));
                    Image  FullScreen = dll_PublicFuntion.Other.LoadImage((string)SendMessage["SavePath"]);

                    Graphics grPhoto = Graphics.FromImage(newRec);

                    Rectangle resultRec = new Rectangle();
                    resultRec.X      = Convert.ToInt32((string)FDic["startX"]);
                    resultRec.Y      = Convert.ToInt32((string)FDic["startY"]);
                    resultRec.Width  = Convert.ToInt32((string)FDic["ImgWidth"]);
                    resultRec.Height = Convert.ToInt32((string)FDic["ImgHeight"]);
                    grPhoto.DrawImage(FullScreen, 0, 0, resultRec, GraphicsUnit.Pixel);

                    grPhoto = Graphics.FromImage(FullScreen);
                    grPhoto.DrawRectangle(new Pen(System.Drawing.Color.Red, 3), resultRec);
                    newRec.Save(string.Format(FuncClass.Check_path($@"IDSData\LedData\{(string)FDic["DataFile"]}") + "{0}.png", $"{timeNow:HH-mm-ss}", System.Drawing.Imaging.ImageFormat.Png));
                    Thread.Sleep(1000);
                    MainResultArray["DataFile"] = (string)FDic["DataFile"];

                    if (newRec != null)
                    {
                        MainResultArray["IDSImagePortion"] = newRec;
                        string fileplace = str + $@"\{(string)FDic["DataFile"]}\{timeNow:HH-mm-ss}.png";

                        Image             GetBitmap  = Image.FromFile(fileplace);
                        Image <Bgr, byte> inputImage = new Image <Bgr, byte>(fileplace);

                        string returnColor = FuncClass.getcolor(inputImage);
                        MainResultArray[Parameters.Remark] = returnColor;
                    }

                    // Delete NowImage in case of wrong time
                    FuncClass.FileDelete(dll_PublicFuntion.Folder.ToolPath + "IDSNowImage.png");
                }
                catch (Exception)
                {
                    // Delete NowImage in case of wrong time
                    FuncClass.FileDelete(dll_PublicFuntion.Folder.ToolPath + "IDSNowImage.png");

                    MainResultArray[Parameters.Status] = "Fail";
                    MainResultArray[Parameters.Remark] = "Image catch fail.";
                }
            }
        }
Пример #3
0
        /// <summary>
        /// PowerDVD 是否播放中
        /// </summary>
        /// <param name="SendMessage"></param>
        /// <param name="MainResultArray"></param>
        /// <param name="SendString"></param>
        /// <param name="GroupName"></param>
        /// <param name="ExcelStepCounter"></param>
        /// <param name="TotalStepCount"></param>
        /// <param name="sheet"></param>
        /// <param name="SocketDataCheck"></param>
        /// <param name="halfSocketRemark"></param>
        /// <param name="AnswerDic"></param>
        public static void Movie_Play_Check(ref Dictionary <string, object> SendMessage, ref Dictionary <string, object> MainResultArray, ref string SendString, string GroupName, ref int ExcelStepCounter, ref int TotalStepCount, ref ISheet sheet, ref int SocketDataCheck, ref string halfSocketRemark, ref Dictionary <string, object> AnswerDic)
        {
            FuncClass.IdsStatus();
            bool socketResult = false;
            // Socket send data
            Dictionary <string, object> SendMessageMovie = new Dictionary <string, object>
            {
                { Parameters.Group, GroupName },
                { Parameters.Behavior, Behavior.Movie_Play_Check },
                { Parameters.Necessary, "" },
                { Parameters.Parameter, "" },
                { Parameters.ServerIP, Parameters.ip },
                { Parameters.Answer, dll_PublicFuntion.Other.DictionaryToXml(AnswerDic) },
            };

            // Parameter => IconName / PicturePath / Wait
            Dictionary <string, object> FDic = new Dictionary <string, object>();

            try { FDic = dll_PublicFuntion.Other.XmlToDictionary(SendMessage[Parameters.Parameter].ToString()); } catch { }

            // Loop five times, break until success
            for (int i = 0; i < 5; i++)
            {
                MainResultArray[Parameters.Remark] = "";
                // Add save path to dictionary at first time
                if (i == 0)
                {
                    SendMessageMovie.Add("SavePath", dll_PublicFuntion.Folder.ToolPath + "IDSNowImage.png");
                    try { SendString = dll_PublicFuntion.Other.DictionaryToXml(SendMessageMovie); } catch { }
                }

                do
                {
                    // Send to server
                    main.ConnectNet(dll_PublicFuntion.Other.DictionaryToXml(SendMessageMovie), TotalStepCount, sheet, GroupName, ExcelStepCounter, ref socketResult, Behavior.Movie_Play_Check);
                    dll_PublicFuntion.Other.Wait(1.5);
                } while (SocketDataCheck == 1);

                if (!socketResult)
                {
                    MainResultArray[Parameters.Status] = "Fail";
                    MainResultArray[Parameters.Remark] = "Can't find powerDVD.";
                    break;
                }

                // take a picture
                FuncClass.IDS_Check(SendMessageMovie, ref MainResultArray, true);

                Thread.Sleep(200);

                if (!File.Exists((string)SendMessageMovie["SavePath"]))
                {
                    MainResultArray[Parameters.Status] = "Fail";
                    MainResultArray[Parameters.Remark] = "IDS connect error.";
                    break;
                }


                // Picture comparison
                if (File.Exists((string)SendMessageMovie["SavePath"]) && socketResult)
                {
                    Image FullScreen = FuncClass.OperateImage((string)SendMessageMovie["SavePath"]);

                    Image SmallPic = FuncClass.OperateImage((string)FDic["PicturePath"]);

                    dll_opencv.OpenCV openCV = new dll_opencv.OpenCV();
                    openCV.SourceLoadImage(FullScreen);
                    openCV.SourceToGray();
                    openCV.MatchLoadImage(SmallPic);
                    openCV.MatchToGray();
                    dll_opencv.OpenCV.MatchDataList matchDataList = openCV.GetMatchPos(Parameters.Confidential, false);

                    double resultConfident = matchDataList.MaxConfidencevalue;
                    Thread.Sleep(50);

                    // Delete NowImage in case of wrong time
                    FuncClass.FileDelete(dll_PublicFuntion.Folder.ToolPath + "IDSNowImage.png");

                    if (resultConfident < Parameters.Confidential)
                    {
                        MainResultArray[Parameters.Status] = "Fail";
                        MainResultArray[Parameters.Remark] = "No match.";
                    }
                    else
                    {
                        MainResultArray[Parameters.Status] = "Pass";
                        break;
                    }
                }
            }
            if ((string)MainResultArray[Parameters.Status] == "Fail")
            {
                // Socket send data
                Dictionary <string, object> SendMessageRestart = new Dictionary <string, object>
                {
                    { Parameters.Group, GroupName },
                    { Parameters.Behavior, Behavior.DVD_Restart },
                    { Parameters.Necessary, "" },
                    { Parameters.Parameter, "" },
                    { Parameters.ServerIP, Parameters.ip },
                    { Parameters.Answer, "" },
                };
                do
                {
                    // Send to server
                    main.ConnectNet(dll_PublicFuntion.Other.DictionaryToXml(SendMessageRestart), TotalStepCount, sheet, GroupName, ExcelStepCounter, ref socketResult, Behavior.DVD_Restart);
                    dll_PublicFuntion.Other.Wait(1.5);
                } while (SocketDataCheck == 1);
                if (socketResult == false)
                {
                    MainResultArray[Parameters.Status] = "Fail";
                    MainResultArray[Parameters.Remark] = halfSocketRemark;
                }
                WaitTime(ref SendMessage);
            }
        }
Пример #4
0
        /// <summary>
        /// 解析度
        /// </summary>
        /// <param name="SendMessage"></param>
        /// <param name="MainResultArray"></param>
        /// <param name="SendString"></param>
        public static void Resolution_Check(ref Dictionary <string, object> SendMessage, ref Dictionary <string, object> MainResultArray, ref string SendString)
        {
            // 檢查IDS是否啟動
            FuncClass.IdsStatus();

            SendMessage.Add("SavePath", dll_PublicFuntion.Folder.ToolPath + "IDSNowImage.png");
            try { SendString = dll_PublicFuntion.Other.DictionaryToXml(SendMessage); } catch { }
            FuncClass.IDS_Check(SendMessage, ref MainResultArray, false);
            Thread.Sleep(200);

            if (!File.Exists((string)SendMessage["SavePath"]))
            {
                MainResultArray[Parameters.Status] = "Fail";
                MainResultArray[Parameters.Remark] = "IDS connect error.";
            }
            if ((string)MainResultArray[Parameters.Status] == "Pass")
            {
                Dictionary <string, object> FDic = new Dictionary <string, object>();
                try { FDic = dll_PublicFuntion.Other.XmlToDictionary(SendMessage[Parameters.Parameter].ToString()); } catch { }

                try
                {
                    Bitmap   newRec  = new Bitmap((int.Parse((string)FDic["ImgWidth"])), int.Parse((string)FDic["ImgHeight"]));
                    Image    NowImg  = dll_PublicFuntion.Other.LoadImage((string)SendMessage["SavePath"]);
                    Graphics grPhoto = Graphics.FromImage(newRec);

                    grPhoto.SmoothingMode      = SmoothingMode.AntiAlias;
                    grPhoto.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                    grPhoto.PixelOffsetMode    = PixelOffsetMode.HighQuality;
                    grPhoto.CompositingQuality = CompositingQuality.HighQuality;

                    Rectangle rectangleHAHA = new Rectangle();
                    rectangleHAHA.X      = Convert.ToInt32((string)FDic["startX"]);
                    rectangleHAHA.Y      = Convert.ToInt32((string)FDic["startY"]);
                    rectangleHAHA.Width  = Convert.ToInt32((string)FDic["ImgWidth"]);
                    rectangleHAHA.Height = Convert.ToInt32((string)FDic["ImgHeight"]);

                    grPhoto.DrawImage(NowImg, 0, 0, rectangleHAHA, GraphicsUnit.Pixel);

                    grPhoto = Graphics.FromImage(NowImg);
                    grPhoto.DrawRectangle(new Pen(System.Drawing.Color.Red, 3), rectangleHAHA);
                    string F1 = string.Format(FuncClass.Check_path($@"IDSData\{(string)FDic["DataFile"]}") + @"{0}.png", "FullScreen");
                    string F2 = string.Format(FuncClass.Check_path($@"IDSData\{(string)FDic["DataFile"]}") + @"{0}.png", "OcrRegion");

                    NowImg.Save(F1, System.Drawing.Imaging.ImageFormat.Png);
                    newRec.Save(F2, System.Drawing.Imaging.ImageFormat.Png);
                    Thread.Sleep(1000);
                    dll_GoogleOCR.GoogleOCR googleOCR = new dll_GoogleOCR.GoogleOCR();
                    MainResultArray["DataFile"] = (string)FDic["DataFile"];

                    if (NowImg != null)
                    {
                        MainResultArray["IDSImageFull"] = NowImg;
                    }
                    if (newRec != null)
                    {
                        MainResultArray["IDSImagePortion"] = newRec;
                    }

                    string OCRresult = googleOCR.UploadFileToTxt(Application.StartupPath + $@"\IDSData\{(string)FDic["DataFile"]}\" + "OcrRegion.png", null, true);
                    string OriOCR    = OCRresult.Replace("_", " ").Trim();

                    // Delete NowImage in case of wrong time
                    FuncClass.FileDelete(dll_PublicFuntion.Folder.ToolPath + "IDSNowImage.png");

                    // OSD display value
                    OCRresult = FuncClass.RexResolution(OCRresult.Replace("_", " ").Trim());

                    // Receive
                    string receMsg = "";
                    Dictionary <string, object> receivedData = new Dictionary <string, object>();

                    // Send to server
                    main.Resolution_ConncetNet(SendString, ref receMsg);
                    receivedData = dll_PublicFuntion.Other.XmlToDictionary(receMsg);

                    // Dut resolution
                    string OriDut        = (string)receivedData["Remark"];
                    string dutResolution = FuncClass.RexResolution(((string)receivedData["Remark"]).Trim());
                    if (OriDut != "")
                    {
                        if (!OCRresult.Equals(dutResolution))
                        {
                            MainResultArray[Parameters.Status] = "Fail";
                            MainResultArray[Parameters.Remark] = $"OSD : {OriOCR} ; Windows : {(string)receivedData["Remark"]}";
                        }
                    }
                    else
                    {
                        MainResultArray[Parameters.Status] = "Fail";
                        MainResultArray[Parameters.Remark] = "No monitor has been detective.";
                    }

                    MainResultArray[Parameters.Remark] = $"OSD : {OriOCR} ; Windows : {OriDut}";
                }
                catch (Exception)
                {
                    MainResultArray[Parameters.Status] = "Fail";
                    MainResultArray[Parameters.Remark] = "Data received error.";
                }
            }
        }