diff --git a/DyeingComputer.csproj b/DyeingComputer.csproj index b944ee2..3dec8a4 100644 --- a/DyeingComputer.csproj +++ b/DyeingComputer.csproj @@ -58,6 +58,9 @@ false + + LOGO\sunlight_logo.ico + @@ -362,6 +365,12 @@ + + + + + + diff --git a/LOGO/SUNLIGHT.ico b/LOGO/SUNLIGHT.ico new file mode 100644 index 0000000..2e138f4 Binary files /dev/null and b/LOGO/SUNLIGHT.ico differ diff --git a/LOGO/sunlight_logo.ico b/LOGO/sunlight_logo.ico new file mode 100644 index 0000000..2fe6131 Binary files /dev/null and b/LOGO/sunlight_logo.ico differ diff --git a/LOGO/sunlight_logo.jpg b/LOGO/sunlight_logo.jpg new file mode 100644 index 0000000..1b98457 Binary files /dev/null and b/LOGO/sunlight_logo.jpg differ diff --git a/LOGO/sunlight_logotext.jpg b/LOGO/sunlight_logotext.jpg new file mode 100644 index 0000000..fee7f29 Binary files /dev/null and b/LOGO/sunlight_logotext.jpg differ diff --git a/LOGO/sunlight_sc.png b/LOGO/sunlight_sc.png new file mode 100644 index 0000000..5165ad8 Binary files /dev/null and b/LOGO/sunlight_sc.png differ diff --git a/ViewModel/MainWindowViewModel.cs b/ViewModel/MainWindowViewModel.cs index d587ac8..6208118 100644 --- a/ViewModel/MainWindowViewModel.cs +++ b/ViewModel/MainWindowViewModel.cs @@ -18,7 +18,6 @@ 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; @@ -91,24 +90,30 @@ namespace DyeingComputer.ViewModel public void CountDown() { - DispatcherTimer timer1s = new DispatcherTimer//初始化循环,每0.5秒调用一次Tick + DispatcherTimer timer1s = new DispatcherTimer//初始化循环,每1秒调用一次Tick { Interval = TimeSpan.FromSeconds(1)//秒 }; timer1s.Tick += Tick_Event_1S; timer1s.Start(); + DispatcherTimer timer5s = new DispatcherTimer//初始化循环,每1秒调用一次Tick + { + Interval = TimeSpan.FromSeconds(5)//秒 + }; + timer5s.Tick += Tick_Event_5S; + timer5s.Start(); + //设置定时器 DispatcherTimer disTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(100) //毫秒 }; - disTimer.Tick += new EventHandler(DisTimer_Tick);//每一秒执行的方法 + disTimer.Tick += new EventHandler(DisTimer_100MS);//每一秒执行的方法 disTimer.Start();//计时开始 } public static object WorkNumder; - int lk; void Tick_Event_1S(object sender, EventArgs e)//Tick_Event周期执行事件 { Sys_Time = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); @@ -116,14 +121,24 @@ namespace DyeingComputer.ViewModel Work_Numder = WorkNumder.ToString(); Status_Str = "qweqeqwqqfwfqef"; + if (LINK_OK) Modbus_link(); 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();//创建串口 + static ModbusFactory factory = new ModbusFactory(); + + // Create Modbus Master + static IModbusMaster master = factory.CreateRtuMaster(port); void UPort() { @@ -134,6 +149,8 @@ namespace DyeingComputer.ViewModel port.DataBits = 8; port.Parity = Parity.None; port.StopBits = StopBits.One; + port.ReadTimeout = 100; + port.WriteTimeout = 100; port.Open();//打开串口 } catch (Exception e) @@ -141,19 +158,29 @@ namespace DyeingComputer.ViewModel LogGing.LogGingDATA("800_SerialPort_Not"); 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 }; + 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 }; - // write three registers - // master.WriteMultipleRegisters(slaveId, startAddress, registers); - } + 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 readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\800COMPUTER.db"; //数据库路径 @@ -171,18 +198,16 @@ namespace DyeingComputer.ViewModel SQLiteHelpers.Close(); } - void IO_data()//刷新 - { - - - updata_dtm("1001", lk); - updata_dtd("2001", Convert.ToBoolean(1)); - updata_dta("4001",10000+lk); - SYSData_A = ToObservableCollection(dt_a); - SYSData_D = ToObservableCollection(dt_d); - SYSData_M = ToObservableCollection(dt_m); + async void IO_data()//刷新 + { + await Task.Run(() => + { + SYSData_A = ToObservableCollection(dt_a); + SYSData_D = ToObservableCollection(dt_d); + SYSData_M = ToObservableCollection(dt_m); + }); } diff --git a/sunlight_logo.ico b/sunlight_logo.ico new file mode 100644 index 0000000..2fe6131 Binary files /dev/null and b/sunlight_logo.ico differ