change - Plc修改为西门子

master
wenjy 9 months ago
parent 28a833ea5c
commit 4bb2a4be80

@ -6,7 +6,7 @@
<connectionStrings> <connectionStrings>
<add name="connectionstring" connectionString="server=localhost;port=3306;user id=root;password=123456;database=sc_byd;Convert Zero Datetime=True;Allow Zero Datetime=True;Connection Timeout=10" /> <add name="connectionstring" connectionString="server=localhost;port=3306;user id=root;password=123456;database=sc_byd;Convert Zero Datetime=True;Allow Zero Datetime=True;Connection Timeout=10" />
<add name="pgsqlconnectionstring" connectionString="PORT=5432;DATABASE=sc_byd_5;HOST=175.27.215.92;PASSWORD=haiwei@123;USER ID=postgres;Pooling=true;Search Path=public;" /> <add name="pgsqlconnectionstring" connectionString="PORT=5432;DATABASE=postgres;HOST=175.27.215.92;PASSWORD=haiwei@123;USER ID=postgres;Pooling=true;Search Path=public;" />
</connectionStrings> </connectionStrings>
<appSettings> <appSettings>

@ -353,7 +353,7 @@ namespace ZJ_BYD
for (int i = 0; i < responseData.Count; i++) for (int i = 0; i < responseData.Count; i++)
{ {
var val = dt.Rows[0][i] == null ? "0" : (string.IsNullOrWhiteSpace(dt.Rows[0][i].ToString()) ? "0" : dt.Rows[0][i].ToString()); var val = dt.Rows[0][i] == null ? "0" : (string.IsNullOrWhiteSpace(dt.Rows[0][i].ToString()) ? "0" : dt.Rows[0][i].ToString());
Program.omronCipNet.Write(responseData[i].Address, float.Parse(val)); Program.siemensS7Net.Write(responseData[i].Address, float.Parse(val));
resultData += val + ","; resultData += val + ",";
if ((i + 1) == int.Parse(len)) if ((i + 1) == int.Parse(len))
{ {

@ -23,14 +23,14 @@ namespace ZJ_BYD.Common
switch (dataType) switch (dataType)
{ {
case "bool": case "bool":
if (Program.omronCipNet == null) if (Program.siemensS7Net == null)
{ {
Program.communicationstatus = "异常"; Program.communicationstatus = "异常";
return (false, strVal); return (false, strVal);
} }
else else
{ {
var operateBoolResult = Program.omronCipNet.ReadBool(address); var operateBoolResult = Program.siemensS7Net.ReadBool(address);
if (!operateBoolResult.IsSuccess) if (!operateBoolResult.IsSuccess)
{ {
return (false, strVal); return (false, strVal);
@ -43,14 +43,14 @@ namespace ZJ_BYD.Common
} }
} }
case "short": case "short":
if (Program.omronCipNet == null) if (Program.siemensS7Net == null)
{ {
Program.communicationstatus = "异常"; Program.communicationstatus = "异常";
return (false, strVal); return (false, strVal);
} }
else else
{ {
var operateShortResult = Program.omronCipNet.ReadInt16(address); var operateShortResult = Program.siemensS7Net.ReadInt16(address);
if (!operateShortResult.IsSuccess) if (!operateShortResult.IsSuccess)
{ {
return (false, strVal); return (false, strVal);
@ -63,14 +63,14 @@ namespace ZJ_BYD.Common
} }
} }
case "ushort": case "ushort":
if (Program.omronCipNet == null) if (Program.siemensS7Net == null)
{ {
Program.communicationstatus = "异常"; Program.communicationstatus = "异常";
return (false, strVal); return (false, strVal);
} }
else else
{ {
var operateShortResult = Program.omronCipNet.ReadUInt16(address); var operateShortResult = Program.siemensS7Net.ReadUInt16(address);
if (!operateShortResult.IsSuccess) if (!operateShortResult.IsSuccess)
{ {
return (false, strVal); return (false, strVal);
@ -83,14 +83,14 @@ namespace ZJ_BYD.Common
} }
} }
case "float": case "float":
if (Program.omronCipNet == null) if (Program.siemensS7Net == null)
{ {
Program.communicationstatus = "异常"; Program.communicationstatus = "异常";
return (false, strVal); return (false, strVal);
} }
else else
{ {
var operateFloatResult = Program.omronCipNet.ReadFloat(address); var operateFloatResult = Program.siemensS7Net.ReadFloat(address);
if (!operateFloatResult.IsSuccess) if (!operateFloatResult.IsSuccess)
{ {
return (false, strVal); return (false, strVal);
@ -103,14 +103,14 @@ namespace ZJ_BYD.Common
} }
} }
case "string": case "string":
if (Program.omronCipNet == null) if (Program.siemensS7Net == null)
{ {
Program.communicationstatus = "异常"; Program.communicationstatus = "异常";
return (false, strVal); return (false, strVal);
} }
else else
{ {
var operateFloatResult = Program.omronCipNet.ReadString(address, ushort.Parse(length), Encoding.UTF8); var operateFloatResult = Program.siemensS7Net.ReadString(address, ushort.Parse(length), Encoding.UTF8);
if (!operateFloatResult.IsSuccess) if (!operateFloatResult.IsSuccess)
{ {
return (false, strVal); return (false, strVal);

@ -330,12 +330,12 @@ namespace ZJ_BYD
{ {
BarCode = resultBarcode; BarCode = resultBarcode;
//打印反馈 //打印反馈
Program.omronCipNet.Write(M17.Address, ushort.Parse("1")); Program.siemensS7Net.Write(M17.Address, ushort.Parse("1"));
} }
else else
{ {
//打印反馈 //打印反馈
Program.omronCipNet.Write(M17.Address, ushort.Parse("2")); Program.siemensS7Net.Write(M17.Address, ushort.Parse("2"));
} }
_logs.Add(new LogVm _logs.Add(new LogVm
{ {
@ -351,7 +351,7 @@ namespace ZJ_BYD
var msg = ex == null ? "操作异常" : ex.Message; var msg = ex == null ? "操作异常" : ex.Message;
LogHelper.WriteErrorLog($"标签打印时异常:{msg}"); LogHelper.WriteErrorLog($"标签打印时异常:{msg}");
//打印反馈 //打印反馈
Program.omronCipNet.Write(M17.Address, ushort.Parse("2")); Program.siemensS7Net.Write(M17.Address, ushort.Parse("2"));
} }
} }
else else
@ -397,17 +397,17 @@ namespace ZJ_BYD
Log = $"{DateTime.Now:HH:mm:ss}>>>>>主条码匹配反馈:{(ok ? "OK" : "NG")},详情:{msg}{Environment.NewLine}"; Log = $"{DateTime.Now:HH:mm:ss}>>>>>主条码匹配反馈:{(ok ? "OK" : "NG")},详情:{msg}{Environment.NewLine}";
if (ok) if (ok)
{ {
Program.omronCipNet.Write(M20.Address, ushort.Parse("1")); Program.siemensS7Net.Write(M20.Address, ushort.Parse("1"));
} }
else else
{ {
Program.omronCipNet.Write(M20.Address, ushort.Parse("2")); Program.siemensS7Net.Write(M20.Address, ushort.Parse("2"));
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
Program.omronCipNet.Write(M20.Address, ushort.Parse("2")); Program.siemensS7Net.Write(M20.Address, ushort.Parse("2"));
var errMsg = ex == null ? "未知异常" : ex.Message; var errMsg = ex == null ? "未知异常" : ex.Message;
LogHandler($"{DateTime.Now:HH:mm:ss}>>>>>{errMsg}"); LogHandler($"{DateTime.Now:HH:mm:ss}>>>>>{errMsg}");
runMainMatch = true; runMainMatch = true;
@ -983,16 +983,16 @@ namespace ZJ_BYD
{ {
CheckCode.SearchEmptyTotalWeight(_plcPoints, out var emptyTotalWeight); CheckCode.SearchEmptyTotalWeight(_plcPoints, out var emptyTotalWeight);
var M31 = _plcPoints.FirstOrDefault(m => m.Key == "M31"); var M31 = _plcPoints.FirstOrDefault(m => m.Key == "M31");
var writeOk = Program.omronCipNet.Write(M31.Address, emptyTotalWeight); var writeOk = Program.siemensS7Net.Write(M31.Address, emptyTotalWeight);
LogHandler($"{DateTime.Now:HH:mm:ss}>>>>>一体机启动反馈:获取压缩机总空重成功,数据值:{emptyTotalWeight}写入M31"); LogHandler($"{DateTime.Now:HH:mm:ss}>>>>>一体机启动反馈:获取压缩机总空重成功,数据值:{emptyTotalWeight}写入M31");
var M26 = _plcPoints.FirstOrDefault(m => m.Key == "M26"); var M26 = _plcPoints.FirstOrDefault(m => m.Key == "M26");
if (writeOk.IsSuccess) if (writeOk.IsSuccess)
{ {
Program.omronCipNet.Write(M26.Address, ushort.Parse("1")); Program.siemensS7Net.Write(M26.Address, ushort.Parse("1"));
} }
else else
{ {
Program.omronCipNet.Write(M26.Address, ushort.Parse("2")); Program.siemensS7Net.Write(M26.Address, ushort.Parse("2"));
} }
} }
else else
@ -1015,11 +1015,11 @@ namespace ZJ_BYD
{ {
if (ok.Value) if (ok.Value)
{ {
Program.omronCipNet.Write(M26.Address, ushort.Parse("1")); Program.siemensS7Net.Write(M26.Address, ushort.Parse("1"));
} }
else else
{ {
Program.omronCipNet.Write(M26.Address, ushort.Parse("2")); Program.siemensS7Net.Write(M26.Address, ushort.Parse("2"));
} }
} }
_logs.Add(new LogVm _logs.Add(new LogVm
@ -1341,7 +1341,7 @@ namespace ZJ_BYD
} }
else else
{ {
Program.omronCipNet.Write(M31.Address, weight); Program.siemensS7Net.Write(M31.Address, weight);
LogHandler($"{DateTime.Now:HH:mm:ss}>>>>>一体机启动反馈:获取[{value.Key}]成功,数据值:{value.Value}写入M31"); LogHandler($"{DateTime.Now:HH:mm:ss}>>>>>一体机启动反馈:获取[{value.Key}]成功,数据值:{value.Value}写入M31");
} }
} }
@ -1350,7 +1350,7 @@ namespace ZJ_BYD
{ {
var value = values.keyValues.ElementAt(1); var value = values.keyValues.ElementAt(1);
var M32 = _plcPoints.FirstOrDefault(m => m.Key == "M32"); var M32 = _plcPoints.FirstOrDefault(m => m.Key == "M32");
Program.omronCipNet.Write(M32.Address, float.Parse(value.Value)); Program.siemensS7Net.Write(M32.Address, float.Parse(value.Value));
LogHandler($"{DateTime.Now:HH:mm:ss}>>>>>一体机启动反馈:获取[{value.Key}]成功,数据值:{value.Value}写入M32"); LogHandler($"{DateTime.Now:HH:mm:ss}>>>>>一体机启动反馈:获取[{value.Key}]成功,数据值:{value.Value}写入M32");
} }
} }
@ -1369,11 +1369,11 @@ namespace ZJ_BYD
var M26 = _plcPoints.FirstOrDefault(m => m.Key == "M26"); var M26 = _plcPoints.FirstOrDefault(m => m.Key == "M26");
if (isCheck) if (isCheck)
{ {
Program.omronCipNet.Write(M26.Address, ushort.Parse("1")); Program.siemensS7Net.Write(M26.Address, ushort.Parse("1"));
} }
else else
{ {
Program.omronCipNet.Write(M26.Address, ushort.Parse("2")); Program.siemensS7Net.Write(M26.Address, ushort.Parse("2"));
} }
} }
catch (Exception ex) catch (Exception ex)
@ -1543,20 +1543,20 @@ namespace ZJ_BYD
{ {
if (isOk) if (isOk)
{ {
var result = Program.omronCipNet.Write(M24.Address, ushort.Parse("1")); var result = Program.siemensS7Net.Write(M24.Address, ushort.Parse("1"));
if (!result.IsSuccess) if (!result.IsSuccess)
{ {
Program.omronCipNet.Write(M24.Address, ushort.Parse("1")); Program.siemensS7Net.Write(M24.Address, ushort.Parse("1"));
} }
savedb = true; savedb = true;
LogHandler($"{DateTime.Now:HH:mm:ss}>>>>>写入PLC地址M24数据值1"); LogHandler($"{DateTime.Now:HH:mm:ss}>>>>>写入PLC地址M24数据值1");
} }
else else
{ {
var result = Program.omronCipNet.Write(M24.Address, ushort.Parse("2")); var result = Program.siemensS7Net.Write(M24.Address, ushort.Parse("2"));
if (!result.IsSuccess) if (!result.IsSuccess)
{ {
Program.omronCipNet.Write(M24.Address, ushort.Parse("2")); Program.siemensS7Net.Write(M24.Address, ushort.Parse("2"));
} }
savedb = true; savedb = true;
LogHandler($"{DateTime.Now:HH:mm:ss}>>>>>写入PLC地址M24数据值2"); LogHandler($"{DateTime.Now:HH:mm:ss}>>>>>写入PLC地址M24数据值2");
@ -1579,13 +1579,13 @@ namespace ZJ_BYD
{ {
if (isOk) if (isOk)
{ {
Program.omronCipNet.Write(M22.Address, ushort.Parse("1")); Program.siemensS7Net.Write(M22.Address, ushort.Parse("1"));
savedb = true; savedb = true;
LogHandler($"{DateTime.Now:HH:mm:ss}>>>>>写入PLC地址M22数据值1"); LogHandler($"{DateTime.Now:HH:mm:ss}>>>>>写入PLC地址M22数据值1");
} }
else else
{ {
Program.omronCipNet.Write(M22.Address, ushort.Parse("2")); Program.siemensS7Net.Write(M22.Address, ushort.Parse("2"));
savedb = true; savedb = true;
LogHandler($"{DateTime.Now:HH:mm:ss}>>>>>写入PLC地址M22数据值2"); LogHandler($"{DateTime.Now:HH:mm:ss}>>>>>写入PLC地址M22数据值2");
} }

@ -210,30 +210,33 @@ namespace ZJ_BYD
//调用MES接口 //调用MES接口
try try
{ {
var mesCheck = RequestMes.CheckUser(site_1, txtUserName.Text.Trim(), txtPwd.Text); #region Delete By wenjy 2024-03-05 登录时取消调用MES接口
if (!mesCheck.ok) //var mesCheck = RequestMes.CheckUser(site_1, txtUserName.Text.Trim(), txtPwd.Text);
{ //if (!mesCheck.ok)
LogHelper.WriteLog(mesCheck.msg); //{
XtraMessageBox.Show(mesCheck.msg); // LogHelper.WriteLog(mesCheck.msg);
return; // XtraMessageBox.Show(mesCheck.msg);
} // return;
if (Program.omronCipNet != null) //}
#endregion
if (Program.siemensS7Net != null)
{ {
foreach (var item in plcPoints) //foreach (var item in plcPoints)
{ //{
var result = Program.omronCipNet.Write(item.Address, ushort.Parse("1")); // var result = Program.siemensS7Net.Write(item.Address, ushort.Parse("1"));
if (!result.IsSuccess) // if (!result.IsSuccess)
{ // {
result = Program.omronCipNet.Write(item.Address, ushort.Parse("1")); // result = Program.siemensS7Net.Write(item.Address, ushort.Parse("1"));
if (!result.IsSuccess) // if (!result.IsSuccess)
{ // {
XtraMessageBox.Show($"在线模式登录时,[{item.StationCode}]工位用户验证结果写入失败,请重新登录!", "系统提示"); // XtraMessageBox.Show($"在线模式登录时,[{item.StationCode}]工位用户验证结果写入失败,请重新登录!", "系统提示");
FaceDeviceHelper.Instance.faceLoginUserInfo.IsLogin = false; // FaceDeviceHelper.Instance.faceLoginUserInfo.IsLogin = false;
Environment.Exit(0); // Environment.Exit(0);
} // }
} // }
Thread.Sleep(100); // Thread.Sleep(100);
} //}
FaceDeviceHelper.Instance.faceLoginUserInfo.IsLogin = true; FaceDeviceHelper.Instance.faceLoginUserInfo.IsLogin = true;
} }
else else
@ -255,14 +258,14 @@ namespace ZJ_BYD
else else
{ {
if (Program.omronCipNet != null) if (Program.siemensS7Net != null)
{ {
foreach (var item in plcPoints) foreach (var item in plcPoints)
{ {
var result = Program.omronCipNet.Write(item.Address, ushort.Parse("2")); var result = Program.siemensS7Net.Write(item.Address, ushort.Parse("2"));
if (!result.IsSuccess) if (!result.IsSuccess)
{ {
result = Program.omronCipNet.Write(item.Address, ushort.Parse("2")); result = Program.siemensS7Net.Write(item.Address, ushort.Parse("2"));
if (!result.IsSuccess) if (!result.IsSuccess)
{ {
XtraMessageBox.Show($"离线模式登录时,[{item.StationCode}]工位用户验证结果写入失败,请重新登录!", "系统提示"); XtraMessageBox.Show($"离线模式登录时,[{item.StationCode}]工位用户验证结果写入失败,请重新登录!", "系统提示");

@ -242,9 +242,9 @@ namespace ZJ_BYD
// overWrite = true; // overWrite = true;
// continue; // continue;
//} //}
//if (Program.omronCipNet == null) //if (Program.siemensS7Net == null)
//{ //{
// LogHelper.WriteLog($"心跳监测时Program.omronCipNet为空进行重连"); // LogHelper.WriteLog($"心跳监测时Program.siemensS7Net为空进行重连");
// SetPlcStatusLbl(lblplcstatus, "PLC通讯状态异常", Color.Red); // SetPlcStatusLbl(lblplcstatus, "PLC通讯状态异常", Color.Red);
// overWrite = true; // overWrite = true;
// ConnectPLC(); // ConnectPLC();
@ -256,7 +256,7 @@ namespace ZJ_BYD
overWrite = true; overWrite = true;
continue; continue;
} }
if (Program.omronCipNet != null) if (Program.siemensS7Net != null)
{ {
for (int i = 0; i < heartPoints.Count; i++) for (int i = 0; i < heartPoints.Count; i++)
{ {
@ -281,10 +281,10 @@ namespace ZJ_BYD
var val = Program.SysMode ? "1" : "2"; var val = Program.SysMode ? "1" : "2";
foreach (var loginPlcItem in loginPlcPoints) foreach (var loginPlcItem in loginPlcPoints)
{ {
var loginResult = Program.omronCipNet.Write(loginPlcItem.Address, ushort.Parse(val)); var loginResult = Program.siemensS7Net.Write(loginPlcItem.Address, ushort.Parse(val));
if (!loginResult.IsSuccess) if (!loginResult.IsSuccess)
{ {
result = Program.omronCipNet.Write(loginPlcItem.Address, ushort.Parse(val)); result = Program.siemensS7Net.Write(loginPlcItem.Address, ushort.Parse(val));
if (!loginResult.IsSuccess) if (!loginResult.IsSuccess)
{ {
XtraMessageBox.Show($"离线模式登录时,[{loginPlcItem.StationCode}]工位用户验证结果写入失败,请重新登录!", "系统提示"); XtraMessageBox.Show($"离线模式登录时,[{loginPlcItem.StationCode}]工位用户验证结果写入失败,请重新登录!", "系统提示");
@ -316,7 +316,7 @@ namespace ZJ_BYD
OperateResult operateResult = null; OperateResult operateResult = null;
Task<OperateResult> task = Task.Run(() => Task<OperateResult> task = Task.Run(() =>
{ {
return Program.omronCipNet.Write(address, ushort.Parse("1")); return Program.siemensS7Net.Write(address, ushort.Parse("1"));
}); });
task.Wait(); task.Wait();
operateResult = task.Result; operateResult = task.Result;
@ -330,7 +330,8 @@ namespace ZJ_BYD
try try
{ {
var connectPLC = new ConnectPLC(); var connectPLC = new ConnectPLC();
Program.omronCipNet = connectPLC.GetOmronCipNet(); //Program.siemensS7Net = connectPLC.GetOmronCipNet();
Program.siemensS7Net = connectPLC.GetSiemensS7Net();
} }
catch (Exception) catch (Exception)
{ {
@ -776,24 +777,24 @@ namespace ZJ_BYD
var result = MessageBox.Show("确定要退出系统吗?", "提示", MessageBoxButtons.OKCancel); var result = MessageBox.Show("确定要退出系统吗?", "提示", MessageBoxButtons.OKCancel);
if (result == DialogResult.OK) if (result == DialogResult.OK)
{ {
if (Program.omronCipNet != null) //if (Program.siemensS7Net != null)
{ //{
var point = Program.PointKeyValues.FirstOrDefault(m => m.Key == "M1"); // var point = Program.PointKeyValues.FirstOrDefault(m => m.Key == "M1");
if (point != null) // if (point != null)
{ // {
var plcResult = Program.omronCipNet.Write(point.Address, ushort.Parse("0")); // var plcResult = Program.siemensS7Net.Write(point.Address, ushort.Parse("0"));
if (!plcResult.IsSuccess) // if (!plcResult.IsSuccess)
{ // {
XtraMessageBox.Show(string.Format("退出登录时,[{0}]工位用户验证结果写入失败!", point.StationCode), "系统提示"); // XtraMessageBox.Show(string.Format("退出登录时,[{0}]工位用户验证结果写入失败!", point.StationCode), "系统提示");
return; // return;
} // }
} // }
else // else
{ // {
XtraMessageBox.Show(string.Format("退出登录时,[{0}]工位M1点位未配置用户验证结果写入失败", point.StationCode), "系统提示"); // XtraMessageBox.Show(string.Format("退出登录时,[{0}]工位M1点位未配置用户验证结果写入失败", point.StationCode), "系统提示");
return; // return;
} // }
} //}
//设置用户登录状态 //设置用户登录状态
FaceDeviceHelper.Instance.faceLoginUserInfo.IsLogin = false; FaceDeviceHelper.Instance.faceLoginUserInfo.IsLogin = false;
FaceDeviceHelper.Instance.faceLoginUserInfo.IsSuccess = false; FaceDeviceHelper.Instance.faceLoginUserInfo.IsSuccess = false;
@ -957,7 +958,7 @@ namespace ZJ_BYD
} }
var M4 = Program.PointKeyValues.FirstOrDefault(m => m.StationCode == station && m.Key == "M4"); var M4 = Program.PointKeyValues.FirstOrDefault(m => m.StationCode == station && m.Key == "M4");
var M6 = Program.PointKeyValues.FirstOrDefault(m => m.StationCode == station && m.Key == "M6"); var M6 = Program.PointKeyValues.FirstOrDefault(m => m.StationCode == station && m.Key == "M6");
var writeResult = Program.omronCipNet.Write(M4.Address, ushort.Parse(machineSortIndex)); var writeResult = Program.siemensS7Net.Write(M4.Address, ushort.Parse(machineSortIndex));
if (!writeResult.IsSuccess) if (!writeResult.IsSuccess)
{ {
LogHelper.WriteLog($"{Program.ActiveStatinCode}切换机型失败"); LogHelper.WriteLog($"{Program.ActiveStatinCode}切换机型失败");
@ -967,7 +968,7 @@ namespace ZJ_BYD
isLoad = true; isLoad = true;
return; return;
} }
writeResult = Program.omronCipNet.Write(M6.Address, true); writeResult = Program.siemensS7Net.Write(M6.Address, true);
if (!writeResult.IsSuccess) if (!writeResult.IsSuccess)
{ {
LogHelper.WriteLog($"{Program.ActiveStatinCode}切换机型失败"); LogHelper.WriteLog($"{Program.ActiveStatinCode}切换机型失败");
@ -978,7 +979,7 @@ namespace ZJ_BYD
return; return;
} }
Thread.Sleep(500); Thread.Sleep(500);
writeResult = Program.omronCipNet.Write(M6.Address, false); writeResult = Program.siemensS7Net.Write(M6.Address, false);
if (!writeResult.IsSuccess) if (!writeResult.IsSuccess)
{ {
LogHelper.WriteLog($"{Program.ActiveStatinCode}切换机型失败"); LogHelper.WriteLog($"{Program.ActiveStatinCode}切换机型失败");

@ -1,5 +1,6 @@
using DevExpress.XtraEditors; using DevExpress.XtraEditors;
using HslCommunication.Profinet.Omron; using HslCommunication.Profinet.Omron;
using HslCommunication.Profinet.Siemens;
using MQTTnet.Client; using MQTTnet.Client;
using SqlSugar; using SqlSugar;
using System; using System;
@ -111,7 +112,8 @@ namespace ZJ_BYD
#region 获取连接PLC对象 #region 获取连接PLC对象
var connectPLC = new ConnectPLC(); var connectPLC = new ConnectPLC();
Program.omronCipNet = connectPLC.GetOmronCipNet(); //Program.siemensS7Net = connectPLC.GetOmronCipNet();
Program.siemensS7Net = connectPLC.GetSiemensS7Net();
#endregion #endregion
#region 定时任务 #region 定时任务
@ -277,6 +279,8 @@ namespace ZJ_BYD
/// </summary> /// </summary>
public static OmronCipNet omronCipNet = null; public static OmronCipNet omronCipNet = null;
public static SiemensS7Net siemensS7Net = null;
/// <summary> /// <summary>
/// 测试文件名称 /// 测试文件名称
/// </summary> /// </summary>

@ -1,4 +1,6 @@
using HslCommunication.Profinet.Omron; using HslCommunication;
using HslCommunication.Profinet.Omron;
using HslCommunication.Profinet.Siemens;
namespace ZJ_BYD.Untils namespace ZJ_BYD.Untils
{ {
@ -6,6 +8,9 @@ namespace ZJ_BYD.Untils
{ {
private OmronCipNet omronCipNet = null; private OmronCipNet omronCipNet = null;
private SiemensS7Net siemensS7Net = null;
public ConnectPLC(string plcIp = "", int plcPort = 0) public ConnectPLC(string plcIp = "", int plcPort = 0)
{ {
if (string.IsNullOrWhiteSpace(plcIp)) if (string.IsNullOrWhiteSpace(plcIp))
@ -16,10 +21,14 @@ namespace ZJ_BYD.Untils
{ {
plcPort = Program.PlcPort; plcPort = Program.PlcPort;
} }
omronCipNet = new OmronCipNet(plcIp, plcPort) /*omronCipNet = new OmronCipNet(plcIp, plcPort)
{ {
ConnectTimeOut = 3000 ConnectTimeOut = 3000
}; };*/
siemensS7Net = new SiemensS7Net(SiemensPLCS.S1500);
siemensS7Net.IpAddress = plcIp;
siemensS7Net.Port = plcPort;
} }
public OmronCipNet GetOmronCipNet() public OmronCipNet GetOmronCipNet()
@ -36,5 +45,20 @@ namespace ZJ_BYD.Untils
} }
} }
public SiemensS7Net GetSiemensS7Net()
{
OperateResult connect = siemensS7Net.ConnectServer();
if (connect.IsSuccess)
{
return siemensS7Net;
}
else
{
LogHelper.WriteLog("西门子PLC连接失败");
return null;
}
}
} }
} }

Loading…
Cancel
Save