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.hqwc.cn/news/168228.html

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

相关文章

畅通工程之局部最小花费问题 (C++)

目录 题目&#xff1a; 思路&#xff1a; 代码&#xff1a; 结果 题目&#xff1a; 思路&#xff1a; 详细思路都在代码注释里 。 代码&#xff1a; #include<iostream>//无向图邻接矩阵 #include<map> #include<algorithm> #define mvnum 1005 using …

探索微信小程序框架的精华——高质量的优秀选择

目录 引言&#xff1a; 1. 框架性能 2. 开发者工具支持 3. 文档和社区支持 4. 扩展能力 5. 使用率和稳定性 结语&#xff1a; 引言&#xff1a; 微信小程序作为一种轻量级、高效便捷的应用形式&#xff0c;已经在移动应用领域占据了重要地位。而其中&#xff0c;选择一个…

【uniapp】仿微信通讯录列表实现

效果图 代码实现 <view class"main-container"><!-- 成员列表 --><scroll-viewclass"member-list":style"computedHeight":scroll-y"true":enable-back-to-top"true":scroll-with-animation"true"…

Hls学习(一)

1&#xff1a;CPU、DSP、GPU都算软件可编程的硬件 2&#xff1a;dsp在递归方面有所减弱&#xff0c;在递归方面有所增强&#xff0c;比如递归啊等&#xff0c;GPU可以同时处理多个进程&#xff0c;对于大块数据&#xff0c;流处理比较适用 3&#xff1a;为了提高运算量处理更多…

SHCTF-校外赛道

SHCTF-校外赛道 [WEEK1]babyRCE 1 (1)more:一页一页的显示档案内容2 (2)less:与 more 类似&#xff0c;但是比 more 更好的是&#xff0c;他可以[pg dn][pg up]翻页3 (3)head:查看头几行4 (4)tac:从最后一行开始显示&#xff0c;可以看出 tac 是 cat 的反向显示5 (5)tail:查看…

PDF Expert for mac(专业pdf编辑器)苹果电脑

PDF Expert for Mac 是一款功能强大、界面简洁的PDF阅读、编辑和转换工具&#xff0c;为Mac用户提供了全面而便捷的PDF处理体验。无论是日常工作中的文档阅读、标注&#xff0c;还是专业需求下的编辑、转换&#xff0c;PDF Expert 都能满足您的各种需求。 首先&#xff0c;PDF…

nfs配置

1.NFS介绍 NFS就是Network File System的缩写&#xff0c;它最大的功能就是可以通过网络&#xff0c;让不同的机器、不同的操 作系统可以共享彼此的文件。 NFS服务器可以让PC将网络中的NFS服务器共享的目录挂载到本地端的文 件系统中&#xff0c;而在本地端的系统中来看&#…

【Kurbernetes集群】Pod资源、Pod资源限制和Pod容器的健康检查(探针)详解

Pod资源 一、Pod概述1.1 Pod的定义1.2 一个Pod能包含几个容器&#xff1f;1.3 Pod的分类1.3.1 控制器管理的Pod1.3.2 自主式Pod1.3.3 静态Pod 1.4 Pod中容器的分类1.4.1 Pause容器1.4.2 初始化容器1.4.3 应用容器 1.5 Pod常见的状态 二、Pod中的策略2.1 镜像拉取策略2.2 Pod中容…

C语言--定义一个包含年月日的结构体Day,实现一个函数,根据传入的结构体指针计算,该日期是当年的第几天?

一.题目要求 输入2000年6月5日&#xff0c;输出&#xff1a;这是2000年的第157天。 二.思路分析 首先定义一个包含年月日的结构体 年份&#xff1a;要判断是否是闰年&#xff0c;闰年的二月有29天&#xff0c;平年的二月有28天。 月份&#xff1a;一个月份分大月和小月&#…

K8S概念与架构

K8S概念与架构 一、Kubernetes 概述1、K8S 是什么2、为什么要用 K8S3、k8s介绍二、Kubernetes 集群架构与组件2.1、Master核心组件 2.2、Node核心组件 三、Kubernetes 核心概念3.1、Pod 控制器 一、Kubernetes 概述 1、K8S 是什么 K8S 的全称为 Kubernetes (K12345678S)&…

基于php js+mysql+laravel技术架构的手术麻醉管理系统源码 手麻系统源码

PHP手术麻醉管理系统源码 手麻系统源码 手术麻醉管理系统定义&#xff1a; 手术麻醉系统主要是由麻醉信息管理和监护设备数据采集系统两个部分组成&#xff0c;主要是将麻醉信息和从监护仪器上采集到的数据以及手术信息进行统计。 手术麻醉系统是指专用于住院患者手术与麻醉…

【Java】Netty创建网络服务端客户端(TCP/UDP)

&#x1f60f;★,:.☆(&#xffe3;▽&#xffe3;)/$:.★ &#x1f60f; 这篇文章主要介绍Netty创建网络服务端客户端示例。 学其所用&#xff0c;用其所学。——梁启超 欢迎来到我的博客&#xff0c;一起学习&#xff0c;共同进步。 喜欢的朋友可以关注一下&#xff0c;下次更…