using iWareModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace iWareCommon.Utils
{
///
/// 业务帮助类
///
public class BusinessHelper
{
///
/// RGV等特殊点位的转换
///
///
///
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;
}
///
/// 获取堆垛机列表
///
///
///
public static List GetSrmDeviceList()
{
return new List() {
EDevice.一号堆垛机,
EDevice.二号堆垛机,
EDevice.三号堆垛机,
EDevice.四号堆垛机
};
}
///
/// 根据库位寻找设备
///
///
///
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("未知设备");
}
}
///
/// 根据设备获取设备类型
///
///
///
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;
}
}
///
/// 根据库位寻找堆垛机的枚举
///
///
///
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 + "找不到堆垛机");
}
///
/// 随机生成1-10000的PLC任务号
///
///
public static string CreatePlcTaskId()
{
int iSeed = 10000;
return new Random(Guid.NewGuid().GetHashCode()).Next(1, iSeed).ToString();
}
///
/// 创建输送线任务号,随机生成(1, 3000)的PLC任务号
///
///
public static string CreatePlcTaskIdForConveyorTask()
{
int iSeed = 3000;
return new Random(Guid.NewGuid().GetHashCode()).Next(1, iSeed).ToString();
}
///
/// 创建堆垛机任务号,随机生成 (1, 99999)的PLC任务号
///
///
public static string CreatePlcTaskIdForSrmTask()
{
int iSeed = 65534;
//从101-9999,为什么要从101开始,因为1-100作为手动任务下发。【EditBy shaocx,2022-05-10】
return new Random(Guid.NewGuid().GetHashCode()).Next(101, iSeed).ToString();
}
}
}