STBootLib.STBoot.GetID C# (CSharp) Méthode

GetID() private méthode

private GetID ( ) : Task
Résultat Task
        private async Task GetID()
        {
            /* command word */
            var tx = new byte[2];
            /* temporary storage for response bytes */
            var tmp = new byte[1];
            /* numbe or response bytes */
            int nbytes;
            /* rx buffer */
            byte[] rx;

            /* store code */
            tx[0] = (byte)STCmds.GET_ID;
            /* set checksum */
            tx[1] = ComputeChecksum(tx, 0, 1);

            /* try to send command and wait for response */
            try {
                /* send bytes */
                await SerialWrite(tx, 0, tx.Length);

                /* wait for response code */
                await SerialRead(tmp, 0, 1);
                /* check response code */
                if (tmp[0] != (byte)STResps.ACK)
                    throw new STBootException("Command Rejected");

                /* wait for number of bytes */
                await SerialRead(tmp, 0, 1);
                /* assign number of bytes that will follow (add for acks) */
                nbytes = tmp[0] + 2;
                /* nbytes must be equal to 3 for stm32 products */
                if (nbytes != 3)
                    throw new STBootException("Invalid length");

                /* prepare buffer */
                rx = new byte[nbytes];
                /* receive response */
                await SerialRead(rx, 0, rx.Length);
            /* oops, something baaad happened! */
            } catch (Exception) {
                /* release semaphore */
                sem.Release();
                /* re-throw */
                throw;
            }

            /* store product id */
            ProductID = (ushort)(rx[0] << 8 | rx[1]);

            /* release semaphore */
            sem.Release();
        }