代码拉取完成,页面将自动刷新
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.Runtime.InteropServices;
namespace clientgui
{
public partial class Form1 : Form
{
[DllImport("ws_dll1.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int connectt(string ipp);
[DllImport("ws_dll1.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr communication(string str);
private Button connect = new Button();
private Button tip = new Button();
private Label titlelabel = new Label();
private TextBox ipin = new TextBox();
private TextBox textin = new TextBox(); //温度
private TextBox textout = new TextBox(); //指令
private TextBox temple = new TextBox(); //指示
public Form1()
{
InitializeComponent();
this.Controls.Add(titlelabel);
this.Controls.Add(connect);
this.Controls.Add(tip);
this.Controls.Add(ipin);
this.Controls.Add(textin);
this.Controls.Add(textout);
this.Controls.Add(temple);
titlelabel.AutoSize = false;
titlelabel.Width = 200;
titlelabel.Height = 50;
titlelabel.TextAlign = System.Drawing.ContentAlignment.TopCenter;
titlelabel.Location = new System.Drawing.Point((this.ClientSize.Width - titlelabel.Width) / 2, 10);
titlelabel.Text = "温度传感器";
titlelabel.ForeColor = System.Drawing.SystemColors.Highlight;
titlelabel.Font = new System.Drawing.Font("宋体", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
connect.Location = new System.Drawing.Point(this.ClientSize.Width - 100, 200);
connect.Text = "连接";
tip.Location = new System.Drawing.Point(this.ClientSize.Width - 100, 400);
tip.Text = "帮助";
tip.Click += new System.EventHandler(tip_Click);
titlelabel.TextAlign = System.Drawing.ContentAlignment.TopCenter;
ipin.Location = new System.Drawing.Point(200, 200);
ipin.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
ipin.Width = 200;
textin.Location = new System.Drawing.Point(200, 200);
textin.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
textin.Width = 200;
textout.Location = new System.Drawing.Point(200, 200);
textout.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
textout.Width = 200;
temple.Location = new System.Drawing.Point(200, 200);
temple.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
temple.Width = 200;
temple.Multiline = true;
temple.Height = 100;
connect.Click += new System.EventHandler(connect_Click);
textout.KeyPress += new System.Windows.Forms.KeyPressEventHandler(textout_KeyPress);
temple.ReadOnly = true;
textin.ReadOnly = true;
}
private void tip_Click(object sender, EventArgs e)
{
MessageBox.Show("1.唤醒:指令框输入“start”唤醒来sensor。"
+ '\r'
+ "2.获取温度:唤醒后,输入“read”,按下回车,来获取温度。"
+ '\r'
+ '\r'
+ "当超过37°C时,提示Warning。");
}
private void connect_Click(object sender, EventArgs e)
{
string ippp;
int b;
ippp = ipin.Text;
b = connectt(ippp);
if (b == 3)
MessageBox.Show("连接成功");
else MessageBox.Show("连接失败");
}
private void textout_KeyPress(object sender, KeyPressEventArgs e)
{
char ch = e.KeyChar;
string inputt, stringrcve;
if (ch == '\r')
{
inputt = textout.Text;
IntPtr rcve = communication(inputt);
stringrcve = Marshal.PtrToStringAnsi(rcve);
char[] temp = stringrcve.ToCharArray();
int len = temp.Length;
if (len > 4 && temp[7] == 's')
temple.Text = "The sensor has been woken up.Input 'read' to get temperature.";
else if (len > 4 && temp[7] == 'h')
temple.Text = "Sensor has not been woken up yet! Please input 'start' first.";
else if ((temp[0] == '3' && temp[1] > '6') || temp[0] == '4')
{
textin.Text = stringrcve;
temple.Text = "WARNING! Abnormal temperature, please check.";
}
else
{
textin.Text = stringrcve;
temple.Text = "Nomal temperature measured.";
}
};
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。