sc 1 year ago
parent
commit
2d340245f8
  1. 9
      DyeingComputer.csproj
  2. BIN
      LOGO/SUNLIGHT.ico
  3. BIN
      LOGO/sunlight_logo.ico
  4. BIN
      LOGO/sunlight_logo.jpg
  5. BIN
      LOGO/sunlight_logotext.jpg
  6. BIN
      LOGO/sunlight_sc.png
  7. 77
      ViewModel/MainWindowViewModel.cs
  8. BIN
      sunlight_logo.ico

9
DyeingComputer.csproj

@ -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
LOGO/SUNLIGHT.ico

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

BIN
LOGO/sunlight_logo.ico

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
LOGO/sunlight_logo.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

BIN
LOGO/sunlight_logotext.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 KiB

BIN
LOGO/sunlight_sc.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

77
ViewModel/MainWindowViewModel.cs

@ -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(); }
bool LINK_OK = false;
IModbusMaster master = factory.CreateRtuMaster(port); public static async void Modbus_link()
{
// byte slaveId = 1; await Task.Run(() =>
// ushort startAddress = 1; {
// ushort[] registers = new ushort[] { 1, 2, 3 }; byte slaveId = 1;
ushort startAddress = 100;
ushort[] registers = new ushort[] { 1, 2, 3 };
// write three registers master.Transport.ReadTimeout = 500;
// master.WriteMultipleRegisters(slaveId, startAddress, registers); 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()//刷新
{
updata_dtm("1001", lk);
updata_dtd("2001", Convert.ToBoolean(1));
updata_dta("4001",10000+lk);
SYSData_A = ToObservableCollection<DATA_A>(dt_a); async void IO_data()//刷新
SYSData_D = ToObservableCollection<DATA_D>(dt_d); {
SYSData_M = ToObservableCollection<DATA_M>(dt_m); await Task.Run(() =>
{
SYSData_A = ToObservableCollection<DATA_A>(dt_a);
SYSData_D = ToObservableCollection<DATA_D>(dt_d);
SYSData_M = ToObservableCollection<DATA_M>(dt_m);
});
} }

BIN
sunlight_logo.ico

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Loading…
Cancel
Save