Files
FT479/WPFWCSDemo/ViewModels/ConvsViewModel.cs
2026-06-29 14:46:32 +08:00

76 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using HslCommunication;
using HslCommunication.Profinet.Siemens;
using Serilog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;
using WPFWCSDemo.Models.Devices.CircleRGV;
using WPFWCSDemo.Models.Devices.Conv;
using WPFWCSDemo.Models.Devices.Conv.ConvGet;
using WPFWCSDemo.Models.Devices.Conv.ConvPut;
namespace WPFWCSDemo.ViewModels
{
public class ConvsViewModel
{
public static SiemensS7Net? convConnection;
public static string ip;
public static void InitializeConv()
{
ip = "192.168.10.5";
convConnection = new SiemensS7Net(SiemensPLCS.S1500, ip);
//设置连接超时时间
convConnection.ConnectTimeOut = 2000;
OperateResult result = convConnection.ConnectServer();
if (result.IsSuccess)
{
Log.Warning($"输送机初始化连接成功!");
return;
}
else
{
Log.Warning($"输送机初始化连接失败,{result.Message},错误代码:ConvData0001");
}
}
/// <summary>
/// 输送机plc连接
/// </summary>
/// <returns>1--正常 -1--失败 0-未知异常</returns>
public static int PlcConnect()
{
if (convConnection is null)
{
convConnection = new SiemensS7Net(SiemensPLCS.S1500, ip);
}
try
{
convConnection.ConnectServer();
//Log.Warning($"输送机连接成功");
return 1;
}
catch (Exception e)
{
Log.Warning($"输送机连接失败,{e.Message},错误代码:ConvData0002");
return -1;
}
}
}
}