本文整理汇总了C#中Command.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# Command.ToArray方法的具体用法?C# Command.ToArray怎么用?C# Command.ToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Command
的用法示例。
在下文中一共展示了Command.ToArray方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Select
public static Stream Select(SmartCard card, SelectType selectType, byte[] file, SelectFileOccurrence fileOccurrence, SelectFileControlInformation fileControlInformation, int expectedLength) {
Command cmd = new Command();
cmd.Instruction = 0xA4;
cmd.Parameter1 = (byte)selectType;
cmd.Parameter2 = (byte)((byte)fileOccurrence | (byte)fileControlInformation);
cmd.Data = file;
cmd.ResponseLength = expectedLength;
byte[] command = cmd.ToArray();
byte[] buffer = new byte[256];
//Console.Write("Sending command {0}...", BitConverter.ToString(command));
int len = card.Transmit(command, buffer);
//Console.WriteLine(BitConverter.ToString(buffer, 0, len));
CommandStatus status = GetStatus(buffer, len);
if (!status.IsNormal())
throw status.ToException();
Stream result = new MemoryStream();
result.Write(buffer, 0, len - 2);
while (status.Sw1 == 0x61) {
throw new NotImplementedException("Reading of remaining length not implemented");
}
return result;
}
示例2: ReadBinary
public static Stream ReadBinary(SmartCard card, int offset, int expectedLength) {
if ((offset < 0) || (offset > 0x7FFF))
throw new ArgumentOutOfRangeException("offset");
Command cmd = new Command();
cmd.Instruction = 0xB0;
cmd.Parameter1 = (byte)((offset >> 8) & 0x7F);
cmd.Parameter2 = (byte)offset;
cmd.ResponseLength = expectedLength;
byte[] command = cmd.ToArray();
byte[] buffer = new byte[expectedLength + 2];
//Console.Write("Sending command {0}...", BitConverter.ToString(command));
int len = card.Transmit(command, buffer);
//Console.WriteLine(BitConverter.ToString(buffer, 0, len));
CommandStatus status = GetStatus(buffer, len);
if (!status.IsNormal())
throw status.ToException();
Stream result = new MemoryStream();
result.Write(buffer, 0, len - 2);
while (status.Sw1 == 0x61) {
throw new NotImplementedException("Reading of remaining length not implemented");
}
result.Position = 0;
return result;
}