using HybirdFrameworkDriver.ModbusTcpMaster; using HybirdFrameworkDriver.Session; using Service.Plc.Msg; namespace Service.Init.Entity { public class PlcInfo { #region 字段 /// /// 设备编号 /// private string _devNo = "001"; /// /// 设备名称 /// private string _devname = "换电PLC"; /// /// 服务端连接IP /// private string _ipaddr = "172.0.20.48"; /// /// 服务端连接端口 /// private int _port = 502; /// /// 站号 /// private byte _site = 0x01; /// /// 连接超时时间。单位秒 /// private int _connecttimeout = 10; /// /// 保持活跃时间。单位秒 /// private int _keepalive = 30; /// /// 连接状态 /// private ConnectState _connect_state = ConnectState.Disconnect; #endregion 字段 public string ChannelId; public int EqmSn; public HostToPlc hostToPlc = new HostToPlc(); public PlcToHost plcToHost = new PlcToHost(); public PlcFault plcFault = new PlcFault(); #region int DataTimeSeconds = 2; DateTime DataValidityTime = DateTime.Now; /// /// plc是否连接 /// public bool Connected { get; set; } /// /// plc是否处于远程模式 /// public bool RemoteNot { get { if ((DateTime.Now - DataValidityTime).Seconds <= DataTimeSeconds) { return RemoteNot; } else { return false; } } set { RemoteNot = value; DataValidityTime = DateTime.Now; } } /// /// 读入口雷达是否感应触发 /// public bool EntranceRadar { get { if ((DateTime.Now - DataValidityTime).Seconds <= 2) { return EntranceRadar; } else { return false; } } set { EntranceRadar = value; DataValidityTime = DateTime.Now; } } /// /// 读取通道定位状态(拍照是否OK) /// public bool ChannelLocationState { get { if ((DateTime.Now - DataValidityTime).Seconds <= 2) { return ChannelLocationState; } else { return false; } } set { ChannelLocationState = value; DataValidityTime = DateTime.Now; } } /// /// 读取plc任务状态电池拆卸中 /// public bool BatteryDisassembly { get { if ((DateTime.Now - DataValidityTime).Seconds <= 2) { return BatteryDisassembly; } else { return false; } } set { BatteryDisassembly = value; DataValidityTime = DateTime.Now; } } /// /// 读取plc任务状态电池入库搬运中 /// public bool StorageBatteries { get { if ((DateTime.Now - DataValidityTime).Seconds <= 2) { return StorageBatteries; } else { return false; } } set { StorageBatteries = value; DataValidityTime = DateTime.Now; } } /// /// 读取plc任务状态电池出库搬运中 /// public bool BatteryDelivery { get { if ((DateTime.Now - DataValidityTime).Seconds <= 2) { return BatteryDelivery; } else { return false; } } set { BatteryDelivery = value; DataValidityTime = DateTime.Now; } } /// /// 读取plc任务状态电池安装中 /// public bool BatteryInstallation { get { if ((DateTime.Now - DataValidityTime).Seconds <= 2) { return BatteryInstallation; } else { return false; } } set { BatteryInstallation = value; DataValidityTime = DateTime.Now; } } /// /// 读取plc任务状态电池安装完成 /// public bool BatteryInstallationComplete { get { if ((DateTime.Now - DataValidityTime).Seconds <= 2) { return BatteryInstallationComplete; } else { return false; } } set { BatteryInstallationComplete = value; DataValidityTime = DateTime.Now; } } /// /// 设置出口灯:绿灯(通知车辆可以驶离) /// public bool SetExitLightGreen { get { if ((DateTime.Now - DataValidityTime).Seconds <= 2) { return SetExitLightGreen; } else { return false; } } set { SetExitLightGreen = value; DataValidityTime = DateTime.Now; } } /// /// 读出口雷达是否感应触发 /// public bool ExitRadarSensingTrigger { get { if ((DateTime.Now - DataValidityTime).Seconds <= 2) { return ExitRadarSensingTrigger; } else { return false; } } set { ExitRadarSensingTrigger = value; DataValidityTime = DateTime.Now; } } /// /// 写入口灯绿 /// /// public bool SendLightGreen() { bool bResult = false; if (Connected) { hostToPlc.LightIn.Value = 1000; bResult = WriteUint16(hostToPlc.LightIn); } return bResult; } /// /// 下发选包数据给plc(入仓位 /// /// 1:缓存位舱位号 2-20 电池存储舱位 /// public bool SendSelectRuleIn(ushort loc) { bool bResult = false; if (Connected) { hostToPlc.EntrySelection.Value = loc; bResult = WriteUint16(hostToPlc.EntrySelection); } return bResult; } /// /// 下发选包数据给plc(出仓位 /// /// 1:缓存位舱位号 2-20 电池存储舱位 /// public bool SendSelectRuleOut(ushort loc) { bool bResult = false; if (Connected) { hostToPlc.ExitSelection.Value = loc; bResult = WriteUint16(hostToPlc.ExitSelection); } return bResult; } /// /// 写入口灯:红灯 /// /// public bool SendLightRed() { bool bResult = false; if (Connected) { hostToPlc.LightIn.Value = 1020; bResult = WriteUint16(hostToPlc.LightIn); } return bResult; } /// /// 下发plc开启换电任务 /// /// public bool SendTaskType() { bool bResult = false; if (Connected) { hostToPlc.TaskType.Value = 1; bResult = WriteUint16(hostToPlc.TaskType); } return bResult; } /// /// 设置出口灯:绿灯 /// /// public bool SendLightOutGreen() { bool bResult = false; if (Connected) { hostToPlc.LightOut.Value = 1000; bResult = WriteUint16(hostToPlc.LightOut); } return bResult; } /// /// 设置出口灯:红灯 /// /// public bool SendLightOutRed() { bool bResult = false; if (Connected) { hostToPlc.LightOut.Value = 1020; bResult = WriteUint16(hostToPlc.LightOut); } return bResult; } #endregion #region 有料检测 /// /// 有料检测 1-20仓 /// public byte MaterialDetec01 { get; set; } public byte MaterialDetec02 { get; set; } public byte MaterialDetec03 { get; set; } public byte MaterialDetec04 { get; set; } public byte MaterialDetec05 { get; set; } public byte MaterialDetec06 { get; set; } public byte MaterialDetec07 { get; set; } public byte MaterialDetec08 { get; set; } public byte MaterialDetec09 { get; set; } public byte MaterialDetec10 { get; set; } public byte MaterialDetec11 { get; set; } public byte MaterialDetec12 { get; set; } public byte MaterialDetec13 { get; set; } public byte MaterialDetec14 { get; set; } public byte MaterialDetec15 { get; set; } public byte MaterialDetec16 { get; set; } public byte MaterialDetec17 { get; set; } public byte MaterialDetec18 { get; set; } public byte MaterialDetec19 { get; set; } public byte MaterialDetec20 { get; set; } #endregion 有料检测 /// /// 舱位状态 在位状态:0-不在位;1-在位;2-无效 /// /// public List ReturnMaterialDetec() { List ret = new List { MaterialDetec01,MaterialDetec02 ,MaterialDetec03 ,MaterialDetec04 ,MaterialDetec05 , MaterialDetec06 ,MaterialDetec07 ,MaterialDetec08 ,MaterialDetec09 ,MaterialDetec10 , MaterialDetec11 ,MaterialDetec12 ,MaterialDetec13 ,MaterialDetec14 ,MaterialDetec15 , MaterialDetec16 ,MaterialDetec17 ,MaterialDetec18 ,MaterialDetec19 ,MaterialDetec20 , }; return ret; } public PlcInfo(string channelId, int eqmSn) { ChannelId = channelId; EqmSn = eqmSn; } public bool WriteUint16(ModbusProperty value) { bool bResult = false; ModbusSession session = SessionMgr.GetModbusSession(ChannelId); bResult = session.Write(value); return bResult; } public bool Writeint16(ModbusProperty value) { bool bResult = false; ModbusSession session = SessionMgr.GetModbusSession(ChannelId); bResult = session.Write(value); return bResult; } } }