This commit is contained in:
sc committed 2024-09-11 00:47:07 +08:00
commit 83467de3a9
3 files changed
+95 -13

No files matched your search

+49 -7
View File
@@ -16,6 +16,13 @@ using DyeingComputer.UserClass;
using System.Reflection;
using System.Windows.Documents;
using System.Runtime.CompilerServices;
using NModbus;
using NModbus.Serial;
using NModbus.Device;
using System.IO.Ports;
using OpenTK.Graphics.ES11;
using DyeingComputer.Properties;
namespace DyeingComputer.ViewModel
{
@@ -47,8 +54,11 @@ namespace DyeingComputer.ViewModel
public MainWindowViewModel()
{
WorkNumder = "----------";
CountDown();
SQL_data();
CountDown(); //启动循环任务
SQL_data(); //读数据库
UPort(); //启动串口
}
public string work_Temp; //显示温度
@@ -113,6 +123,39 @@ namespace DyeingComputer.ViewModel
lk++;
}
public SerialPort port = new SerialPort();//创建串口
void UPort()
{
try
{
port.PortName = "COM5";
port.BaudRate = 9600;//配置
port.DataBits = 8;
port.Parity = Parity.None;
port.StopBits = StopBits.One;
port.Open();//打开串口
}
catch (Exception e)
{
LogGing.LogGingDATA("800_SerialPort_Not");
LogGing.LogGingDATA(e.Message);
}
// var factory = new ModbusFactory();
// IModbusMaster master = factory.CreateRtuMaster(port);
// IModbusSerialMaster master = ModbusSerialMaster.CreateRtu(port);
byte slaveId = 1;
ushort startAddress = 100;
ushort[] registers = new ushort[] { 1, 2, 3 };
// write three registers
var master = ModbusRtuMaster.CreateSerial("COM1", 9600, Parity.None, 8, StopBits.One);
}
private SQLiteHelper SQLiteHelpers = null; //定义数据库
private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\800COMPUTER.db"; //数据库路径
DataTable dt_d = new DataTable("DIO");
@@ -127,14 +170,13 @@ namespace DyeingComputer.ViewModel
dt_a = SQLiteHelpers.ExecuteDataSet("select * from IOName where type='AI' OR type='AO'", null).Tables[0];
dt_m = SQLiteHelpers.ExecuteDataSet("select * from IOName where type='M'", null).Tables[0];
SQLiteHelpers.Close();
}
void IO_data()//刷新
void IO_data()//刷新
{
updata_dtm("1", lk);
updata_dtd("1", Convert.ToBoolean(1));
updata_dta("1",10000+lk);
updata_dtm("1001", lk);
updata_dtd("2001", Convert.ToBoolean(1));
updata_dta("4001",10000+lk);
SYSData_A = ToObservableCollection<DATA_A>(dt_a);