📄 selectrecord.cs
字号:
//==========================================================================================
//
// WJ.MPR.Reader.SelectRecord
// Copyright (c) 2006, WJ Communications, Inc.
//
// SelectRecord class
//
//==========================================================================================
using System;
using WJ.MPR.Util;
namespace WJ.MPR.Reader
{
/// <summary>
/// For Gen2, tag populations are selected using a select records.
/// Select Records are sent before an inventory round.
/// Tags that match the Select criteria perform the action specified by the Record.
/// This changes their state in such a way that they alone are read during the ensuing
/// inventory round.
/// </summary>
public class SelectRecord
{
#region Private Properties
private byte target;
private byte action;
private byte memBank;
private ushort pointer;
private byte length;
private byteList mask = new byteList(0, MaskByteLength); // Defaults to a correctly sized all zero mask
private byte truncate;
#endregion
#region Public Properties
/// <summary>
/// What bit to modify on selected tag:
/// 0x00: S0 inventoried flag.
/// 0x01: S1 inventoried flag.
/// 0x02: S2 inventoried flag.
/// 0x03: S3 inventoried flag.
/// 0x04: SL flag.
/// </summary>
public byte Target { get { return target; } }
/// <summary>
/// Action to perform on Matching and Non-Matching tags
/// Action Matching Non-Matching
/// 0x00 SL/A !SL/B
/// 0x01 SL/A -
/// 0x02 - !SL/B
/// 0x03 ~SL/~I SL/A
/// 0x04 !SL/B SL/A
/// 0x05 !SL/B -
/// 0x06 - SL/A
/// 0x07 - ~SL/~I
/// </summary>
public byte Action { get { return action; } }
/// <summary>
/// Memory Bank in which to perform match.
/// 0x01: EPC
/// 0x02: TID
/// 0x03: User
/// </summary>
public byte MemBank { get { return memBank; } }
/// <summary>
/// The memory bit address at which to start matching.
/// </summary>
public ushort Pointer { get { return pointer; } }
/// <summary>
/// Number of bits of Mask to use.
/// Always starts counting from MSbit of MSByte.
/// </summary>
public byte Length { get { return length; } }
/// <summary>
/// Bits to match. MSbit justified.
/// </summary>
public byteList Mask { get { return mask; } }
/// <summary>
/// Always set to 0x00: Disable truncation.
/// </summary>
public byte Truncate { get { return truncate; } }
#endregion
/// <summary>
/// Total length of Select Record, in bytes.
/// </summary>
public const int ByteLength = 39;
/// <summary>
/// Maximum length of the Select Record Mask, in bytes.
/// </summary>
public const int MaskByteLength = 32;
/// <summary>
/// Constructor to build a Select Record Structure.
/// </summary>
/// <param name="Target">What bit to modify on selected tag.</param>
/// <param name="Action">Action to perform on Selected/Not Selected tags.</param>
/// <param name="MemBank">In which Memory Bank to match.</param>
/// <param name="Pointer">Where to start matching.</param>
/// <param name="Length">Number of bits to use of Mask.</param>
/// <param name="Mask">Mask to match.</param>
/// <param name="Truncate">Always Set to 0x00.</param>
public SelectRecord(byte Target, byte Action, byte MemBank, ushort Pointer, byte Length, byteList Mask, byte Truncate)
{
this.target = Target;
this.action = Action;
this.memBank = MemBank;
this.pointer = Pointer;
this.length = Length;
// Copy the first 32 bytes, if available, from Mask.
// If > 32 bytes in Mask, just take 32 of them.
// If < 32 bytes in Mask, just copy bytes found, the rest are pre-initialized to 0.
if (Mask != null)
{
int maskLen = Mask.Count;
if (Mask.Count > MaskByteLength)
{ maskLen = MaskByteLength; }
for (int bCnt = 0; bCnt < maskLen; bCnt++ )
{ this.mask[bCnt] = Mask[bCnt]; }
}
this.truncate = Truncate;
}
/// <summary>
/// Constructor to build a Select Record Structure from a byteList.
/// </summary>
/// <param name="data">Record bytes packed into a byteList, as the MPR sees them.</param>
public SelectRecord(byteList data)
{
// If the right number of bytes are provided, parse them into the SelectRecord fields.
if ((data != null) && (data.Count == ByteLength))
{
target = data[0];
action = data[1];
memBank = data[2];
pointer = Helpers.b2us(data[3], data[4]);
length = data[5];
mask = data.subList(6, 6 + MaskByteLength);
truncate = data[6 + MaskByteLength];
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -