|
|
@ -28,6 +28,7 @@ using System.Runtime.Remoting.Channels; |
|
|
|
using System.Diagnostics.Eventing.Reader; |
|
|
|
using System.IO; |
|
|
|
using System.Threading; |
|
|
|
using TouchSocket.Sockets; |
|
|
|
|
|
|
|
|
|
|
|
namespace DyeingComputer.ViewModel |
|
|
@ -139,7 +140,9 @@ namespace DyeingComputer.ViewModel |
|
|
|
public int MS17;//副缸
|
|
|
|
public int MS18;//副缸
|
|
|
|
public int MS19;//副缸
|
|
|
|
void SYS_SET() |
|
|
|
|
|
|
|
public static bool set_=false; |
|
|
|
public void SYS_SET() |
|
|
|
{ |
|
|
|
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
|
|
|
SQLiteHelpers.Open(); //打开数据库
|
|
|
@ -245,9 +248,9 @@ namespace DyeingComputer.ViewModel |
|
|
|
//设置定时器
|
|
|
|
DispatcherTimer disTimer = new DispatcherTimer |
|
|
|
{ |
|
|
|
Interval = TimeSpan.FromMilliseconds(200) //毫秒
|
|
|
|
Interval = TimeSpan.FromMilliseconds(500) //毫秒
|
|
|
|
}; |
|
|
|
disTimer.Tick += DisTimer_200MS; |
|
|
|
disTimer.Tick += DisTimer_500MS; |
|
|
|
disTimer.Start();//计时开始
|
|
|
|
}//时间周期初始化
|
|
|
|
void Tick_Event_1S()//Tick_Event周期执行事件1S
|
|
|
@ -259,7 +262,7 @@ namespace DyeingComputer.ViewModel |
|
|
|
StatusStr = Status_Str; |
|
|
|
Program_Name = ProgramName; |
|
|
|
if(dt_TP==null) Process_step = dt_TP.Select("Step=" + RUN_STEPID).First().Field<string>("ParameterName"); |
|
|
|
|
|
|
|
if (set_) { set_ = false;SYS_SET(); }//设置更新
|
|
|
|
if (!SETP_runtime) DIDETime++; |
|
|
|
|
|
|
|
STEP_RUN(); |
|
|
@ -285,13 +288,13 @@ namespace DyeingComputer.ViewModel |
|
|
|
if (string.IsNullOrEmpty(Name_err.ToString()) && ((Selet_dtm("1010") < 1) || (Selet_dtm("1010") > 160))) |
|
|
|
{ Name_err = Resources.Temperature + Resources.Sensor + Resources.Malfunction; } //温度故障提示
|
|
|
|
} |
|
|
|
void DisTimer_200MS(object sender, EventArgs e)//Tick_Event周期执行事件200MS
|
|
|
|
void DisTimer_500MS(object sender, EventArgs e)//Tick_Event周期执行事件200MS
|
|
|
|
{ |
|
|
|
timer1s_++; |
|
|
|
timer5s_++; |
|
|
|
|
|
|
|
if (timer1s_ > 5) Tick_Event_1S(); |
|
|
|
if (timer5s_ > 25) Tick_Event_5S(); |
|
|
|
if (timer1s_ >= 2) { timer1s_ =0; Tick_Event_1S(); } |
|
|
|
if (timer5s_ >=10) { timer5s_ = 0; Tick_Event_5S(); } |
|
|
|
|
|
|
|
if (LINK_OK) IO_data(); |
|
|
|
|
|
|
@ -1423,21 +1426,23 @@ namespace DyeingComputer.ViewModel |
|
|
|
|
|
|
|
public static SerialPort port = new SerialPort();//创建串口
|
|
|
|
static ModbusFactory factory = new ModbusFactory(); |
|
|
|
string protocols_; |
|
|
|
// Create Modbus Master
|
|
|
|
static IModbusMaster master = factory.CreateRtuMaster(port); |
|
|
|
void UPort() |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
protocols_ = Configini.IniReadvalue("SYS", "Protocols"); |
|
|
|
port.PortName = Configini.IniReadvalue("SYS", "COM"); |
|
|
|
port.BaudRate = 115200;//配置
|
|
|
|
port.BaudRate = 57600;//配置
|
|
|
|
port.DataBits = 8; |
|
|
|
port.Parity = Parity.None; |
|
|
|
port.Parity = Parity.Even; |
|
|
|
port.StopBits = StopBits.One; |
|
|
|
port.ReadTimeout = 1000; |
|
|
|
port.WriteTimeout = 1000; |
|
|
|
port.Open();//打开串口
|
|
|
|
Modbus_link(); |
|
|
|
Port_link(); |
|
|
|
} |
|
|
|
catch (Exception e) |
|
|
|
{ |
|
|
@ -1460,7 +1465,7 @@ namespace DyeingComputer.ViewModel |
|
|
|
ushort[] RW = new ushort[63]; |
|
|
|
ushort RW_L = 63; |
|
|
|
readonly byte slaveId = 1; |
|
|
|
private async void Modbus_link() |
|
|
|
private async void Port_link() |
|
|
|
{ |
|
|
|
if (Name_err.ToString() != "800_SerialPort_Not") |
|
|
|
{ |
|
|
@ -1468,10 +1473,20 @@ namespace DyeingComputer.ViewModel |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
DO = master.ReadCoils(slaveId, 02255, DO_L); //读取线圈
|
|
|
|
RW = master.ReadHoldingRegisters(slaveId, 06000, RW_L); //读取寄存器
|
|
|
|
master.WriteMultipleCoils(slaveId, 02000, DQ); //写入线圈
|
|
|
|
master.WriteMultipleRegisters(slaveId, 07000, DW); //写入寄存器
|
|
|
|
if (protocols_ == "MODBUS_RTU") |
|
|
|
{ |
|
|
|
DO = master.ReadCoils(slaveId, 0, DO_L); //读取线圈
|
|
|
|
RW = master.ReadHoldingRegisters(slaveId, 0, RW_L); //读取寄存器
|
|
|
|
master.WriteMultipleCoils(slaveId, 0, DQ); //写入线圈
|
|
|
|
master.WriteMultipleRegisters(slaveId, 0, DW); //写入寄存器
|
|
|
|
}//MODBUSRTU
|
|
|
|
else |
|
|
|
{ |
|
|
|
DO = master.ReadCoils(slaveId, 02255, DO_L); //读取线圈
|
|
|
|
RW = master.ReadHoldingRegisters(slaveId, 06000, RW_L); //读取寄存器
|
|
|
|
master.WriteMultipleCoils(slaveId, 02000, DQ); //写入线圈
|
|
|
|
master.WriteMultipleRegisters(slaveId, 07000, DW); //写入寄存器
|
|
|
|
}//SCMODBUSRTU
|
|
|
|
LINK_OK = true; |
|
|
|
Name_err = ""; |
|
|
|
LINK_RUN++; |
|
|
@ -1484,7 +1499,7 @@ namespace DyeingComputer.ViewModel |
|
|
|
} |
|
|
|
finally |
|
|
|
{ |
|
|
|
Modbus_link(); |
|
|
|
Port_link(); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
@ -1776,12 +1791,11 @@ namespace DyeingComputer.ViewModel |
|
|
|
{ |
|
|
|
lock (dt_d)//锁
|
|
|
|
{ |
|
|
|
DataRow drEmploye = dt_d.Select("PLC=" + key).First(); |
|
|
|
drEmploye.BeginEdit(); |
|
|
|
drEmploye["DIO"] = Value; |
|
|
|
drEmploye.EndEdit(); |
|
|
|
drEmploye.AcceptChanges(); |
|
|
|
drEmploye.ClearErrors(); |
|
|
|
DataRow[] arrRows = dt_d.Select("PLC=" + key); |
|
|
|
foreach (DataRow row in arrRows) |
|
|
|
{ |
|
|
|
row["DIO"] = Value; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
@ -1795,12 +1809,11 @@ namespace DyeingComputer.ViewModel |
|
|
|
{ |
|
|
|
lock (dt_a) |
|
|
|
{ |
|
|
|
DataRow drEmploye = dt_a.Select("PLC=" + key).First(); |
|
|
|
drEmploye.BeginEdit(); |
|
|
|
drEmploye["AIO"] = Value; |
|
|
|
drEmploye.EndEdit(); |
|
|
|
drEmploye.AcceptChanges(); |
|
|
|
drEmploye.ClearErrors(); |
|
|
|
DataRow[] arrRows = dt_a.Select("PLC=" + key); |
|
|
|
foreach (DataRow row in arrRows) |
|
|
|
{ |
|
|
|
row["AIO"] = Value; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|