public bool excuteTelnet() { bool ret = false; //get setting string rtsp_link = (string)settingInfo.GetType().GetProperty("cameraRtspLink").GetValue(settingInfo); double std_sharpness = (double)settingInfo.GetType().GetProperty("sharpnessStandard").GetValue(settingInfo); double std_tolerance = (double)settingInfo.GetType().GetProperty("toleranceSharpness").GetValue(settingInfo); string areatest = (string)settingInfo.GetType().GetProperty("areaTestChart").GetValue(settingInfo); double scale = 0; //get testing var prop_macethernet = testingInfo.GetType().GetProperty("macEthernet"); var prop_totalresult = testingInfo.GetType().GetProperty("TotalResult"); var prop_imagesource = testingInfo.GetType().GetProperty("imageSource"); var prop_imagecrop = testingInfo.GetType().GetProperty("imageCrop"); var prop_logsystem = testingInfo.GetType().GetProperty("logSystem"); string log_value = (string)prop_logsystem.GetValue(testingInfo); try { //login to camera log_value += string.Format("\n-------------------------------\n"); log_value += string.Format("{0}, Login to ip camera\n", DateTime.Now); prop_logsystem.SetValue(testingInfo, log_value); string camera_ip = (string)settingInfo.GetType().GetProperty("cameraIP").GetValue(settingInfo); string telnet_user = (string)settingInfo.GetType().GetProperty("cameraTelnetUser").GetValue(settingInfo); string telnet_pass = (string)settingInfo.GetType().GetProperty("cameraTelnetPassword").GetValue(settingInfo); ret = _loginToCamera(camera_ip, telnet_user, telnet_pass, ref camera); log_value = (string)prop_logsystem.GetValue(testingInfo); log_value += string.Format("...kết quả {0}\n", ret ? "Passed" : "Failed"); prop_logsystem.SetValue(testingInfo, log_value); if (!ret) { goto END; } //get mac ethernet log_value += string.Format("\n-------------------------------\n"); log_value += string.Format("{0}, Đọc địa chỉ mac ethernet\n", DateTime.Now); prop_logsystem.SetValue(testingInfo, log_value); string mac_ethernet = ""; ret = _getMacEthernet(camera, out mac_ethernet); prop_macethernet.SetValue(testingInfo, mac_ethernet); log_value = (string)prop_logsystem.GetValue(testingInfo); log_value += string.Format("...kết quả {0}\n", ret ? "Passed" : "Failed"); prop_logsystem.SetValue(testingInfo, log_value); if (!ret) { goto END; } //stream video and judgement log_value += string.Format("\n-------------------------------\n"); log_value += string.Format("{0}, Stream và phán định độ nét hình ảnh camera\n", DateTime.Now); log_value += string.Format("...Tiêu chuẩn: > {0}\n", std_sharpness - std_tolerance); prop_logsystem.SetValue(testingInfo, log_value); capture = new VideoCapture(rtsp_link); if (!capture.IsOpened) { ret = false; log_value = (string)prop_logsystem.GetValue(testingInfo); log_value += string.Format("...kết quả {0}\n", ret ? "Passed" : "Failed"); prop_logsystem.SetValue(testingInfo, log_value); goto END; } isStreaming = true; int count = 0; RE: Mat m = new Mat(); if (capture != null) { capture.Read(m); } if (!m.IsEmpty) { Image <Bgr, Byte> img = m.ToImage <Bgr, Byte>(); int iw = img.Width; int ih = img.Height; string[] buffer = areatest.Split(','); int rect_left = (int)double.Parse(buffer[0]); int rect_top = (int)double.Parse(buffer[1]); int rect_width = (int)double.Parse(buffer[2]); int rect_height = (int)double.Parse(buffer[3]); var rect = new System.Drawing.Rectangle(rect_left, rect_top, rect_width, rect_height); //show rectangle CvInvoke.Rectangle(m, rect, new MCvScalar(0, 0, 255), 3, LineType.AntiAlias); //crop image by rectangle Image <Gray, byte> image_crop = globalUtility.CropFromImage(img, rect); //calculate sharpness int s = globalUtility.getSharpnessValueFromImage(image_crop); int pixel = image_crop.Width * image_crop.Height; scale = s / (pixel * 1.0); //judgement double ll_value = std_sharpness - std_tolerance; ret = scale >= ll_value; prop_totalresult.SetValue(testingInfo, ret ? "Passed" : "Failed"); count++; //thoi gian CvInvoke.PutText(m, string.Format("Now is {0}", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")), new System.Drawing.Point(30, 50), FontFace.HersheySimplex, 1, ret ? new MCvScalar(0, 255, 0) : new MCvScalar(0, 0, 255), 2, LineType.AntiAlias); //do net tieu chuan CvInvoke.PutText(m, string.Format("Standard value: {0}", ll_value), new System.Drawing.Point(30, 100), FontFace.HersheySimplex, 1, ret ? new MCvScalar(0, 255, 0) : new MCvScalar(0, 0, 255), 2, LineType.AntiAlias); //do net thuc te CvInvoke.PutText(m, string.Format("Actual value: {0}", Math.Round(scale, 5)), new System.Drawing.Point(30, 150), FontFace.HersheySimplex, 1, ret ? new MCvScalar(0, 255, 0) : new MCvScalar(0, 0, 255), 2, LineType.AntiAlias); //ket qua CvInvoke.PutText(m, string.Format("{0}", ret ? "Passed" : "Failed"), new System.Drawing.Point(30, 350), FontFace.HersheySimplex, 4, ret ? new MCvScalar(0, 255, 0) : new MCvScalar(0, 0, 255), 2, LineType.AntiAlias); //mac address CvInvoke.PutText(m, string.Format("{0}:{1}:{2}:{3}:{4}:{5}", mac_ethernet.Substring(0, 2), mac_ethernet.Substring(2, 2), mac_ethernet.Substring(4, 2), mac_ethernet.Substring(6, 2), mac_ethernet.Substring(8, 2), mac_ethernet.Substring(10, 2) ), new System.Drawing.Point(30, 650), FontFace.HersheySimplex, 2, new MCvScalar(0, 0, 255), 2, LineType.AntiAlias); //show image var bi = globalUtility.ToBitmapSource(m.Bitmap); bi.Freeze(); prop_imagesource.SetValue(testingInfo, bi); //show crop var ci = globalUtility.Bitmap2BitmapImage(image_crop.Bitmap); ci.Freeze(); prop_imagecrop.SetValue(testingInfo, ci); } Thread.Sleep(10); if (isStreaming) { goto RE; } log_value += string.Format("...kết quả: {0}, {1}\n", scale, ret ? "Passed" : "Failed"); prop_logsystem.SetValue(testingInfo, log_value); } catch (Exception ex) { log_value += ex.ToString(); prop_logsystem.SetValue(testingInfo, log_value); goto END; } END: if (capture != null) { capture.Dispose(); } if (camera != null && camera.IsConnected()) { camera.Close(); } return(ret); }
//Nap fw thuong mai qua cong telnet public bool excuteTelnet() { bool ret = false; bool flag_check = false; var prop_rebootresult = uploadInfo.GetType().GetProperty("rebootResult"); prop_rebootresult.SetValue(uploadInfo, "Passed"); //get logsytem var prop_logsystem = uploadInfo.GetType().GetProperty("logSystem"); string log_value = (string)prop_logsystem.GetValue(uploadInfo); Dut.IPCamera <U> camera = null; try { //login to camera //###############################################################// log_value += string.Format("\n-------------------------------\n"); log_value += string.Format("{0}, Login to ip camera\n", DateTime.Now); prop_logsystem.SetValue(uploadInfo, log_value); string camera_ip = (string)uploadInfo.GetType().GetProperty("ipAddress").GetValue(uploadInfo); string telnet_user = (string)settingInfo.GetType().GetProperty("cameraTelnetUser").GetValue(settingInfo); string telnet_pass = (string)settingInfo.GetType().GetProperty("cameraTelnetPassword").GetValue(settingInfo); ret = _loginToCamera(camera_ip, telnet_user, telnet_pass, ref camera); log_value = (string)prop_logsystem.GetValue(uploadInfo); log_value += string.Format("...kết quả {0}\n", ret ? "Passed" : "Failed"); prop_logsystem.SetValue(uploadInfo, log_value); if (!ret) { goto END; } //check firmware build time //###############################################################// flag_check = (bool)settingInfo.GetType().GetProperty("IsCheckFirmwareBuildTime").GetValue(settingInfo); if (flag_check) { var prop_fwresult = uploadInfo.GetType().GetProperty("firmwareResult"); prop_fwresult.SetValue(uploadInfo, "Waiting..."); log_value += string.Format("\n-------------------------------\n"); log_value += string.Format("{0}, check firmware business build time\n", DateTime.Now); prop_logsystem.SetValue(uploadInfo, log_value); string fw_buildtime = (string)settingInfo.GetType().GetProperty("firmwareBuildTime").GetValue(settingInfo); log_value += string.Format("...tiêu chuẩn: {0}\n", fw_buildtime); log_value += string.Format("...thực tế:\n"); prop_logsystem.SetValue(uploadInfo, log_value); string act_buildtime = ""; ret = _checkFWBuildTime(camera, fw_buildtime, out act_buildtime); log_value = (string)prop_logsystem.GetValue(uploadInfo); log_value += string.Format("...kết quả {0}\n", ret ? "Passed" : "Failed"); prop_logsystem.SetValue(uploadInfo, log_value); prop_fwresult.SetValue(uploadInfo, ret ? "Passed" : "Failed"); uploadInfo.GetType().GetProperty("firmwareBuildTime").SetValue(uploadInfo, act_buildtime); if (!ret) { goto END; } } //check mac address //###############################################################// flag_check = (bool)settingInfo.GetType().GetProperty("IsCheckMacEthernet").GetValue(settingInfo); if (flag_check) { var prop_macresult = uploadInfo.GetType().GetProperty("macResult"); prop_macresult.SetValue(uploadInfo, "Waiting..."); log_value += string.Format("\n-------------------------------\n"); log_value += string.Format("{0}, check mac ethernet\n", DateTime.Now); prop_logsystem.SetValue(uploadInfo, log_value); string mac_header = (string)settingInfo.GetType().GetProperty("vnptMacHeader").GetValue(settingInfo); ret = _checkMacEthernet(camera, mac_header); log_value = (string)prop_logsystem.GetValue(uploadInfo); log_value += string.Format("...kết quả {0}\n", ret ? "Passed" : "Failed"); prop_logsystem.SetValue(uploadInfo, log_value); prop_macresult.SetValue(uploadInfo, ret ? "Passed" : "Failed"); if (!ret) { goto END; } } //check serial number //###############################################################// flag_check = (bool)settingInfo.GetType().GetProperty("IsCheckSerialNumber").GetValue(settingInfo); if (flag_check) { var prop_serialresult = uploadInfo.GetType().GetProperty("serialResult"); prop_serialresult.SetValue(uploadInfo, "Waiting..."); log_value += string.Format("\n-------------------------------\n"); log_value += string.Format("{0}, check serial number\n", DateTime.Now); prop_logsystem.SetValue(uploadInfo, log_value); string vnpt_productnumber = (string)settingInfo.GetType().GetProperty("vnptProductNumber").GetValue(settingInfo); string vnpt_maccode = (string)settingInfo.GetType().GetProperty("productMacCode").GetValue(settingInfo); string act_serial = ""; ret = _checkSerialNumber(camera, vnpt_productnumber, vnpt_maccode, out act_serial); log_value = (string)prop_logsystem.GetValue(uploadInfo); log_value += string.Format("...kết quả {0}\n", ret ? "Passed" : "Failed"); prop_logsystem.SetValue(uploadInfo, log_value); prop_serialresult.SetValue(uploadInfo, ret ? "Passed" : "Failed"); uploadInfo.GetType().GetProperty("serialNumber").SetValue(uploadInfo, act_serial); if (!ret) { goto END; } } //check uid //###############################################################// flag_check = (bool)settingInfo.GetType().GetProperty("IsCheckUID").GetValue(settingInfo); if (flag_check) { var prop_uidresult = uploadInfo.GetType().GetProperty("uidResult"); prop_uidresult.SetValue(uploadInfo, "Waiting..."); log_value += string.Format("\n-------------------------------\n"); log_value += string.Format("{0}, check uid\n", DateTime.Now); prop_logsystem.SetValue(uploadInfo, log_value); string vnpt_uidheader = (string)settingInfo.GetType().GetProperty("vnptUidHeader").GetValue(settingInfo); string act_uid = ""; ret = _checkUIDCode(camera, vnpt_uidheader, out act_uid); log_value = (string)prop_logsystem.GetValue(uploadInfo); log_value += string.Format("...kết quả {0}\n", ret ? "Passed" : "Failed"); prop_logsystem.SetValue(uploadInfo, log_value); prop_uidresult.SetValue(uploadInfo, ret ? "Passed" : "Failed"); uploadInfo.GetType().GetProperty("uidCode").SetValue(uploadInfo, act_uid); if (!ret) { goto END; } } //check hardware version //###############################################################// flag_check = (bool)settingInfo.GetType().GetProperty("IsCheckHardwareVersion").GetValue(settingInfo); if (flag_check) { var prop_hwresult = uploadInfo.GetType().GetProperty("hardwareResult"); prop_hwresult.SetValue(uploadInfo, "Waiting..."); log_value += string.Format("\n-------------------------------\n"); log_value += string.Format("{0}, check hardware version\n", DateTime.Now); prop_logsystem.SetValue(uploadInfo, log_value); string hw_version = (string)settingInfo.GetType().GetProperty("hardwareVersion").GetValue(settingInfo); log_value += string.Format("...tiêu chuẩn: {0}\n", hw_version); log_value += string.Format("...thực tế:\n"); prop_logsystem.SetValue(uploadInfo, log_value); string act_hw_ver = ""; ret = _checkHardwareVersion(camera, hw_version, out act_hw_ver); log_value = (string)prop_logsystem.GetValue(uploadInfo); log_value += string.Format("...kết quả {0}\n", ret ? "Passed" : "Failed"); prop_logsystem.SetValue(uploadInfo, log_value); prop_hwresult.SetValue(uploadInfo, ret ? "Passed" : "Failed"); uploadInfo.GetType().GetProperty("hardwareVersion").SetValue(uploadInfo, act_hw_ver); if (!ret) { goto END; } } } catch (Exception ex) { log_value += ex.ToString(); prop_logsystem.SetValue(uploadInfo, log_value); goto END; } END: if (camera != null && camera.IsConnected()) { camera.Close(); } return(ret); }
public bool excuteUart() { bool ret = false; //get logsytem var prop_logsystem = testingInfo.GetType().GetProperty("logSystem"); string log_value = (string)prop_logsystem.GetValue(testingInfo); string mac_ethernet = (string)testingInfo.GetType().GetProperty("macEthernet").GetValue(testingInfo); log_value += string.Format("\n-------------------------------\n"); log_value += string.Format("{0}, Nhập mac từ barcode reader\n", DateTime.Now); log_value += string.Format("...{0}\n", mac_ethernet); prop_logsystem.SetValue(testingInfo, log_value); try { //check mac address ret = _isVnptMacAddress(mac_ethernet); log_value = (string)prop_logsystem.GetValue(testingInfo); log_value += string.Format("...kết quả {0}\n", ret ? "Passed" : "Failed"); prop_logsystem.SetValue(testingInfo, log_value); if (!ret) { goto END; } //open serial port string serial_port = (string)testingInfo.GetType().GetProperty("serialPortName").GetValue(testingInfo); ret = _openSerialPort(serial_port); log_value = (string)prop_logsystem.GetValue(testingInfo); log_value += string.Format("...kết quả {0}\n", ret ? "Passed" : "Failed"); prop_logsystem.SetValue(testingInfo, log_value); if (!ret) { goto END; } //login to uboot (wait 30s) ret = _loginToUboot(30); log_value = (string)prop_logsystem.GetValue(testingInfo); log_value += string.Format("...kết quả {0}\n", ret ? "Passed" : "Failed"); prop_logsystem.SetValue(testingInfo, log_value); if (!ret) { goto END; } //set mac ethernet ret = _setMacEthernet(mac_ethernet); log_value = (string)prop_logsystem.GetValue(testingInfo); log_value += string.Format("...kết quả {0}\n", ret ? "Passed" : "Failed"); prop_logsystem.SetValue(testingInfo, log_value); testingInfo.GetType().GetProperty("setMacResult").SetValue(testingInfo, ret ? "Passed" : "Failed"); if (!ret) { goto END; } //upload firmware basic string camera_ip = (string)testingInfo.GetType().GetProperty("ipAddress").GetValue(testingInfo); string file_firmware = (string)settingInfo.GetType().GetProperty("fileFirmware").GetValue(settingInfo); ret = _uploadFirmwareBasic(camera_ip, file_firmware, 90); log_value = (string)prop_logsystem.GetValue(testingInfo); log_value += string.Format("...kết quả {0}\n", ret ? "Passed" : "Failed"); prop_logsystem.SetValue(testingInfo, log_value); testingInfo.GetType().GetProperty("uploadResult").SetValue(testingInfo, ret ? "Passed" : "Failed"); if (!ret) { goto END; } //reboot camera and wait camera reboot complete ret = _rebootCamera(); log_value = (string)prop_logsystem.GetValue(testingInfo); log_value += string.Format("...kết quả {0}\n", ret ? "Passed" : "Failed"); prop_logsystem.SetValue(testingInfo, log_value); if (!ret) { goto END; } //wait camera reboot complete ret = _waitCameraRebootComplete(60); log_value = (string)prop_logsystem.GetValue(testingInfo); log_value += string.Format("...kết quả {0}\n", ret ? "Passed" : "Failed"); prop_logsystem.SetValue(testingInfo, log_value); if (!ret) { goto END; } //set static ip string static_ip = (string)settingInfo.GetType().GetProperty("cameraStaticIP").GetValue(settingInfo); ret = _setStaticIP(static_ip); log_value = (string)prop_logsystem.GetValue(testingInfo); log_value += string.Format("...kết quả {0}\n", ret ? "Passed" : "Failed"); prop_logsystem.SetValue(testingInfo, log_value); testingInfo.GetType().GetProperty("setIpResult").SetValue(testingInfo, ret ? "Passed" : "Failed"); if (!ret) { goto END; } //write uid string uid_header = (string)settingInfo.GetType().GetProperty("vnptUidHeader").GetValue(settingInfo); string uid_code = "";; ret = _setUidCode(uid_header, mac_ethernet, out uid_code); log_value = (string)prop_logsystem.GetValue(testingInfo); log_value += string.Format("...kết quả {0}\n", ret ? "Passed" : "Failed"); prop_logsystem.SetValue(testingInfo, log_value); testingInfo.GetType().GetProperty("uidCode").SetValue(testingInfo, uid_code); goto END; } catch (Exception ex) { log_value += ex.ToString(); prop_logsystem.SetValue(testingInfo, log_value); goto END; } END: if (camera != null && camera.IsConnected()) { camera.Close(); } return(ret); }