本文整理汇总了C#中Gurux.DLMS.GXDLMSSettings.IncreaseBlockIndex方法的典型用法代码示例。如果您正苦于以下问题:C# GXDLMSSettings.IncreaseBlockIndex方法的具体用法?C# GXDLMSSettings.IncreaseBlockIndex怎么用?C# GXDLMSSettings.IncreaseBlockIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gurux.DLMS.GXDLMSSettings
的用法示例。
在下文中一共展示了GXDLMSSettings.IncreaseBlockIndex方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleSetRequestNormal
private static void HandleSetRequestNormal(GXDLMSSettings settings, GXDLMSServer server, GXByteBuffer data, byte type, GXDLMSLNParameters p, GXByteBuffer replyData, GXDLMSTranslatorStructure xml)
{
object value = null;
GXDataInfo reply = new GXDataInfo();
// CI
ObjectType ci = (ObjectType)data.GetUInt16();
byte[] ln = new byte[6];
data.Get(ln);
// Attribute index.
byte index = data.GetUInt8();
// Get Access Selection.
data.GetUInt8();
if (xml != null)
{
AppendAttributeDescriptor(xml, (int)ci, ln, index);
xml.AppendStartTag(TranslatorTags.Value);
GXDataInfo di = new GXDataInfo();
di.xml = xml;
value = GXCommon.GetData(settings, data, di);
if (!di.Complete)
{
value = GXCommon.ToHex(data.Data, false, data.Position, data.Size - data.Position);
}
else if (value is byte[])
{
value = GXCommon.ToHex((byte[])value, false);
}
xml.AppendEndTag(TranslatorTags.Value);
return;
}
if (type == 2)
{
p.multipleBlocks = data.GetUInt8() == 0;
UInt32 blockNumber = data.GetUInt32();
if (blockNumber != settings.BlockIndex)
{
Debug.WriteLine("HandleSetRequest failed. Invalid block number. " + settings.BlockIndex + "/" + blockNumber);
p.status = (byte)ErrorCode.DataBlockNumberInvalid;
return;
}
settings.IncreaseBlockIndex();
int size = GXCommon.GetObjectCount(data);
int realSize = data.Size - data.Position;
if (size != realSize)
{
Debug.WriteLine("HandleSetRequest failed. Invalid block size.");
p.status = (byte)ErrorCode.DataBlockUnavailable;
return;
}
}
if (!p.multipleBlocks)
{
settings.ResetBlockIndex();
value = GXCommon.GetData(settings, data, reply);
}
GXDLMSObject obj = settings.Objects.FindByLN(ci, GXDLMSObject.ToLogicalName(ln));
if (obj == null)
{
obj = server.NotifyFindObject(ci, 0, GXDLMSObject.ToLogicalName(ln));
}
// If target is unknown.
if (obj == null)
{
// Device reports a undefined object.
p.status = (byte)ErrorCode.UndefinedObject;
}
else
{
AccessMode am = obj.GetAccess(index);
// If write is denied.
if (am != AccessMode.Write && am != AccessMode.ReadWrite)
{
//Read Write denied.
p.status = (byte)ErrorCode.ReadWriteDenied;
}
else
{
try
{
if (value is byte[])
{
DataType dt = (obj as IGXDLMSBase).GetDataType(index);
if (dt != DataType.None && dt != DataType.OctetString)
{
value = GXDLMSClient.ChangeType((byte[])value, dt);
}
}
ValueEventArgs e = new ValueEventArgs(settings, obj, index, 0, null);
e.Value = value;
ValueEventArgs[] list = new ValueEventArgs[] { e };
if (p.multipleBlocks)
{
server.transaction = new GXDLMSLongTransaction(list, Command.GetRequest, data);
}
server.NotifyWrite(list);
if (e.Error != 0)
{
p.status = (byte)e.Error;
}
//.........这里部分代码省略.........
示例2: GetRequestNextDataBlock
/// <summary>
/// Handle get request next data block command.
/// </summary>
/// <param name="data">Received data.</param>
private static void GetRequestNextDataBlock(GXDLMSSettings settings, GXDLMSServer server, GXByteBuffer data, GXByteBuffer replyData, GXDLMSTranslatorStructure xml)
{
GXByteBuffer bb = new GXByteBuffer();
UInt32 index;
// Get block index.
index = data.GetUInt32();
if (xml != null)
{
xml.AppendLine(TranslatorTags.BlockNumber, null, xml.IntegerToHex(index, 8));
return;
}
if (index != settings.BlockIndex)
{
Debug.WriteLine("handleGetRequest failed. Invalid block number. " + settings.BlockIndex + "/" + index);
GXDLMS.GetLNPdu(new GXDLMSLNParameters(settings, Command.GetResponse, 2, null, bb, (byte)ErrorCode.DataBlockNumberInvalid), replyData);
}
else
{
settings.IncreaseBlockIndex();
GXDLMSLNParameters p = new GXDLMSLNParameters(settings, Command.GetResponse, 2, null, bb, (byte)ErrorCode.Ok);
//If transaction is not in progress.
if (server.transaction == null)
{
p.status = (byte)ErrorCode.NoLongGetOrReadInProgress;
}
else
{
bb.Set(server.transaction.data);
bool moreData = settings.Index != settings.Count;
if (moreData)
{
//If there is multiple blocks on the buffer.
//This might happen when Max PDU size is very small.
if (bb.Size < settings.MaxPduSize)
{
foreach (ValueEventArgs arg in server.transaction.targets)
{
object value;
if (arg.Handled)
{
server.NotifyRead(new ValueEventArgs[] { arg });
value = arg.Value;
}
else
{
value = (arg.Target as IGXDLMSBase).GetValue(settings, arg);
}
//Add data.
GXDLMS.AppendData(settings, arg.Target, arg.Index, bb, value);
}
moreData = settings.Index != settings.Count;
}
}
p.multipleBlocks = true;
GXDLMS.GetLNPdu(p, replyData);
if (moreData || bb.Size - bb.Position != 0)
{
server.transaction.data = bb;
}
else
{
server.transaction = null;
}
}
}
}
示例3: ReceiverReady
///<summary>
///Generates an acknowledgment message, with which the server is informed to send next packets.
///</summary>
///<param name="type">
/// Frame type.
/// </param>
///<returns>
///Acknowledgment message as byte array.
///</returns>
internal static byte[] ReceiverReady(GXDLMSSettings settings, RequestTypes type)
{
if (type == RequestTypes.None)
{
throw new ArgumentException("Invalid receiverReady RequestTypes parameter.");
}
// Get next frame.
if ((type & RequestTypes.Frame) != 0)
{
byte id = settings.ReceiverReady();
return GetHdlcFrame(settings, id, null);
}
Command cmd;
if (settings.UseLogicalNameReferencing)
{
if (settings.IsServer)
{
cmd = Command.GetResponse;
}
else
{
cmd = Command.GetRequest;
}
}
else
{
if (settings.IsServer)
{
cmd = Command.ReadResponse;
}
else
{
cmd = Command.ReadRequest;
}
}
// Get next block.
GXByteBuffer bb = new GXByteBuffer(6);
if (settings.UseLogicalNameReferencing)
{
bb.SetUInt32(settings.BlockIndex);
}
else
{
bb.SetUInt16((UInt16)settings.BlockIndex);
}
settings.IncreaseBlockIndex();
byte[][] reply;
if (settings.UseLogicalNameReferencing)
{
GXDLMSLNParameters p = new GXDLMSLNParameters(settings, cmd, (byte)GetCommandType.NextDataBlock, bb, null, 0xff);
reply = GXDLMS.GetLnMessages(p);
}
else
{
GXDLMSSNParameters p = new GXDLMSSNParameters(settings, cmd, 1, (byte)VariableAccessSpecification.BlockNumberAccess, bb, null);
reply = GXDLMS.GetSnMessages(p);
}
return reply[0];
}
示例4: HandleReadResponse
//.........这里部分代码省略.........
}
reply.Xml.AppendStartTag(Command.ReadResponse, SingleReadResponse.Data);
GXDataInfo di = new GXDataInfo();
di.xml = reply.Xml;
GXCommon.GetData(settings, reply.Data, di);
reply.Xml.AppendEndTag(Command.ReadResponse, SingleReadResponse.Data);
if (reply.Xml.OutputType == TranslatorOutputType.StandardXml)
{
reply.Xml.AppendEndTag(TranslatorTags.Choice);
}
}
else if (cnt == 1)
{
GetDataFromBlock(reply.Data, 0);
}
else
{
reply.ReadPosition = reply.Data.Position;
GetValueFromData(settings, reply);
if (reply.Data.Position == reply.ReadPosition)
{
//If multiple values remove command.
if (cnt != 1 && reply.TotalCount == 0)
{
++index;
}
reply.TotalCount = 0;
reply.Data.Position = index;
GetDataFromBlock(reply.Data, 0);
reply.Value = null;
//Ask that data is parsed after last block is received.
reply.CommandType = (byte)SingleReadResponse.DataBlockResult;
return false;
}
reply.Data.Position = reply.ReadPosition;
values.Add(reply.Value);
reply.Value = null;
}
break;
case SingleReadResponse.DataAccessError:
// Get error code.
reply.Error = reply.Data.GetUInt8();
if (reply.Xml != null)
{
if (reply.Xml.OutputType == TranslatorOutputType.StandardXml)
{
reply.Xml.AppendStartTag(TranslatorTags.Choice);
}
reply.Xml.AppendLine(
(int)Command.ReadResponse << 8
| (int)SingleReadResponse.DataAccessError,
null,
GXDLMSTranslator.ErrorCodeToString(
reply.Xml.OutputType,
(ErrorCode)reply.Error));
if (reply.Xml.OutputType == TranslatorOutputType.StandardXml)
{
reply.Xml.AppendEndTag(TranslatorTags.Choice);
}
//reply.Xml.AppendLine("<" + SingleReadResponse.DataAccessError.ToString() + " Value=\"" + ((ErrorCode)reply.Error).ToString() + "\" />");
}
break;
case SingleReadResponse.DataBlockResult:
if (!ReadResponseDataBlockResult(settings, reply, index))
{
//If xml only received bytes are shown. Data is not try to parse.
if (reply.Xml != null)
{
reply.Xml.AppendEndTag(Command.ReadResponse);
}
return false;
}
break;
case SingleReadResponse.BlockNumber:
// Get Block number.
UInt32 number = reply.Data.GetUInt16();
if (number != settings.BlockIndex)
{
throw new ArgumentException(
"Invalid Block number. It is " + number
+ " and it should be " + settings.BlockIndex + ".");
}
settings.IncreaseBlockIndex();
reply.MoreData = (RequestTypes)(reply.MoreData | RequestTypes.DataBlock);
break;
default:
throw new GXDLMSException("HandleReadResponse failed. Invalid tag.");
}
}
if (reply.Xml != null)
{
reply.Xml.AppendEndTag(Command.ReadResponse);
return true;
}
if (values != null)
{
reply.Value = values.ToArray();
}
return cnt == 1;
}
示例5: HandleReadDataBlockAccess
private static void HandleReadDataBlockAccess(
GXDLMSSettings settings, GXDLMSServer server,
Command command, GXByteBuffer data, int cnt, GXByteBuffer replyData, GXDLMSTranslatorStructure xml)
{
GXByteBuffer bb = new GXByteBuffer();
byte lastBlock = data.GetUInt8();
UInt16 blockNumber = data.GetUInt16();
if (xml != null)
{
if (command == Command.WriteResponse)
{
xml.AppendStartTag(TranslatorTags.WriteDataBlockAccess);
}
else
{
xml.AppendStartTag(TranslatorTags.ReadDataBlockAccess);
}
xml.AppendLine("<LastBlock Value=\"" + xml.IntegerToHex(lastBlock, 2) + "\" />");
xml.AppendLine("<BlockNumber Value=\"" + xml.IntegerToHex(blockNumber, 4) + "\" />");
if (command == Command.WriteResponse)
{
xml.AppendEndTag(TranslatorTags.WriteDataBlockAccess);
}
else
{
xml.AppendEndTag(TranslatorTags.ReadDataBlockAccess);
}
return;
}
if (blockNumber != settings.BlockIndex)
{
Debug.WriteLine("handleReadRequest failed. Invalid block number. " + settings.BlockIndex + "/" + blockNumber);
bb.SetUInt8(ErrorCode.DataBlockNumberInvalid);
GXDLMS.GetSNPdu(new GXDLMSSNParameters(settings, command, 1, (byte)SingleReadResponse.DataAccessError, bb, null), replyData);
settings.ResetBlockIndex();
return;
}
int count = 1;
byte type = (byte)DataType.OctetString;
if (command == Command.WriteResponse)
{
count = GXCommon.GetObjectCount(data);
type = data.GetUInt8();
}
int size = GXCommon.GetObjectCount(data);
int realSize = data.Size - data.Position;
if (count != 1 || type != (byte)DataType.OctetString || size != realSize)
{
Debug.WriteLine("handleGetRequest failed. Invalid block size.");
bb.SetUInt8(ErrorCode.DataBlockUnavailable);
GXDLMS.GetSNPdu(new GXDLMSSNParameters(settings, command, cnt, (byte)SingleReadResponse.DataAccessError, bb, null), replyData);
settings.ResetBlockIndex();
return;
}
if (server.transaction == null)
{
server.transaction = new GXDLMSLongTransaction(null, command, data);
}
else
{
server.transaction.data.Set(data);
}
if (lastBlock == 0)
{
bb.SetUInt16(blockNumber);
settings.IncreaseBlockIndex();
if (command == Command.ReadResponse)
{
type = (byte)SingleReadResponse.BlockNumber;
}
else
{
type = (byte)SingleWriteResponse.BlockNumber;
}
GXDLMS.GetSNPdu(new GXDLMSSNParameters(settings, command, cnt, type, null, bb), replyData);
return;
}
else
{
if (server.transaction != null)
{
data.Size = 0;
data.Set(server.transaction.data);
server.transaction = null;
}
if (command == Command.ReadResponse)
{
HandleReadRequest(settings, server, data, replyData, xml);
}
else
{
HandleWriteRequest(settings, server, data, replyData, xml);
}
settings.ResetBlockIndex();
}
}
示例6: HandleReadBlockNumberAccess
/// <summary>
/// Handle read Block in blocks.
/// </summary>
/// <param name="data">Received data.</param>
private static void HandleReadBlockNumberAccess(GXDLMSSettings settings, GXDLMSServer server, GXByteBuffer data, GXByteBuffer replyData, GXDLMSTranslatorStructure xml)
{
UInt16 blockNumber = data.GetUInt16();
if (xml != null)
{
xml.AppendStartTag(Command.ReadRequest, VariableAccessSpecification.BlockNumberAccess);
xml.AppendLine("<BlockNumber Value=\"" + xml.IntegerToHex(blockNumber, 4) + "\" />");
xml.AppendEndTag(Command.ReadRequest, VariableAccessSpecification.BlockNumberAccess);
return;
}
if (blockNumber != settings.BlockIndex)
{
GXByteBuffer bb = new GXByteBuffer();
Debug.WriteLine("handleReadRequest failed. Invalid block number. " + settings.BlockIndex + "/" + blockNumber);
bb.SetUInt8(ErrorCode.DataBlockNumberInvalid);
GXDLMS.GetSNPdu(new GXDLMSSNParameters(settings, Command.ReadResponse, 1, (byte)SingleReadResponse.DataAccessError, bb, null), replyData);
settings.ResetBlockIndex();
return;
}
if (settings.Index != settings.Count && server.transaction.data.Size < settings.MaxPduSize)
{
List<ValueEventArgs> reads = new List<ValueEventArgs>();
List<ValueEventArgs> actions = new List<ValueEventArgs>();
foreach (ValueEventArgs it in server.transaction.targets)
{
if (it.action)
{
actions.Add(it);
}
else
{
reads.Add(it);
}
}
if (reads.Count != 0)
{
server.NotifyRead(reads.ToArray());
}
if (actions.Count != 0)
{
server.NotifyAction(actions.ToArray());
}
GetReadData(settings, server.transaction.targets, server.transaction.data);
}
settings.IncreaseBlockIndex();
GXDLMSSNParameters p = new GXDLMSSNParameters(settings, Command.ReadResponse, 1,
(byte)SingleReadResponse.DataBlockResult, null, server.transaction.data);
p.multipleBlocks = true;
GXDLMS.GetSNPdu(p, replyData);
//If all data is sent.
if (server.transaction.data.Size == server.transaction.data.Position)
{
server.transaction = null;
settings.ResetBlockIndex();
}
else
{
server.transaction.data.Trim();
}
}