private void UpdateState() { EncapsRRData rrData = new EncapsRRData(); rrData.CPF = new CommonPacket(); rrData.CPF.AddressItem = CommonPacketItem.GetNullAddressItem(); UnconnectedSend ucmm = new UnconnectedSend(); ucmm.RequestPath = CommonPaths.ConnectionManager; ucmm.RoutePath = _path; ucmm.Priority_TimeTick = _session.ConnectionParameters.PriorityAndTick; ucmm.Timeout_Ticks = _session.ConnectionParameters.ConnectionTimeoutTicks; ucmm.MessageRequest = new MR_Request(); ucmm.MessageRequest.Service = 0x03; ucmm.MessageRequest.Request_Path = CommonPaths.IdentityObject; ucmm.MessageRequest.Request_Data = new byte[] { 0x07, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00 }; rrData.CPF.DataItem = CommonPacketItem.GetUnconnectedDataItem(ucmm.Pack()); EncapsReply reply = _session.SendRRData(rrData.CPF.AddressItem, rrData.CPF.DataItem); if (reply == null) { return; } if (reply.Status == 0) { UnconnectedSendReply ucReply = reply; if (ucReply.GeneralStatus == 0x00) { UnconnectedSendReply_Success succReply = ucReply as UnconnectedSendReply_Success; DecodeAttributeReply(succReply.ServiceResponse); } else { //Failed, for some reason... //TODO: Decipher the code and add it to the error property } } }
private static TemplateInfo ReadStructAttributes(ushort structureId, LogixProcessor processor) { //First we have to get the template info... GetStructAttribsRequest attribsReq = new GetStructAttribsRequest(structureId); CommonPacketItem addressItem = CommonPacketItem.GetNullAddressItem(); UnconnectedSend ucmm = new UnconnectedSend(); ucmm.Priority_TimeTick = 0x07; ucmm.Timeout_Ticks = 0x9B; ucmm.RoutePath = processor.Path; ucmm.MessageRequest = new MR_Request(); ucmm.MessageRequest.Request_Path = new byte[] { 0x20, 0x6C, 0x25, 0x00, (byte)((structureId & 0x00FF)), (byte)((structureId & 0xFF00) >> 8) }; ucmm.MessageRequest.Service = 0x03; ucmm.MessageRequest.Request_Data = new byte[] { 0x04, 0x00, 0x04, 0x00, 0x03, 0x00, 0x02, 0x00, 0x01, 0x00 }; ucmm.RequestPath = CommonPaths.ConnectionManager; CommonPacketItem dataItem = CommonPacketItem.GetUnconnectedDataItem(ucmm.Pack()); EncapsReply reply = processor.SessionInfo.SendRRData(addressItem, dataItem); if (reply.Status != 0x00) return null; //We have to get the data out... EncapsRRData rrData = new EncapsRRData(); CommonPacket cpf = new CommonPacket(); int temp = 0; rrData.Expand(reply.EncapsData, 0, out temp); cpf = rrData.CPF; byte[] replyData = new byte[28]; Buffer.BlockCopy(cpf.DataItem.Data, 4, replyData, 0, 28); GetStructAttribsReply structAttribs = new GetStructAttribsReply(replyData); //Great... now we can request the structure template and be able to read it! ucmm.MessageRequest.Service = 0x4C; //We can only read about 480 bytes at a time, so we may have to break it up... uint bytesRemaining = (structAttribs.TemplateSize - 5) * 4; uint offset = 0; List<byte> structInfoBytes = new List<byte>(); while (bytesRemaining > 0) { ushort bytesToRead; if (bytesRemaining < 480) { bytesToRead = (ushort)bytesRemaining; bytesRemaining = 0; } else { bytesToRead = 480; bytesRemaining -= 480; } byte[] tempB = new byte[6]; Buffer.BlockCopy(BitConverter.GetBytes(offset), 0, tempB, 0, 4); Buffer.BlockCopy(BitConverter.GetBytes(bytesToRead), 0, tempB, 4, 2); ucmm.MessageRequest.Request_Data = tempB; dataItem = CommonPacketItem.GetUnconnectedDataItem(ucmm.Pack()); reply = processor.SessionInfo.SendRRData(addressItem, dataItem); if (reply.Status != 0x00) continue; rrData.Expand(reply.EncapsData, 0, out temp); cpf = rrData.CPF; //get the data out... tempB = new byte[cpf.DataItem.Data.Length - 4]; Buffer.BlockCopy(cpf.DataItem.Data, 4, tempB, 0, cpf.DataItem.Data.Length - 4); structInfoBytes.AddRange(tempB); offset += bytesToRead; } //Now we have all the data!!!! return new TemplateInfo(structInfoBytes.ToArray(), structAttribs); }
private List <LogixTagInfo> GetTagInfo() { CommonPacketItem addressItem = CommonPacketItem.GetNullAddressItem(); UnconnectedSend ucmm = new UnconnectedSend(); ucmm.RequestPath = CommonPaths.ConnectionManager; ucmm.RoutePath = _path; ucmm.Priority_TimeTick = _session.ConnectionParameters.PriorityAndTick; ucmm.Timeout_Ticks = _session.ConnectionParameters.ConnectionTimeoutTicks; ucmm.MessageRequest = new MR_Request(); ucmm.MessageRequest.Service = 0x55; ucmm.MessageRequest.Request_Path = new byte[] { 0x20, 0x6B, 0x25, 0x00, 0x00, 0x00 }; //Last 2 bytes are the offset... ucmm.MessageRequest.Request_Data = new byte[] { 0x04, 0x00, 0x02, 0x00, 0x07, 0x00, 0x08, 0x00, 0x01, 0x00 }; CommonPacketItem dataItem = CommonPacketItem.GetUnconnectedDataItem(ucmm.Pack()); EncapsReply reply = _session.SendRRData(addressItem, dataItem); List <LogixTagInfo> retVal = new List <LogixTagInfo>(); if (reply.Status == 0) { UnconnectedSendReply ucReply = reply; if (ucReply.GeneralStatus == 0x00 || ucReply.GeneralStatus == 0x06) { UnconnectedSendReply_Success succReply = ucReply as UnconnectedSendReply_Success; List <byte> replyBytes = new List <byte>(); uint lastOffset = 0x0000; retVal.AddRange(DecodeTagInfo(succReply.ServiceResponse, out lastOffset)); while (ucReply.GeneralStatus == 0x06) { lastOffset += 1; if (lastOffset <= 0xFFFF) { Buffer.BlockCopy(BitConverter.GetBytes((ushort)lastOffset), 0, ucmm.MessageRequest.Request_Path, 4, 2); } else { byte[] tempPath = new byte[8]; Buffer.BlockCopy(ucmm.MessageRequest.Request_Path, 0, tempPath, 0, 6); Buffer.BlockCopy(BitConverter.GetBytes(lastOffset), 0, tempPath, 4, 4); ucmm.MessageRequest.Request_Path = tempPath; } dataItem = CommonPacketItem.GetUnconnectedDataItem(ucmm.Pack()); reply = _session.SendRRData(addressItem, dataItem); if (reply.Status == 0x00) { ucReply = reply; if (ucReply.GeneralStatus == 0x00 || ucReply.GeneralStatus == 0x06) { succReply = ucReply as UnconnectedSendReply_Success; retVal.AddRange(DecodeTagInfo(succReply.ServiceResponse, out lastOffset)); } } } } } return(retVal); }