change - PLC电机控制代码完善

master
wangsr 1 year ago
parent acef76c492
commit 61e5d44119

@ -17,18 +17,24 @@ namespace Mesnac.Action.ChemicalWeighing.EngineeringDebuggingMode.ElectronicMach
int ManualModeIsOpen;
int ManualModeIsStart;
int AutoModeIsStart;
string DmName;
string DmName = "DM1GDP01";
public ElectronicMachinery()
{
InitializeComponent();
ManualModeIsOpen = GetDataNameValue("_ManualMode").NowValue.ToInt();
ManualModeIsStart = GetDataNameValue("_StartManual").NowValue.ToInt();
AutoModeIsStart = Plc.DM1GDP01_StartAuto.NowValue.ToInt();
StateMonitor();
}
private void StateMonitor()
{
ManualModeIsOpen = GetDataToInt("_ManualMode");
ManualModeIsStart = GetDataToInt("_StartManual");
AutoModeIsStart = GetDataToInt("_StartAuto");
if (ManualModeIsOpen == 0)
{
ManualMode.Text = "切换手动模式";
ModeLable.Text = "自动模式";
if(ManualModeIsStart == 0)
if (AutoModeIsStart == 0)
{
OnOffControl.Text = "启动";
OnOffLable.Text = "状态:关";
@ -43,7 +49,7 @@ namespace Mesnac.Action.ChemicalWeighing.EngineeringDebuggingMode.ElectronicMach
{
ManualMode.Text = "切换自动模式";
ModeLable.Text = "手动模式";
if (AutoModeIsStart == 0)
if (ManualModeIsStart == 0)
{
OnOffControl.Text = "启动";
OnOffLable.Text = "状态:关";
@ -56,11 +62,21 @@ namespace Mesnac.Action.ChemicalWeighing.EngineeringDebuggingMode.ElectronicMach
}
}
public DataKeyValue GetDataNameValue(string dmValue)
private DataKeyValue GetDataNameValue(string dmValue)
{
return new DataKeyValue(DmName + dmValue);
}
private int GetDataToInt(String dmValue)
{
return GetDataNameValue(dmValue).NowValue.ToInt();
}
private void SetDataValue(String dmValue, int value)
{
Plc.PlcWriteByDataKey(GetDataNameValue(dmValue), new Object[] { value });
}
private void DMChange_SelectedIndexChanged(object sender, EventArgs e)
{
switch (DMChange.Text)
@ -96,14 +112,15 @@ namespace Mesnac.Action.ChemicalWeighing.EngineeringDebuggingMode.ElectronicMach
DmName = "DM1GDS05";
break;
}
StateMonitor();
}
private void ManualMode_Click(object sender, EventArgs e)
{
if(ManualModeIsOpen == 0)
{
Plc.PlcWriteByDataKey(GetDataNameValue("_ManualMode"), new Object[] { 1 });
Plc.PlcWriteByDataKey(GetDataNameValue("_AutoMode"), new Object[] { 0 });
SetDataValue("_ManualMode", 1);
SetDataValue("_AutoMode", 0 );
ManualMode.Text = "切换自动模式";
ModeLable.Text = "手动模式";
ManualModeIsOpen = 1;
@ -120,8 +137,8 @@ namespace Mesnac.Action.ChemicalWeighing.EngineeringDebuggingMode.ElectronicMach
}
else
{
Plc.PlcWriteByDataKey(GetDataNameValue("_ManualMode"), new Object[] { 0 });
Plc.PlcWriteByDataKey(GetDataNameValue("_AutoMode"), new Object[] { 1 });
SetDataValue("_ManualMode", 0);
SetDataValue("_AutoMode", 1);
ManualMode.Text = "切换手动模式";
ModeLable.Text = "自动模式";
ManualModeIsOpen = 0;
@ -144,16 +161,16 @@ namespace Mesnac.Action.ChemicalWeighing.EngineeringDebuggingMode.ElectronicMach
{
if (AutoModeIsStart == 0)
{
Plc.PlcWriteByDataKey(GetDataNameValue("_StartAuto"), new Object[] { 1 });
Plc.PlcWriteByDataKey(GetDataNameValue("_StopAuto"), new Object[] { 0 });
SetDataValue("_StartAuto", 1);
SetDataValue("_StopAuto", 0);
OnOffControl.Text = "关闭";
OnOffLable.Text = "状态:开";
AutoModeIsStart = 1;
}
else
{
Plc.PlcWriteByDataKey(GetDataNameValue("_StartAuto"), new Object[] { 0 });
Plc.PlcWriteByDataKey(GetDataNameValue("_StopAuto"), new Object[] { 1 });
SetDataValue("_StartAuto", 0);
SetDataValue("_StopAuto", 1);
OnOffControl.Text = "启动";
OnOffLable.Text = "状态:关";
AutoModeIsStart = 0;
@ -163,16 +180,16 @@ namespace Mesnac.Action.ChemicalWeighing.EngineeringDebuggingMode.ElectronicMach
{
if (ManualModeIsStart == 0)
{
Plc.PlcWriteByDataKey(GetDataNameValue("_StartManual"), new Object[] { 1 });
Plc.PlcWriteByDataKey(GetDataNameValue("_StopManual"), new Object[] { 0 });
SetDataValue("_StartManual", 1);
SetDataValue("_StopManual", 0);
OnOffControl.Text = "关闭";
OnOffLable.Text = "状态:开";
ManualModeIsStart = 1;
}
else
{
Plc.PlcWriteByDataKey(GetDataNameValue("_StartManual"), new Object[] { 0 });
Plc.PlcWriteByDataKey(GetDataNameValue("_StopManual"), new Object[] { 1 });
SetDataValue("_StartManual", 0);
SetDataValue("_StopManual", 1);
OnOffControl.Text = "启动";
OnOffLable.Text = "状态:关";
ManualModeIsStart = 0;
@ -182,17 +199,17 @@ namespace Mesnac.Action.ChemicalWeighing.EngineeringDebuggingMode.ElectronicMach
private void AlarmReset_Click(object sender, EventArgs e)
{
Plc.PlcWriteByDataKey(GetDataNameValue("_AlarmReset"), new Object[] { 1 });
SetDataValue("_AlarmReset", 1);
}
private void Running_Click(object sender, EventArgs e)
{
Plc.PlcWriteByDataKey(GetDataNameValue("_Running"), new Object[] { 1 });
SetDataValue("_Running", 1);
}
private void Run_Click(object sender, EventArgs e)
{
Plc.PlcWriteByDataKey(GetDataNameValue("_Run"), new Object[] { 1 });
SetDataValue("_Run", 1);
}

@ -31,7 +31,7 @@
<!--机台号-->
<add key="EquipCode" value="01"/>
<!--设备时钟类型值包括Thread或Timer-->
<add key="BASE_EQUIP_CLOCKTYPE" value="Timer"/>
<add key="BASE_EQUIP_CLOCKTYPE" value="Thread"/>
<!-- 是否加载数据源树 -->
<add key="IsLoadDataSourceTree" value="true"/>
<!--是否开启保存回放数据-->

@ -7,7 +7,7 @@
<ReadHz value="1000" />
<UnitLen value="8" />
<Connection mode="Net">
<IP value="192.168.153.100" />
<IP value="192.168.0.1" />
<Rack value="0" />
<Slot value="0" />
</Connection>
@ -6147,7 +6147,7 @@
<Data name="From_SiloO_Alarm" runname="From_SiloO_Alarm" start="275" len="1" method="Default_Bit(0,1)" max="" issave="False" subtractor="" remark="" />
</Data>
</Group>
<Group name="FC5_Motor" block="91" start="0" len="46" access="ReadWrite" remark="" isautoread="False">
<Group name="FC5_Motor" block="91" start="0" len="46" access="ReadWrite" remark="" isautoread="True">
<Data>
<Data name="DM1GDP01_ManualMode" runname="DM1GDP01_ManualMode" start="0" len="1" method="Default_Bit(0,1)" max="" issave="True" subtractor="" remark="手动模式" />
<Data name="DM1GDP01_AutoMode" runname="DM1GDP01_AutoMode" start="0" len="1" method="Default_Bit(1,1)" max="" issave="True" subtractor="" remark="自动模式" />

Loading…
Cancel
Save