添加项目文件。
This commit is contained in:
220
口罩泄露定制款/Form/frm_Motor.cs
Normal file
220
口罩泄露定制款/Form/frm_Motor.cs
Normal file
@@ -0,0 +1,220 @@
|
||||
using Modbus.Device;
|
||||
using Sunny.UI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace 口罩泄露定制款
|
||||
{
|
||||
public partial class frm_Motor : UIForm
|
||||
{
|
||||
ModbusMaster _master;
|
||||
DataChange dc = new DataChange();
|
||||
Function fc;
|
||||
public frm_Motor(ModbusMaster master)
|
||||
{
|
||||
InitializeComponent();
|
||||
_master = master;
|
||||
if (_master != null)
|
||||
{
|
||||
Task.Run(() => ReadPLCData());
|
||||
fc=new Function(_master);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#region 读取PLC数据
|
||||
ushort[] data_D410_D411 = new ushort[2];
|
||||
ushort[] data_D420_D423 = new ushort[4];
|
||||
ushort[] data_D442_D443 = new ushort[2];
|
||||
ushort[] data_D450_D451 = new ushort[2];
|
||||
ushort[] data_D460_D465 = new ushort[6];
|
||||
ushort[] data_D480_D481 = new ushort[2];
|
||||
ushort[] data_D488_D489 = new ushort[2];
|
||||
ushort[] data_D502_D507 = new ushort[6];
|
||||
|
||||
bool[] data_M90_M92 = new bool[3];
|
||||
bool[] data_M60_M62 = new bool[3];
|
||||
|
||||
float _huxipinglv;
|
||||
float _huxiliang;
|
||||
float _huxibeishu;
|
||||
float _hushoudongsudu;
|
||||
float _xishoudongsudu;
|
||||
float _huweizhi;
|
||||
float _xiweizhi;
|
||||
float _huliang;
|
||||
float _xiliang;
|
||||
|
||||
int _huxishijian;
|
||||
int _ceshifen;
|
||||
int _ceshimiao;
|
||||
void ReadPLCData()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (this.IsDisposed || _master == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
data_D410_D411 = _master.ReadHoldingRegisters(1, 410, 2);
|
||||
data_D420_D423 = _master.ReadHoldingRegisters(1, 420, 4);
|
||||
data_D442_D443 = _master.ReadHoldingRegisters(1, 442, 2);
|
||||
data_D450_D451 = _master.ReadHoldingRegisters(1, 450, 2);
|
||||
data_D460_D465 = _master.ReadHoldingRegisters(1, 460, 6);
|
||||
data_D480_D481 = _master.ReadHoldingRegisters(1, 480, 2);
|
||||
data_D488_D489 = _master.ReadHoldingRegisters(1, 488, 2);
|
||||
data_D502_D507 = _master.ReadHoldingRegisters(1, 502, 6);
|
||||
|
||||
data_M90_M92 = _master.ReadInputs(1, 90, 3);
|
||||
data_M60_M62 = _master.ReadInputs(1, 60, 3);
|
||||
|
||||
_huxipinglv = dc.UshortToFloat(data_D410_D411[1], data_D410_D411[0]);
|
||||
_huxiliang = dc.UshortToFloat(data_D420_D423[1], data_D420_D423[0]);
|
||||
_huxibeishu = dc.UshortToFloat(data_D420_D423[3], data_D420_D423[2]);
|
||||
_hushoudongsudu = dc.UshortToFloat(data_D450_D451[1], data_D450_D451[0]);
|
||||
_xishoudongsudu = dc.UshortToFloat(data_D442_D443[1], data_D442_D443[0]);
|
||||
_huweizhi = dc.UshortToFloat(data_D460_D465[1], data_D460_D465[0]);
|
||||
_xiweizhi = dc.UshortToFloat(data_D460_D465[5], data_D460_D465[4]);
|
||||
_huliang = dc.UshortToFloat(data_D480_D481[1], data_D480_D481[0]);
|
||||
_xiliang = dc.UshortToFloat(data_D488_D489[1], data_D488_D489[0]);
|
||||
_huxishijian = dc.UshortToInt1(data_D502_D507[4], data_D502_D507[5]);
|
||||
_ceshifen = dc.UshortToInt1(data_D502_D507[2], data_D502_D507[3]);
|
||||
_ceshimiao = dc.UshortToInt1(data_D502_D507[0], data_D502_D507[1]);
|
||||
Thread.Sleep(100);
|
||||
|
||||
}
|
||||
catch { break; }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
private void timerUI_Tick(object sender, EventArgs e)
|
||||
{
|
||||
tb_呼吸频率.Text = _huxipinglv.ToString("F2");
|
||||
tb_呼吸量.Text = _huxiliang.ToString("F2");
|
||||
tb_呼吸倍数.Text = _huxibeishu.ToString("F2");
|
||||
tb_呼手动速度.Text = _hushoudongsudu.ToString("F2");
|
||||
tb_吸手动速度.Text = _xishoudongsudu.ToString("F2");
|
||||
tb_呼吸时间.Text = _huxishijian.ToString();
|
||||
|
||||
tb_呼位置.Text = _huweizhi.ToString("F2");
|
||||
tb_吸位置.Text = _xiweizhi.ToString("F2");
|
||||
tb_呼量.Text = _huliang.ToString("F2");
|
||||
tb_吸量.Text = _xiliang.ToString("F2");
|
||||
tb_测试分.Text = _ceshifen.ToString();
|
||||
tb_测试秒.Text = _ceshimiao.ToString();
|
||||
if (data_M60_M62[1])
|
||||
{ btn_测试开始.Text = "测试中";btn_测试开始.FillColor = Color.Red; }
|
||||
else
|
||||
{ btn_测试开始.Text = "测试开始";btn_测试开始.FillColor = Color.FromArgb(80, 160, 255);}
|
||||
if (data_M90_M92[1])
|
||||
{ btn_复位.Text = "复位中"; btn_复位.FillColor = Color.Red; }
|
||||
else
|
||||
{ btn_复位.Text = "复位"; btn_复位.FillColor = Color.FromArgb(80, 160, 255); }
|
||||
}
|
||||
|
||||
private void tb_呼吸频率_ButtonClick(object sender, EventArgs e)
|
||||
{
|
||||
fc.WriteToPLC(tb_呼吸频率.Text,410, Function.DataType.浮点型);
|
||||
}
|
||||
|
||||
private void tb_呼吸量_ButtonClick(object sender, EventArgs e)
|
||||
{
|
||||
fc.WriteToPLC(tb_呼吸量.Text, 420, Function.DataType.浮点型);
|
||||
}
|
||||
|
||||
private void tb_呼吸倍数_ButtonClick(object sender, EventArgs e)
|
||||
{
|
||||
fc.WriteToPLC(tb_呼吸倍数.Text, 422, Function.DataType.浮点型);
|
||||
}
|
||||
|
||||
private void tb_呼手动速度_ButtonClick(object sender, EventArgs e)
|
||||
{
|
||||
fc.WriteToPLC(tb_呼手动速度.Text, 450, Function.DataType.浮点型);
|
||||
}
|
||||
|
||||
private void tb_吸手动速度_ButtonClick(object sender, EventArgs e)
|
||||
{
|
||||
fc.WriteToPLC(tb_吸手动速度.Text, 442, Function.DataType.浮点型);
|
||||
}
|
||||
|
||||
private void tb_呼吸时间_ButtonClick(object sender, EventArgs e)
|
||||
{
|
||||
fc.WriteToPLC(tb_呼吸时间.Text, 506, Function.DataType.整形);
|
||||
}
|
||||
|
||||
private void btn_复位_Click(object sender, EventArgs e)
|
||||
{
|
||||
fc.BtnClickFunction(Function.ButtonType.复归型, 90);
|
||||
}
|
||||
|
||||
private void btn_呼前_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
fc.BtnClickFunction(Function.ButtonType.置位型, 1);
|
||||
}
|
||||
|
||||
private void btn_呼前_MouseUp(object sender, MouseEventArgs e)
|
||||
{
|
||||
fc.BtnClickFunction(Function.ButtonType.复位型, 1);
|
||||
}
|
||||
|
||||
private void btn_呼后_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
fc.BtnClickFunction(Function.ButtonType.置位型, 2);
|
||||
}
|
||||
|
||||
private void btn_呼后_MouseUp(object sender, MouseEventArgs e)
|
||||
{
|
||||
fc.BtnClickFunction(Function.ButtonType.复位型, 2);
|
||||
}
|
||||
|
||||
private void btn_吸前_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
fc.BtnClickFunction(Function.ButtonType.置位型, 3);
|
||||
}
|
||||
|
||||
private void btn_吸前_MouseUp(object sender, MouseEventArgs e)
|
||||
{
|
||||
fc.BtnClickFunction(Function.ButtonType.复位型, 3);
|
||||
}
|
||||
|
||||
private void btn_吸后_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
fc.BtnClickFunction(Function.ButtonType.置位型,4);
|
||||
}
|
||||
|
||||
private void btn_吸后_MouseUp(object sender, MouseEventArgs e)
|
||||
{
|
||||
fc.BtnClickFunction(Function.ButtonType.复位型, 4);
|
||||
}
|
||||
|
||||
private void btn_测试开始_Click(object sender, EventArgs e)
|
||||
{
|
||||
fc.BtnClickFunction(Function.ButtonType.复归型, 60);
|
||||
}
|
||||
|
||||
private void btn_测试停止_Click(object sender, EventArgs e)
|
||||
{
|
||||
fc.BtnClickFunction(Function.ButtonType.复归型, 62);
|
||||
}
|
||||
|
||||
private void frm_Motor_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
this.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user