BgApiDriver.BgApi.Send C# (CSharp) Method

Send() private method

Sends a command and receives a response from a ble device.
private Send ( BgApiCommand command, bool no_return ) : BgApiResponse
command BgApiCommand The BgApiCommand to send.
no_return bool True, iff the command has no response (ex. the reset command does not return a response).
return BgApiResponse
        private BgApiResponse Send(BgApiCommand command, bool no_return)
        {
            try
            {
                // ensure an open connection before attempting to send
                Open();
                // wait for response
                m_waitHandleResponse.Reset();
                m_response = null;

                log("--> " + string.Join(" ", command.Data.Select(x => x.ToString("X2"))));

                // write command
                m_stream.Write(command.Data, 0, command.Data.Length);
                m_stream.Flush();

                if (no_return)
                {
                    // do not expect a response for this command
                    return null;
                }

                // what is the maximum wait time for a response
                if (!m_waitHandleResponse.WaitOne(5000))
                {
                    throw new BgApiException("Response timeout");
                }
                log("<-- " + string.Join(" ", m_response.Data.Select(x => x.ToString("X2"))));
                return m_response;
            }
            catch (Exception e)
            {
                log(e.Message);
                // do not assume anything about the state of the ble device
                // after an exception
                Close();
                throw e;
            }
        }
BgApi