Glonoin 2015-11-22 13:23 采纳率: 16.7%
浏览 1424
已采纳

返回值哪里有问题。。

图片说明
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;
        }
    }
  • 写回答

1条回答 默认 最新

  • Prol0421 2015-11-22 14:51
    关注

    “if (receivedata1[2] == 0x00)//如果获取卡号成功”进不来,你从哪回?“if (receivedata2[2] == 0x00)”进不来,你又从哪回?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值