diff --git a/App.xaml.cs b/App.xaml.cs
index 36f4a71..c1a9a0b 100644
--- a/App.xaml.cs
+++ b/App.xaml.cs
@@ -1,4 +1,5 @@
-using System;
+using DyeingComputer.UserClass;
+using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
@@ -24,12 +25,14 @@ namespace DyeingComputer
//DyeingComputer.Properties.Resources.Culture = new System.Globalization.CultureInfo("en-US");//设定语言
}
System.Threading.Mutex mutex;
- void App_Startup(object sender, StartupEventArgs e) //程序只允许启动一次
+ void App_Startup(object sender, StartupEventArgs e)
{
+ LogGing.LogGingDATA("800_Start");
bool ret;
- mutex = new System.Threading.Mutex(true, "ElectronicNeedleTherapySystem", out ret);
+ mutex = new System.Threading.Mutex(true, "ElectronicNeedleTherapySystem", out ret);//程序只允许启动一次
if (!ret)
{
+ LogGing.LogGingDATA("800_The program has been launched");
MessageBox.Show("The program has been launched");
Environment.Exit(0);
}
@@ -108,8 +111,8 @@ namespace DyeingComputer
///
private void Application_Startup(object sender, StartupEventArgs e)
- {
- Application.Current.StartupUri = new Uri("MainWindow.xaml", UriKind.Relative);//和MainWindwo同一目录
+ {
+ Application.Current.StartupUri = new Uri("MainWindow.xaml", UriKind.Relative);//和MainWindwo同一目录
}
}
diff --git a/DyeingComputer.csproj b/DyeingComputer.csproj
index 1d1b3c7..b944ee2 100644
--- a/DyeingComputer.csproj
+++ b/DyeingComputer.csproj
@@ -16,9 +16,24 @@
true
+ publish\
+ true
+ Disk
+ false
+ Foreground
+ 7
+ Days
+ false
+ false
+ true
+ 0
+ 1.0.0.%2a
+ false
+ false
+ true
- AnyCPU
+ x64
true
full
false
@@ -26,6 +41,7 @@
DEBUG;TRACE
prompt
4
+ false
AnyCPU
@@ -36,6 +52,12 @@
prompt
4
+
+ DyeingComputer.App
+
+
+ false
+
@@ -308,6 +330,9 @@
3.0.81
+
+ 3.0.81
+
5.0.37
@@ -339,5 +364,17 @@
+
+
+ False
+ Microsoft .NET Framework 4.7.2 %28x86 和 x64%29
+ true
+
+
+ False
+ .NET Framework 3.5 SP1
+ false
+
+
\ No newline at end of file
diff --git a/ViewModel/MainWindowViewModel.cs b/ViewModel/MainWindowViewModel.cs
index 90d2053..f096ecf 100644
--- a/ViewModel/MainWindowViewModel.cs
+++ b/ViewModel/MainWindowViewModel.cs
@@ -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(dt_a);