This commit is contained in:
sc committed 2024-11-20 22:37:23 +08:00
commit 4a63a33e44
3 files changed
+61 -23

No files matched your search

+34 -15
View File
@@ -1,4 +1,5 @@
using OpenTK.Graphics.ES11;
using Newtonsoft.Json.Linq;
using OpenTK.Graphics.ES11;
using SunlightCentralizedControlManagement_SCCM_.Properties;
using SunlightCentralizedControlManagement_SCCM_.UserClass;
using System;
@@ -75,13 +76,13 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
Sys_Time = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
}
void Tick_Event_5S(object sender, EventArgs e)//Tick_Event周期执行事件5S
{
for (int i = 0; i < Machinesdata_Count; i++)
{
MachiensTcpClient[i].SendAsync("SC800");
// MachiensTcpClient[i].SendAsync("SC800");
}
}
void DisTimer_500MS(object sender, EventArgs e)//Tick_Event周期执行事件500MS
@@ -96,34 +97,33 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
{
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
SQLiteHelpers.Open(); //打开数据库
Machines = SQLiteHelpers.ExecuteDataSet("select * from Machines ", null).Tables[0]; //读取表写入缓存
Machines = SQLiteHelpers.ExecuteDataSet("select * from Machines Order by id", null).Tables[0]; //读取表写入缓存
SQLiteHelpers.Close();
CountDown();
TcpClientNEW();
}
private readonly TcpClient[] MachiensTcpClient = new TcpClient[999];
public int Machinesdata_Count;
public void TcpClientNEW()
public async void TcpClientNEW()
{
DataRow[] machinesdata = Machines.Select("PORT>0 AND IP<>''");//获取连接有效的组
bool Machine_ = false;
DataRow[] machinesdata = Machines.Select("PORT>0 AND IP<>''", "id asc");//获取连接有效的组
Machinesdata_Count = machinesdata.Count();
for (int i = 0; i < Machinesdata_Count; i++)
{
MachiensTcpClient[i] = new TcpClient();
DataRow dt= machinesdata[i];
DataRow dt = machinesdata[i];
_= AsyncTcpClient.TcpClient(MachiensTcpClient[i] //建立tcp连接
, Selet_Machines(MainWindowViewModel.Machines, "IP", Convert.ToInt16( dt["ID"])).ToString()
Machine_ = await AsyncTcpClient.TcpClient(MachiensTcpClient[i] //建立tcp连接
, Selet_Machines(MainWindowViewModel.Machines, "IP", Convert.ToInt16(dt["ID"])).ToString()
, Selet_Machines(MainWindowViewModel.Machines, "PORT", Convert.ToInt16(dt["ID"])).ToString());
}
}
if (!Machine_) Updata_Machines(Machines , Convert.ToInt16(dt["ID"]), "State" ,"309" );
}
}
public static string SYS_WorkNumder; //工单号
public static int SYS_AT1; //附缸1-3
@@ -152,5 +152,24 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
}
}
public static void Updata_Machines(DataTable DB, int key, string name, string Value)//更新数据
{
try
{
lock (DB)
{
DataRow drEmployee = DB.Select("ID='" + key + "'").First();
drEmployee.BeginEdit();
drEmployee[name] = Value;
drEmployee.EndEdit();
drEmployee.AcceptChanges();
drEmployee.ClearErrors();
}
}
catch (Exception)
{
// LogGing.LogGingDATA("SDTD:" + ex.ToString());
}
}
}
}