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

news2024/12/26 23:30:26

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);
                //熄灭所有LED
                inpOutManager.OutPortData(0X32, 0X02);
                inpOutManager.OutPortData(0X30, 0X21);
                Thread.Sleep(1000);
                //返还权限给EC
                inpOutManager.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);
                //返还权限给EC
                inpOutManager.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;
                }
            });
        }
        #endregion

        private 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();//开始测试
        }
        #endregion


        bool 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.coloradmin.cn/o/1193664.html

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

相关文章

多级缓存之缓存同步

缓存数据同步的常见方式有三种&#xff1a; 设置有效期&#xff1a;给缓存设置有效期&#xff0c;到期后自动删除。再次查询时更新 优势&#xff1a;简单、方便缺点&#xff1a;时效性差&#xff0c;缓存过期之前可能不一致场景&#xff1a;更新频率较低&#xff0c;时效性要…

d3.js

D3&#xff1a;Data-Driven Documents • 通过D3提供的接口来基于数据操控文档的各个图元。 标题对于D3(本讲解)最为重要的标签&#xff0c;主要操作的对象(画布) HTML - 导入D3.js D3.js作为JavaScript的外库&#xff0c;必须先将其导入&#xff0c;如&#xff1a; Python的…

[autojs]用户界面GUI编程

用户界面: UI视图: View attr(name, value)attr(name)whidgravitylayout_gravitymarginmarginLeftmarginRightmarginTopmarginBottompaddingpaddingLeftpaddingRightpaddingToppaddingBottombgalphaforegroundminHeightminWidthvisibilityrotationtransformPivotXtransformPivo…

移位操作符 位操作符详解

hello hello&#xff0c;想我了吗? &#x1f604;&#x1f604;&#x1f604; 首先是移位操作符&#xff1a;<< 左移操作符 >> 右移操作符 注&#xff1a;移位操作符的操作数只能是整数。 << 左移操作符&#xff1a;移位规则&#xff1a; 左边抛弃、…

我的AIGC部署实践03

我的AIGC部署实践03 这会是AIGC部署实践的第三回&#xff0c;用免费的GPU部署自己的stable-diffusion下面我们就开始吧。 1.创建项目 创建项目的镜像及数据集如下&#xff1a; 选择完成后点击创建&#xff0c;代码选择暂不上传。 2.初始化开发环境实例 点击最右侧的“开发…

服务器往客户端发送字符串的网络编程

服务器主要就是能够打开命令行提供的网络端口&#xff0c;然后一有客户端连接上&#xff0c;就会向客户端发送Welcome to Our Server!这段话。 服务器代码serverSayWelcome.c的代码如下&#xff1a; #include <stdio.h> #include <stdlib.h> #include <string.…

【ARM Trace32(劳特巴赫) 使用介绍 3 - trace32 访问运行时的内存】

请阅读【ARM Coresight SoC-400/SoC-600 专栏导读】 文章目录 1.1 trace32 访问运行时的内存1.1.1 侵入式 运行时内存访问1.1.2 非侵入式运行时访问1.1.3 缓存一致性的非侵入式运行时访问 1.2 Trace32 侵入式和非侵入式 运行时访问1.2.1 侵入式访问1.2.2 非侵入式运行时访问 1…

C++:关联式容器map的使用

1、map的简介 map是关联容器&#xff0c;它按照特定的次序(按照key来比较)存储由键值key和值value组合而成的元素。 在map中&#xff0c;键值key通常用于排序和惟一地标识元素&#xff0c;而值value中存储与此键值key关联的内容。键值key和值value的类型可能不同&#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&…

【Linux系统化学习】冯诺依曼体系结构 | 操作系统

个人主页点击直达&#xff1a;小白不是程序媛 Linux专栏&#xff1a;Linux系统化学习 目录 冯诺依曼体系结构 组成介绍 CPU和内存 以使用微信发消息为例理解冯诺依曼体系结构 操作系统 冯诺依曼体系结构 随着世界上第一台计算机ENIAC&#xff08;埃尼阿克&#xff09;的…

2、鸿蒙开发工具首次运行时开发环境配置

请务必在第一次运行时配置好开发环境&#xff0c;如果取消了配置&#xff0c;后续再配置会比较麻烦 1、点击工具图标运行 2、在欢迎页中点击“Agree” 3、默认“Do not import setting”&#xff0c;点击“OK” 3、此片设置Nodejs和Ohpm的安装&#xff0c;其中&#xff0c; …

传来喜讯,优维又获奖了!!!

优维科技作为国内DevOps领域的行业领先企业&#xff0c;从诞生之日起&#xff0c;就一直致力于为中国企业提供一流的数字化运维服务&#xff0c;不断深耕核心技术&#xff0c;向客户提供专业强大的产品与服务。多年来&#xff0c;不仅获得了大量客户认可&#xff0c;更是屡次获…

Apache Airflow (三) :Airflow WebUI操作介绍

&#x1f3e1; 个人主页&#xff1a;IT贫道_大数据OLAP体系技术栈,Apache Doris,Clickhouse 技术-CSDN博客 &#x1f6a9; 私聊博主&#xff1a;加入大数据技术讨论群聊&#xff0c;获取更多大数据资料。 &#x1f514; 博主个人B栈地址&#xff1a;豹哥教你大数据的个人空间-豹…

Android修行手册 - POI操作Excel常用样式(字体,背景,颜色,Style)

点击跳转>Unity3D特效百例点击跳转>案例项目实战源码点击跳转>游戏脚本-辅助自动化点击跳转>Android控件全解手册点击跳转>Scratch编程案例点击跳转>软考全系列 &#x1f449;关于作者 专注于Android/Unity和各种游戏开发技巧&#xff0c;以及各种资源分享&…

【媒体邀约】媒体宣传——企业成长的催化剂

传媒如春雨&#xff0c;润物细无声&#xff0c;大家好&#xff0c;我是51媒体网胡老师。 媒体宣传是企业成长的催化剂&#xff0c;它在各种方面对企业的成功和发展起到了关键作用。 1. 曝光和知名度&#xff1a; 媒体宣传可以将企业和其产品或服务推向广泛的受众&#xff0c;…

SQL第四次上机实验

1.查询借阅了计算机类或者文学类图书的读者的借书证号 USE TSGL GO SELECT DISTINCT Reader.Lno FROM Book,Lend,Reader WHERE Book.ISBNLend.ISBN AND Lend.LnoReader.Lno AND Class 计算机类 OR Class 文学类2.查询同时借阅了计算机类和文学类图书的读者的借书证号 USE T…

C语言之文件操作(剩余部分)

上篇博客字数到极限了&#xff0c;给大家把内容补充在这一篇&#xff0c;我们还剩下文件读取结束的判定和文件缓冲区的内容没有介绍&#xff0c;让我们开始下面的学习吧&#xff01; 目录 1.文件读取结束的判定 1.1feof函数 1.2ferror函数 代码示例 2.文件缓冲区 2.1fflu…

制造行业怎么做?看低代码如何引领未来

随着科技的不断发展&#xff0c;制造行业正面临着巨大的变革和挑战。为了提高生产效率、降低成本并更好地适应快速变化的市场需求&#xff0c;越来越多的制造企业将目光投向了低代码开发平台。在众多低代码开发平台中&#xff0c;JNPF低代码快速开发平台凭借其卓越的性能和灵活…

“三门问题”解决方案:换不换?更换策略与贝叶斯策略?附 Java 验证代码

文章目录 前言一、什么是“三门问题”&#xff1f;二、“三门问题”解决策略详解2.1、错误策略&#xff1a;直觉策略与随机策略2.2、更换策略与事件分析计算2.3、贝叶斯策略及分析流程 三、Java 语言验证“三门问题”总结 前言 “三门问题”作为一道经典逻辑推理题&#xff0c;…