Ejemplo n.º 1
0
        public void InitializeAllReadRegisterCommands(List <DataPoint> dataPoints)
        {
            if (null == dataPoints)
            {
                return;
            }

            List <List <DataPoint> > dataPointsGroupedForRead = DataPointGrouper.GroupingDataPointsForReadRegister(dataPoints);

            foreach (var dataPointsGroup in dataPointsGroupedForRead)
            {
                List <List <byte> > requestCommadBytes =
                    RequestCommandByteStreamCreater.CreateRequestCommandByteStreamForReadRegisterBy(dataPointsGroup);

                foreach (var requestCommadByte in requestCommadBytes)
                {
                    ReadRegisterCommand readRegisterCommand = new ReadRegisterCommand();

                    //请求唯一性,用guid标示唯一性
                    List <byte> guidBytes = Guid.NewGuid().ToByteArray().ToList();
                    requestCommadByte.AddRange(guidBytes);

                    readRegisterCommand.ReadCommand = requestCommadByte;

                    //把所有的读命令保存在内存中,换取速度
                    this.allReadRegisterCommands.Enqueue(readRegisterCommand);
                }
            }
        }
        private void InitializeAllReadRegisterCommands(List <DataPoint> dataPoints)
        {
            if (null != dataPoints)
            {
                return;
            }

            List <List <DataPoint> > dataPointsGroupedForRead = DataPointGrouper.GroupingDataPointsForReadRegister(dataPoints);

            foreach (var dataPointsGroup in dataPointsGroupedForRead)
            {
                List <List <byte> > requestCommadBytes =
                    RequestCommandByteStreamCreater.CreateRequestCommandByteStreamForReadRegisterBy(dataPointsGroup);

                foreach (var requestCommadByte in requestCommadBytes)
                {
                    ReadRegisterCommand readRegisterCommand = new ReadRegisterCommand();
                    readRegisterCommand.ReadCommand = requestCommadByte;

                    //把所有的读命令保存在内存中,换取速度
                    this.allReadRegisterCommands.Enqueue(readRegisterCommand);
                }
            }
        }
Ejemplo n.º 3
0
        public void AddWriteRegisterCommands(List <DataPoint> dataPoints)
        {
            if (null == dataPoints || dataPoints.Count < 1)
            {
                return;
            }

            DataAnalyzeMode dataAnalyzeMode = ModbusConfigService.GetCurrentDataAnalyzeMode();

            List <List <DataPoint> > dataPointsGroupedForWrite
                = DataPointGrouper.GroupingDataPointsForWriteRegister(dataPoints);

            foreach (var dataPointsGroup in dataPointsGroupedForWrite)
            {
                List <List <byte> > requestCommadBytes =
                    RequestCommandByteStreamCreater.CreateRequestCommandByteStreamForWriteRegisterBy(dataAnalyzeMode, dataPointsGroup);

                foreach (var requestCommadByte in requestCommadBytes)
                {
                    WriteRegisterCommand writeRegisterCommand = new WriteRegisterCommand();

                    //请求唯一性,用guid标示唯一性
                    List <byte> guidBytes = Guid.NewGuid().ToByteArray().ToList();
                    requestCommadByte.AddRange(guidBytes);
                    writeRegisterCommand.WriteCommand = requestCommadByte;

                    //TODO:删除,测试用的
                    //List<byte> textBytes = new List<byte>();

                    //textBytes.Add((byte)0x02);
                    //textBytes.Add((byte)0x10);
                    //textBytes.Add((byte)0x00);
                    //textBytes.Add((byte)0x72);
                    //textBytes.Add((byte)0x04);
                    //textBytes.Add((byte)0x01);
                    //textBytes.Add((byte)0x02);
                    //textBytes.Add((byte)0x03);
                    //textBytes.Add((byte)0x04);
                    //textBytes.Add((byte)0x09);
                    //textBytes.Add((byte)0x09);

                    //GUID
                    //textBytes.Add((byte)0x02);
                    //textBytes.Add((byte)0x02);
                    //textBytes.Add((byte)0x02);
                    //textBytes.Add((byte)0x02);
                    //textBytes.Add((byte)0x02);
                    //textBytes.Add((byte)0x02);
                    //textBytes.Add((byte)0x02);
                    //textBytes.Add((byte)0x02);

                    //textBytes.Add((byte)0x02);
                    //textBytes.Add((byte)0x02);
                    //textBytes.Add((byte)0x02);
                    //textBytes.Add((byte)0x02);
                    //textBytes.Add((byte)0x02);
                    //textBytes.Add((byte)0x02);
                    //textBytes.Add((byte)0x02);
                    //textBytes.Add((byte)0x02);

                    //writeRegisterCommand.WriteCommand = textBytes;

                    this.allWriterRegisterCommands.Enqueue(writeRegisterCommand);
                }
            }
        }