Windows环境+C#实现显示接口测试

代码如下:

using Models;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Tools;
using DisplayMode = Models.DisplayMode;namespace TestItem
{public partial class VideoTestManager : Form{private string originalDirectory = System.Environment.CurrentDirectory; // 保存当前目录private string programName = string.Empty;//程式名称public event Action<bool> CallExit = null;//回调函数private bool isPass = false;private string readValues = null; // 测试参数private string testArgs = null;//测试参数private List<string> testItem=null;//测试项目private string playFileName = string.Empty;//播放文件名称private List<DisplayEntity> displayEntity;//显示实体private int random_number = 0;//随机数private int input_number = 0;//输入数#region 构造函数//显示模式public VideoTestManager(){InitializeComponent();this.CallExit += (isPass) => { }; // 初始化事件this.Load += VideoTestManager_Load;this.FormClosing += VideoTestManager_FormClosing;this.KeyDown += VideoTestManager_KeyDown;this.KeyPreview = true; // Enable the form to receive key events}#endregion#region 窗体加载private const byte VK_LEFT = 0x25;private const byte VK_RIGHT = 0x27;private async void VideoTestManager_Load(object sender, EventArgs e){if (await this.GetTestArgs()){this.SetHeaderStyle(); // 设置表头信息样式this.displayEntity = new List<DisplayEntity>();//初始化显示实体timer_Test.Enabled = true;}}#endregion#region 切屏显示/// <summary>/// 切屏显示/// </summary>/// <param name="mode"></param>/// <exception cref="ArgumentOutOfRangeException"></exception>private void SwitchDisplayMode(DisplayMode mode){string argument;switch (mode){case DisplayMode.Internal:argument = "/internal";break;case DisplayMode.Clone:argument = "/clone";break;case DisplayMode.Extend:argument = "/extend";break;case DisplayMode.External:argument = "/external";break;default:throw new ArgumentOutOfRangeException();}Process.Start("DisplaySwitch.exe", argument);}#endregion#region 获取测试参数private async Task<bool> GetTestArgs(){try{//获取程式名称this.programName = AuxiliaryItemArray.GetProgramName(this.lbl_ShowResult) != null ? AuxiliaryItemArray.GetProgramName(this.lbl_ShowResult) + @".exe" : null;if (this.programName == null)return false;// 获取测试参数this.testArgs = AuxiliaryItemArray.GetTestParameter(this.originalDirectory, this.programName, this.lbl_ShowResult);if (this.testArgs == null)return false;//解析参数string[] args = this.testArgs.Split('|');this.playFileName = args[1].Split('=')[1];this.testItem = new List<string>();this.testItem = args[0].Split(',').ToList();this.lbl_TestArgs.BeginInvoke(new Action(() => { this.lbl_TestArgs.Text= args[0];}));return this.testItem.Count>0;}catch (Exception ex){this.Invoke(new Action(() =>{AuxiliaryItemArray.Loginfo($@"获取测试参数:{ex.Message}", false, lbl_ShowResult);}));return false;}}#endregion#region 播放视频/// <summary>/// 播放视频/// </summary>/// <param name="playFileName">播放文件</param>/// <returns></returns>private async Task<bool>Mp4Play(string playFileName){try{//设置播放器URL// 获取当前目录string currentDirectory = AppDomain.CurrentDomain.BaseDirectory;// 拼接视频文件路径string videoPath = Path.Combine(currentDirectory, "Video", playFileName);if (File.Exists(videoPath)){// 设置播放器URLwmpPlayer.URL = videoPath;// 设置循环播放模式wmpPlayer.settings.setMode("loop", true);return true;}else{this.Invoke(new Action(() =>{AuxiliaryItemArray.Loginfo("视频文件未找到: " + videoPath, false, lbl_ShowResult);}));return false;}}catch(Exception ex){this.Invoke(new Action(() =>{AuxiliaryItemArray.Loginfo($@"播放MP4错误:{ex.Message}", false, lbl_ShowResult);}));return false;}}#endregion#region 设置表头信息样式private void SetHeaderStyle(){// 设置参数列宽度,使用百分比this.tabPanel_Args.ColumnStyles[0].SizeType = SizeType.Percent;this.tabPanel_Args.ColumnStyles[0].Width = 25;this.tabPanel_Args.ColumnStyles[1].SizeType = SizeType.Percent;this.tabPanel_Args.ColumnStyles[1].Width = 25;this.tabPanel_Args.ColumnStyles[2].SizeType = SizeType.Percent;this.tabPanel_Args.ColumnStyles[2].Width = 25;this.tabPanel_Args.ColumnStyles[3].SizeType = SizeType.Percent;this.tabPanel_Args.ColumnStyles[3].Width = 25;}#endregion#region 关闭窗体private void VideoTestManager_FormClosing(object sender, FormClosingEventArgs e){this.readValues = JsonConvert.SerializeObject(this.displayEntity, Formatting.Indented);//将实体类转换成json文件AuxiliaryItemArray.UpdateJsonInfo(this.programName, this.readValues, this.isPass, this.originalDirectory, this.lbl_ShowResult);this.ProcessExit(this.isPass);}#endregion#region 关闭进程private void ProcessExit(bool isPass){CallExit?.Invoke(isPass);}#endregion#region 定时触发器private async void timer_Test_Tick(object sender, EventArgs e){timer_Test.Enabled = false;bool testResult = true;string[] testArgsValues = this.testArgs.Split(',');foreach (var a in testArgsValues){if (!this.displayEntity.Any(d => d.ProtName == a)){testResult = false;break;}}if (testResult){this.readValues = JsonConvert.SerializeObject(this.displayEntity, Formatting.Indented);//将实体类转换成json文件AuxiliaryItemArray.UpdateJsonInfo(this.programName, this.readValues, true, this.originalDirectory, this.lbl_ShowResult);this.ProcessExit(this.isPass);}else{DisplayManager displayManager = new DisplayManager();DisplayEntity tempdata = new DisplayEntity();displayManager.DetectDisplays();if (displayManager.displayEntity.Count > 0){foreach (DisplayEntity ds in displayManager.displayEntity){this.currentTestPort = new DisplayEntity();if (!displayEntity.Any(d => d.ProtName == ds.ProtName) || displayEntity.Count == 0){this.currentTestPort = ds;tempdata = ds;TestDisplayPort();//测试显示接口if (ds.DeviceName.ToUpper().Contains("DISPLAY1")){this.SwitchDisplayMode(DisplayMode.Internal);//仅第一个屏显示this.currentTestPort.SwDisplayMode = DisplayMode.Internal;break;}else{this.SwitchDisplayMode(DisplayMode.External);//仅第二个屏显示this.currentTestPort.SwDisplayMode = DisplayMode.External;break;}}}}}}#endregion#region 显示接口测试/// <summary>/// 测试显示接口/// </summary>/// <param name="protName">接口名称</param>private async void TestDisplayPort(){this.input_number = 0;Random random = new Random();this.random_number = random.Next(1,9);this.lbl_ShowResult.BeginInvoke(new Action(() => {this.lbl_ShowResult.ForeColor = Color.SteelBlue;this.lbl_ShowResult.Text = $@"{this.currentTestPort.ProtName}接口测试中..";}));this.lbl_Random.BeginInvoke(new Action(() => {this.lbl_Random.Text = this.random_number.ToString();}));await this.Mp4Play(this.playFileName);//Mp4播放waitTime = 20;timer_random.Enabled = true;}#endregion#region 随机数检测private int waitTime = 0;//等待时间private DisplayEntity currentTestPort;//当前测试接口private async void timer_random_Tick(object sender, EventArgs e){if(waitTime==0){if(currentTestPort.ProtName=="VGA"){this.lbl_VGA_result.Text = "FAIL";this.lbl_VGA_result.ForeColor = Color.Red;}else if(currentTestPort.ProtName == "DVI"){this.lbl_DVI_result.Text = "FAIL";this.lbl_DVI_result.ForeColor = Color.Red;}else if (currentTestPort.ProtName == "DP"){this.lbl_DP_result.Text = "FAIL";this.lbl_DP_result.ForeColor = Color.Red;}else if (currentTestPort.ProtName == "HDMI"){this.lbl_HDMI_result.Text = "FAIL";this.lbl_HDMI_result.ForeColor = Color.Red;}this.lbl_ShowResult.BeginInvoke(new Action(() => {this.lbl_ShowResult.Text = $@"{this.currentTestPort.ProtName}接口测试Fail";this.lbl_ShowResult.ForeColor = Color.Red;}));this.SwitchDisplayMode(DisplayMode.Extend);//扩展屏显示await this.Mp4Play(this.playFileName);//Mp4播放timer_random.Enabled = false;this.timer_Test.Enabled = true;}else{if(this.input_number==0)waitTime--;else{if (currentTestPort.ProtName == "VGA"){this.lbl_VGA_result.Text = this.input_number == this.random_number ? "PASS" : "FAIL";this.lbl_VGA_result.ForeColor = this.input_number == this.random_number ? Color.Green : Color.Red;}else if (currentTestPort.ProtName == "DVI"){this.lbl_DVI_result.Text = this.input_number == this.random_number ? "PASS" : "FAIL";this.lbl_DVI_result.ForeColor = this.input_number == this.random_number ? Color.Green : Color.Red;}else if (currentTestPort.ProtName == "DP"){this.lbl_DP_result.Text = this.input_number == this.random_number ? "PASS" : "FAIL";this.lbl_DP_result.ForeColor = this.input_number == this.random_number ? Color.Green : Color.Red;}else if (currentTestPort.ProtName == "HDMI"){this.lbl_HDMI_result.Text = this.input_number == this.random_number ? "PASS" : "FAIL";this.lbl_HDMI_result.ForeColor = this.input_number == this.random_number ? Color.Green : Color.Red;}this.timer_random.Enabled = false;if (this.input_number == this.random_number){this.currentTestPort.TestResult = "PASS";this.displayEntity.Add(this.currentTestPort);}this.lbl_ShowResult.BeginInvoke(new Action(() => {this.lbl_ShowResult.Text = $@"{this.currentTestPort.ProtName}接口测试PASS";this.lbl_ShowResult.ForeColor = Color.Green;}));this.waitTime = 0;this.SwitchDisplayMode(DisplayMode.Extend);//扩展屏显示await this.Mp4Play(this.playFileName);//Mp4播放this.timer_Test.Enabled = true;}}}#endregion#region 键盘入事件/// <summary>/// 键盘键入事件/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void VideoTestManager_KeyDown(object sender, KeyEventArgs e){// Check if the pressed key is a number key (both top row and numpad)if ((e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9) || (e.KeyCode >= Keys.NumPad0 && e.KeyCode <= Keys.NumPad9)){// Get the digit from the key codeint digit = (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9) ? e.KeyCode - Keys.D0 : e.KeyCode - Keys.NumPad0;// Handle the digit input, for example:this.input_number = digit;}}#endregion}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Runtime.InteropServices;
using Models;namespace Tools
{public class DisplayManager{public List<DisplayEntity> displayEntity; // 显示实体[DllImport("user32.dll")]private static extern bool EnumDisplayDevices(string lpDevice, uint iDevNum, ref DISPLAY_DEVICE lpDisplayDevice, uint dwFlags);[StructLayout(LayoutKind.Sequential)]private struct DISPLAY_DEVICE{public int cb;[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]public string DeviceName;[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]public string DeviceString;public int StateFlags;[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]public string DeviceID;[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]public string DeviceKey;}/// <summary>/// 检测接入的显示接口/// </summary>public void DetectDisplays(){displayEntity = new List<DisplayEntity>();// 使用WMI查询显示器连接类型ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\wmi", "SELECT * FROM WmiMonitorConnectionParams");foreach (ManagementObject queryObj in searcher.Get()){uint videoOutputTechnology = (uint)queryObj["VideoOutputTechnology"];string connectionType = GetConnectionType(videoOutputTechnology);displayEntity.Add(new DisplayEntity{DeviceIndex = displayEntity.Count,DeviceName = queryObj["InstanceName"]?.ToString(),//DeviceString = DeviceString = d.DeviceString,ProtName = connectionType});}DeviceString();}/// <summary>/// 检测接入的显示接口/// </summary>public void DeviceString(){DISPLAY_DEVICE d = new DISPLAY_DEVICE();d.cb = Marshal.SizeOf(d);int deviceIndex = 0;//this.displayEntity = new List<DisplayEntity>();while (EnumDisplayDevices(null, (uint)deviceIndex, ref d, 0)){if (deviceIndex < displayEntity.Count){displayEntity[deviceIndex].DeviceString = d.DeviceString;displayEntity[deviceIndex].DeviceName = d.DeviceName;}//Console.WriteLine($"Device {deviceIndex}: {d.DeviceName} - {d.DeviceString}");//this.displayEntity.Add(new DisplayEntity()//{//    DeviceIndex = deviceIndex,//    DeviceName = d.DeviceName,//    DeviceString = d.DeviceString//});deviceIndex++;}}/// <summary>/// 获取连接的显示类型/// </summary>/// <param name="videoOutputTechnology"></param>/// <returns></returns>private string GetConnectionType(uint videoOutputTechnology){// 根据WMI查询结果中的VideoOutputTechnology值返回连接类型switch (videoOutputTechnology){case 0x00000000: return "HD15 (VGA)";case 0x00000001: return "S-Video";case 0x00000002: return "Composite video";case 0x00000003: return "Component video (YPbPr)";case 0x00000004: return "DVI";case 0x00000005: return "HDMI";case 0x00000006: return "LVDS";case 0x00000007: return "DJPN";case 0x00000008: return "SDI";case 0x00000009: return "DP";//case 0x00000009: return "DisplayPort external";//case 0x0000000A: return "DisplayPort embedded";case 0x0000000A: return "VGA";case 0x0000000B: return "UDI external";case 0x0000000C: return "UDI embedded";case 0x0000000D: return "SDTVDongle";case 0x80000000: return "Miracast";case 0x80000001: return "Indirect Display";default: return "Unknown";}}}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;namespace Models
{public class DisplayEntity{/// <summary>/// 硬件指针/// </summary>public int DeviceIndex { get; set; }/// <summary>/// 硬件名称/// </summary>public string DeviceName { get; set; }/// <summary>/// 硬件字符串/// </summary>public string DeviceString { get; set; }/// <summary>/// 接口名称/// </summary>public string ProtName { get; set; }/// <summary>/// 切换的显示模式/// </summary>public DisplayMode SwDisplayMode { get; set; } = DisplayMode.Internal;/// <summary>/// 测试结果/// </summary>public string TestResult { get; set; } = "Wait";}public enum DisplayMode{Internal,//仅电脑屏幕Clone,//复制Extend,//扩展External//仅第二屏幕}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/44165.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

大模型“聚会”:国内卷价格,国外卷能力

[ GPT-4o和谷歌Gemini不断宣传现阶段AI能力大幅度提高&#xff0c;那么这两家&#xff0c;谁的大模型能力更强呢&#xff1f;这篇文章里&#xff0c;作者就展开了多维度的测试和体验&#xff0c;想了解的同学&#xff0c;可以来看一下。 在中美AI大模型的竞争上&#xff0c;正衍…

从数据仓库到数据湖(上):数据湖导论

文章目录 一、什么是数据湖&#xff1f;起源数据湖的特征 二、为什么要用数据湖&#xff1f;三、数据湖与数据仓库的区别数据仓库和数据湖的对比 四、数据湖本质数据存储架构数据处理工具&#xff1a;三类第一类工具第二类工具第三类工具 小结 五、总结六、参考资料 一、什么是…

MQ四兄弟:如何保证消息顺序性

在当今的分布式系统架构中&#xff0c;消息队列&#xff08;MQ&#xff09;是不可或缺的组成部分。它们在确保系统组件之间高效通信方面发挥着关键作用。特别是在金融交易、物流跟踪等对消息处理顺序有严格要求的场景中&#xff0c;消息队列的顺序性保证显得更为重要。接下来&a…

使用libguestfs挂载qcow2磁盘镜像

挂载qcow2磁盘镜像的第一种方法是使用 libguestfs&#xff0c;它提供了一系列工具来访问和编辑 VM 磁盘镜像。libguestfs 支持几乎所有类型的磁盘镜像&#xff0c;包括 qcow2。你可以像下面这样&#xff0c;在Linux上安装libguestfs工具集。 1、安装guestmount工具 在基于 De…

Go语言---Json

JSON (JavaScript Object Notation)是一种比XML 更轻量级的数据交换格式&#xff0c;在易于人们阅读和编写的同时&#xff0c;也易于程序解析和生成。尽管JSON是 JavaScript的一个子集&#xff0c;但 JSON采用完全独立于编程语言的文本格式&#xff0c;且表现为键/值对集合的文…

【大模型LLM面试合集】大语言模型架构_layer_normalization

2.layer_normalization 1.Normalization 1.1 Batch Norm 为什么要进行BN呢&#xff1f; 在深度神经网络训练的过程中&#xff0c;通常以输入网络的每一个mini-batch进行训练&#xff0c;这样每个batch具有不同的分布&#xff0c;使模型训练起来特别困难。Internal Covariat…

【C++高阶】高效数据存储:理解并模拟实现红黑树Map与Set

&#x1f4dd;个人主页&#x1f339;&#xff1a;Eternity._ ⏩收录专栏⏪&#xff1a;C “ 登神长阶 ” &#x1f921;往期回顾&#x1f921;&#xff1a;了解 红黑树 &#x1f339;&#x1f339;期待您的关注 &#x1f339;&#x1f339; ❀模拟实现Map与Set &#x1f4d2;1.…

js ES6 part1

听了介绍感觉就是把js在oop的使用 作用域 作用域&#xff08;scope&#xff09;规定了变量能够被访问的“范围”&#xff0c;离开了这个“范围”变量便不能被访问&#xff0c; 作用域分为&#xff1a; 局部作用域、 全局作用域 1. 函数作用域&#xff1a; 在函数内部声明的…

爬取天气数据,利用Pyecharts作轮播图

爬取网站链接&#xff1a;https://lishi.tianqi.com/xiamen/202312.html 爬取了厦门市2023年一整年的天气数据&#xff0c;包括最高温&#xff0c;最低温&#xff0c;天气&#xff0c;风力风向等 爬虫代码&#xff1a; import requests import pandas as pd import csv from…

UML建模案例分析-时序图和类图的对应关系

概念 简单地说&#xff0c;类图定义了系统中的对象&#xff0c;时序图定义了对象之间的交互。 例子 一个电子商务系统&#xff0c;会员可通过电子商务系统购买零件。具体功能需求如下&#xff1a; 会员请求结账时&#xff0c;系统验证会员的账户是否处于登录状态&#xff1…

防火墙图形化界面策略和用户认证(华为)

目录 策略概要认证概要实验拓扑图题目要求一要求二要求三要求四要求五要求六 策略概要 安全策略概要&#xff1a; 安全策略&#xff08;Security Policy&#xff09;在安全领域具有双重含义。宏观上&#xff0c;安全策略指的是一个组织为保证其信息安全而建立的一套安全需求、…

uniapp 微信小程序接入MQTT

MQTT安装 前期准备 由于微信小程序需要wss&#xff0c;所以要有域名SSL证书 新建目录/srv/mosquitto/config&#xff0c;/srv/mosquitto/config/cert 目录/srv/mosquitto/config中新建配置文件mosquitto.conf&#xff0c;文件内容 persistence true persistence_location /m…

在树莓派设备上导出系统镜像

镜像导出 前提条件&#xff1a; 已获取可以正常使用的设备。已获取鼠标、键盘和电源适配器。已将设备接入可正常使用的网络。 操作步骤&#xff1a; 连接适配器给设备上电&#xff0c;正常启动设备&#xff0c;连接鼠标和键盘。在终端命令窗格执行如下命令&#xff0c;安装…

[PM]流程与结构设计

流程图 流程就是为了达到特定目标, 进行的一系列有逻辑性的操作步骤, 由两个及已上的步骤, 完成一个完整的行为过程, 即可称为流程, 流程图就是对这个过程的图形化展示 分类 业务流程图 概念: 描述业务流程的一种图, 通过特定符号和连线表示具体某个业务的处理步骤和过程作…

极狐GitLab亮相世界人工智能大会,开启开源大模型赋能软件研发新时代

GitLab 是一个全球知名的一体化 DevOps 平台&#xff0c;很多人都通过私有化部署 GitLab 来进行源代码托管。极狐GitLab &#xff1a;https://gitlab.cn/install?channelcontent&utm_sourcecsdn 是 GitLab 在中国的发行版&#xff0c;专门为中国程序员服务。可以一键式部署…

285个地级市-胡焕庸线数据

全国285个地级市-胡焕庸线数据.zip资源-CSDN文库 胡焕庸线&#xff1a;中国人口与生态的分界线 胡焕庸线&#xff0c;一条在中国地理学界具有划时代意义的分界线&#xff0c;由著名地理学家胡焕庸于1935年提出。这条线从黑龙江省的瑷珲&#xff08;现黑河市&#xff09;延伸至…

HippoRAG如何从大脑获取线索以改进LLM检索

知识存储和检索正在成为大型语言模型(LLM)应用的重要组成部分。虽然检索增强生成(RAG)在该领域取得了巨大进步&#xff0c;但一些局限性仍然没有克服。 俄亥俄州立大学和斯坦福大学的研究团队推出了HippoRAG&#xff0c;这是一种创新性的检索框架&#xff0c;其设计理念源于人类…

数学建模美赛论文文档

目录 1. 摘要&#xff1a;1.1 阅读并理解题目1.2 背景介绍1.3 问题提出 2. 目录&#xff1a;2.1 引言&#xff08;Introduction&#xff09;2.2 假设与合理性说明&#xff08;Assumptions and Justifications&#xff09;2.3 符号说明&#xff08;Notations&#xff09;2.4 模型…

线下线上游戏电竞陪伴APP小程序H5同城线下约玩APP开发,语聊约玩平台搭建游戏陪玩APP源码

开发一款线下陪玩约玩APP的实际意义和在生活中的应用场景 1、满足社交需求:现代社会人们的社交圈往往受到时间、地点和其他限制的影响。线下陪玩约玩APP可以提供一个平台&#xff0c;让用户通过约玩的方式结识新朋友、扩大社交圈 2、解决孤独感:有些人由于工作忙碌、居住环境单…

论文阅读2-《Dynamic Multimodal Fusion》

摘要 &#xff08;DynMM&#xff09;&#xff0c;一种新的方法&#xff0c;自适应融合多模态数据和 d在推理过程中生成依赖于数据的前向路径。为此&#xff0c;我们提出了一种门控功能来提供基于多模态特征和一个的模态级或融合级决策提高计算效率的源感知损失函数。 细节 模…