public static void Post_XAGL_WM2000KZG_StartWell(ModbusRtuOverTcp client, RedisClient redisClient, string messageString) { var par = messageString.FromJson <ControlRequest>(); try { var modbusAddress = par.ModbusAddress; if (!par.UseMockData) { var startAddress = (ushort)4131; var address = $"s={par.ModbusAddress};{startAddress}"; client.WriteOneRegister(address, (ushort)(1)); } if (!par.UserName.IsNullOrEmpty()) { ServerEventHelper.SendSseMessage(par.UserName, par.SessionId, 0, "ok"); } } catch (Exception ex) { Logger.Error(ex.Message); Logger.Error(ex.StackTrace); Logger.Error(ex.Source); if (par.UserName.IsNullOrEmpty()) { ServerEventHelper.SendSseMessage(par.UserName, par.SessionId, -1, ex.Message); } } }
public static void Post_XAAS_WII_StopWell(ModbusRtuOverTcp client, RedisClient redisClient, string messageString) { var par = messageString.FromJson <ControlRequest>(); try { var modbusAddress = par.ModbusAddress; ClientInfo.CurrentModbusPoolAddress = modbusAddress; if (!par.UseMockData) { //写入82值到40491(Holding register)寄存器,设置油井的状态为停止。 var startAddress = (ushort)40491; var address = $"s={par.ModbusAddress};{startAddress}"; client.WriteOneRegister(address, (ushort)(82)); //用于通过ServerEvent给调用着返回消息 if (!par.UserName.IsNullOrEmpty()) { ServerEventHelper.SendSseMessage(par.UserName, par.SessionId, 0, "ok"); } } else { } } catch (Exception ex) { Logger.Error(ex.Message); Logger.Error(ex.StackTrace); Logger.Error(ex.Source); if (!par.UserName.IsNullOrEmpty()) { ServerEventHelper.SendSseMessage(par.UserName, par.SessionId, -1, ex.Message); } } }
public static void Post_XAGL_WM3000KZG_StopWell(ModbusRtuOverTcp client, RedisClient redisClient, string messageString) { var par = messageString.FromJson <ControlRequest>(); /* * 65 03 10 06 00 01 68 ef * 65 03 1a 32 00 01 2a f9 * 65 03 10 0a 00 01 a8 ec * 65 06 10 19 00 06 d4 eb */ try { var modbusAddress = par.ModbusAddress; ClientInfo.CurrentModbusPoolAddress = modbusAddress; if (!par.UseMockData) { //var read = await client.ReadAsync($"s={par.ModbusAddress};x=3;4102", 1); //read = await client.ReadAsync($"s={par.ModbusAddress};x=3;6706", 1); //(1)读4106(Holding register)寄存器为1表示正转运行,3表示停机状态。 //read = await client.ReadAsync($"s={par.ModbusAddress};x=3;4106", 1); //写入0值到4121(Holding register)寄存器,设置油井的状态为开启。 //var result2 = await client.WriteAsync($"s={ par.ModbusAddress};x=6;4121", (ushort)(6)); var startaddress = (ushort)4121; var address = $"s={par.ModbusAddress};{startaddress}"; client.WriteOneRegister(address, (ushort)(6)); //(3)读取4121(Holding register)寄存器,判断状态是否写入。 //var result3 = await client.ReadHoldingRegisters(modbusAddress, 4121, 1); //(4)读取1283(Input status)寄存器,置位为1表示喇叭正在报警。 //var result4 = await client.ReadHoldingRegisters(modbusAddress, 4102, 1); //1 //(5)读取1537(Holding register)寄存器,读取告警时间长度。 //var result5 = await client.ReadHoldingRegisters(modbusAddress, 6706, 1); //100 //用于通过ServerEvent给调用着返回消息 if (!par.UserName.IsNullOrEmpty()) { ServerEventHelper.SendSseMessage(par.UserName, par.SessionId, 0, "ok"); } } else { } } catch (Exception ex) { Logger.Error(ex.Message); Logger.Error(ex.StackTrace); Logger.Error(ex.Source); if (!par.UserName.IsNullOrEmpty()) { ServerEventHelper.SendSseMessage(par.UserName, par.SessionId, -1, ex.Message); } } }
public static async Task Post_XAGL_WM3000KZG_StrokeFrequency(ModbusRtuOverTcp client, RedisClient redisClient, string messageString) { var par = messageString.FromJson <ControlRequest>(); try { var modbusAddress = par.ModbusAddress; ClientInfo.CurrentModbusPoolAddress = modbusAddress; //await client.WriteAsync($"s={ par.ModbusAddress};x=6;7629", (ushort)(1)); var startAddress = (ushort)7629; var address = $"s={par.ModbusAddress};{startAddress}"; /* * 65 06 1d cd 00 01 d7 bd * 65 06 1d ce 00 19 27 b7 * 65 05 08 80 ff 00 87 96 */ client.WriteOneRegister(address, (ushort)(1)); var stroke = (int)(float.Parse(par.CommandParameter) * 10); //(1)7630(Holding register)寄存器为47,代表当前设定冲次4.7次。 //await client.WriteAsync($"s={ par.ModbusAddress};x=6;7630", (ushort)(stroke)); startAddress = (ushort)7630; address = $"s={par.ModbusAddress};{startAddress}"; // client.WriteOneRegister(address, (ushort)(stroke)); //(2)写2176(Coil status)置位此寄存器。 await client.WriteAsync($"s={ par.ModbusAddress};x=5;2176", true); //(3)读7627(Holding register)寄存器为47,代表当前设定冲次4.7次。 //var result4 = await client.ReadHoldingRegisters(modbusAddress, 7627, 1); //用于通过ServerEvent给调用着返回消息 if (!par.UserName.IsNullOrEmpty()) { ServerEventHelper.SendSseMessage(par.UserName, par.SessionId, 0, "ok"); } } catch (Exception ex) { Logger.Error(ex.Message); Logger.Error(ex.StackTrace); Logger.Error(ex.Source); if (!par.UserName.IsNullOrEmpty()) { ServerEventHelper.SendSseMessage(par.UserName, par.SessionId, -1, ex.Message); } } }