Ejemplo n.º 1
0
        byte[] gbyImgRaw_tmp = new byte[240 * 320 / 4]; // 19200
        //byte[] gbyImg2
        private int SerialResponseReceiver()
        {
            if (sPort.IsOpen)
            {
                Thread.Sleep(1000);
                string strRecData;

                if (sPort.BytesToRead > 0)
                {
                    strRecData = "";
                    byte[] buff = new byte[SB_OEM_PKT_SIZE];
                    sPort.Read(buff, 0, SB_OEM_PKT_SIZE);
                    strRecData = FingerSensorPacket.ByteToHexString(buff);
                    Console.WriteLine("RECE: " + strRecData);
                    //55 AA 01 00 00 00 00 00 30 00 30 01
                    if (buff[0] != STX1 || buff[1] != STX2)
                    {
                        return(PKT_HDR_ERR);
                    }
                    if (BitConverter.ToUInt16(buff, 2) != devID)
                    {
                        return(PKT_DEV_ID_ERR);
                    }
                    lastAck = BitConverter.ToUInt16(buff, 8);
                }
                else
                {
                    return(PKT_COMM_ERR);
                }
            }
            return(0);
        }
Ejemplo n.º 2
0
 private void SendCmd(FingerSensorPacket.SB_OEM_PKT pkt, int pktSize)
 {
     byte[] _pkt = FingerSensorPacket.StructureToByte(pkt);
     Console.WriteLine("SEND: " + FingerSensorPacket.ByteToHexString(_pkt));
     isRecv = true;
     sPort.Write(_pkt, 0, pktSize);
     //SerialDataReceived();
 }
Ejemplo n.º 3
0
        private int SerialDataReceiver(int buffSize)
        {
            if (sPort.IsOpen)
            {
                string strRecData;
                Console.WriteLine("buff size: " + buffSize);
                while (sPort.BytesToRead < buffSize)
                {
                    ;
                }
                if (sPort.BytesToRead > 0)
                {
                    strRecData = "";
                    byte[] comBuff = new byte[buffSize];
                    //comBuff = Encoding.UTF8.GetBytes(sPort.ReadExisting());
                    int rSize = sPort.Read(comBuff, 0, buffSize);
                    Console.WriteLine("serial read size: " + rSize);
                    strRecData = FingerSensorPacket.ByteToHexString(comBuff);
                    Console.WriteLine("RECE: " + strRecData);

                    /*
                     * [0]      5A          : Data start code1
                     * [1]      A5          : Data start code2
                     * [2-3]    DeviceID    : Device ID
                     * [n..]    Data        : n byte data
                     * [4+n]    checkSum    : checksum
                     */
                    if (comBuff[0] != STX3 || comBuff[1] != STX4)
                    {
                        return(PKT_HDR_ERR);
                    }
                    //BitConverter.ToUInt16(comBuff, 2);
                    if (BitConverter.ToUInt16(comBuff, 2) != devID)
                    {
                        return(PKT_DEV_ID_ERR);
                    }
                    switch (buffSize - 6)
                    {
                    case 52116:     // Image
                        Array.Copy(comBuff, 4, gbyImg256_tmp, 0, buffSize - 6);
                        break;

                    case 30:     // open device info
                        Array.Copy(comBuff, 4, buffDevInfo, 0, buffSize - 6);
                        break;

                    case 19200:     // rawImage
                        Array.Copy(comBuff, 4, gbyImgRaw_tmp, 0, buffSize - 6);
                        break;
                    }
                }
                else
                {
                    return(PKT_COMM_ERR);
                }
            }
            return(0);
        }
Ejemplo n.º 4
0
        private int SendCmdOrAck(ushort cmd, int param)
        {
            FingerSensorPacket.SB_OEM_PKT pkt = new FingerSensorPacket.SB_OEM_PKT();
            pkt.head1  = (byte)STX1;
            pkt.head2  = (byte)STX2;
            pkt.devId  = devID;
            pkt.cmd    = cmd;
            pkt.param  = param;
            pkt.chkSum = FingerSensorPacket.CalcChkSumOfCmdAckPkt(pkt);

            SendCmd(pkt, SB_OEM_PKT_SIZE);
            return(0);
        }