示例#1
0
        public static void Cacular(byte[] data)
        {
            //DtuId:212
            //WellId:3
            //配注仪状态: 0
            Console.WriteLine($"配注仪状态 : {data[4]}");
            //设定流量回读: 0.17
            var t = BCDUtils.BCDToUshort((ushort)(data[5] << 8 | data[6]));

            Console.WriteLine($"设定流量回读 : {t / 100.0}");

            //瞬时流量: 0.15
            t = BCDUtils.BCDToUshort((ushort)(data[7] << 8 | data[8]));
            Console.WriteLine($"瞬时流量 : { t / 100.0}");

            //累计流量: 607.26
            var t1 = BCDUtils.BCDToUshort((ushort)(data[9] << 8 | data[10]));
            var t2 = BCDUtils.BCDToUshort((ushort)(data[11] << 8 | data[12]));

            Console.WriteLine($"累计流量 : {(t1 * 10000 + t2) / 100.0}");
            //扩展: 0.0
            //水井压力: 7.35
            t = BCDUtils.BCDToUshort((ushort)(data[17] << 8 | data[18]));
            Console.WriteLine($"水井压力 : {t / 100.0}");
        }
示例#2
0
        public List <string> AnSenWaterInject(byte[] data)
        {
            List <string> results = new List <string>();

            if (data.Length < 8)
            {
                return(results);
            }
            var client = new ModbusRtuOverTcp();

            //配注仪状态: 0
            var r0     = data[0];
            var status = (BCDUtils.BCDToUshort(r0) >> 4) & 0x01;  //阀门状态
            var mode   = (BCDUtils.BCDToUshort(r0) >> 1) & 0x01;  //阀门工作模式

            //设定流量回读: 0.17
            var t = BCDUtils.BCDToUshort((ushort)(data[2] << 8 | data[3]));

            var r1 = t / 100.0;

            //瞬时流量: 0.15
            t = BCDUtils.BCDToUshort((ushort)(data[4] << 8 | data[5]));
            var r2 = t / 100.0;


            //累计流量: 607.26
            var t1 = BCDUtils.BCDToUshort((ushort)(data[6] << 8 | data[7]));
            var t2 = BCDUtils.BCDToUshort((ushort)(data[8] << 8 | data[9]));

            var r3 = (t1 * 10000 + t2) / 100.0;

            //扩展: 0.0
            //水井压力: 7.35
            t = BCDUtils.BCDToUshort((ushort)(data[14] << 8 | data[15]));
            var r4 = t / 100.0;

            var actual = $"流量回读: {r1} ,管压: {r4} ,瞬时流量: {r2} ,表头累计: {r3}";

            results.Add(actual);
            return(results);
        }
示例#3
0
        public static IotDataWaterWell GetCacularResult(byte[] data)
        {
            //0.5配注
            //0.38瞬时
            //6682.76 当日累计
            //11.53 管压
            IotDataWaterWell waterWell = new IotDataWaterWell();
            //配注仪状态: 0
            var r0 = data[4];
            //设定流量回读: 0.17
            var t = BCDUtils.BCDToUshort((ushort)(data[5] << 8 | data[6]));

            var r1 = t / 100.0;

            //瞬时流量: 0.15
            t = BCDUtils.BCDToUshort((ushort)(data[7] << 8 | data[8]));
            var r2 = t / 100.0;


            //累计流量: 6682.89
            var t1 = BCDUtils.BCDToUshort((ushort)(data[9] << 8 | data[10]));
            var t2 = BCDUtils.BCDToUshort((ushort)(data[11] << 8 | data[12]));

            var r3 = t1 * 100 + t2 / 100.0;

            //扩展: 0.0
            //水井压力: 10.83
            t = BCDUtils.BCDToUshort((ushort)(data[17] << 8 | data[18]));
            var r4 = t / 100.0;

            waterWell.SettedFlow        = r1; //设定流量回读
            waterWell.TubePressure      = r4; //管压
            waterWell.InstantaneousFlow = r2; //瞬时流量
            waterWell.CumulativeFlow    = r3; //表头累计

            Console.WriteLine("waterWell:" + waterWell.ToJson());
            waterWell.PrintDump();
            return(waterWell);
        }
示例#4
0
        private static async Task DataReceiver(Metadata md)
        {
            var header = "[" + md.TcpClient.Client.RemoteEndPoint.ToString() + "]";

            Console.WriteLine(header + " data receiver started");

            try
            {
                while (true)
                {
                    if (!IsClientConnected(md.TcpClient))
                    {
                        Console.WriteLine(header + " client no longer connected");
                        break;
                    }

                    if (Token.IsCancellationRequested)
                    {
                        Console.WriteLine(header + " cancellation requested");
                        break;
                    }

                    var data = await DataReadAsync(md.TcpClient, Token);

                    if (data == null || data.Length < 1)
                    {
                        await Task.Delay(30);

                        continue;
                    }

                    Console.WriteLine(data + ": " + BytesToHexString(data));
                    var length = data.Length;

                    if (data.Length == 3)
                    {
                        var deviceId = data[2];

                        switch (data[1])
                        {
                        case 0xC7:
                            Console.WriteLine($"收到设备[0x{deviceId}]注册包");
                            break;

                        case 0xC8:
                            Console.WriteLine($"收到设备[0x{deviceId}]心跳包");
                            break;
                        }
                    }

                    if (length == 25)
                    {
                        var crc32 = data.Take(length - 2).ToArray().CRC16();

                        if (data[length - 2] == crc32[0] && data[length - 1] == crc32[1])
                        {
                            //DtuId:212
                            //WellId:3
                            //配注仪状态: 0
                            Console.WriteLine($"配注仪状态 : {data[4]}");
                            //设定流量回读: 0.17
                            var t = BCDUtils.BCDToUshort((ushort)(data[5] << 8 | data[6]));
                            Console.WriteLine($"设定流量回读 : {t / 100.0}");

                            //瞬时流量: 0.15
                            t = BCDUtils.BCDToUshort((ushort)(data[7] << 8 | data[8]));
                            Console.WriteLine($"瞬时流量 : { t / 100.0}");

                            //累计流量: 607.26
                            var t1 = BCDUtils.BCDToUshort((ushort)(data[9] << 8 | data[10]));
                            var t2 = BCDUtils.BCDToUshort((ushort)(data[11] << 8 | data[12]));
                            Console.WriteLine($"累计流量 : {(t1 *10000 +  t2) / 100.0}");
                            //扩展: 0.0
                            //水井压力: 7.35
                            t = BCDUtils.BCDToUshort((ushort)(data[17] << 8 | data[18]));
                            Console.WriteLine($"水井压力 : {t / 100.0}");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(
                    Environment.NewLine +
                    header +
                    " DataReceiver Exception: " +
                    Environment.NewLine +
                    e.ToString() +
                    Environment.NewLine);
            }

            Console.WriteLine(header + " data receiver terminating");

            Clients.TryRemove(md.TcpClient.Client.RemoteEndPoint.ToString(), out _);
            md.Dispose();
        }