change-添加实际PLC点位

master
liuwf 5 months ago
parent 7d57ce7841
commit 0dba9ef187

@ -273,7 +273,7 @@ namespace SlnMesnac.Business
{
if (plc != null && plc.IsConnected)
{
plc.writeInt16ByAddress("M100", 8);
plc.writeInt32ByAddress("DB22.DBW2", 8);
Task.Run(() =>
{
// 设置计时器
@ -281,7 +281,7 @@ namespace SlnMesnac.Business
stopwatch.Start();
while (true)
{
if (plc.readInt16ByAddress("M100") == 0)
if (plc.readInt32ByAddress("DB22.DBW2") == 0)
{
logger.LogInformation("PLC复位成功,启动线体");
RefreshMessageEvent?.Invoke("PLC复位成功,启动线体", true);
@ -291,6 +291,7 @@ namespace SlnMesnac.Business
{
logger.LogError("PLC复位超时");
RefreshMessageEvent?.Invoke("PLC复位超时", true);
break;
}
Thread.Sleep(100);
}
@ -318,7 +319,7 @@ namespace SlnMesnac.Business
{
if (plc != null && plc.IsConnected)
{
plc.writeInt16ByAddress("M100", 9);
plc.writeInt32ByAddress("DB22.DBW2", 9);
Task.Run(() =>
{
// 设置计时器
@ -326,7 +327,7 @@ namespace SlnMesnac.Business
stopwatch.Start();
while (true)
{
if (plc.readInt16ByAddress("M100") == 1)
if (plc.readInt32ByAddress("DB22.DBW2") == 1)
{
logger.LogInformation("PLC复位成功,启动线体");
RefreshMessageEvent?.Invoke("PLC复位成功,启动线体", true);
@ -336,6 +337,7 @@ namespace SlnMesnac.Business
{
logger.LogError("PLC复位超时");
RefreshMessageEvent?.Invoke("PLC复位超时", true);
break;
}
Thread.Sleep(100);
}

@ -109,16 +109,27 @@ namespace SlnMesnac.Common
{
if (serialPort.IsOpen)
{
byte[] buffer = null;
if (data == "NG")
{
buffer = GetBytesByCommand("OpenRed");
byte[] buffer = GetBytesByCommand("CloseRed");
serialPort.Write(buffer, 0x0, 0x4);
byte[] buffer1 = GetBytesByCommand("OpenRed");
serialPort.Write(buffer1, 0x0, 0x4);
}
else if (data == "OK")
{
buffer = GetBytesByCommand("CloseRed");
byte[] buffer = GetBytesByCommand("CloseRed");
serialPort.Write(buffer, 0x0, 0x4);
byte[] buffer1 = GetBytesByCommand("OpenGreen");
serialPort.Write(buffer1, 0x0, 0x4);
}
serialPort.Write(buffer, 0x0, 0x4);
else if(data == "Exit")
{
byte[] buffer = GetBytesByCommand("CloseRed");
serialPort.Write(buffer, 0x0, 0x4);
}
}
else
{
@ -142,18 +153,16 @@ namespace SlnMesnac.Common
byte[] buffer = null;
switch (command)
{
// 打开红灯+蜂鸣
case "OpenRed": buffer = new byte[] { 0xA0, 0x00, 0x02, 0xA2 }; break;
// 关闭红灯+蜂鸣
// 打开红灯闪烁+蜂鸣
case "OpenRed": buffer = new byte[] { 0xA0, 0x07, 0x02, 0xA9 }; break;
// 打开红灯闪烁
//case "OpenRed": buffer = new byte[] { 0xA0, 0x03, 0x02, 0xA5 }; break;
// 全部关闭
case "CloseRed": buffer = new byte[] { 0xA0, 0x00, 0x00, 0xA0 }; break;
////闪烁红灯+蜂鸣
//case "FlashRed": buffer = new byte[] { 0xA0, 0x07, 0x02, 0xA9 }; break;
//// 打开绿灯
//case "OpenGreen": buffer = new byte[] { 0xA0, 0x00, 0x01, 0xA1 }; break;
//// 关闭绿灯
//case "CloseGreen": buffer = new byte[] { 0xA0, 0x00, 0x00, 0xA0 }; break;
//// 闪烁绿灯
//case "FlashGreen": buffer = new byte[] { 0xA0, 0x00, 0x02, 0xA2 }; break;
case "OpenGreen": buffer = new byte[] { 0xA0, 0x02, 0x01, 0xA3 }; break;
default:return null;
}
return buffer;

@ -130,6 +130,30 @@ namespace SlnMesnac.Plc.Factory
}
}
/// <summary>
/// 根据地址读取int32数据
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override int readInt32ByAddress(string address)
{
try
{
OperateResult<int> read = inovanceTcp.ReadInt32(address);
if (!read.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};读取int32数据失败{read.Content}");
}
return read.Content;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};读取int32数据异常{ex.Message}");
}
}
/// <summary>
/// 根据地址写入int16数据
/// </summary>
@ -203,6 +227,20 @@ namespace SlnMesnac.Plc.Factory
}
}
/// <summary>
/// 根据地址写入int16数据
/// </summary>
/// <param name="address"></param>
/// <param name="value"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override bool writeInt32ByAddress(string address, int value)
{
throw new NotImplementedException("未实现异常");
}
/// <summary>
/// 通过PLC地址读取string类型数据
/// </summary>

@ -119,6 +119,30 @@ namespace SlnMesnac.Plc.Factory
}
}
/// <summary>
/// 根据地址读取int32数据
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override int readInt32ByAddress(string address)
{
try
{
OperateResult<int> read = melsec_net.ReadInt32(address);
if (!read.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};读取int16数据失败{read.Content}");
}
return read.Content;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};读取int16数据异常{ex.Message}");
}
}
/// <summary>
/// 根据地址写入int16数据
/// </summary>
@ -143,6 +167,31 @@ namespace SlnMesnac.Plc.Factory
}
}
/// <summary>
/// 根据地址写入int16数据
/// </summary>
/// <param name="address"></param>
/// <param name="value"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override bool writeInt32ByAddress(string address, int value)
{
try
{
OperateResult operateResult = melsec_net.Write(address, value);
if (!operateResult.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};写入int32数据失败{operateResult.Message}");
}
return operateResult.IsSuccess;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};写入int32数据异常{ex.Message}");
}
}
/// <summary>
/// 通过PLC地址读取string类型数据
/// </summary>

@ -122,6 +122,29 @@ namespace SlnMesnac.Plc.Factory
}
}
/// <summary>
/// 根据地址读取int32数据
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override int readInt32ByAddress(string address)
{
try
{
OperateResult<int> read = omronFinsNet.ReadInt32(address);
if (!read.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};读取int32数据失败{read.Content}");
}
return read.Content;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};读取int32数据异常{ex.Message}");
}
}
/// <summary>
/// 根据地址写入int16数据
/// </summary>
@ -146,6 +169,29 @@ namespace SlnMesnac.Plc.Factory
}
}
/// <summary>
/// 根据地址写入int32数据
/// </summary>
/// <param name="address"></param>
/// <param name="value"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override bool writeInt32ByAddress(string address, int value)
{
try
{
OperateResult operateResult = omronFinsNet.Write(address, value);
if (!operateResult.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};写入int32数据失败{operateResult.Message}");
}
return operateResult.IsSuccess;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};写入int32数据异常{ex.Message}");
}
}
/// <summary>
/// 通过PLC地址读取string类型数据
/// </summary>

@ -120,6 +120,29 @@ namespace SlnMesnac.Plc.Factory
}
}
/// <summary>
/// 根据地址读取int32数据
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override int readInt32ByAddress(string address)
{
try
{
OperateResult<int> read = s7.ReadInt32(address);
if (!read.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};读取int32数据失败{read.Content}");
}
return read.Content;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};读取int32数据异常{ex.Message}");
}
}
/// <summary>
/// 根据地址写入int16数据
/// </summary>
@ -144,6 +167,32 @@ namespace SlnMesnac.Plc.Factory
}
}
/// <summary>
/// 根据地址写入int32数据
/// </summary>
/// <param name="address"></param>
/// <param name="value"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override bool writeInt32ByAddress(string address, int value)
{
try
{
OperateResult operateResult = s7.Write(address, value);
if (!operateResult.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};写入int32数据失败{operateResult.Message}");
}
return operateResult.IsSuccess;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};写入int32数据异常{ex.Message}");
}
}
/// <summary>
/// 通过PLC地址读取string类型数据
/// </summary>

@ -35,7 +35,16 @@
/// <param name="address"></param>
/// <returns></returns>
public abstract int readInt16ByAddress(string address);
/// <summary>
/// 通过PLC地址读取int32类型数据
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public abstract int readInt32ByAddress(string address);
/// <summary>
/// 通过PLC地址写入int16类型数据
/// </summary>
@ -43,7 +52,15 @@
/// <param name="value"></param>
/// <returns></returns>
public abstract bool writeInt16ByAddress(string address,int value);
/// <summary>
/// 通过PLC地址写入int32类型数据
/// </summary>
/// <param name="address"></param>
/// <param name="value"></param>
/// <returns></returns>
public abstract bool writeInt32ByAddress(string address, int value);
/// <summary>
/// 通过PLC地址读取string类型数据
/// </summary>

@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Serilog;
using SlnMesnac.Common;
using SlnMesnac.Config;
using System;
using System.Collections.Generic;
@ -23,7 +24,7 @@ namespace SlnMesnac.WPF
private System.Threading.Mutex mutex;
private LierdaCracker cracker = new LierdaCracker();
public static IServiceProvider ServiceProvider;
private GunHelper gunHelper = GunHelper.Instance;
// Startup事件
protected override async void OnStartup(StartupEventArgs e)
{
@ -71,6 +72,8 @@ namespace SlnMesnac.WPF
Log.Information($"系统退出,当前时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
// 释放资源
// ...
// 关闭指示灯
gunHelper.SendData("Exit");
}

@ -59,6 +59,9 @@ namespace SlnMesnac.WPF.ViewModel
logoConfigService = App.ServiceProvider.GetService<ILogoConfigService>();
_logger2 = App.ServiceProvider.GetService<ILogger<LogoBusiness>>();
logoBusiness = LogoBusiness.GetInstance(_logger2, logoConfigService, baseMaterialService, ocrVerfiyService, plcPool, tcpServer);
//程序启动,打开绿色指示灯
gunHelper.SendData("OK");
}
/// <summary>

@ -49,7 +49,7 @@ namespace SlnMesnac.WPF.ViewModel
private StatisticsPageView statisticsPageView = new StatisticsPageView();
private ConfigPage configPage = new ConfigPage();
private DebugConfig config = DebugConfig.Instance;
private GunHelper gunHelper = GunHelper.Instance;
public delegate void RefreDataGrid();
public static event RefreDataGrid RefreDataGridEvent;
public MainWindowViewModel()
@ -68,8 +68,8 @@ namespace SlnMesnac.WPF.ViewModel
FormControlCommand = new RelayCommand<object>(x => FormControl(x));
TcpServer.RefreshStateEvent += RefreshScanner;
//PLC状态刷新
StartState();
RefreshTime();
@ -166,7 +166,6 @@ namespace SlnMesnac.WPF.ViewModel
#endregion
public void StartState()
@ -227,7 +226,7 @@ namespace SlnMesnac.WPF.ViewModel
// 关闭当前窗口
case "Exit":
{
gunHelper.SendData("Exit");
Environment.Exit(0);
}

@ -26,7 +26,7 @@
"configId": 1,
"plcType": "SiemensPlc",
"plcIp": "127.0.0.1",
"plcPort": 6000,
"plcPort": 102,
"plcKey": "plc",
"isFlage": true
},
@ -52,20 +52,20 @@
"equipIp": "127.0.0.1",
"equipPort": 6009,
"equipKey": "test2",
"isFlage": true
"isFlage": false
}
],
"ScannerConfig": [
{
"Id": 1,
"Ip": "10.10.92.142",
"Name": "test1"
},
{
"Id": 2,
"Ip": "10.10.92.143",
"Name": "test2"
}
]
//"ScannerConfig": [
// {
// "Id": 1,
// "Ip": "10.10.92.142",
// "Name": "test1"
// },
// {
// "Id": 2,
// "Ip": "10.10.92.143",
// "Name": "test2"
// }
//]
}
}

Loading…
Cancel
Save