98 lines
3.4 KiB
C#
98 lines
3.4 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Serilog;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net.NetworkInformation;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using WPFWCSDemo.Common;
|
|
using WPFWCSDemo.Data;
|
|
using WPFWCSDemo.Models.Devices.CircleRGV;
|
|
using WPFWCSDemo.Models.Devices.CircleRGVStation;
|
|
using WPFWCSDemo.StateCode;
|
|
using WPFWCSDemo.ViewModels;
|
|
|
|
namespace WPFWCSDemo.Schedules.CommonTask
|
|
{
|
|
public class Common
|
|
{
|
|
int deviceCount = RGVStation.RGVCount;
|
|
|
|
/// <summary>
|
|
/// 记录输送口请求值
|
|
/// </summary>
|
|
public static void RecordRequestValue()
|
|
{
|
|
//获取所有输送口请求状态
|
|
using CircleRGVStationState? circleRGVStationState = CircleRGVsViewModel.GetCircleRGVStaionState();
|
|
|
|
//地面站【允许下发】
|
|
if (circleRGVStationState is null) return;
|
|
|
|
int a = circleRGVStationState.Read_GetRequest_1001 == true ? 1 : 0;
|
|
int b = circleRGVStationState.Read_GetRequest_1003 == true ? 1 : 0;
|
|
int c = circleRGVStationState.Read_GetRequest_1005 == true ? 1 : 0;
|
|
int d = circleRGVStationState.Read_GetRequest_1007 == true ? 1 : 0;
|
|
int e = circleRGVStationState.Read_GetRequest_1008 == true ? 1 : 0;
|
|
|
|
int ab = circleRGVStationState.Read_GetRequest_1013 == true ? 1 : 0;
|
|
int bOut = circleRGVStationState.Read_PutRequest_1002 == true ? 1 : 0;
|
|
int cd = circleRGVStationState.Read_PutRequest_1004 == true ? 1 : 0;
|
|
int cOut = circleRGVStationState.Read_PutRequest_1006 == true ? 1 : 0;
|
|
|
|
//1009放货口
|
|
int f = circleRGVStationState.Read_PutRequest_1009 == true ? 1 : 0;
|
|
//1010放货口
|
|
int g = circleRGVStationState.Read_PutRequest_1010 == true ? 1 : 0;
|
|
|
|
using var context = new AppDbContext();
|
|
|
|
context.Database.ExecuteSqlInterpolated(
|
|
$"INSERT INTO CONVREQUEST VALUES({a},{b},{c},{d},{e},{DateTime.Now.ToString(TimeFormat.stringFormat)},{ab},{bOut},{cd},{cOut},{Guid.NewGuid()},{f},{g})");
|
|
|
|
context.Database.ExecuteSqlInterpolated(
|
|
$"DELETE FROM CONVREQUEST WHERE [TIME]<{DateTime.Now.AddHours(-24).ToString(TimeFormat.stringFormat)}");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 检测plc网络
|
|
/// </summary>
|
|
/// <param name="ipAddress">ip地址</param>
|
|
/// <param name="timeout"></param>
|
|
/// <returns></returns>
|
|
public static async Task<bool> GetPingForRGVStation(string ipAddress, int timeout = 5000)
|
|
{
|
|
try
|
|
{
|
|
using (Ping ping = new Ping())
|
|
{
|
|
PingReply reply = await ping.SendPingAsync(ipAddress, timeout);
|
|
|
|
return reply.Status == IPStatus.Success;
|
|
}
|
|
}
|
|
catch (PingException e)
|
|
{
|
|
Log.Error($"【地面站网络异常】{e.Message}");
|
|
Log.Error($"【地面站网络异常】{e.InnerException}");
|
|
return false;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error($"【地面站网络异常】{e.Message}");
|
|
Log.Error($"【地面站网络异常】{e.InnerException}");
|
|
return false;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|