Esempio n. 1
0
        internal void GenerateRequests()
        {
            int rSize = 0;

            _readRequest  = LogixServices.BuildLogixReadDataRequest(_address, _elements, out rSize);
            _writeRequest = LogixServices.BuildLogixWriteDataRequest(_address, _dataType, _elements, new byte[] { });
        }
Esempio n. 2
0
        private void DistributeWriteRequest(PacketMap pm, byte[] requestData, int alignment)
        {
            try
            {
                //Ok, the request may have to be broken up into multiple requests...
                if (requestData.Length > MAX_MSR_SIZE)
                {
                    //This will have to be broken up... the overhead of an MSR packet is 12 bytes, so
                    //that means we can only fit up to MAX_MSR_SIZE - 12 bytes into a single packet.
                    //We need to figure out how much data we can stuff into one packet, then make
                    //multiple ones based on that...
                    //The first packet should always be the maximum size we can fit into one request...
                    WriteDataServiceRequest fragReq = LogixServices.BuildFragmentedWriteRequest(
                        _tags[pm.TagIndex].Address, _tags[pm.TagIndex].DataType, _tags[pm.TagIndex].Elements,
                        0, null, _tags[pm.TagIndex].StructHandle);
                    int  maxSize       = MAX_MSR_SIZE - 12 - fragReq.Size;
                    int  alignedSize   = maxSize - (maxSize % alignment);
                    int  remainingSize = requestData.Length;
                    uint offset        = 0;

                    while (remainingSize > 0)
                    {
                        //We can fit up to alignedSize bytes in the array...
                        byte[] temp;
                        if (remainingSize < alignedSize)
                        {
                            temp          = new byte[remainingSize];
                            remainingSize = 0;
                        }
                        else
                        {
                            temp           = new byte[alignedSize];
                            remainingSize -= alignedSize;
                        }

                        Buffer.BlockCopy(requestData, (int)offset, temp, 0, temp.Length);

                        fragReq = LogixServices.BuildFragmentedWriteRequest(_tags[pm.TagIndex].Address,
                                                                            _tags[pm.TagIndex].DataType, _tags[pm.TagIndex].Elements, offset, temp,
                                                                            _tags[pm.TagIndex].StructHandle);

                        offset += (uint)temp.Length;

                        FindWritePacketOrCreate(pm, fragReq);
                    }
                }
                else
                {
                    //We can fit it into a single packet, we just need to find
                    //one
                    WriteDataServiceRequest request = LogixServices.BuildLogixWriteDataRequest(
                        _tags[pm.TagIndex].Address, _tags[pm.TagIndex].DataType, _tags[pm.TagIndex].Elements,
                        requestData, _tags[pm.TagIndex].StructHandle);

                    FindWritePacketOrCreate(pm, request);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("LogixTagGroup DistributeWriteRequest: " + ex.Message + " " + ex.StackTrace);
            }
        }