using System;
|
|
using Newtonsoft.Json;
|
using Newtonsoft.Json.Linq;
|
|
namespace HH.WCS.Mobox3.DSZSH.device {
|
/// <summary>
|
/// 输送线PLC设备
|
/// </summary>
|
public class ProductionLineDevice {
|
|
public string Ip { get; set; }
|
public int Port { get; set; }
|
|
public ProductionLineDevice(string ip, int port) {
|
Ip = ip;
|
Port = port;
|
}
|
|
public ProductionLineDevice(string id, string ip, int port) {
|
Ip = ip;
|
Port = port;
|
Id = id;
|
}
|
|
public ProductionLineDevice(Config.ProductionLine line) {
|
Ip = line.PlcIp;
|
Port = line.PlcPort;
|
Id = line.Id;
|
}
|
|
public string Id { get; set; }
|
|
/// <summary>
|
/// 系统状态:0本地 1联动(AGV模式) 2故障
|
/// </summary>
|
public int SystemState { get; set; }
|
|
/// <summary>
|
/// 满垛下线:1输送线末端有成品料,需要AGV搬运 0默认值
|
/// </summary>
|
public int FullOffline { get; set; }
|
|
/// <summary>
|
/// 呼叫托盘垛:1需要空托,呼叫AGV配送 0默认值
|
/// </summary>
|
public int CallPallet { get; set; }
|
|
/// <summary>
|
/// 允许 AGV 放托盘垛:1允许放垛 0默认值
|
/// </summary>
|
public int AllowAgvPlacePallet { get; set; }
|
|
/// <summary>
|
/// AGV 正在取货:下线AGV写入1,取货完成后恢复0
|
/// </summary>
|
public int AgvPicking { get; set; }
|
|
/// <summary>
|
/// AGV 正在取货:下线AGV写入1,取货完成后恢复0
|
/// </summary>
|
/// <param name="value"></param>
|
/// <returns></returns>
|
public bool SetAgvPicking(int value) {
|
if (!ModbusHelper.WriteSingleRegister(10, value, Ip, Port)) {
|
return false;
|
}
|
|
AgvPicking = value;
|
return true;
|
}
|
|
/// <summary>
|
/// AGV 正在放托盘垛:上线AGV写入1,放托完成后恢复0
|
/// </summary>
|
public int AgvPlacingPallet { get; set; }
|
|
/// <summary>
|
/// AGV 正在放托盘垛:上线AGV写入1,放托完成后恢复0
|
/// </summary>
|
public bool SetAgvPlacingPallet(int value) {
|
if (!ModbusHelper.WriteSingleRegister(11, value, Ip, Port)) {
|
return false;
|
}
|
|
AgvPlacingPallet = value;
|
return true;
|
}
|
|
public bool LoadDeviceStateOk() {
|
var readArray = ModbusHelper.ReadHoldingRegisters(0, 20, Ip, Port);
|
if (readArray == null || readArray.Length < 12) {
|
return false;
|
}
|
|
// 只读地址数据
|
SystemState = readArray[0];
|
FullOffline = readArray[1];
|
CallPallet = readArray[2];
|
AllowAgvPlacePallet = readArray[3];
|
// 可写地址数据
|
AgvPicking = readArray[10];
|
AgvPlacingPallet = readArray[11];
|
|
var log = JsonConvert.SerializeObject(readArray);
|
LogHelper.Info(log);
|
return true;
|
}
|
}
|
}
|