动态IO映射实现
This commit is contained in:
commit
9c492444c9
3 files changed
+176
-20
No files matched your search
@@ -54,8 +54,8 @@ namespace DyeingComputer.ViewModel
|
||||
|
||||
public class MainWindowViewModel : ViewModelBase
|
||||
{
|
||||
private SQLiteHelper SQLiteHelpers = null; //定义数据库
|
||||
private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\800COMPUTER.db"; //数据库路径
|
||||
private static SQLiteHelper SQLiteHelpers = null; //定义数据库
|
||||
private readonly static string DBAddress = Environment.CurrentDirectory + "\\DataBase\\800COMPUTER.db"; //数据库路径
|
||||
private readonly string ChartAdress = Environment.CurrentDirectory + "\\DataBase\\Chart.db"; //数据库路径
|
||||
private IniFile.IniFiles Configini = new IniFile.IniFiles(Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "DyeingComputer.ini");
|
||||
private PID pid = new PID();
|
||||
@@ -1164,7 +1164,7 @@ namespace DyeingComputer.ViewModel
|
||||
public static DataTable dt_d = new DataTable("DIO");
|
||||
public static DataTable dt_a = new DataTable("AIO");
|
||||
public static DataTable dt_m = new DataTable("M");
|
||||
void SQL_data()//获得io表
|
||||
public static void SQL_data()//获得io表
|
||||
{
|
||||
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
||||
SQLiteHelpers.Open(); //打开数据库
|
||||
@@ -1196,12 +1196,15 @@ namespace DyeingComputer.ViewModel
|
||||
|
||||
await Task.Run(() =>
|
||||
{
|
||||
for (ushort i = 0; i < DO_L; i++) { Updata_dtd((i + 2001).ToString(), DO[i]); }
|
||||
for (ushort i = 0; i < DQ_L; i++) { DQ[i] = Selet_dtd((i + 3001).ToString()); }
|
||||
for (ushort i = 0; i < RW_L; i++) { Updata_dta((i + 4001).ToString(), RW[i]); }
|
||||
for (ushort i = 0; i < DW_L; i++) { DW[i] = Convert.ToUInt16(Selet_dta((i + 5001).ToString())); }
|
||||
for (ushort i = 0; i < DO_L; i++) { Upplc_dtd((i + 2001).ToString(), DO[i]); }
|
||||
for (ushort i = 0; i < DQ_L; i++) { DQ[i] = Seplc_dtd((i + 3001).ToString()); }
|
||||
for (ushort i = 0; i < RW_L; i++) { Upplc_dta((i + 4001).ToString(), RW[i]); }
|
||||
for (ushort i = 0; i < DW_L; i++) { DW[i] = Convert.ToUInt16(Seplc_dta((i + 5001).ToString())); }
|
||||
});
|
||||
}
|
||||
|
||||
public static object D_view=true;
|
||||
public static object A_view=true;
|
||||
private async void IO_view()//IO显示
|
||||
{
|
||||
await Task.Run(() =>
|
||||
@@ -1214,13 +1217,13 @@ namespace DyeingComputer.ViewModel
|
||||
|
||||
try
|
||||
{
|
||||
SYSData_A = ToObservableCollection<DATA_A>(dt_a);
|
||||
if ((bool)A_view) SYSData_A = ToObservableCollection<DATA_A>(dt_a);
|
||||
}
|
||||
catch (Exception ex) { Name_err = "IO_SYSData_A" + "(" + ex.Message + ")"; }
|
||||
|
||||
try
|
||||
{
|
||||
SYSData_D = ToObservableCollection<DATA_D>(dt_d);
|
||||
if ((bool)D_view) SYSData_D = ToObservableCollection<DATA_D>(dt_d);
|
||||
}
|
||||
catch (Exception ex) { Name_err = "IO_SYSData_D" + "(" + ex.Message + ")"; }
|
||||
});
|
||||
@@ -1341,6 +1344,83 @@ namespace DyeingComputer.ViewModel
|
||||
}
|
||||
}
|
||||
|
||||
public static void Upplc_dtd(string key, bool Value)//更新PLCD
|
||||
{
|
||||
try
|
||||
{
|
||||
lock (dt_d)//锁
|
||||
{
|
||||
DataRow drEmploye = dt_d.Select("PLC=" + key).First();
|
||||
drEmploye.BeginEdit();
|
||||
drEmploye["DIO"] = Value;
|
||||
drEmploye.EndEdit();
|
||||
drEmploye.AcceptChanges();
|
||||
drEmploye.ClearErrors();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogGing.LogGingDATA("PLCDTD:" + ex.ToString());
|
||||
}
|
||||
}
|
||||
public static void Upplc_dta(string key, int Value)//更新PLCA寄存器
|
||||
{
|
||||
try
|
||||
{
|
||||
lock (dt_a)
|
||||
{
|
||||
DataRow drEmploye = dt_a.Select("PLC=" + key).First();
|
||||
drEmploye.BeginEdit();
|
||||
drEmploye["AIO"] = Value;
|
||||
drEmploye.EndEdit();
|
||||
drEmploye.AcceptChanges();
|
||||
drEmploye.ClearErrors();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogGing.LogGingDATA("PLCDTA:" + ex.ToString());
|
||||
}
|
||||
}
|
||||
public static bool Seplc_dtd(string key)//PLCD寄存器
|
||||
{
|
||||
try
|
||||
{
|
||||
lock (dt_d)
|
||||
{
|
||||
// DataRow[] arrRows = dt_d.Select("ID='" + key + "'");
|
||||
// bool index = Convert.ToBoolean(arrRows[0]["DIO"].ToString());
|
||||
DataRow drEmployee = dt_d.Select("PLC=" + key).First();
|
||||
bool index = drEmployee.Field<bool>("DIO");
|
||||
return index;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogGing.LogGingDATA("PLCDTD:" + ex.ToString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static int Seplc_dta(string key)//PLCA寄存器
|
||||
{
|
||||
try
|
||||
{
|
||||
lock (dt_a)
|
||||
{
|
||||
// DataRow[] arrRows = dt_a.Select("ID='" + key + "'");
|
||||
// int index = Convert.ToInt16(arrRows[0]["AIO"].ToString());
|
||||
DataRow drEmployee = dt_a.Select("PLC=" + key).First();
|
||||
int index = drEmployee.Field<int>("AIO");
|
||||
return index;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogGing.LogGingDATA("PLCDTA:" + ex.ToString());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
ObservableCollection<DATA_A> sysData_A = new ObservableCollection<DATA_A>();
|
||||
ObservableCollection<DATA_D> sysData_D = new ObservableCollection<DATA_D>();
|
||||
ObservableCollection<DATA_M> sysData_M = new ObservableCollection<DATA_M>();
|
||||
@@ -1379,6 +1459,7 @@ namespace DyeingComputer.ViewModel
|
||||
public string IOName { get; set; }
|
||||
public int AIO { get; set; }
|
||||
public string ID { get; set; }
|
||||
public string PLC { get; set; }
|
||||
public string type { get; set; }
|
||||
}
|
||||
public class DATA_D
|
||||
@@ -1386,6 +1467,7 @@ namespace DyeingComputer.ViewModel
|
||||
public string IOName { get; set; }
|
||||
public bool DIO { get; set; }
|
||||
public string ID { get; set; }
|
||||
public string PLC { get; set; }
|
||||
public string type { get; set; }
|
||||
}
|
||||
public class DATA_M
|
||||
@@ -1393,6 +1475,7 @@ namespace DyeingComputer.ViewModel
|
||||
public string IOName { get; set; }
|
||||
public double Value { get; set; }
|
||||
public string ID { get; set; }
|
||||
public string PLC { get; set; }
|
||||
public string type { get; set; }
|
||||
}
|
||||
public ObservableCollection<T> ToObservableCollection<T>(DataTable dt) where T : class, new()
|
||||
|
||||
Reference in new issue
Block a user