diff --git a/App.xaml.cs b/App.xaml.cs
index 7f1e9ee..11c0fce 100644
--- a/App.xaml.cs
+++ b/App.xaml.cs
@@ -18,14 +18,16 @@ namespace DyeingComputer
///
public partial class App : Application
{
+ private UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "DyeingComputer.ini");
public App()
{
this.Startup += new StartupEventHandler(App_Startup);
this.DispatcherUnhandledException += new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler(App_DispatcherUnhandledException);
- //DyeingComputer.Properties.Resources.Culture = new System.Globalization.CultureInfo("en-US");//设定语言
+ DyeingComputer.Properties.Resources.Culture = new System.Globalization.CultureInfo(Configini.IniReadvalue("SYS", "Language"));//设定语言
}
+
System.Threading.Mutex mutex;
void App_Startup(object sender, StartupEventArgs e)
{
diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs
index 35314ca..388bf48 100644
--- a/Properties/Resources.Designer.cs
+++ b/Properties/Resources.Designer.cs
@@ -258,6 +258,15 @@ namespace DyeingComputer.Properties {
}
}
+ ///
+ /// 查找类似 Dide 的本地化字符串。
+ ///
+ public static string Dide {
+ get {
+ return ResourceManager.GetString("Dide", resourceCulture);
+ }
+ }
+
///
/// 查找类似 Directives 的本地化字符串。
///
@@ -411,6 +420,15 @@ namespace DyeingComputer.Properties {
}
}
+ ///
+ /// 查找类似 Language 的本地化字符串。
+ ///
+ public static string Language {
+ get {
+ return ResourceManager.GetString("Language", resourceCulture);
+ }
+ }
+
///
/// 查找类似 LineUp 的本地化字符串。
///
diff --git a/Properties/Resources.en-US.resx b/Properties/Resources.en-US.resx
index 3564312..eb18298 100644
--- a/Properties/Resources.en-US.resx
+++ b/Properties/Resources.en-US.resx
@@ -408,4 +408,10 @@
Port
+
+ Dide
+
+
+ Language
+
\ No newline at end of file
diff --git a/Properties/Resources.resx b/Properties/Resources.resx
index 2093e2b..03bffdb 100644
--- a/Properties/Resources.resx
+++ b/Properties/Resources.resx
@@ -408,4 +408,10 @@
Port
+
+ Dide
+
+
+ Language
+
\ No newline at end of file
diff --git a/Properties/Resources.zh-CN.resx b/Properties/Resources.zh-CN.resx
index ad52957..ef937bd 100644
--- a/Properties/Resources.zh-CN.resx
+++ b/Properties/Resources.zh-CN.resx
@@ -408,4 +408,10 @@
端口号
+
+ 待机
+
+
+ 语言
+
\ No newline at end of file
diff --git a/Properties/Resources.zh-TW.resx b/Properties/Resources.zh-TW.resx
index 2d8225e..8583960 100644
--- a/Properties/Resources.zh-TW.resx
+++ b/Properties/Resources.zh-TW.resx
@@ -408,4 +408,10 @@
連接埠
+
+ 待機
+
+
+ 語言
+
\ No newline at end of file
diff --git a/View/EngineerSetView.xaml b/View/EngineerSetView.xaml
index 9ff566a..1958322 100644
--- a/View/EngineerSetView.xaml
+++ b/View/EngineerSetView.xaml
@@ -8,7 +8,10 @@
mc:Ignorable="d"
d:DesignHeight="630" d:DesignWidth="1280" VerticalAlignment="Top">
-
-
+
+
+
+
+
diff --git a/View/EngineerSetView.xaml.cs b/View/EngineerSetView.xaml.cs
index f64f005..0844a4a 100644
--- a/View/EngineerSetView.xaml.cs
+++ b/View/EngineerSetView.xaml.cs
@@ -27,6 +27,10 @@ namespace DyeingComputer.View
string[] ports = System.IO.Ports.SerialPort.GetPortNames();
comboBoxCOM.ItemsSource = ports;
comboBoxCOM.Text = Configini.IniReadvalue("SYS", "COM");
+
+ string[] Language = {"en-US","zh-CN","zh -TW" };
+ comboBoxLanguage.ItemsSource = Language;
+ comboBoxLanguage.Text = Configini.IniReadvalue("SYS", "Language");
}
//调用配置文件
private UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "DyeingComputer.ini");
@@ -35,5 +39,10 @@ namespace DyeingComputer.View
{
Configini.IniWritevalue("SYS","COM",comboBoxCOM.SelectedValue.ToString());
}
+
+ private void comboBoxLanguage_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ Configini.IniWritevalue("SYS", "Language", comboBoxLanguage.SelectedValue.ToString());
+ }
}
}
diff --git a/ViewModel/MainWindowViewModel.cs b/ViewModel/MainWindowViewModel.cs
index 19eac8f..e6083bf 100644
--- a/ViewModel/MainWindowViewModel.cs
+++ b/ViewModel/MainWindowViewModel.cs
@@ -51,28 +51,16 @@ namespace DyeingComputer.ViewModel
{
private SQLiteHelper SQLiteHelpers = null; //定义数据库
private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\800COMPUTER.db"; //数据库路径
- private PID PID = null;
private IniFile.IniFiles Configini = new IniFile.IniFiles(Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "DyeingComputer.ini");
PID pid = new PID();
public MainWindowViewModel()
{
- SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
- SQLiteHelpers.Open(); //打开数据库
- pid.Kp = Convert.ToDouble( SQLiteHelpers.ExecuteScalar("select value from system where ParameterID = 'ST01'", null)); //读取
- pid.Ki = Convert.ToDouble( SQLiteHelpers.ExecuteScalar("select value from system where ParameterID = 'ST02'", null));
- pid.Kd = Convert.ToDouble( SQLiteHelpers.ExecuteScalar("select value from system where ParameterID = 'ST03'", null));
- pid.N = Convert.ToDouble(SQLiteHelpers.ExecuteScalar("select value from system where ParameterID = 'ST04'", null));
- pid.OutputUpperLimit = Convert.ToDouble(SQLiteHelpers.ExecuteScalar("select value from system where ParameterID = 'ST05'", null));
- pid.OutputLowerLimit = Convert.ToDouble(SQLiteHelpers.ExecuteScalar("select value from system where ParameterID = 'ST06'", null));
- SQLiteHelpers.Close();
-
WorkNumder = "----------";
SYS_SET(); //crbl
CountDown(); //启动循环任务
SQL_data(); //读数据库
UPort(); //启动串口
-
}
double ST11;
@@ -80,8 +68,32 @@ namespace DyeingComputer.ViewModel
{
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
SQLiteHelpers.Open(); //打开数据库
- ST11 = Convert.ToDouble(SQLiteHelpers.ExecuteScalar("select value from system where ParameterID = 'ST11'", null));
+ dt_sys = SQLiteHelpers.ExecuteDataSet("select * from System", null).Tables[0]; //读取表写入缓存
SQLiteHelpers.Close();
+
+ ST11 = Convert.ToDouble(Selet_sys("ST11"));//温度偏差参数
+
+ pid.Kp = Convert.ToDouble(Selet_sys("ST01")); //读取pid
+ pid.Ki = Convert.ToDouble(Selet_sys("ST02"));
+ pid.Kd = Convert.ToDouble(Selet_sys("ST03"));
+ pid.N = Convert.ToDouble(Selet_sys("ST04"));
+ pid.OutputUpperLimit = Convert.ToDouble(Selet_sys("ST05"));
+ pid.OutputLowerLimit = Convert.ToDouble(Selet_sys("ST06"));
+ }
+ DataTable dt_sys = new DataTable();
+ public string Selet_sys(string key)//配置缓存
+ {
+ try
+ {
+ DataRow[] arrRows = dt_sys.Select("ParameterID ='" + key+"'");
+ string index = arrRows[0]["Value"].ToString();
+ return index;
+ }
+ catch (Exception ex)
+ {
+ LogGing.LogGingDATA(ex.ToString());
+ return "0";
+ }
}
public string work_Temp; //显示温度
@@ -113,7 +125,7 @@ namespace DyeingComputer.ViewModel
{
DispatcherTimer timer1s = new DispatcherTimer//初始化循环,每1秒调用一次Tick
{
- Interval = TimeSpan.FromSeconds(0.5)//秒
+ Interval = TimeSpan.FromSeconds(1)//秒
};
timer1s.Tick += Tick_Event_1S;
timer1s.Start();
@@ -136,6 +148,7 @@ namespace DyeingComputer.ViewModel
public static object Name_err;
public static object WorkNumder;
+ public Int32 DIDETime;
void Tick_Event_1S(object sender, EventArgs e)//Tick_Event周期执行事件1S
{
Sys_Time = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
@@ -144,13 +157,16 @@ namespace DyeingComputer.ViewModel
// Status_Str = "qweqeqwqqfwfqef";
if (LINK_OK) Modbus_link();
+ if (!SETP_runtime) STEP_RUN();
+
+ DIDETime++;
IO_data();
}
void Tick_Event_5S(object sender, EventArgs e)//Tick_Event周期执行事件5S
{
if (!LINK_OK) Modbus_link();
if (Name_err != null) Status_Str = Name_err.ToString();
- STEP_RUN();
+ if(SETP_runtime) STEP_RUN();
}
void DisTimer_100MS(object sender, EventArgs e)//Tick_Event周期执行事件100MS
{
@@ -165,19 +181,61 @@ namespace DyeingComputer.ViewModel
double STEP_P3 = 0;
double STEP_P4 = 0;
double STEP_P5 = 0;
+ bool SETP_runtime = false;
- void STEP_START(object sender, AddressUpdateEventArgs e)
- {
-
+ public void STEP_START(object sender, AddressUpdateEventArgs e)
+ {
if (e.StepID == "001")
{
- updata_dtm("1003",Convert.ToDouble( e.P2));
+ STEP_ID = "001";
+ STEP_P1 = Convert.ToDouble(e.P1);
+ STEP_P2 = Convert.ToDouble(e.P2);
+ STEP_P3 = Convert.ToDouble(e.P3);
+
+ updata_dtm("1003",Convert.ToDouble( e.P2)/12);
+
+ SETP_runtime=true;
+ //STEP_RUN();
}
}
void STEP_RUN()
{
+ if (SETP_runtime)
+ {
+ switch (STEP_ID)
+ {
+ case "001":
+
+ break;
+ case "007":
+
+ break;
+ case "008":
+
+ break;
+ case "013":
+
+ break;
+ case "015":
+ break;
+ case "017":
+
+ break;
+ default: break;
+ }
+ }
+ else
+ {
+ if (Name_err == null)
+ {
+ int TIMEH = DIDETime / 3600;
+ int TIMEM = (DIDETime - TIMEH * 3600) / 60;
+ int TIMES = DIDETime - TIMEH*3600 - TIMEM*60;
+ Status_Str = Properties.Resources.Dide + string.Format(" {0:D4}", TIMEH) +":"+ string.Format(" {0:D2}", TIMEM) + ":" + string.Format(" {0:D2}", TIMES);
+ }
+ }
}
@@ -270,17 +328,11 @@ namespace DyeingComputer.ViewModel
await Task.Run(() =>
{
- lock (dt_d)
- {
- 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++) { DQ[i] = Selet_dtd((i + 3001).ToString()); }
- }
- lock (dt_a)
- {
- 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++) { 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++) { 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())); }
});
await Task.Run(() =>
@@ -293,58 +345,111 @@ namespace DyeingComputer.ViewModel
public int Selet_dtm(string key)//M寄存器
{
- DataRow[] arrRows = dt_m.Select("ID=" + key);
- int index = Convert.ToInt16(arrRows[0]["Value"].ToString());
- return index;
- }
+ try
+ {
+ DataRow[] arrRows = dt_m.Select("ID='" + key+"'");
+ int index = Convert.ToInt16(arrRows[0]["Value"].ToString());
+ return index;
+ }
+ catch (Exception ex)
+ {
+ LogGing.LogGingDATA(ex.ToString());
+ return -1;
+ }
+ }
public bool Selet_dtd(string key)//D寄存器
{
- DataRow[] arrRows = dt_d.Select("ID=" + key);
+ try {
+ DataRow[] arrRows = dt_d.Select("ID='" + key + "'");
bool index = Convert.ToBoolean(arrRows[0]["DIO"].ToString());
return index;
+ }
+ catch (Exception ex)
+ {
+ LogGing.LogGingDATA(ex.ToString());
+ return false;
+ }
}
public int Selet_dta(string key)//A寄存器
{
- DataRow[] arrRows = dt_a.Select("ID=" + key);
+ try {
+ DataRow[] arrRows = dt_a.Select("ID='" + key + "'");
int index = Convert.ToInt16(arrRows[0]["AIO"].ToString());
return index;
+ }
+ catch (Exception ex)
+ {
+ LogGing.LogGingDATA(ex.ToString());
+ return -1;
+ }
}
public void updata_dtm(string key,double Value)//更新M寄存器
{
- DataRow[] arrRows = dt_m.Select("ID="+key);
- int index = dt_m.Rows.IndexOf(arrRows[0]);
- if (index != -1)
+ try
{
- DataRow drEmployee = dt_m.Rows[index];
- drEmployee.BeginEdit();
- drEmployee["Value"] = Value;
- drEmployee.EndEdit();
+ lock (dt_m)
+ {
+ DataRow[] arrRows = dt_m.Select("ID='" + key + "'");
+ int index = dt_m.Rows.IndexOf(arrRows[0]);
+ if (index != -1)
+ {
+ DataRow drEmployee = dt_m.Rows[index];
+ drEmployee.BeginEdit();
+ drEmployee["Value"] = Value;
+ drEmployee.EndEdit();
+ }
+ }
}
+ catch (Exception ex)
+ {
+ LogGing.LogGingDATA(ex.ToString());
+ }
+
}
public void updata_dtd(string key, bool Value)//更新D寄存器
{
- DataRow[] arrRows = dt_d.Select("ID='" + key+"'");
- int index = dt_d.Rows.IndexOf(arrRows[0]);
- if (index != -1)
+ try
+ {
+ lock (dt_d)//锁
+ {
+ 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();
+ }
+ }
+ }
+ catch (Exception ex)
{
- DataRow drEmployee = dt_d.Rows[index];
- drEmployee.BeginEdit();
- drEmployee["DIO"] = Value;
- drEmployee.EndEdit();
- drEmployee.AcceptChanges();
- drEmployee.ClearErrors();
+ LogGing.LogGingDATA(ex.ToString());
}
}
public void updata_dta(string key, int Value)//更新A寄存器
{
- DataRow[] arrRows = dt_a.Select("ID=" + key);
- int index = dt_a.Rows.IndexOf(arrRows[0]);
- if (index != -1)
+ try
+ {
+ lock (dt_a)
+ {
+ DataRow[] arrRows = dt_a.Select("ID='" + key + "'");
+ int index = dt_a.Rows.IndexOf(arrRows[0]);
+ if (index != -1)
+ {
+ DataRow drEmployee = dt_a.Rows[index];
+ drEmployee.BeginEdit();
+ drEmployee["AIO"] = Value;
+ drEmployee.EndEdit();
+ }
+ }
+ }
+ catch (Exception ex)
{
- DataRow drEmployee = dt_a.Rows[index];
- drEmployee.BeginEdit();
- drEmployee["AIO"] = Value;
- drEmployee.EndEdit();
+ LogGing.LogGingDATA(ex.ToString());
}
}
diff --git a/Windows/ViewStep.xaml b/Windows/ViewStep.xaml
index 4b09b29..2e608c2 100644
--- a/Windows/ViewStep.xaml
+++ b/Windows/ViewStep.xaml
@@ -18,19 +18,19 @@
+ Text="0" PreviewTextInput="Tb_KeyP1" InputMethod.IsInputMethodEnabled="False" FontSize="20" HorizontalContentAlignment="Right" />
+ Text="0" PreviewTextInput="Tb_KeyP2" InputMethod.IsInputMethodEnabled="False" FontSize="20" HorizontalContentAlignment="Right" />
+ Text="0" PreviewTextInput="Tb_KeyP3" InputMethod.IsInputMethodEnabled="False" FontSize="20" HorizontalContentAlignment="Right" />
+ Text="0" PreviewTextInput="Tb_KeyP4" InputMethod.IsInputMethodEnabled="False" FontSize="20" HorizontalContentAlignment="Right" />
+ Text="0" PreviewTextInput="Tb_KeyP5" InputMethod.IsInputMethodEnabled="False" FontSize="20" HorizontalContentAlignment="Right" />
diff --git a/Windows/ViewStep.xaml.cs b/Windows/ViewStep.xaml.cs
index d8ff356..9a2af12 100644
--- a/Windows/ViewStep.xaml.cs
+++ b/Windows/ViewStep.xaml.cs
@@ -53,11 +53,55 @@ namespace DyeingComputer.Windows
private void Tb_KeyPress(object sender, TextCompositionEventArgs e)//输入事件
{
-
- //Regex re = new Regex("[^0-9.-]+");
- Regex re = new Regex(@"^[0-9]+(.[0-9]{1,3})?$");// 非零的正整数
+ Regex re = new Regex(@"^[0-9.]+(.[0-9]{1,3})?$");// 非零的正整数
e.Handled = !re.IsMatch(e.Text);
}
+ private void Tb_KeyP1(object sender, TextCompositionEventArgs e)//输入事件P1
+ {
+ Regex numbeRegex = new Regex("^[.][0-9]+$|^[0-9]*[.]{0,1}[0-9]*$");
+ e.Handled =
+ !numbeRegex.IsMatch(
+ P1.Text.Insert(
+ P1.SelectionStart, e.Text));
+ P1.Text = P1.Text.Trim();
+ }
+ private void Tb_KeyP2(object sender, TextCompositionEventArgs e)//输入事件P2
+ {
+ Regex numbeRegex = new Regex("^[.][0-9]+$|^[0-9]*[.]{0,1}[0-9]*$");
+ e.Handled =
+ !numbeRegex.IsMatch(
+ P2.Text.Insert(
+ P2.SelectionStart, e.Text));
+ P2.Text = P2.Text.Trim();
+ }
+ private void Tb_KeyP3(object sender, TextCompositionEventArgs e)//输入事件P3
+ {
+ Regex numbeRegex = new Regex("^[.][0-9]+$|^[0-9]*[.]{0,1}[0-9]*$");
+ e.Handled =
+ !numbeRegex.IsMatch(
+ P3.Text.Insert(
+ P3.SelectionStart, e.Text));
+ P3.Text = P3.Text.Trim();
+ }
+ private void Tb_KeyP4(object sender, TextCompositionEventArgs e)//输入事件P4
+ {
+ Regex numbeRegex = new Regex("^[.][0-9]+$|^[0-9]*[.]{0,1}[0-9]*$");
+ e.Handled =
+ !numbeRegex.IsMatch(
+ P4.Text.Insert(
+ P4.SelectionStart, e.Text));
+ P4.Text = P4.Text.Trim();
+ }
+ private void Tb_KeyP5(object sender, TextCompositionEventArgs e)//输入事件P5
+ {
+ Regex numbeRegex = new Regex("^[.][0-9]+$|^[0-9]*[.]{0,1}[0-9]*$");
+ e.Handled =
+ !numbeRegex.IsMatch(
+ P5.Text.Insert(
+ P5.SelectionStart, e.Text));
+ P5.Text = P5.Text.Trim();
+ }
+
private readonly string[] a = {"001","007","008","013","015" ,"017", "020", "022", "031", "035", "036", "039", "040", "041", "049", "050",
"051", "054", "055", "056","064","065","066","067","090","091","093","094" };