Merge branch 'master' of http://www.scserverddns.top:13000/sc/DyeingComputer
This commit is contained in:
commit
21d5cbc00a
4 files changed
+39
-25
No files matched your search
@@ -12,9 +12,9 @@ namespace DyeingComputer.ConvertMoels
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
String G = value.ToString();
|
||||
bool G =(Boolean) value;
|
||||
// bool G = (bool)value;
|
||||
if (G == "False")//判断单元格值是否为零
|
||||
if (!G)//判断单元格值是否为零
|
||||
{
|
||||
return "";//零返回
|
||||
}
|
||||
@@ -26,7 +26,7 @@ namespace DyeingComputer.ConvertMoels
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return null;
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,13 +14,13 @@ namespace DyeingComputer.ConvertMoels
|
||||
{
|
||||
String G = value.ToString();
|
||||
// bool G = (bool)value;
|
||||
if ((G == "AI")||(G == "DI"))//判断单元格值是否为零
|
||||
if ((G == "AI")||(G == "DO"))//判断单元格值是否为零
|
||||
{
|
||||
return "green";//零返回
|
||||
}
|
||||
else
|
||||
{
|
||||
return "red";//非零返回红色
|
||||
return "blue";//非零返回红色
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+7
-1
@@ -67,7 +67,13 @@
|
||||
<DataGridTextColumn Header="{x:Static lang:Resources.ParameterSet}" Width="100" Binding="{Binding DIO}" IsReadOnly="True">
|
||||
<DataGridTextColumn.ElementStyle>
|
||||
<Style TargetType="{x:Type TextBlock}">
|
||||
<Setter Property="Background" Value="{Binding Path=DIO,Converter={StaticResource BoolRBConvert}}"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding Path= DIO}" Value="False">
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding Path= DIO}" Value="True">
|
||||
<Setter Property="Foreground" Value="Red"></Setter>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</DataGridTextColumn.ElementStyle>
|
||||
</DataGridTextColumn>
|
||||
|
||||
@@ -94,7 +94,7 @@ namespace DyeingComputer.ViewModel
|
||||
{
|
||||
DispatcherTimer timer1s = new DispatcherTimer//初始化循环,每1秒调用一次Tick
|
||||
{
|
||||
Interval = TimeSpan.FromSeconds(1)//秒
|
||||
Interval = TimeSpan.FromSeconds(0.5)//秒
|
||||
};
|
||||
timer1s.Tick += Tick_Event_1S;
|
||||
timer1s.Start();
|
||||
@@ -165,8 +165,12 @@ namespace DyeingComputer.ViewModel
|
||||
private bool LINK_OK = false;
|
||||
private int LINK_RUN = 0;
|
||||
private int LINK_ERR = 0;
|
||||
bool[] DQ = new bool[12];
|
||||
ushort DQ_L = 12;
|
||||
bool[] DQ = new bool[128];
|
||||
ushort DQ_L = 128;
|
||||
bool[] DO = new bool[128];
|
||||
ushort DO_L = 128;
|
||||
readonly byte slaveId = 1;
|
||||
|
||||
private async void Modbus_link()
|
||||
{
|
||||
await Task.Run(() =>
|
||||
@@ -178,21 +182,22 @@ namespace DyeingComputer.ViewModel
|
||||
// write three registers
|
||||
|
||||
LINK_RUN++;
|
||||
// try
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
|
||||
byte slaveId = 1;
|
||||
ushort startAddress = 46001;
|
||||
ushort[] registers = new ushort[] { 1, 2, 3 };
|
||||
// ushort startAddress = 46001;
|
||||
// ushort[] registers = new ushort[] { 1, 2, 3 };
|
||||
// master.WriteMultipleRegisters(slaveId, startAddress, registers);
|
||||
|
||||
// bool[] x = master.ReadInputs(slaveId, 1001, 100);
|
||||
DQ = master.ReadCoils(slaveId,0, DQ_L);
|
||||
|
||||
DO = master.ReadCoils(slaveId, 01000, DO_L);
|
||||
DQ = master.ReadCoils(slaveId, 00000, DQ_L);
|
||||
LINK_OK=true;
|
||||
}
|
||||
// catch (Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
LINK_OK=false;
|
||||
LINK_ERR++;
|
||||
// LogGing.LogGingDATA(ex.Message);
|
||||
Name_err = "PLC"+Properties.Resources.Connectionlost;
|
||||
@@ -213,7 +218,7 @@ namespace DyeingComputer.ViewModel
|
||||
{
|
||||
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
||||
SQLiteHelpers.Open(); //打开数据库
|
||||
dt_d = SQLiteHelpers.ExecuteDataSet("select * from IOName where type='DI' OR type='DO'", null).Tables[0]; //读取表写入缓存
|
||||
dt_d = SQLiteHelpers.ExecuteDataSet("select * from IOName where ID>'2000' AND ID<'4000'", null).Tables[0]; //读取表写入缓存
|
||||
dt_a = SQLiteHelpers.ExecuteDataSet("select * from IOName where type='AI' OR type='AO'", null).Tables[0];
|
||||
dt_m = SQLiteHelpers.ExecuteDataSet("select * from IOName where type='M'", null).Tables[0];
|
||||
SQLiteHelpers.Close();
|
||||
@@ -223,14 +228,12 @@ 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++) { updata_dtd((i + 3001).ToString(), DQ[i]); }
|
||||
});
|
||||
|
||||
for (ushort i = 0; i < DQ_L; i++)
|
||||
await Task.Run(() =>
|
||||
{
|
||||
|
||||
//updata_dtd(i.ToString(), DQ[i]);
|
||||
|
||||
}
|
||||
updata_dtd("1", false);
|
||||
SYSData_A = ToObservableCollection<DATA_A>(dt_a);
|
||||
SYSData_D = ToObservableCollection<DATA_D>(dt_d);
|
||||
SYSData_M = ToObservableCollection<DATA_M>(dt_m);
|
||||
@@ -266,12 +269,17 @@ namespace DyeingComputer.ViewModel
|
||||
}
|
||||
void updata_dtd(string key, bool Value)//更新D寄存器
|
||||
{
|
||||
DataRow[] arrRows = dt_d.Select("ID=" + key);
|
||||
DataRow[] arrRows = dt_d.Select("ID='" + key+"'");
|
||||
int index = dt_d.Rows.IndexOf(arrRows[0]);
|
||||
if (index != -1)
|
||||
{
|
||||
DataRow drEmployee = dt_d.Rows[index];
|
||||
drEmployee.BeginEdit();
|
||||
drEmployee["DIO"] = Value;
|
||||
drEmployee.EndEdit();
|
||||
drEmployee.AcceptChanges();
|
||||
drEmployee.ClearErrors();
|
||||
}
|
||||
}
|
||||
void updata_dta(string key, int Value)//更新A寄存器
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user