Merge branch 'dep' into wangsr

master
wangsr 1 year ago
commit 069ce8225d

@ -102,6 +102,11 @@ namespace MCRun
if (Mesnac.Gui.Common.RunEngine.Instance.Init(projectPath, true, true, true)) //初始化运行引擎
{
AppConfigHandler.Instance.InitCustomerMenuAndToolStrip(WorkbenchSingleton.Workbench.TopMenu, WorkbenchSingleton.Workbench.ToolStrip); //初始化自定义系统菜单和工具栏
//初始化HslCommunication 11.0.6.0
PlcBusiness.Instance.InitPlcConnect(PlcType.SiemensPlc, "127.0.0.1", 12);
//初始化连接报警器
DoControl.Instance.ComOn();
}
//if (!Mesnac.Basic.InfluxDbHelper.Instance.IsStartDbServer)
@ -120,9 +125,6 @@ namespace MCRun
};
WorkbenchSingleton.InitializeWorkbench();
PlcBusiness.Instance.InitPlcConnect(PlcType.SiemensPlc, "127.0.0.1", 12);
DoControl.Instance.ComOn();
ICSharpCode.Core.LoggingService<Program>.Debug("starting workbench...");
Form frmMain = WorkbenchSingleton.Workbench as Form;

@ -13,7 +13,7 @@ namespace Mesnac.DoUtils
/// <summary>
/// 报警灯控制类
/// </summary>
public class DoControl
public sealed class DoControl
{
public SerialPort serialPort = new SerialPort("COM5");
private static readonly Lazy<DoControl> lazy = new Lazy<DoControl>(() => new DoControl());
@ -38,9 +38,16 @@ namespace Mesnac.DoUtils
/// </summary>
public void ComOn()
{
if (!serialPort.IsOpen)
try
{
serialPort.Open();
if (!serialPort.IsOpen)
{
serialPort.Open();
ICSharpCode.Core.LoggingService<DoControl>.Debug($"打开报警器串口成功,串口:{serialPort.PortName};波特率:{serialPort.BaudRate}");
}
}catch (Exception ex)
{
ICSharpCode.Core.LoggingService<DoControl>.Error($"报警器串口打开异常,串口:{serialPort.PortName};波特率:{serialPort.BaudRate};异常信息:{ex.Message}");
}
}
/// <summary>
@ -129,12 +136,14 @@ namespace Mesnac.DoUtils
/// <param name="dOOnOff">启停状态</param>
public void DOControl(DOName dOName, DOOnOff dOOnOff)
{
//ComOn();
if (!serialPort.IsOpen)
if (serialPort.IsOpen)
{
serialPort.Write(new byte[] { 0xE3, 0x01, 0x09, (byte)dOName, (byte)dOOnOff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0, 12);
}
else
{
serialPort.Open();
ComOn();
}
serialPort.Write(new byte[] { 0xE3, 0x01, 0x09, (byte)dOName, (byte)dOOnOff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0, 12);
}
/// <summary>

@ -34,6 +34,12 @@
<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
</PropertyGroup>
<ItemGroup>
<Reference Include="ICSharpCode.Core">
<HintPath>..\PlugInPlatform\ICSharpCode.Core.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.Data.Core">
<HintPath>..\PlugInPlatform\ICSharpCode.Data.Core.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />

@ -9,7 +9,7 @@ using System.Threading.Tasks;
namespace Mesnac.PlcUtils.Impl
{
public class OmronNJPlc
public class OmronNJPlc:IPlc
{
private StringChange stringChange = StringChange.Instance;

Loading…
Cancel
Save