Workstation.dll程序为实现封装好的 使用效果如图所示
C#传感器输入数据模拟命令行接收
首先设置textbox,并在设置栏中将背景设置为黑色,字体设置为白色,尽可能还原命令行。
botton4为显示按钮
botton5为退出按钮// An highlighted block using sun.management; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Windows.Forms.DataVisualization.Charting; using System.Runtime.InteropServices; using System.Net.Sockets; using System.Net; using System.IO; namespace WindowsFormsApptest { public partial class console : Form { [DllImport("Workstation.dll", EntryPoint = "getIP", CallingConvention = CallingConvention.Cdecl)] public unsafe static extern IntPtr getIP(); [DllImport("Workstation.dll", EntryPoint = "initSensors", CallingConvention = CallingConvention.Cdecl)] public static extern int initSensors(); [DllImport("Workstation.dll", EntryPoint = "getCodedDataPackage_ModeNormal", CallingConvention = CallingConvention.Cdecl)] public unsafe static extern IntPtr getCodedDataPackage_ModeNormal(int sensorID); [DllImport("Workstation.dll", EntryPoint = "decodeDataPackage_ModeNormal", CallingConvention = CallingConvention.Cdecl)] public unsafe static extern int* decodeDataPackage_ModeNorma(string codeDataPackage); static int num2; public console(int num) { InitializeComponent(); num2 = num; } unsafe public static int[] receive() { int[] m = new int[1018]; int* recDecodeBuff; //定义解码数据缓冲区 IntPtr recCodedBuff = getCodedDataPackage_ModeNormal(num2); string strun = Marshal.PtrToStringAnsi(recCodedBuff); recDecodeBuff = decodeDataPackage_ModeNorma(strun); for (int i = 0; i < 1018; i++) { if (recDecodeBuff != null) { m[i] = recDecodeBuff[i]; } else { m = null; } } return m; } private void button4_Click(object sender, EventArgs e) { int[] sensor = new int[1018]; sensor = receive(); if (sensor == null) { switch (num2) { case 1: { MessageBox.Show(" 温度传感器数据异常 ", " 警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } break; case 2: { MessageBox.Show(" 湿度传感器数据异常 ", " 警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } break; case 3: { MessageBox.Show(" PM2.5传感器数据异常 ", " 警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } break; case 4: { MessageBox.Show(" 光照传感器数据异常 ", " 警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } break; case 5: { MessageBox.Show(" CO传感器数据异常 ", " 警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } break; default: { MessageBox.Show(" 请选择传感器类型 ", " 警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } break; } } else { this.textBox1.Text = this.textBox1.Text + "ask for protocol successfully!" + "rn"; this.textBox1.Text = this.textBox1.Text + "creat socket successfully!" + "rn"; this.textBox1.Text = this.textBox1.Text + "connect successfully!" + "rn"; for (int i = 0; i < sensor.Length - 1; i++) { this.textBox1.Text = this.textBox1.Text + sensor[i] + ','; } this.textBox1.Text = "rn" + this.textBox1.Text + "请按任意键继续..."; } } private void button5_Click(object sender, EventArgs e) { System.Environment.Exit(0); } } }
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox网页视频下载器 下载地址: ImovieBox网页视频下载器-最新版本下载
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
阅读和此文章类似的: 全球云计算