问题描述
- 返回值哪里有问题。。
public ErrorCode InquiryCard(ref string SerialNo)
{
if (!_Active) return ErrorCode.DeviceNoOpen;
try
{
//生成寻卡待发命令
byte[] send = new byte[6];
send[0] = 0xFE;
send[1] = 0x05;
send[2] = 0x10;
send[3] = 0x52;
//计算检校位byte[] CrcByteData = new byte[3]; Array.Copy(send 1 CrcByteData 0 CrcByteData.Length); int cRc16 = CRC_16.GetCRC_16(CrcByteData); //取出高8位和低8位 byte _sendHight = HiByte(cRc16); byte _sendLower = LoByte(cRc16); send[4] = _sendHight; send[5] = _sendLower; //发送命令 _SerialPort.Write(send 0 send.Length); //接收命令 byte[] receivedata = GetPortStream(7); //根据协议比对询卡是否成功 if (receivedata[2] == 0x00)//如果寻卡成功 { /* ********************* * 寻卡成功后则获取卡号* ***********************/ //生成获取卡号待发命令 byte[] send1 = new byte[7]; send1[0] = 0xFE; send1[1] = 0x06; send1[2] = 0x11; send1[3] = 0x93; send1[4] = 0x00; //计算检校位 byte[] CrcByteData1 = new byte[4]; Array.Copy(send1 1 CrcByteData1 0 CrcByteData1.Length); int cRc16_1 = CRC_16.GetCRC_16(CrcByteData1); //取出高8位和低8位 byte _sendHight1 = HiByte(cRc16_1); byte _sendLower1 = LoByte(cRc16_1); send1[5] = _sendHight1; send1[6] = _sendLower1; //发送命令 _SerialPort.Write(send1 0 send1.Length); //接收命令 byte[] receivedata1 = GetPortStream(9); //根据协议比对询卡是否成功 if (receivedata1[2] == 0x00)//如果获取卡号成功 { Array.Copy(receivedata1 3 _CardNumbers 0 _CardNumbers.Length); SerialNo = ByteArrayToHexString(_CardNumbers); /* *********************** * 获取卡号成功后则选中卡* *************************/ //生成选中卡待发命令 byte[] send2 = new byte[10]; send2[0] = 0xFE; send2[1] = 0x09; send2[2] = 0x13; send2[3] = 0x93; send2[4] = _CardNumbers[0]; send2[5] = _CardNumbers[1]; send2[6] = _CardNumbers[2]; send2[7] = _CardNumbers[3]; //计算检校位 byte[] CrcByteData2 = new byte[7]; Array.Copy(send2 1 CrcByteData2 0 CrcByteData2.Length); int cRc16_2 = CRC_16.GetCRC_16(CrcByteData2); //取出高8位和低8位 byte _sendHight2 = HiByte(cRc16_2); byte _sendLower2 = LoByte(cRc16_2); send2[8] = _sendHight2; send2[9] = _sendLower2; //发送命令 _SerialPort.Write(send2 0 send2.Length); //接收命令 byte[] receivedata2 = GetPortStream(6); //根据协议比对询卡是否成功 if (receivedata2[2] == 0x00) { return ErrorCode.Success; } } } else if (receivedata[2] == 0xFF) { return ErrorCode.Fail; } else { return ErrorCode.PacketLoss; } } catch { return ErrorCode.Abnormal; } }
解决方案
“if (receivedata1[2] == 0x00)//如果获取卡号成功”进不来,你从哪回?“if (receivedata2[2] == 0x00)”进不来,你又从哪回?
解决方案二:
grep 返回值问题
CreateIoCompletionPort 返回值的问题
fread 返回值的问题
时间: 2024-09-15 19:45:03