This commit is contained in:
xyy
2026-01-06 21:51:23 +08:00
parent 92e4bc9151
commit 3a8b6926dd
2 changed files with 23 additions and 17 deletions

View File

@@ -251,7 +251,7 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
{
// 创建串口对象
serialPort = new SerialPort();
serialPort.PortName = "COM3";
serialPort.PortName = "COM2";
serialPort.BaudRate = 38400;
serialPort.DataBits = 8;
serialPort.Parity = Parity.None;

View File

@@ -1,5 +1,6 @@
using BasicDemo;
using Modbus.Device;
using NModbus.Device;
using Sunny.UI;
using System;
using System.Collections.Generic;
@@ -10,6 +11,7 @@ using System.Drawing;
using System.Globalization;
using System.IO.Ports;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
@@ -102,22 +104,26 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
{
return;
}
string labelText = await Task.Factory.StartNew(() =>
{
if (this.InvokeRequired)
{
return (string)this.Invoke(new Func<string>(() => uiLabel23.Text));
}
else
{
return uiLabel23.Text;
}
});
await Task.Run(() =>
{
ma?.WriteToPLCForNew(labelText, 74, Function.DataType., 3);
});
//string labelText = await Task.Factory.StartNew(() =>
//{
// if (this.InvokeRequired)
// {
// return (string)this.Invoke(new Func<string>(() => uiLabel23.Text));
// }
// else
// {
// return uiLabel23.Text;
// }
//});
//await Task.Run(() =>
//{
// ushort value = double.Parse(uiLabel23.Text);
//ma?.WriteToPLCForNew(labelText, 74, Function.DataType.浮点型, 3);
float value = float.Parse(uiLabel23.Text);
await _modbusMaster.WriteMultipleRegistersAsync(1, 74, c.SplitFloatToUShortArray((float)value));
//});
}
catch (Exception ex)