程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> c#-返回值哪裡有問題。。

c#-返回值哪裡有問題。。

編輯:編程綜合問答
返回值哪裡有問題。。

圖片說明
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)”進不來,你又從哪回?

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved