C#基于inpoutx64读写ECRAM硬件信息

inpoutx64.dll分享路径:

链接:https://pan.baidu.com/s/1rOt0xtt9EcsrFQtf7S91ag 
提取码:7om1 
 

1.InpOutManager:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;namespace TestLEDWinFrm
{public class InpOutManager{public bool IsInpOutDriverOpen { get; set; }//端口是否已打开public short PORT_INDEX { get; } = 0x66;//端口号public short EC_COMMAND_WRITE { get; } = 0X81;//EC命令写入public short PORT_DATA { get; } = 0X62;//端口数据public string Err { get; set; }//错误信息[DllImport("inpoutx64.dll", EntryPoint = "IsInpOutDriverOpen")]public static extern uint isInpOutDriverOpen();[DllImport("inpoutx64.dll", EntryPoint = "Out32")]public static extern void Out32(short PortAddress, short Data);[DllImport("inpoutx64.dll", EntryPoint = "Inp32")]public static extern byte Inp32(short PortAddress);//[DllImport("inpout32.dll")]//private static extern void DlPortWritePortUshort(short PortAddress, ushort Data);//[DllImport("inpout32.dll")]//private static extern ushort DlPortReadPortUshort(short PortAddress);//[DllImport("inpout32.dll")]//private static extern void DlPortWritePortUlong(int PortAddress, uint Data);//[DllImport("inpout32.dll")]//private static extern uint DlPortReadPortUlong(int PortAddress);//[DllImport("inpoutx64.dll")]//private static extern bool GetPhysLong(ref int PortAddress, ref uint Data);//[DllImport("inpoutx64.dll")]//private static extern bool SetPhysLong(ref int PortAddress, ref uint Data);//[DllImport("inpoutx64.dll", EntryPoint = "IsInpOutDriverOpen")]//private static extern UInt32 IsInpOutDriverOpen_x64();//[DllImport("inpoutx64.dll", EntryPoint = "Out32")]//private static extern void Out32_x64(short PortAddress, short Data);//[DllImport("inpoutx64.dll", EntryPoint = "Inp32")]//private static extern char Inp32_x64(short PortAddress);//[DllImport("inpoutx64.dll", EntryPoint = "DlPortWritePortUshort")]//private static extern void DlPortWritePortUshort_x64(short PortAddress, ushort Data);//[DllImport("inpoutx64.dll", EntryPoint = "DlPortReadPortUshort")]//private static extern ushort DlPortReadPortUshort_x64(short PortAddress);//[DllImport("inpoutx64.dll", EntryPoint = "DlPortWritePortUlong")]//private static extern void DlPortWritePortUlong_x64(int PortAddress, uint Data);//[DllImport("inpoutx64.dll", EntryPoint = "DlPortReadPortUlong")]//private static extern uint DlPortReadPortUlong_x64(int PortAddress);//[DllImport("inpoutx64.dll", EntryPoint = "GetPhysLong")]//private static extern bool GetPhysLong_x64(ref int PortAddress, ref uint Data);//[DllImport("inpoutx64.dll", EntryPoint = "SetPhysLong")]//private static extern bool SetPhysLong_x64(ref int PortAddress, ref uint Data);public InpOutManager(){this.IsInpOutDriverOpen=isInpOutDriverOpen()>0?true:false;}/// <summary>/// 读取端口数据/// </summary>/// <param name="PortAddress"></param>/// <returns></returns>public bool InputPortData(short PortAddress){try{Inp32(PortAddress);return true;}catch(Exception ex){this.Err = ex.Message;return false;}}//Out32(short PortAddress, short Data)public bool OutPortData(short PortAddress,short Data){try{WaitECInputBufferEmpty();Out32(0x66,0x81);//Out32(PORT_INDEX,EC_COMMAND_WRITE);WaitECInputBufferEmpty();Out32(0x62,PortAddress);//Out32(PORT_DATA,PortAddress);WaitECInputBufferEmpty();Out32(0x62,Data);//Out32(PORT_DATA,Data);return true;}catch(Exception ex){this.Err=ex.Message;return false;}}private void WaitECInputBufferEmpty(){var IBF = 2;do{IBF = Inp32(0x66)&2;//IBF = (PORT_INDEX)&2;}while (IBF == 2);}}
}
namespace TestLEDWinFrm
{public partial class MainWinFrm : Form{InpOutManager inpOutManager;private System.Windows.Forms.Timer timer;private int randcount = 0;public MainWinFrm(){InitializeComponent();inpOutManager = new InpOutManager();//返还权限给EC//inpOutManager.OutPortData(0X32, 0X04);//inpOutManager.OutPortData(0X30, 0X21);}#region 所有LED灯点亮测试/// <summary>/// 所有LED灯点亮测试/// </summary>/// <param name="count">次数</param>public void AllLEDIllumeTest(int count){int i = 0;while (i < count){//点亮所有LED灯inpOutManager.OutPortData(0X32, 0X01);inpOutManager.OutPortData(0X30, 0X21);Thread.Sleep(1000);//熄灭所有LEDinpOutManager.OutPortData(0X32, 0X02);inpOutManager.OutPortData(0X30, 0X21);Thread.Sleep(1000);//返还权限给ECinpOutManager.OutPortData(0X32, 0X04);inpOutManager.OutPortData(0X30, 0X21);i++;}}#endregion#region 电源LED点亮测试/// <summary>/// 电源LED点亮测试/// </summary>/// <param name="count"></param>public void BatteryLedIllumTest(int count){int i = 0;while (i < count){//点亮Battery指示灯inpOutManager.OutPortData(0X32, 0X03);inpOutManager.OutPortData(0X30, 0X21);Thread.Sleep(1000);//熄灭所有指示灯inpOutManager.OutPortData(0X32, 0X02);inpOutManager.OutPortData(0X30, 0X21);Thread.Sleep(1000);//返还权限给ECinpOutManager.OutPortData(0X32, 0X04);inpOutManager.OutPortData(0X30, 0X21);i++;}}#endregion#region 历史记录private void btn_StartTest_Click(object sender, EventArgs e){//inpOutManager.InputPortData(0X32);inpOutManager.OutPortData(0X32, 0X01);//inpOutManager.InputPortData(0X30);inpOutManager.OutPortData(0X30, 0X21);}private void button1_Click(object sender, EventArgs e){//熄灭所有LED//inpOutManager.InputPortData(0X32);inpOutManager.OutPortData(0X32, 0X02);//inpOutManager.InputPortData(0X30);inpOutManager.OutPortData(0X30, 0X21);}private void button2_Click(object sender, EventArgs e){//点亮第二个battery led//inpOutManager.InputPortData(0X32);inpOutManager.OutPortData(0X32, 0X03);//inpOutManager.InputPortData(0X30);inpOutManager.OutPortData(0X30, 0X21);//WinIoFunction.SetPhysValue("0X32", "0X03");//WinIoFunction.SetPhysValue("0X30", "0X21");}private void button3_Click(object sender, EventArgs e){//点亮第二个battery led//inpOutManager.InputPortData(0X32);inpOutManager.OutPortData(0X32, 0X04);//inpOutManager.InputPortData(0X30);inpOutManager.OutPortData(0X30, 0X21);//WinIoFunction.SetPhysValue("0X32", "0X04");//WinIoFunction.SetPhysValue("0X30", "0X21");}#endregion#region 关闭private void btn_Close_Click(object sender, EventArgs e){System.Environment.Exit(1);//程式退出返回1}#endregion#region 窗体移动private Point mouseOff;//鼠标移动位置变量private bool leftFlag;//标签是否为左键private void Frm_MouseDown(object sender, MouseEventArgs e){if (e.Button == MouseButtons.Left){mouseOff = new Point(-e.X, -e.Y); //得到变量的值leftFlag = true;                  //点击左键按下时标注为true;}}private void Frm_MouseMove(object sender, MouseEventArgs e){if (leftFlag){Point mouseSet = Control.MousePosition;mouseSet.Offset(mouseOff.X, mouseOff.Y);  //设置移动后的位置Location = mouseSet;}}private void Frm_MouseUp(object sender, MouseEventArgs e){if (leftFlag){leftFlag = false;//释放鼠标后标注为false;}}#endregion#region 时间同步private void Timer_Tick(object sender, EventArgs e){ts_DateTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");}#endregion#region 桌面加载private void MainWinFrm_Load(object sender, EventArgs e){timer = new System.Windows.Forms.Timer();timer.Interval = 1000;timer.Tick += Timer_Tick!;timer.Enabled = true;}#endregion#region 移动鼠标坐标private void MainFrm_Move(object sender, EventArgs e){// 获取当前鼠标的坐标Point cursorPosition = Cursor.Position;TS_X.Text = cursorPosition.X.ToString();TS_Y.Text = cursorPosition.Y.ToString();}#endregion#region 日志信息private void Loginfo(string log, bool isPass, int item = 0){Invoke(() =>{ListViewItem li_er = new ListViewItem();li_er.SubItems[0].Text = log;li_er.SubItems.Add(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));li_er.ForeColor = isPass ? Color.Green : Color.Red;lv_log.Items.Add(li_er);if (item == 1){//this.txt_ScanSn.Enabled = true;//this.Focus();btn_StartTest.Enabled = false;btn_Restart.Enabled = false;}else if (item == 2)//启动重测{//this.txt_ScanSn.Enabled = false;btn_Restart.Enabled = true;btn_StartTest.Enabled = false;}});}#endregionprivate void btn_StartTest_Click_1(object sender, EventArgs e){btn_StartTest.Enabled = false;this.StartTest();//开始测试}#region 开始测试public void StartTest(){//lbl_TestItem.Text = "开始所有LED指示灯,随机闪烁次数测试!!";//lbl_TestImage.Image = Properties.Resources._1;//Random random = new Random();//this.randcount = random.Next(1, 5);//this.AllLEDIllumeTest(this.randcount);//随机数lbl_TestItem.Text = "开始电源充电指示灯,随机闪烁次数测试!!";lbl_TestImage.Image = Properties.Resources._2;Random random = new Random();this.randcount = random.Next(1, 5);this.BatteryLedIllumTest(this.randcount);//随机电源指示灯次数foreach (Control control in this.groupBox5.Controls){if (control is Button){((Button)control).Enabled = true;}}}#endregion#region 初始化界面private void Winitial(bool IsEnable){foreach (Control control in this.groupBox5.Controls){if (control is Button){((Button)control).Enabled = IsEnable;}}lbl_TestImage.Image = null;lbl_TestItem.Text = "待开始电源指示灯测试!!";lbl_TestResult.Text = "待测试";lbl_TestImage.ForeColor = Color.SandyBrown;}#endregion#region 重测试private void btn_Restart_Click(object sender, EventArgs e){this.Winitial(false);//初始化this.StartTest();//开始测试}#endregionbool isFirst = true;private void btn_num_Click(object sender, EventArgs e){if (isFirst){if (((Button)sender).Text == this.randcount.ToString()){this.lbl_TestResult.ForeColor = Color.Green;this.lbl_TestResult.Text = "PASS";//lbl_TestItem.Text = "开始电源充电指示灯,随机闪烁次数测试!!";//lbl_TestImage.Image = Properties.Resources._2;//Random random = new Random();//this.randcount = random.Next(1, 5);//this.BatteryLedIllumTest(this.randcount);//随机电源指示灯次数lbl_TestItem.Text = "开始所有LED指示灯,随机闪烁次数测试!!";lbl_TestImage.Image = Properties.Resources._1;Random random = new Random();this.randcount = random.Next(1, 5);this.AllLEDIllumeTest(this.randcount);//随机数isFirst = false;}else{this.lbl_TestResult.ForeColor = Color.Red;this.lbl_TestResult.Text = "FAIL";btn_Restart.Enabled = true;btn_StartTest.Enabled = false;isFirst = true;//this.Loginfo("所有LED点亮测试,闪烁次数与实际选择的序号不符,测试结果FAIL!!", false);this.Loginfo("电源指示灯测试,闪烁次数与实际选择的序号不符,测试结果FAIL!!", false);foreach (Control control in this.groupBox5.Controls){if (control is Button){((Button)control).Enabled = false;}}}}else{if (((Button)sender).Text == this.randcount.ToString()){this.lbl_TestResult.ForeColor = Color.Green;this.lbl_TestResult.Text = "PASS";timer1.Enabled = true;}else{this.lbl_TestResult.ForeColor = Color.Red;this.lbl_TestResult.Text = "FAIL";btn_Restart.Enabled = true;btn_StartTest.Enabled = false;isFirst = true;//this.Loginfo("电源指示灯测试,闪烁次数与实际选择的序号不符,测试结果FAIL!!", false);this.Loginfo("所有LED点亮测试,闪烁次数与实际选择的序号不符,测试结果FAIL!!", false);foreach (Control control in this.groupBox5.Controls){if (control is Button){((Button)control).Enabled = false;}}}}}private int index = 5;private void timer1_Tick(object sender, EventArgs e){lbl_Exit.Visible = true;if (index > 0){lbl_Exit.Text = index.ToString();index--;}else{System.Environment.Exit(0);}}}
}

UI展示:

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

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

相关文章

基于Docker容器DevOps应用方案

文章目录 基于docker容器DevOps应用方案环境基础配置1.所有主机永久关闭防火墙和selinux2.配置yum源3.docker的安装教程 配置主机名与IP地址解析部署gitlab.server主机1.安装gitlab2.配置gitlab3.破解管理员密码4.验证web页面 部署jenkins.server主机1.部署tomcat2.安装jenkins…

Ubuntu(WSL) mysql8.0.31 源码安装

要在 Ubuntu 上使用调试功能安装 MySQL 8.0 的源码&#xff0c;可以按照以下详细步骤进行操作&#xff1a; 1. 更新系统 首先&#xff0c;确保你的 Ubuntu 系统是最新的。运行以下命令更新系统软件包&#xff1a; sudo apt update sudo apt upgrade 2. 下载 MySQL 源码 访…

Wix使用velo添加Google ads tag并在form表单提交时向谷歌发送事件

往head里加代码时&#xff0c;不能看谷歌的代码&#xff0c;要看wix的代码&#xff0c;不然必定踩坑 https://support.wix.com/en/article/tracking-google-ads-conversions-using-wix-custom-code 这里的代码才对&#xff0c;因为wix搞了个velo&#xff0c;这个velo很傻x&am…

ChatGPT、GPT-4 Turbo接口调用

接口地址 https://chat.xutongbao.top/api/light/chat/createChatCompletion 请求方式 post 请求参数 model可选值&#xff1a; “gpt-3.5-turbo-1106”、 “gpt-3.5-turbo-16k” 、 “gpt-4”、“gpt-4-1106-preview”。 默认值为&#xff1a; “gpt-3.5-turbo-1106” to…

时间序列预测模型实战案例(十)(个人创新模型)通过堆叠CNN、GRU、LSTM实现多元预测和单元预测

本文介绍 本篇博客为大家讲解的是通过组堆叠CNN、GRU、LSTM个数&#xff0c;建立多元预测和单元预测的时间序列预测模型&#xff0c;其效果要比单用GRU、LSTM效果好的多&#xff0c;其结合了CNN的特征提取功能、GRU和LSTM用于处理数据中的时间依赖关系的功能。通过将它们组合在…

基于GCC的工具objdump实现反汇编

一&#xff1a;objdump介绍 在 Linux中&#xff0c;一切皆文件。 Linux 编程实际上是编写处理各种文件的代码。系统由许多类型的文件组成&#xff0c;但目标文件具有一种特殊的设计&#xff0c;提供了灵活和多样的用途。 目标文件是包含带有附加地址和值的助记符号的路线图。这…

PHP编写采集药品官方数据的程序

在 PHP 中编写爬虫程序&#xff0c;首先我们需要引入一些必要的库&#xff0c;如 curl 和 file_get_contents。然后&#xff0c;我们需要设置爬虫ip信息&#xff0c;以便我们可以从指定的爬虫ip服务器上获取数据。 // 引入必要的库 require_once curl.php;// 设置爬虫ip信息 $p…

招聘信息采集

首先&#xff0c;我们需要使用PHP的curl库来发送HTTP请求。以下是一个基本的示例&#xff1a; <?php // 初始化curl $ch curl_init();// 设置代理 curl_setopt($ch, CURLOPT_PROXY, "jshk.com.cn");// 设置URL curl_setopt($ch, CURLOPT_URL, "http://www…

leetcode一道比较难的链表题

今天还是继续来分享我们的链表题&#xff0c;这个题目有点难&#xff0c;主要是思路比较难想&#xff0c;但是如果沥青思路写起来就比较简单了&#xff08;我乱讲的&#xff09; 随机链表的复制 这个是题目的描述&#xff0c;大家也可以在链接里看&#xff0c;那我把这道题目…

VNC连接服务器实现远程桌面 --以AutoDL云服务器为例

VNC连接服务器实现远程桌面 --以AutoDL云服务器为例 针对本地机为Windows 云服务器租显卡跑些小模型很方便&#xff0c;但是当你想做可视化的时候&#xff0c;可能会遇到麻烦&#xff0c;云服务器没有显示输出界面&#xff0c;无法可视化一些检测任务的结果&#xff0c;或者可…

chrome 的vue3的开发者devtool不起作用

问题&#xff1a; 刚刚vue2升级到vue3&#xff0c;旧的devtool识别不了vue3数据。 原因&#xff1a; devtool版本过低。升级到最新。 解决&#xff1a; 去github下载vuetool项目代码&#xff1a; GitHub - vuejs/devtools: ⚙️ Browser devtools extension for debugging…

Dell戴尔灵越Inspiron 7700 AIO一体机电脑原厂预装Windows10系统

链接&#xff1a;https://pan.baidu.com/s/1-slgR9t4Df_eko0Y6xaeyw?pwdmk0p 提取码&#xff1a;mk0p 灵越7700一体机原装出厂系统自带声卡驱动、无线网卡驱动、面部识别等所有驱动、出厂主题壁纸、系统属性专属LOGO标志、Office办公软件、MyDell等预装程序 由于时间关系,…

GEE ——errors & debuggings (2023GEE峰会总结)

简介&#xff1a; 在gee中有三种错误&#xff0c;一种就是系统错误&#xff0c;也就是我们看到的会在JavaScript code editor中出现的错误&#xff0c;也就是在程序还没有启动之前就会提示的错误&#xff0c;而客户端错误则主要是会提示一些在代码过程中的错误&#xff0c;比如…

【数据结构】树与二叉树(八):二叉树的中序遍历(非递归算法NIO)

文章目录 5.2.1 二叉树二叉树性质引理5.1&#xff1a;二叉树中层数为i的结点至多有 2 i 2^i 2i个&#xff0c;其中 i ≥ 0 i \geq 0 i≥0。引理5.2&#xff1a;高度为k的二叉树中至多有 2 k 1 − 1 2^{k1}-1 2k1−1个结点&#xff0c;其中 k ≥ 0 k \geq 0 k≥0。引理5.3&…

从零开始的C++(十四)

继承&#xff1a; 作用&#xff1a;减少重复代码&#xff0c;简化程序。 用法&#xff1a; class b&#xff1a;public a {//...b中成员 } 在如上代码中&#xff0c;b类以public的方式继承了a类。规定a类是父类、基类&#xff0c;b类是子类、派生类。 关于继承方式&#xf…

力扣字符串--总结篇

前言 字符串学了三天&#xff0c;七道题。初窥kmp&#xff0c;已经感受到算法的博大精深了。 内容 对字符串的操作可以归结为以下几类&#xff1a; 字符串的比较、连接操作&#xff08;不同编程语言实现方式有所不同&#xff09;&#xff1b; 涉及子串的操作&#xff0c;比…

Electron-vue出现GET http://localhost:9080/__webpack_hmr net::ERR_ABORTED解决方案

GET http://localhost:9080/__webpack_hmr net::ERR_ABORTED解决方案 使用版本解决方案解决总结 使用版本 以下是我解决此问题时使用的electron和vue等的一些版本信息 【附】经过测试 electron 的版本为 13.1.4 时也能解决 解决方案 将项目下的 .electron-vue/dev-runner.js…

【PWN · ret2csu】[HNCTF 2022 WEEK2]ret2csu

记一道ret2csu 一、题目 二、思路 1.ret2csu用write泄露write的真实地址->泄露libc->获得system的真实地址 2.ret2csu用read写/bin/sh字符串到bss段上 3.ret2csu用write将system的真实地址写到bss段上 4.ret2csu调用system 三、exp from pwn import * from pwn impo…

[100天算法】-最短无序连续子数组(day 70)

题目描述 给定一个整数数组&#xff0c;你需要寻找一个连续的子数组&#xff0c;如果对这个子数组进行升序排序&#xff0c;那么整个数组都会变为升序排序。你找到的子数组应是最短的&#xff0c;请输出它的长度。示例 1:输入: [2, 6, 4, 8, 10, 9, 15] 输出: 5 解释: 你只需要…

Linux下内网穿透实现云原生观测分析工具的远程访问

&#x1f4d1;前言 本文主要是Linux下内网穿透实现云原生观测分析工具的远程访问设置的文章&#xff0c;如果有什么需要改进的地方还请大佬指出⛺️ &#x1f3ac;作者简介&#xff1a;大家好&#xff0c;我是青衿&#x1f947; ☁️博客首页&#xff1a;CSDN主页放风讲故事 &…