private void FindWritePacketOrCreate(PacketMap pm, WriteDataServiceRequest request)
        {
            //The data is already broken up into appropriately sized chunks, we just have
            //to find a place to put it...

            int rSize = request.Size;

            for (int i = 0; i < _writeMsrPackets.Count; i++)
            {
                if (_writeMsrPackets[i].Size + rSize < MAX_MSR_SIZE)
                {
                    //This one will fit the packet
                    int svc = _writeMsrPackets[i].AddService(request.Pack());
                    pm.PacketIndex.Add(i);
                    pm.ServiceIndex.Add(i);
                    return;
                }
            }

            //If we got here, we have to create a new one...
            MultiServiceRequest msr = new MultiServiceRequest();

            pm.PacketIndex.Add(_writeMsrPackets.Count);
            _writeMsrPackets.Add(msr);
            pm.ServiceIndex.Add(msr.AddService(request.Pack()));
        }
Example #2
0
        public static WriteDataServiceReply WriteLogixData(SessionInfo si, string tagAddress, ushort dataType, ushort elementCount, byte[] data, ushort structHandle = 0x0000)
#endif
        {
            WriteDataServiceRequest request = BuildLogixWriteDataRequest(tagAddress, dataType, elementCount, data, structHandle);

            EncapsRRData rrData = new EncapsRRData();

            rrData.CPF             = new CommonPacket();
            rrData.CPF.AddressItem = CommonPacketItem.GetConnectedAddressItem(si.ConnectionParameters.O2T_CID);
            rrData.CPF.DataItem    = CommonPacketItem.GetConnectedDataItem(request.Pack(), SequenceNumberGenerator.SequenceNumber);
            rrData.Timeout         = 2000;

            EncapsReply reply = si.SendUnitData(rrData.CPF.AddressItem, rrData.CPF.DataItem);

            if (reply == null)
            {
                return(null);
            }

            if (reply.Status != 0)
            {
                return(null);
            }

            return(new WriteDataServiceReply(reply));
        }