io更新逻辑修改设置生效方式修改
This commit is contained in:
commit
82720d78da
11 files changed
+82
-46
No files matched your search
Generated
+9
@@ -834,6 +834,15 @@ namespace DyeingComputer.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 Protocols 的本地化字符串。
|
||||
/// </summary>
|
||||
public static string Protocols {
|
||||
get {
|
||||
return ResourceManager.GetString("Protocols", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 Pump 的本地化字符串。
|
||||
/// </summary>
|
||||
|
||||
@@ -489,4 +489,7 @@
|
||||
<data name="DyeingMachine" xml:space="preserve">
|
||||
<value>Dyeing</value>
|
||||
</data>
|
||||
<data name="Protocols" xml:space="preserve">
|
||||
<value>Protocols</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -489,4 +489,7 @@
|
||||
<data name="DyeingMachine" xml:space="preserve">
|
||||
<value>DyeingMachine</value>
|
||||
</data>
|
||||
<data name="Protocols" xml:space="preserve">
|
||||
<value>Protocols</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -489,4 +489,7 @@
|
||||
<data name="DyeingMachine" xml:space="preserve">
|
||||
<value>染色机</value>
|
||||
</data>
|
||||
<data name="Protocols" xml:space="preserve">
|
||||
<value>协议</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -483,10 +483,13 @@
|
||||
<data name="Bottom" xml:space="preserve">
|
||||
<value>底</value>
|
||||
</data>
|
||||
<data name="DyeingMachine" xml:space="preserve">
|
||||
<value>染色機</value>
|
||||
</data>
|
||||
<data name="Receipt" xml:space="preserve">
|
||||
<value>領料單</value>
|
||||
</data>
|
||||
<data name="DyeingMachine" xml:space="preserve">
|
||||
<value>染色機</value>
|
||||
</data>
|
||||
<data name="Protocols" xml:space="preserve">
|
||||
<value />
|
||||
</data>
|
||||
</root>
|
||||
@@ -8,10 +8,12 @@
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="500" d:DesignWidth="800">
|
||||
<Grid>
|
||||
<ComboBox HorizontalAlignment="Left" Height="30" Margin="150,10,0,0" x:Name="comboBoxCOM" VerticalAlignment="Top" Width="200" SelectionChanged="comboBoxCOM_SelectionChanged" FontSize="20" IsEditable="True" IsReadOnly="True"/>
|
||||
<TextBlock HorizontalAlignment="Left" Height="40" Margin="10,10,0,0" TextWrapping="Wrap" Text="{x:Static lang:Resources.Port}" VerticalAlignment="Top" Width="120" FontSize="25"/>
|
||||
<ComboBox HorizontalAlignment="Left" Height="30" Margin="150,50,0,0" x:Name="comboBoxLanguage" VerticalAlignment="Top" Width="200" SelectionChanged="comboBoxLanguage_SelectionChanged" FontSize="20" IsEditable="True" IsReadOnly="True"/>
|
||||
<TextBlock HorizontalAlignment="Left" Height="40" Margin="10,50,0,0" TextWrapping="Wrap" Text="{x:Static lang:Resources.Language}" VerticalAlignment="Top" Width="120" FontSize="25"/>
|
||||
<ComboBox HorizontalAlignment="Left" Height="30" Margin="150,50,0,0" x:Name="comboBoxCOM" VerticalAlignment="Top" Width="200" SelectionChanged="comboBoxCOM_SelectionChanged" FontSize="20" IsEditable="True" IsReadOnly="True"/>
|
||||
<TextBlock HorizontalAlignment="Left" Height="40" Margin="10,50,0,0" TextWrapping="Wrap" Text="{x:Static lang:Resources.Port}" VerticalAlignment="Top" Width="120" FontSize="25"/>
|
||||
<ComboBox HorizontalAlignment="Left" Height="30" Margin="150,90,0,0" x:Name="comboBoxCOMmod" VerticalAlignment="Top" Width="200" SelectionChanged="comboBoxCOMmod_SelectionChanged" FontSize="20" IsEditable="True" IsReadOnly="True"/>
|
||||
<TextBlock HorizontalAlignment="Left" Height="40" Margin="10,90,0,0" TextWrapping="Wrap" Text="{x:Static lang:Resources.Protocols}" VerticalAlignment="Top" Width="120" FontSize="25"/>
|
||||
<ComboBox HorizontalAlignment="Left" Height="30" Margin="150,10,0,0" x:Name="comboBoxLanguage" VerticalAlignment="Top" Width="200" SelectionChanged="comboBoxLanguage_SelectionChanged" FontSize="20" IsEditable="True" IsReadOnly="True"/>
|
||||
<TextBlock HorizontalAlignment="Left" Height="40" Margin="10,10,0,0" TextWrapping="Wrap" Text="{x:Static lang:Resources.Language}" VerticalAlignment="Top" Width="120" FontSize="25"/>
|
||||
<TextBlock Name="RX" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Bottom" Height="30" Width="100" Margin="5,0,0,0"/>
|
||||
<TextBlock Name="TX" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Bottom" Height="30" Width="100" Margin="200,0,0,0"/>
|
||||
|
||||
|
||||
@@ -31,6 +31,10 @@ namespace DyeingComputer.View
|
||||
comboBoxCOM.ItemsSource = ports;
|
||||
comboBoxCOM.Text = Configini.IniReadvalue("SYS", "COM");
|
||||
|
||||
string[] protocols = { "SUNLIGHT_R", "MODBUS_RTU" };
|
||||
comboBoxCOMmod.ItemsSource = protocols;
|
||||
comboBoxCOMmod.Text = Configini.IniReadvalue("SYS", "Protocols");
|
||||
|
||||
string[] Language = { "en-US", "zh-CN", "zh -TW" };
|
||||
comboBoxLanguage.ItemsSource = Language;
|
||||
comboBoxLanguage.Text = Configini.IniReadvalue("SYS", "Language");
|
||||
@@ -42,7 +46,10 @@ namespace DyeingComputer.View
|
||||
{
|
||||
Configini.IniWritevalue("SYS", "COM", comboBoxCOM.SelectedValue.ToString());
|
||||
}
|
||||
|
||||
private void comboBoxCOMmod_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
Configini.IniWritevalue("SYS", "Protocols", comboBoxCOMmod.SelectedValue.ToString());
|
||||
}
|
||||
private void comboBoxLanguage_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
Configini.IniWritevalue("SYS", "Language", comboBoxLanguage.SelectedValue.ToString());
|
||||
@@ -64,5 +71,7 @@ namespace DyeingComputer.View
|
||||
RX.Text = MainWindowViewModel.RX.ToString();
|
||||
TX.Text = MainWindowViewModel.TX.ToString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+2
-14
@@ -57,13 +57,7 @@
|
||||
</DataGrid.CellStyle>
|
||||
<DataGrid.Columns>
|
||||
<!--列信息绑定-->
|
||||
<DataGridTextColumn Header="DIO" Width="100" Binding="{Binding ID}" IsReadOnly="True">
|
||||
<DataGridTextColumn.ElementStyle>
|
||||
<Style TargetType="{x:Type TextBlock}">
|
||||
<Setter Property="Foreground" Value="{Binding Path=type,Converter={StaticResource IORBConvert}}"/>
|
||||
</Style>
|
||||
</DataGridTextColumn.ElementStyle>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Header="DIO" MinWidth="0" MaxWidth="0" Binding="{Binding ID}" IsReadOnly="True"/>
|
||||
<DataGridTextColumn Header="PLC" Width="100" Binding="{Binding PLC}">
|
||||
<DataGridTextColumn.ElementStyle>
|
||||
<Style TargetType="{x:Type TextBlock}">
|
||||
@@ -125,13 +119,7 @@
|
||||
</DataGrid.CellStyle>
|
||||
<DataGrid.Columns>
|
||||
<!--列信息绑定-->
|
||||
<DataGridTextColumn Header="AIO" Width="100" Binding="{Binding ID}" IsReadOnly="True">
|
||||
<DataGridTextColumn.ElementStyle>
|
||||
<Style TargetType="{x:Type TextBlock}">
|
||||
<Setter Property="Foreground" Value="{Binding Path=type,Converter={StaticResource IORBConvert}}"/>
|
||||
</Style>
|
||||
</DataGridTextColumn.ElementStyle>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Header="AIO" MinWidth="0" MaxWidth="0" Binding="{Binding ID}" IsReadOnly="True"/>
|
||||
<DataGridTextColumn Header="PLC" Width="100" Binding="{Binding PLC}">
|
||||
<DataGridTextColumn.ElementStyle>
|
||||
<Style TargetType="{x:Type TextBlock}">
|
||||
|
||||
@@ -66,6 +66,7 @@ namespace DyeingComputer.View
|
||||
MainWindowViewModel.dt_ParameterSet = SQLiteHelpers.ExecuteDataSet("select * from Parameters order by ParameterID asc", null).Tables[0]; //读取计划表写入缓存
|
||||
SQLiteHelpers.Close();//关闭数据库
|
||||
}
|
||||
MainWindowViewModel.set_ = true;
|
||||
}
|
||||
|
||||
private void UserControl_Loaded(object sender, RoutedEventArgs e)//打开页面时的操作
|
||||
|
||||
@@ -61,6 +61,8 @@ namespace DyeingComputer.View
|
||||
MainWindowViewModel.dt_SysSet = SQLiteHelpers.ExecuteDataSet("select * from System order by ParameterID asc", null).Tables[0];
|
||||
SQLiteHelpers.Close();//关闭数据库
|
||||
}
|
||||
|
||||
MainWindowViewModel.set_ = true;
|
||||
}
|
||||
|
||||
private void UserControl_Loaded(object sender, RoutedEventArgs e)//打开页面时的操作
|
||||
|
||||
@@ -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,18 +1465,28 @@ 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")
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
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)
|
||||
|
||||
Reference in new issue
Block a user