This commit is contained in:
sc committed 2024-09-12 00:23:36 +08:00
commit 2d340245f8
8 files changed
+59 -25

No files matched your search

+9
View File
@@ -58,6 +58,9 @@
<PropertyGroup> <PropertyGroup>
<SignManifests>false</SignManifests> <SignManifests>false</SignManifests>
</PropertyGroup> </PropertyGroup>
<PropertyGroup>
<ApplicationIcon>LOGO\sunlight_logo.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" /> <Reference Include="System.ComponentModel.DataAnnotations" />
@@ -362,6 +365,12 @@
<Content Include="Fonts\font-awesome-4.7.0\css\font-awesome.css" /> <Content Include="Fonts\font-awesome-4.7.0\css\font-awesome.css" />
<Content Include="Fonts\font-awesome-4.7.0\css\font-awesome.min.css" /> <Content Include="Fonts\font-awesome-4.7.0\css\font-awesome.min.css" />
<Content Include="Fonts\font-awesome-4.7.0\fonts\fontawesome-webfont.svg" /> <Content Include="Fonts\font-awesome-4.7.0\fonts\fontawesome-webfont.svg" />
<Resource Include="sunlight_logo.ico" />
<Resource Include="LOGO\SUNLIGHT.ico" />
<Resource Include="LOGO\sunlight_logo.ico" />
<Resource Include="LOGO\sunlight_logo.jpg" />
<Resource Include="LOGO\sunlight_logotext.jpg" />
<Resource Include="LOGO\sunlight_sc.png" />
<Resource Include="Fonts\font-awesome-4.7.0\HELP-US-OUT.txt" /> <Resource Include="Fonts\font-awesome-4.7.0\HELP-US-OUT.txt" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

+50 -25
View File
@@ -18,7 +18,6 @@ using System.Windows.Documents;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using NModbus; using NModbus;
using NModbus.Serial; using NModbus.Serial;
using NModbus.Device;
using System.IO.Ports; using System.IO.Ports;
using OpenTK.Graphics.ES11; using OpenTK.Graphics.ES11;
using DyeingComputer.Properties; using DyeingComputer.Properties;
@@ -91,24 +90,30 @@ namespace DyeingComputer.ViewModel
public void CountDown() public void CountDown()
{ {
DispatcherTimer timer1s = new DispatcherTimer//初始化循环,每0.5秒调用一次Tick DispatcherTimer timer1s = new DispatcherTimer//初始化循环,每1秒调用一次Tick
{ {
Interval = TimeSpan.FromSeconds(1)//秒 Interval = TimeSpan.FromSeconds(1)//秒
}; };
timer1s.Tick += Tick_Event_1S; timer1s.Tick += Tick_Event_1S;
timer1s.Start(); timer1s.Start();
DispatcherTimer timer5s = new DispatcherTimer//初始化循环,每1秒调用一次Tick
{
Interval = TimeSpan.FromSeconds(5)//秒
};
timer5s.Tick += Tick_Event_5S;
timer5s.Start();
//设置定时器 //设置定时器
DispatcherTimer disTimer = new DispatcherTimer DispatcherTimer disTimer = new DispatcherTimer
{ {
Interval = TimeSpan.FromMilliseconds(100) //毫秒 Interval = TimeSpan.FromMilliseconds(100) //毫秒
}; };
disTimer.Tick += new EventHandler(DisTimer_Tick);//每一秒执行的方法 disTimer.Tick += new EventHandler(DisTimer_100MS);//每一秒执行的方法
disTimer.Start();//计时开始 disTimer.Start();//计时开始
} }
public static object WorkNumder; public static object WorkNumder;
int lk;
void Tick_Event_1S(object sender, EventArgs e)//Tick_Event周期执行事件 void Tick_Event_1S(object sender, EventArgs e)//Tick_Event周期执行事件
{ {
Sys_Time = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); Sys_Time = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
@@ -116,14 +121,24 @@ namespace DyeingComputer.ViewModel
Work_Numder = WorkNumder.ToString(); Work_Numder = WorkNumder.ToString();
Status_Str = "qweqeqwqqfwfqef"; Status_Str = "qweqeqwqqfwfqef";
if (LINK_OK) Modbus_link();
IO_data(); IO_data();
} }
void DisTimer_Tick(object sender, EventArgs e)//Tick_Event周期执行事件 void Tick_Event_5S(object sender, EventArgs e)//Tick_Event周期执行事件
{ {
lk++; if (!LINK_OK) Modbus_link();
}
void DisTimer_100MS(object sender, EventArgs e)//Tick_Event周期执行事件
{
} }
public static SerialPort port = new SerialPort();//创建串口 public static SerialPort port = new SerialPort();//创建串口
static ModbusFactory factory = new ModbusFactory();
// Create Modbus Master
static IModbusMaster master = factory.CreateRtuMaster(port);
void UPort() void UPort()
{ {
@@ -134,6 +149,8 @@ namespace DyeingComputer.ViewModel
port.DataBits = 8; port.DataBits = 8;
port.Parity = Parity.None; port.Parity = Parity.None;
port.StopBits = StopBits.One; port.StopBits = StopBits.One;
port.ReadTimeout = 100;
port.WriteTimeout = 100;
port.Open();//打开串口 port.Open();//打开串口
} }
catch (Exception e) catch (Exception e)
@@ -141,19 +158,29 @@ namespace DyeingComputer.ViewModel
LogGing.LogGingDATA("800_SerialPort_Not"); LogGing.LogGingDATA("800_SerialPort_Not");
LogGing.LogGingDATA(e.Message); LogGing.LogGingDATA(e.Message);
} }
ModbusFactory factory = new ModbusFactory();
IModbusMaster master = factory.CreateRtuMaster(port);
// byte slaveId = 1;
// ushort startAddress = 1;
// ushort[] registers = new ushort[] { 1, 2, 3 };
// write three registers
// master.WriteMultipleRegisters(slaveId, startAddress, registers);
} }
bool LINK_OK = false;
public static async void Modbus_link()
{
await Task.Run(() =>
{
byte slaveId = 1;
ushort startAddress = 100;
ushort[] registers = new ushort[] { 1, 2, 3 };
master.Transport.ReadTimeout = 500;
master.Transport.WriteTimeout = 500;
//master.Transport.Retries = 100;
// write three registers
try
{
master.WriteMultipleRegisters(slaveId, startAddress, registers);
}
catch (Exception ex) { }
});
}
private SQLiteHelper SQLiteHelpers = null; //定义数据库 private SQLiteHelper SQLiteHelpers = null; //定义数据库
private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\800COMPUTER.db"; //数据库路径 private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\800COMPUTER.db"; //数据库路径
@@ -171,18 +198,16 @@ namespace DyeingComputer.ViewModel
SQLiteHelpers.Close(); SQLiteHelpers.Close();
} }
void IO_data()//刷新
async void IO_data()//刷新
{
await Task.Run(() =>
{ {
updata_dtm("1001", lk);
updata_dtd("2001", Convert.ToBoolean(1));
updata_dta("4001",10000+lk);
SYSData_A = ToObservableCollection<DATA_A>(dt_a); SYSData_A = ToObservableCollection<DATA_A>(dt_a);
SYSData_D = ToObservableCollection<DATA_D>(dt_d); SYSData_D = ToObservableCollection<DATA_D>(dt_d);
SYSData_M = ToObservableCollection<DATA_M>(dt_m); SYSData_M = ToObservableCollection<DATA_M>(dt_m);
});
} }
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB