3 Star 22 Fork 0

Alkaid / Temperature sensor

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
gui.txt 5.49 KB
一键复制 编辑 Web IDE 原始数据 按行查看 历史
Alkaid 提交于 2020-06-23 15:58 . 界面设计
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)
{
}
}
}
C++
1
https://gitee.com/Alkaid666/Temperature-sensor.git
git@gitee.com:Alkaid666/Temperature-sensor.git
Alkaid666
Temperature-sensor
Temperature sensor
master

搜索帮助

14c37bed 8189591 565d56ea 8189591