当前位置: 首页 > news >正文

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展示:

相关文章:

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

inpoutx64.dll分享路径&#xff1a; 链接&#xff1a;https://pan.baidu.com/s/1rOt0xtt9EcsrFQtf7S91ag 提取码&#xff1a;7om1 1.InpOutManager&#xff1a; using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServi…...

图论13-最小生成树-Kruskal算法+Prim算法

文章目录 1 最小生成树2 最小生成树Kruskal算法的实现2.1 算法思想2.2 算法实现2.2.1 如果图不联通&#xff0c;直接返回空&#xff0c;该图没有mst2.2.2 获得图中的所有边&#xff0c;并且进行排序2.2.2.1 Edge类要实现Comparable接口&#xff0c;并重写compareTo方法 2.2.3 取…...

免费博客搭建笔记

title: 免费博客搭建笔记 tags: 博客搭建 本次是对自己在网上学习github搭建一个 &#x1f447;个人免费静态网站的总结当然不是很完美&#x1f447; Bow to the new king iYANG (yangsongl1n.github.io) 接着我会从我的写笔记的个人习惯来逐步介绍如何搭建这个网站 1.写笔…...

网络运维Day10

文章目录 SHELL基础查看有哪些解释器使用usermod修改用户解释器BASH基本特性 shell脚本的设计与运行编写问世脚本脚本格式规范执行shell脚本方法一方法二实验 变量自定义变量环境变量位置变量案例 预定义变量 变量的扩展运用多种引号的区别双引号的应用单引号的应用反撇号或$()…...

@Cacheable 注解的 @CacheManager 示例

pom.xml 依赖包&#xff1a; <dependency><groupId>org.springframework.data</groupId><artifactId>spring-data-redis</artifactId></dependency><dependency><groupId>redis.clients</groupId><artifactId>jed…...

springboot二维码示例

pom.xml依赖 <dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.8.16</version></dependency><dependency><groupId>com.google.zxing</groupId><artifactId>…...

nacos做服务配置和服务器发现

一、创建项目 1、创建一个spring-boot的项目 2、创建三个模块file、system、gateway模块 3、file和system分别配置启动信息,并且创建一个简单的控制器 server.port9000 spring.application.namefile server.servlet.context-path/file4、在根目录下引入依赖 <properties&g…...

KCC@广州与 TiDB 社区联手—广州开源盛宴

10月21日&#xff0c;KCC广州与 TiDB 社区联手&#xff0c;在海珠区保利中悦广场 29 楼召开了一次难忘的开源盛宴。这不仅仅是 KCC广州的又一次线下见面&#xff0c;更代表着与 TiDB 社区及广州技术社区的首次深度合作。 活动的策划与组织由 KCC广州负责人 - 惠世冀、PingCAP 的…...

CSS3 分页、框大小、弹性盒子

一、CSS3分页&#xff1a; 网站有很多个页面&#xff0c;需要使用分页来为每个页面做导航。示例&#xff1a; <style> ul.pagination { display: inline-block; padding: 0; margin: 0; } ul.pagination li {display: inline;} ul.pagination li a { color: black; f…...

GEE问题——GEE中循环的使用map()函数,以提取指定范围内的逐日的二氧化氮平均浓度为例

问题: 我有一个简单的代码,可以帮助计算德克萨斯州每个县的对流层二氧化氮平均浓度。目前,我可以将其导出为我指定的任何日期范围的 csv 表,但我想 1) 提取每天平均值,例如 3 个月(2020 年 3 月至 2020 年 5 月,约 90 天)--手动多次运行肯定不是办法,而且我的编码技…...

短信验证码实现(阿里云)

如果实现短信验证&#xff0c;上教程&#xff0c;这里用的阿里云短信服务 短信服务 (aliyun.com) 进入短信服务后开通就行&#xff0c;可以体验100条免费&#xff0c;刚好测试用 这里由自定义和专用&#xff0c;测试的话就选择专用吧&#xff0c;自定义要审核&#xff0c; Se…...

如何对element弹窗进行二次封装

方式一使用$refs 个人比较喜欢用这种的 通过$refs打开的同时 还能给弹窗组件传参 一些框架使用的也是这种方式 父组件 <template><div><el-button type"text" click"handleDialogOpen">打开嵌套表单的 Dialog</el-button><Dia…...

【微服务专题】手写模拟SpringBoot

目录 前言阅读对象阅读导航前置知识笔记正文一、工程项目准备1.1 新建项目1.1 pom.xml1.2 业务模拟 二、模拟SpringBoot启动&#xff1a;好戏开场2.1 启动配置类2.1.1 shen-base-springboot新增2.1.2 shen-example客户端新增启动类 三、run方法的实现3.1 步骤一&#xff1a;启动…...

七个优秀微服务跟踪工具

随着微服务架构复杂性的增加&#xff0c;在问题出现时确定问题的根本原因变得更具挑战性。日志和指标为我们提供了有用的信息&#xff0c;但并不能提供系统的完整概况。这就是跟踪的用武之地。通过跟踪&#xff0c;开发人员可以监控微服务之间的请求进度&#xff0c;从而使他们…...

redis 问题解决 1

1.1 常见考点 1、Redis 为何这么快? Redis 是一款基于内存的数据结构存储系统,它之所以能够提供非常快的读写性能,主要是因为以下几个方面的原因: 基于内存存储:Redis 所有的数据都存储在内存中,而内存的访问速度比磁盘要快得多。因此,Redis 可以提供非常快的读写性能…...

odoo16前端框架源码阅读——启动、菜单、动作

odoo16前端框架源码阅读——启动、菜单、动作 目录&#xff1a;addons/web/static/src 1、main.js odoo实际上是一个单页应用&#xff0c;从名字看&#xff0c;这是前端的入口文件&#xff0c;文件内容也很简单。 /** odoo-module **/import { startWebClient } from "…...

C/C++(a/b)*c的值 2021年6月电子学会青少年软件编程(C/C++)等级考试一级真题答案解析

目录 C/C(a/b)*c的值 一、题目要求 1、编程实现 2、输入输出 二、算法分析 三、程序编写 四、程序说明 五、运行结果 六、考点分析 C/C(a/b)*c的值 2021年6月 C/C编程等级考试一级编程题 一、题目要求 1、编程实现 给定整数a、b、c&#xff0c;计算(a / b)*c的值&…...

CIFAR-100数据集的加载和预处理教程

一、CIFAR-100数据集介绍 CIFAR-100&#xff08;Canadian Institute for Advanced Research - 100 classes&#xff09;是一个经典的图像分类数据集&#xff0c;用于计算机视觉领域的研究和算法测试。它是CIFAR-10数据集的扩展版本&#xff0c;包含了更多的类别&#xff0c;用…...

C#,数值计算——函数计算,Eulsum的计算方法与源程序

1 文本格式 using System; namespace Legalsoft.Truffer { public class Eulsum { private double[] wksp { get; set; } private int n { get; set; } private int ncv { get; set; } public bool cnvgd { get; set; } pri…...

ChatGLM3 langchain_demo 代码解析

ChatGLM3 langchain_demo 代码解析 0. 背景1. 项目代码结构2. 代码解析2-1. utils.py2-2. ChatGLM3.py2-3. Tool/Calculator.py2-4. Tool/Weather.py2-5. main.py 0. 背景 学习 ChatGLM3 的项目内容&#xff0c;过程中使用 AI 代码工具&#xff0c;对代码进行解释&#xff0c;…...

C++:std::is_convertible

C++标志库中提供is_convertible,可以测试一种类型是否可以转换为另一只类型: template <class From, class To> struct is_convertible; 使用举例: #include <iostream> #include <string>using namespace std;struct A { }; struct B : A { };int main…...

页面渲染流程与性能优化

页面渲染流程与性能优化详解&#xff08;完整版&#xff09; 一、现代浏览器渲染流程&#xff08;详细说明&#xff09; 1. 构建DOM树 浏览器接收到HTML文档后&#xff0c;会逐步解析并构建DOM&#xff08;Document Object Model&#xff09;树。具体过程如下&#xff1a; (…...

ETLCloud可能遇到的问题有哪些?常见坑位解析

数据集成平台ETLCloud&#xff0c;主要用于支持数据的抽取&#xff08;Extract&#xff09;、转换&#xff08;Transform&#xff09;和加载&#xff08;Load&#xff09;过程。提供了一个简洁直观的界面&#xff0c;以便用户可以在不同的数据源之间轻松地进行数据迁移和转换。…...

linux 下常用变更-8

1、删除普通用户 查询用户初始UID和GIDls -l /home/ ###家目录中查看UID cat /etc/group ###此文件查看GID删除用户1.编辑文件 /etc/passwd 找到对应的行&#xff0c;YW343:x:0:0::/home/YW343:/bin/bash 2.将标红的位置修改为用户对应初始UID和GID&#xff1a; YW3…...

ElasticSearch搜索引擎之倒排索引及其底层算法

文章目录 一、搜索引擎1、什么是搜索引擎?2、搜索引擎的分类3、常用的搜索引擎4、搜索引擎的特点二、倒排索引1、简介2、为什么倒排索引不用B+树1.创建时间长,文件大。2.其次,树深,IO次数可怕。3.索引可能会失效。4.精准度差。三. 倒排索引四、算法1、Term Index的算法2、 …...

Spring AI与Spring Modulith核心技术解析

Spring AI核心架构解析 Spring AI&#xff08;https://spring.io/projects/spring-ai&#xff09;作为Spring生态中的AI集成框架&#xff0c;其核心设计理念是通过模块化架构降低AI应用的开发复杂度。与Python生态中的LangChain/LlamaIndex等工具类似&#xff0c;但特别为多语…...

SAP学习笔记 - 开发26 - 前端Fiori开发 OData V2 和 V4 的差异 (Deepseek整理)

上一章用到了V2 的概念&#xff0c;其实 Fiori当中还有 V4&#xff0c;咱们这一章来总结一下 V2 和 V4。 SAP学习笔记 - 开发25 - 前端Fiori开发 Remote OData Service(使用远端Odata服务)&#xff0c;代理中间件&#xff08;ui5-middleware-simpleproxy&#xff09;-CSDN博客…...

自然语言处理——文本分类

文本分类 传统机器学习方法文本表示向量空间模型 特征选择文档频率互信息信息增益&#xff08;IG&#xff09; 分类器设计贝叶斯理论&#xff1a;线性判别函数 文本分类性能评估P-R曲线ROC曲线 将文本文档或句子分类为预定义的类或类别&#xff0c; 有单标签多类别文本分类和多…...

Spring AOP代理对象生成原理

代理对象生成的关键类是【AnnotationAwareAspectJAutoProxyCreator】&#xff0c;这个类继承了【BeanPostProcessor】是一个后置处理器 在bean对象生命周期中初始化时执行【org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization】方法时…...

对象回调初步研究

_OBJECT_TYPE结构分析 在介绍什么是对象回调前&#xff0c;首先要熟悉下结构 以我们上篇线程回调介绍过的导出的PsProcessType 结构为例&#xff0c;用_OBJECT_TYPE这个结构来解析它&#xff0c;0x80处就是今天要介绍的回调链表&#xff0c;但是先不着急&#xff0c;先把目光…...