change - PLC类型修改

master
wenjy 2 months ago
parent 5a37cd9694
commit 844534ecf6

@ -59,8 +59,6 @@ namespace SlnMesnac.Business
{ {
_record_busbar_TempServices = record_busbar_TempServices; _record_busbar_TempServices = record_busbar_TempServices;
_appConfig = appConfig; _appConfig = appConfig;
} }
public void Start() public void Start()
@ -114,13 +112,13 @@ namespace SlnMesnac.Business
base.InitEquip(1); //判断PLC状态下发工作模式 base.InitEquip(1); //判断PLC状态下发工作模式
int address = _plc.readInt16ByAddress("VD2005"); //读取轨道电机当前位置,判断原点及起始位置 int address = _plc.readInt32ByAddress("VD2005"); //读取轨道电机当前位置,判断原点及起始位置
//获取电柜信息 //获取电柜信息
List<base_cabinet_info> cabinet_Infos = new List<base_cabinet_info>(); List<base_cabinet_info> cabinet_Infos = new List<base_cabinet_info>();
base.GetCabinetInfos(address, out cabinet_Infos); base.GetCabinetInfos(address, out cabinet_Infos);
if (!_plc.writeInt16ByAddress("VD1517", 1)) //下发轨道电机启动信号 if (!_plc.writeInt32ByAddress("VD1517", 1)) //下发轨道电机启动信号
{ {
throw new ArgumentException($"启动信号写入PLC失败VD1517写1"); throw new ArgumentException($"启动信号写入PLC失败VD1517写1");
} }
@ -132,7 +130,7 @@ namespace SlnMesnac.Business
this.SendTrackMotorAddress(item); this.SendTrackMotorAddress(item);
if (!_plc.writeInt16ByAddress("VD1513", 1)) //母排检测完成下发检测完成信号,升降电机可以回到原位等待 if (!_plc.writeInt32ByAddress("VD1513", 1)) //母排检测完成下发检测完成信号,升降电机可以回到原位等待
{ {
throw new ArgumentException($"下发母排检测完成下发检测完成信号写入失败VD1513写1"); throw new ArgumentException($"下发母排检测完成下发检测完成信号写入失败VD1513写1");
} }
@ -156,7 +154,7 @@ namespace SlnMesnac.Business
/// <exception cref="ArgumentException"></exception> /// <exception cref="ArgumentException"></exception>
private void SendTrackMotorAddress(base_cabinet_info item) private void SendTrackMotorAddress(base_cabinet_info item)
{ {
if (!_plc.writeInt16ByAddress("VD1521", item.cabinetCode)) //下发电柜编号,通知轨道电机前往指定电柜位置 if (!_plc.writeInt32ByAddress("VD1521", item.cabinetCode)) //下发电柜编号,通知轨道电机前往指定电柜位置
{ {
throw new ArgumentException($"下发轨道电机前往指定位置编号写入失败VD1521写{item.cabinetCode}"); throw new ArgumentException($"下发轨道电机前往指定位置编号写入失败VD1521写{item.cabinetCode}");
} }
@ -166,6 +164,11 @@ namespace SlnMesnac.Business
this.SendLiftMotorDict(item.cabinetCode); this.SendLiftMotorDict(item.cabinetCode);
if (!_plc.writeInt32ByAddress("VD1521", 0))
{
throw new ArgumentException($"电柜检测完成轨道电机地址写0失败VD1521写0");
}
} }
/// <summary> /// <summary>
@ -180,7 +183,7 @@ namespace SlnMesnac.Business
base.GetBusbarInfos(cabinetCode, out busbar_Infos); base.GetBusbarInfos(cabinetCode, out busbar_Infos);
foreach (var busbar in busbar_Infos) foreach (var busbar in busbar_Infos)
{ {
if (!_plc.writeDoubleByAddress("VD1525", Convert.ToDouble(busbar.busbarDist))) //下发母排距离,升降电机升降的距离 if (!_plc.writeFloatByAddress("VD1525", ((float)busbar.busbarDist))) //下发母排距离,升降电机升降的距离
{ {
throw new ArgumentException($"下发母排升降距离写入失败VD1525写{busbar.cabinetCode}"); throw new ArgumentException($"下发母排升降距离写入失败VD1525写{busbar.cabinetCode}");
} }
@ -201,21 +204,12 @@ namespace SlnMesnac.Business
this.SaveBusbarTemp(busbar.busbarCode, busbar.cabinetCode, _realTemperatureInfo,busbar.isPictures); this.SaveBusbarTemp(busbar.busbarCode, busbar.cabinetCode, _realTemperatureInfo,busbar.isPictures);
Task.Delay(1000).Wait(); Task.Delay(1000).Wait();
if (!_plc.writeDoubleByAddress("VD1525", 0)) if (!_plc.writeFloatByAddress("VD1525", 0))
{ {
throw new ArgumentException($"母排检测完成向PLC升降距离写0失败VD1525写0"); throw new ArgumentException($"母排检测完成向PLC升降距离写0失败VD1525写0");
} }
_log.Info($"母排检测完成向PLC升降距离写0成功VD1525写0"); _log.Info($"母排检测完成向PLC升降距离写0成功VD1525写0");
if (busbar.isEnd == 1)
{
if(!_plc.writeInt16ByAddress("VD1513", 1))
{
throw new ArgumentException($"最后一层检测完成向PLC写入检测完成信号失败VD1513写1");
}
_log.Info($"最后一层检测完成向PLC写入检测完成信号成功VD1513写1");
}
if(busbar.isRotate == 1) if(busbar.isRotate == 1)
{ {
GimbaRotationControlEvent?.Invoke("20", "4", "10"); GimbaRotationControlEvent?.Invoke("20", "4", "10");
@ -236,11 +230,11 @@ namespace SlnMesnac.Business
bool is_arrive = true; bool is_arrive = true;
while (is_arrive) while (is_arrive)
{ {
int is_arrive_flag = _plc.readInt16ByAddress(signal); //读取PLC轨道电机到位信号 int is_arrive_flag = _plc.readInt32ByAddress(signal); //读取PLC轨道电机到位信号
if (is_arrive_flag == 1) if (is_arrive_flag == 1)
{ {
_log.Info($"PLC已到达指定位置{signal}值为{is_arrive_flag}"); _log.Info($"PLC已到达指定位置{signal}值为{is_arrive_flag}");
if (!_plc.writeInt16ByAddress(signal, 0)) if (!_plc.writeInt32ByAddress(signal, 0))
{ {
throw new ArgumentException($"PLC到位信号复位失败{signal}写0"); throw new ArgumentException($"PLC到位信号复位失败{signal}写0");
} }
@ -317,7 +311,7 @@ namespace SlnMesnac.Business
public int GetTrackMotorAddress() public int GetTrackMotorAddress()
{ {
int is_arrive_flag = _plc.readInt16ByAddress("VD2005"); int is_arrive_flag = _plc.readInt32ByAddress("VD2005");
return is_arrive_flag; return is_arrive_flag;
} }

@ -63,7 +63,7 @@ namespace SlnMesnac.Business.@base
int plcFlag = 0; int plcFlag = 0;
do do
{ {
plcFlag = _plc.readInt16ByAddress("VD1509"); //PLC状态 plcFlag = _plc.readInt32ByAddress("VD1509"); //PLC状态
if (plcFlag != 1) if (plcFlag != 1)
{ {
_log.Info($"PLC状态不具备启动条件:VD1509值为{plcFlag}"); _log.Info($"PLC状态不具备启动条件:VD1509值为{plcFlag}");
@ -71,7 +71,7 @@ namespace SlnMesnac.Business.@base
continue; continue;
} }
if (!_plc.writeInt16ByAddress("VD1533", model)) //工作模式:1-自动2-巡检3-手动 if (!_plc.writeInt32ByAddress("VD1533", model)) //工作模式:1-自动2-巡检3-手动
{ {
throw new ArgumentException($"工作模式:自动模式写入PLC失败VD1533写{model}"); throw new ArgumentException($"工作模式:自动模式写入PLC失败VD1533写{model}");
} }

@ -342,5 +342,25 @@ namespace SlnMesnac.Plc.Factory
throw new InvalidOperationException($"根据地址:{address};写入double数据异常{ex.Message}"); throw new InvalidOperationException($"根据地址:{address};写入double数据异常{ex.Message}");
} }
} }
public override bool writeFloatByAddress(string address, float value)
{
throw new NotImplementedException();
}
public override int readInt32ByAddress(string address)
{
throw new NotImplementedException();
}
public override bool writeInt32ByAddress(string address, int value)
{
throw new NotImplementedException();
}
public override float readFloatByAddress(string address)
{
throw new NotImplementedException();
}
} }
} }

@ -283,5 +283,25 @@ namespace SlnMesnac.Plc.Factory
throw new InvalidOperationException($"根据地址:{address};写入double数据异常{ex.Message}"); throw new InvalidOperationException($"根据地址:{address};写入double数据异常{ex.Message}");
} }
} }
public override bool writeFloatByAddress(string address, float value)
{
throw new NotImplementedException();
}
public override int readInt32ByAddress(string address)
{
throw new NotImplementedException();
}
public override bool writeInt32ByAddress(string address, int value)
{
throw new NotImplementedException();
}
public override float readFloatByAddress(string address)
{
throw new NotImplementedException();
}
} }
} }

@ -286,5 +286,25 @@ namespace SlnMesnac.Plc.Factory
throw new InvalidOperationException($"根据地址:{address};写入double数据异常{ex.Message}"); throw new InvalidOperationException($"根据地址:{address};写入double数据异常{ex.Message}");
} }
} }
public override int readInt32ByAddress(string address)
{
throw new NotImplementedException();
}
public override bool writeInt32ByAddress(string address, int value)
{
throw new NotImplementedException();
}
public override bool writeFloatByAddress(string address, float value)
{
throw new NotImplementedException();
}
public override float readFloatByAddress(string address)
{
throw new NotImplementedException();
}
} }
} }

@ -271,7 +271,7 @@ namespace SlnMesnac.Plc.Factory
{ {
try try
{ {
OperateResult operateResult = s7.Write(address,value); OperateResult operateResult = s7.Write(address, value);
if (!operateResult.IsSuccess) if (!operateResult.IsSuccess)
{ {
throw new InvalidOperationException($"根据地址:{address};写入double数据失败{operateResult.Message}"); throw new InvalidOperationException($"根据地址:{address};写入double数据失败{operateResult.Message}");
@ -283,5 +283,99 @@ namespace SlnMesnac.Plc.Factory
throw new InvalidOperationException($"根据地址:{address};写入double数据异常{ex.Message}"); throw new InvalidOperationException($"根据地址:{address};写入double数据异常{ex.Message}");
} }
} }
/// <summary>
/// 通过PLC地址读取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>
/// 通过PLC地址写入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, Convert.ToInt32(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地址读取Float类型数据
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override float readFloatByAddress(string address)
{
try
{
OperateResult<float> read = s7.ReadFloat(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>
/// 通过PLC地址写入Float类型数据
/// </summary>
/// <param name="address"></param>
/// <param name="value"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override bool writeFloatByAddress(string address, float value)
{
try
{
OperateResult operateResult = s7.Write(address, value);
if (!operateResult.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};写入float数据失败{operateResult.Message}");
}
return operateResult.IsSuccess;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};写入float数据异常{ex.Message}");
}
}
} }
} }

@ -20,6 +20,8 @@
* V1.0.0 * V1.0.0
*--------------------------------------------------------------------*/ *--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >> #endregion << 版 本 注 释 >>
using System.ComponentModel;
namespace SlnMesnac.Plc namespace SlnMesnac.Plc
{ {
public abstract class PlcAbsractFactory public abstract class PlcAbsractFactory
@ -105,5 +107,14 @@ namespace SlnMesnac.Plc
/// <param name="value"></param> /// <param name="value"></param>
/// <returns></returns> /// <returns></returns>
public abstract bool writeDoubleByAddress(string address, double value); public abstract bool writeDoubleByAddress(string address, double value);
public abstract int readInt32ByAddress(string address);
public abstract bool writeInt32ByAddress(string address, int value);
public abstract float readFloatByAddress(string address);
public abstract bool writeFloatByAddress(string address, float value);
} }
} }

@ -16,7 +16,7 @@
"cameraPort": 8000, "cameraPort": 8000,
"cameraUserName": "admin", "cameraUserName": "admin",
"cameraPassword": "haiwei@2024", "cameraPassword": "haiwei@2024",
"checkCycle": 5, "checkCycle": 50,
"SqlConfig": [ "SqlConfig": [
{ {
"configId": "iot", "configId": "iot",

Loading…
Cancel
Save