예제 #1
0
        public static void Get_XAGL_WM2000KZG_ControllerStatus_Mock(ModbusRtuOverTcp client, RedisClient redisClient, string messageString)
        {
            var par = messageString.FromJson <ControlRequest>();

            try
            {
                var iotDataOilWellControllerState = new IotDataOilWellControllerState()
                {
                    NetworkNode = ClientInfo.ManyIpAddress,
                    AlarmCode   = 0,
                    AlarmMsg    = "正常"
                };

                iotDataOilWellControllerState.WellId       = par.DeviceId;
                iotDataOilWellControllerState.DeviceTypeId = par.DeviceTypeId;
                iotDataOilWellControllerState.DateTime     = DateTime.Now;
                iotDataOilWellControllerState.Mock         = par.UseMockData;

                redisClient.AddItemToList("YCIOT:IOT_Data_OilWell_ControllerState", iotDataOilWellControllerState.ToJson().IndentJson());
                redisClient.Set($"Group:OilWell:{par.DeviceName}-{par.DeviceId}:ControllerState", iotDataOilWellControllerState);
                redisClient.Set($"Single:OilWell:ControllerState:{par.DeviceName}-{par.DeviceId}", iotDataOilWellControllerState);
            }
            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);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// 读取控制器数据
        /// </summary>
        /// <param name="client"></param>
        /// <param name="redisClient"></param>
        /// <param name="messageString"></param>
        /// <returns></returns>
        public static async Task Get_XAGL_WM3000KZG_ControllerStatus(ModbusRtuOverTcp client, RedisClient redisClient, string messageString)
        {
            var par = messageString.FromJson <ControlRequest>();

            try
            {
                var iotDataOilWellControllerState = new IotDataOilWellControllerState()
                {
                    NetworkNode = ClientInfo.ManyIpAddress,
                    AlarmCode   = 0,
                    AlarmMsg    = "正常"
                };
                var logIotModbusPoll = par.ConvertTo <LogIotModbusPoll>();

                logIotModbusPoll.State  = 0;
                logIotModbusPoll.Result = "ok";

                var modbusAddress = par.ModbusAddress;
                iotDataOilWellControllerState.DateTime     = DateTime.Now;
                iotDataOilWellControllerState.DeviceTypeId = par.DeviceTypeId;
                iotDataOilWellControllerState.Mock         = false;

                var flag = true;

                ClientInfo.CurrentModbusPoolAddress = modbusAddress;

                iotDataOilWellControllerState.DateTime = DateTime.Now;
                iotDataOilWellControllerState.WellId   = par.DeviceId;

                lock (ClientInfo.locker)
                {
                    ClientInfo.RequestTime     = DateTime.Now;
                    ClientInfo.ExpectedType    = 0x03;
                    ClientInfo.ExpectedDataLen = 29 * 2;
                }

                var read = await client.ReadAsync($"s={par.ModbusAddress};x=3;4096", 4124 - 4096 + 1);

                if (read.IsSuccess)
                {
                    // 耗电量  4096  变比 1
                    var value = client.ByteTransform.TransInt16(read.Content, 0);
                    iotDataOilWellControllerState.FrequencyConversionActivePower = value;

                    // 当前冲次  4097  变比 0.1
                    value = client.ByteTransform.TransInt16(read.Content, 2);
                    iotDataOilWellControllerState.Stroke = Math.Round(value * 0.1, 2);

                    // 电流平衡度  4098  变比 0.01
                    value = client.ByteTransform.TransInt16(read.Content, 4);
                    iotDataOilWellControllerState.CurrentBalance = Math.Round(value * 0.01 * 100, 2);

                    // 上行最大电流  4099  变比 0.0
                    value = client.ByteTransform.TransInt16(read.Content, 6);
                    iotDataOilWellControllerState.MaxUpCurrent = Math.Round(value * 0.01, 2);

                    // 下行最大电流  4100  变比 0.01
                    value = client.ByteTransform.TransInt16(read.Content, 8);
                    iotDataOilWellControllerState.MaxDownCurrent = Math.Round(value * 0.01, 2);

                    //变频器报警代码  4101  变比 1
                    value = client.ByteTransform.TransInt16(read.Content, 10);
                    iotDataOilWellControllerState.AlarmCode = value;

                    // 起停状态  4103  变比 1--->4102
                    value = client.ByteTransform.TransInt16(read.Content, 16);
                    iotDataOilWellControllerState.StartAndStopStatus = value; //2020-04-15 由6变为8

                    #region 去掉启停状态抛弃  后期可修改为插入异常标识 yangzx 20201014
                    ////当启停状态非1和3时候,直接抛弃
                    //if (value != 1 && value != 3)
                    //{
                    //    iotDataOilWellControllerState.AlarmCode = -1;
                    //    iotDataOilWellControllerState.AlarmMsg = "数据异常";

                    //    iotDataOilWellControllerState.Mock = par.UseMockData;
                    //    logIotModbusPoll.DateTime = DateTime.Now;
                    //    logIotModbusPoll.State = -1;
                    //    logIotModbusPoll.Result = $"读取变频器启停状态异常,读取异常值为:{value}";

                    //    redisClient.AddItemToList("YCIOT:ERROR:Log_IOT_Modbus_Poll", logIotModbusPoll.ToJson().IndentJson());
                    //    return;
                    //}
                    #endregion

                    // 运行频率  4105  变比 1--->4103
                    value = client.ByteTransform.TransInt16(read.Content, 14);
                    iotDataOilWellControllerState.Frequency = Math.Round(value * 0.01, 2);

                    // 运行状态  4106  变比 1--->4104
                    value = client.ByteTransform.TransInt16(read.Content, 12);
                    iotDataOilWellControllerState.RunState = value;  //2020-04-15 由8变为6

                    //变频累积运行时间4105
                    value = client.ByteTransform.TransInt16(read.Content, 18);
                    iotDataOilWellControllerState.TotalRunTime = value;

                    //变频母线电压4106
                    value = client.ByteTransform.TransInt16(read.Content, 20);
                    iotDataOilWellControllerState.BusBarVoltage = Math.Round(value * 0.1, 2);

                    //工变频切换 4122
                    value = client.ByteTransform.TransInt16(read.Content, 52);
                    iotDataOilWellControllerState.WorkAndChangeFrequencySwitch = value;

                    //就地远程切换4123
                    value = client.ByteTransform.TransInt16(read.Content, 54);
                    iotDataOilWellControllerState.LocalAndFarSwitch = value;
                }
                else
                {
                    flag = false;

                    iotDataOilWellControllerState.AlarmCode = -1;
                    iotDataOilWellControllerState.AlarmMsg  = "数据异常";

                    iotDataOilWellControllerState.Mock = par.UseMockData;
                    logIotModbusPoll.DateTime          = DateTime.Now;
                    logIotModbusPoll.State             = -1;
                    logIotModbusPoll.Result            = $"读取变频器状态数据异常!{read.Message}";

                    $"{logIotModbusPoll.Result}".Info();

                    redisClient.AddItemToList("YCIOT:ERROR:Log_IOT_Modbus_Poll", logIotModbusPoll.ToJson().IndentJson());
                }

                if (flag)
                {
                    lock (ClientInfo.locker)
                    {
                        ClientInfo.RequestTime     = DateTime.Now;
                        ClientInfo.ExpectedType    = 0x03;
                        ClientInfo.ExpectedDataLen = 4;
                    }
                    //抽油机冲程7632--
                    read = await client.ReadAsync($"s={par.ModbusAddress};x=3;7632", 2);

                    if (read.IsSuccess)
                    {
                        var value = client.ByteTransform.TransInt16(read.Content, 0);
                        iotDataOilWellControllerState.MaxDisplacement = Math.Round(value * 0.1, 2);
                    }
                    else
                    {
                        flag = false;

                        iotDataOilWellControllerState.AlarmCode = -1;
                        iotDataOilWellControllerState.AlarmMsg  = "数据异常";
                        iotDataOilWellControllerState.Mock      = par.UseMockData;
                        logIotModbusPoll.DateTime = DateTime.Now;
                        logIotModbusPoll.State    = -1;
                        logIotModbusPoll.Result   = $"读取冲程数据异常![{read.Message}]";
                        redisClient.AddItemToList("YCIOT:ERROR:Log_IOT_Modbus_Poll", logIotModbusPoll.ToJson().IndentJson());
                    }
                }

                iotDataOilWellControllerState.NetworkNode = ClientInfo.ManyIpAddress;

                //Redis中写入设备最后状态

                if (flag == true || par.UseMockData)
                {
                    iotDataOilWellControllerState.Mock = par.UseMockData;

                    redisClient.AddItemToList("YCIOT:IOT_Data_OilWell_ControllerState", iotDataOilWellControllerState.ToJson().IndentJson());
                    redisClient.Set($"Group:OilWell:{par.DeviceName}-{par.DeviceId}:ControllerState", iotDataOilWellControllerState);
                    redisClient.Set($"Single:OilWell:ControllerState:{par.DeviceName}-{par.DeviceId}", iotDataOilWellControllerState);
                }

                //用于通过ServerEvent给调用着返回消息
                if (!par.UserName.IsNullOrEmpty())
                {
                    ServerEventHelper.SendSseMessage(par.UserName, par.SessionId, flag ? 0 : -2, iotDataOilWellControllerState.ToJson().IndentJson());
                }
            }
            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);
                }
            }
        }
예제 #3
0
        public static async Task Get_XAGL_WM1000KZG_ControllerStatus(ModbusRtuOverTcp client, RedisClient redisClient, string messageString)
        {
            var par = messageString.FromJson <ControlRequest>();

            try
            {
                var iotDataOilWellControllerState = new IotDataOilWellControllerState()
                {
                    NetworkNode = ClientInfo.ManyIpAddress,
                    AlarmCode   = 0,
                    AlarmMsg    = "正常"
                };

                var logIotModbusPoll = par.ConvertTo <LogIotModbusPoll>();

                logIotModbusPoll.State  = 0;
                logIotModbusPoll.Result = "ok";

                var modbusAddress = par.ModbusAddress;
                iotDataOilWellControllerState.DeviceTypeId = par.DeviceTypeId;
                iotDataOilWellControllerState.Mock         = false;

                var flag = true;

                ClientInfo.CurrentModbusPoolAddress = modbusAddress;

                iotDataOilWellControllerState.DateTime = DateTime.Now;
                iotDataOilWellControllerState.WellId   = par.DeviceId;

                lock (ClientInfo.locker)
                {
                    ClientInfo.RequestTime     = DateTime.Now;
                    ClientInfo.ExpectedType    = 0x03;
                    ClientInfo.ExpectedDataLen = 6;
                }
                var read = await client.ReadAsync($"s={par.ModbusAddress};x=3;4116", 3);

                if (read.IsSuccess)
                {
                    var value = client.ByteTransform.TransInt16(read.Content, 4);
                    iotDataOilWellControllerState.AlarmCode = value;

                    value = client.ByteTransform.TransInt16(read.Content, 2);
                    iotDataOilWellControllerState.StartAndStopStatus = value;

                    value = client.ByteTransform.TransInt16(read.Content, 0);
                    iotDataOilWellControllerState.LocalAndFarSwitch = value;
                }
                else
                {
                    flag = false;

                    iotDataOilWellControllerState.AlarmCode = -1;
                    iotDataOilWellControllerState.AlarmMsg  = "数据异常";

                    iotDataOilWellControllerState.Mock = par.UseMockData;
                    logIotModbusPoll.DateTime          = DateTime.Now;
                    logIotModbusPoll.State             = -1;
                    logIotModbusPoll.Result            = "读取变频器状态数据异常!";

                    redisClient.AddItemToList("YCIOT:ERROR:Log_IOT_Modbus_Poll", logIotModbusPoll.ToJson().IndentJson());
                }

                iotDataOilWellControllerState.NetworkNode = ClientInfo.ManyIpAddress;

                //Redis中写入设备最后状态

                if (flag == true || par.UseMockData)
                {
                    iotDataOilWellControllerState.Mock = par.UseMockData;
                    redisClient.AddItemToList("YCIOT:IOT_Data_OilWell_ControllerState", iotDataOilWellControllerState.ToJson().IndentJson());
                    redisClient.Set($"Group:OilWell:{par.DeviceName}-{par.DeviceId}:ControllerState", iotDataOilWellControllerState);
                    redisClient.Set($"Single:OilWell:ControllerState:{par.DeviceName}-{par.DeviceId}", iotDataOilWellControllerState);
                }

                //用于通过ServerEvent给调用着返回消息
                if (!par.UserName.IsNullOrEmpty())
                {
                    ServerEventHelper.SendSseMessage(par.UserName, par.SessionId, flag ? 0 : -2, iotDataOilWellControllerState.ToJson().IndentJson());
                }
            }
            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);
                }
            }
        }
예제 #4
0
        /// <summary>
        /// 读取控制器数据
        /// </summary>
        /// <param name="client"></param>
        /// <param name="redisClient"></param>
        /// <param name="messageString"></param>
        /// <returns></returns>
        public static async Task Get_XAGL_WM2000KZG_ControllerStatus(ModbusRtuOverTcp client, RedisClient redisClient, string messageString)
        {
            var par = messageString.FromJson <ControlRequest>();

            try
            {
                var iotDataOilWellControllerState = new IotDataOilWellControllerState()
                {
                    NetworkNode = ClientInfo.ManyIpAddress,
                    AlarmCode   = 0,
                    AlarmMsg    = "正常"
                };
                var logIotModbusPoll = par.ConvertTo <LogIotModbusPoll>();

                logIotModbusPoll.State  = 0;
                logIotModbusPoll.Result = "ok";

                var modbusAddress = par.ModbusAddress;
                iotDataOilWellControllerState.DateTime     = DateTime.Now;
                iotDataOilWellControllerState.DeviceTypeId = par.DeviceTypeId;
                iotDataOilWellControllerState.Mock         = false;

                var flag = true;

                ClientInfo.CurrentModbusPoolAddress = modbusAddress;

                iotDataOilWellControllerState.DateTime = DateTime.Now;
                iotDataOilWellControllerState.WellId   = par.DeviceId;


                #region  变频器基本监视参数

                lock (ClientInfo.locker)
                {
                    ClientInfo.RequestTime     = DateTime.Now;
                    ClientInfo.ExpectedType    = 0x03;
                    ClientInfo.ExpectedDataLen = 9 * 2;
                }

                var read = await client.ReadAsync($"s={par.ModbusAddress};x=3;4096", 4104 - 4096 + 1);

                if (read.IsSuccess)
                {
                    // 耗电量  4096  变比 1
                    var value = client.ByteTransform.TransInt16(read.Content, 0);
                    iotDataOilWellControllerState.FrequencyConversionActivePower = value;

                    //电流平衡度  4097 变比  0.01
                    value = client.ByteTransform.TransInt16(read.Content, 2);
                    iotDataOilWellControllerState.CurrentBalance = Math.Round(value * 0.01, 2);

                    // 上行最大电流  4098  变比 0.01
                    value = client.ByteTransform.TransInt16(read.Content, 4);
                    iotDataOilWellControllerState.MaxUpCurrent = Math.Round(value * 0.01, 2);

                    // 下行最大电流  4099  变比 0.01
                    value = client.ByteTransform.TransInt16(read.Content, 6);
                    iotDataOilWellControllerState.MaxDownCurrent = Math.Round(value * 0.01, 2);

                    //变频器报警代码  4100  变比 1
                    value = client.ByteTransform.TransInt16(read.Content, 8);
                    iotDataOilWellControllerState.AlarmCode = value;

                    // 起停状态  4101  变比 1
                    value = client.ByteTransform.TransInt16(read.Content, 10);
                    iotDataOilWellControllerState.StartAndStopStatus = value;

                    // 运行频率  4102  变比0.01
                    value = client.ByteTransform.TransInt16(read.Content, 12);
                    iotDataOilWellControllerState.Frequency = Math.Round(value * 0.01, 2);

                    // 运行状态  4103  变比 1
                    value = client.ByteTransform.TransInt16(read.Content, 14);
                    iotDataOilWellControllerState.RunState = value;

                    //变频功率因素角度
                    value = client.ByteTransform.TransInt16(read.Content, 16);
                    iotDataOilWellControllerState.PowerFactorAngle = value;
                }
                else
                {
                    flag = false;

                    iotDataOilWellControllerState.AlarmCode = -1;
                    iotDataOilWellControllerState.AlarmMsg  = "数据异常";

                    iotDataOilWellControllerState.Mock = par.UseMockData;
                    logIotModbusPoll.DateTime          = DateTime.Now;
                    logIotModbusPoll.State             = -1;
                    logIotModbusPoll.Result            = $"读取变频器基本监视参数异常!{read.Message}";

                    $"{logIotModbusPoll.Result}".Info();

                    redisClient.AddItemToList("YCIOT:ERROR:Log_IOT_Modbus_Poll", logIotModbusPoll.ToJson().IndentJson());
                }

                #endregion


                #region   工变频切换、就地远程切换

                if (flag)
                {
                    lock (ClientInfo.locker)
                    {
                        ClientInfo.RequestTime     = DateTime.Now;
                        ClientInfo.ExpectedType    = 0x03;
                        ClientInfo.ExpectedDataLen = 4;
                    }

                    read = await client.ReadAsync($"s={par.ModbusAddress};x=3;4128", 3);

                    if (read.IsSuccess)
                    {
                        //工变频切换 4128    0工;1变
                        var value = client.ByteTransform.TransInt16(read.Content, 0);
                        iotDataOilWellControllerState.WorkAndChangeFrequencySwitch = value;

                        //就地远程切换4129   0就;1远
                        value = client.ByteTransform.TransInt16(read.Content, 2);
                        iotDataOilWellControllerState.LocalAndFarSwitch = value;

                        //点数采集4130
                        value = client.ByteTransform.TransInt16(read.Content, 4);
                        iotDataOilWellControllerState.CountFetchAddress = value;
                    }
                    else
                    {
                        flag = false;

                        iotDataOilWellControllerState.AlarmCode = -1;
                        iotDataOilWellControllerState.AlarmMsg  = "数据异常";
                        iotDataOilWellControllerState.Mock      = par.UseMockData;
                        logIotModbusPoll.DateTime = DateTime.Now;
                        logIotModbusPoll.State    = -1;
                        logIotModbusPoll.Result   = $"读取工变频切换和就地远程切换异常![{read.Message}]";
                        redisClient.AddItemToList("YCIOT:ERROR:Log_IOT_Modbus_Poll", logIotModbusPoll.ToJson().IndentJson());
                    }
                }

                #endregion


                #region  双字节监视参数

                if (flag)
                {
                    lock (ClientInfo.locker)
                    {
                        ClientInfo.RequestTime     = DateTime.Now;
                        ClientInfo.ExpectedType    = 0x03;
                        ClientInfo.ExpectedDataLen = 8 * 2;
                    }

                    read = await client.ReadAsync($"s={par.ModbusAddress};x=3;4133", 8);

                    if (read.IsSuccess)
                    {
                        //变频累积运行时间
                        var value0 = client.ByteTransform.TransInt16(read.Content, 0);
                        var value1 = client.ByteTransform.TransInt16(read.Content, 2);

                        iotDataOilWellControllerState.TotalRunTime = value1 * 10000 + value0;

                        //变频累积上电时间
                        value0 = client.ByteTransform.TransInt16(read.Content, 4);
                        value1 = client.ByteTransform.TransInt16(read.Content, 6);

                        iotDataOilWellControllerState.TotalPowerupTime = value1 * 10000 + value0;

                        //变频当前上电时间
                        value0 = client.ByteTransform.TransInt16(read.Content, 8);
                        value1 = client.ByteTransform.TransInt16(read.Content, 10);
                        iotDataOilWellControllerState.CurrentPowerupTime = value1 * 10000 + value0;

                        //变频当前运行时间
                        value0 = client.ByteTransform.TransInt16(read.Content, 12);
                        value1 = client.ByteTransform.TransInt16(read.Content, 14);
                        iotDataOilWellControllerState.CurrentRunTime = value1 * 10000 + value0;
                    }
                    else
                    {
                        flag = false;

                        iotDataOilWellControllerState.AlarmCode = -1;
                        iotDataOilWellControllerState.AlarmMsg  = "数据异常";
                        iotDataOilWellControllerState.Mock      = par.UseMockData;
                        logIotModbusPoll.DateTime = DateTime.Now;
                        logIotModbusPoll.State    = -1;
                        logIotModbusPoll.Result   = $"读取变频累积运行时间异常![{read.Message}]";
                        redisClient.AddItemToList("YCIOT:ERROR:Log_IOT_Modbus_Poll", logIotModbusPoll.ToJson().IndentJson());
                    }
                }

                #endregion


                #region 其它参数(井口压力)

                if (flag)
                {
                    lock (ClientInfo.locker)
                    {
                        ClientInfo.RequestTime     = DateTime.Now;
                        ClientInfo.ExpectedType    = 0x03;
                        ClientInfo.ExpectedDataLen = 3 * 2;
                    }

                    read = await client.ReadAsync($"s={par.ModbusAddress};x=3;4166", 3);

                    if (read.IsSuccess)
                    {
                        //井口压力1   4166
                        var value = client.ByteTransform.TransInt16(read.Content, 0);

                        //井口压力2   4167
                        value = client.ByteTransform.TransInt16(read.Content, 2);

                        //井口压力3   4168
                        value = client.ByteTransform.TransInt16(read.Content, 4);
                    }
                    else
                    {
                        flag = false;

                        iotDataOilWellControllerState.AlarmCode = -1;
                        iotDataOilWellControllerState.AlarmMsg  = "数据异常";
                        iotDataOilWellControllerState.Mock      = par.UseMockData;
                        logIotModbusPoll.DateTime = DateTime.Now;
                        logIotModbusPoll.State    = -1;
                        logIotModbusPoll.Result   = $"读取井口压力数据异常![{read.Message}]";
                        redisClient.AddItemToList("YCIOT:ERROR:Log_IOT_Modbus_Poll", logIotModbusPoll.ToJson().IndentJson());
                    }
                }

                #endregion


                iotDataOilWellControllerState.NetworkNode = ClientInfo.ManyIpAddress;

                //写入设备最后状态

                if (flag == true || par.UseMockData)
                {
                    iotDataOilWellControllerState.Mock = par.UseMockData;

                    redisClient.AddItemToList("YCIOT:IOT_Data_OilWell_ControllerState", iotDataOilWellControllerState.ToJson().IndentJson());
                    redisClient.Set($"Group:OilWell:{par.DeviceName}-{par.DeviceId}:ControllerState", iotDataOilWellControllerState);
                    redisClient.Set($"Single:OilWell:ControllerState:{par.DeviceName}-{par.DeviceId}", iotDataOilWellControllerState);
                }

                //用于通过ServerEvent给调用着返回消息
                if (!par.UserName.IsNullOrEmpty())
                {
                    ServerEventHelper.SendSseMessage(par.UserName, par.SessionId, flag ? 0 : -2, iotDataOilWellControllerState.ToJson().IndentJson());
                }
            }

            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);
                }
            }
        }