|
|
using iWareModel;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace iWareCommon.Utils
|
{
|
/// <summary>
|
/// 业务帮助类
|
/// </summary>
|
public class BusinessHelper
|
{
|
/// <summary>
|
/// RGV等特殊点位的转换
|
/// </summary>
|
/// <param name="name"></param>
|
/// <returns></returns>
|
public static int ConvertStationCodeForRGV(string name)
|
{
|
if (name.ToUpper() == "RGV1040")
|
{
|
return 1040;
|
}
|
else if (name == "提升机1030")
|
{
|
return 1030;
|
}
|
else if (name == "拆盘机1020")
|
{
|
return 1020;
|
}
|
return 0;
|
}
|
|
/// <summary>
|
/// 获取堆垛机列表
|
/// </summary>
|
/// <param name="placeNo"></param>
|
/// <returns></returns>
|
public static List<EDevice> GetSrmDeviceList()
|
{
|
return new List<EDevice>() {
|
EDevice.一号堆垛机,
|
EDevice.二号堆垛机,
|
EDevice.三号堆垛机,
|
EDevice.四号堆垛机
|
};
|
}
|
|
/// <summary>
|
/// 根据库位寻找设备
|
/// </summary>
|
/// <param name="placeNo"></param>
|
/// <returns></returns>
|
public static EDevice GetDeviceByPlaceNo(EDeviceType deviceType, string placeNo)
|
{
|
switch (deviceType)
|
{
|
case EDeviceType.堆垛机:
|
return GetSrmDeviceByPlaceNo(placeNo);
|
case EDeviceType.RGV:
|
return EDevice.RGV;
|
default:
|
throw new Exception("未知设备");
|
}
|
}
|
|
/// <summary>
|
/// 根据设备获取设备类型
|
/// </summary>
|
/// <param name="device"></param>
|
/// <returns></returns>
|
public static EDeviceType GetEDeviceTypeByEDevice(EDevice device)
|
{
|
switch (device)
|
{
|
case EDevice.AGV:
|
return EDeviceType.AGV;
|
case EDevice.一号堆垛机:
|
case EDevice.二号堆垛机:
|
case EDevice.三号堆垛机:
|
case EDevice.四号堆垛机:
|
return EDeviceType.堆垛机;
|
default:
|
return EDeviceType.RGV;
|
}
|
}
|
|
/// <summary>
|
/// 根据库位寻找堆垛机的枚举
|
/// </summary>
|
/// <param name="placeNo"></param>
|
/// <returns></returns>
|
public static EDevice GetSrmDeviceByPlaceNo(string placeNo)
|
{
|
var arr = placeNo.Split('-');
|
int i = Convert.ToInt16(arr[0]);
|
if (i == 1)
|
return EDevice.一号堆垛机;
|
if (i == 2)
|
return EDevice.二号堆垛机;
|
if (i == 3)
|
return EDevice.三号堆垛机;
|
if (i == 4)
|
return EDevice.四号堆垛机;
|
throw new Exception("库位不正确,根据库位" + placeNo + "找不到堆垛机");
|
}
|
|
|
/// <summary>
|
/// 随机生成1-10000的PLC任务号
|
/// </summary>
|
/// <returns></returns>
|
public static string CreatePlcTaskId()
|
{
|
int iSeed = 10000;
|
return new Random(Guid.NewGuid().GetHashCode()).Next(1, iSeed).ToString();
|
}
|
/// <summary>
|
/// 创建输送线任务号,随机生成(1, 3000)的PLC任务号
|
/// </summary>
|
/// <returns></returns>
|
public static string CreatePlcTaskIdForConveyorTask()
|
{
|
int iSeed = 3000;
|
return new Random(Guid.NewGuid().GetHashCode()).Next(1, iSeed).ToString();
|
}
|
/// <summary>
|
/// 创建堆垛机任务号,随机生成 (1, 99999)的PLC任务号
|
/// </summary>
|
/// <returns></returns>
|
public static string CreatePlcTaskIdForSrmTask()
|
{
|
int iSeed = 99999;
|
//从101-9999,为什么要从101开始,因为1-100作为手动任务下发。【EditBy shaocx,2022-05-10】
|
return new Random(Guid.NewGuid().GetHashCode()).Next(101, iSeed).ToString();
|
}
|
}
|
}
|