private Packet SendAndReceive(Packet packet, int receive, int delay) { if (_port.IsOpen) _port.DiscardOutBuffer(); SendPacket(packet); Thread.Sleep(delay); Packet result = GetResponse(receive + Constants.PACKET_OVERHEAD_BYTES); //if (_port.IsOpen) _port.DiscardInBuffer(); //_buffer.Clear(); return result; }
private void SendPacket(Packet packet) { if (_port == null || !_port.IsOpen) { return; } try { _port.Write(packet.Data, 0, packet.Data.Length); while (_port.BytesToWrite > 0) Thread.Sleep(1); } catch (Exception) { // exception handling } }
private bool CheckResponse(Packet response) { APStatus BM_errorstate = (APStatus)response.Data[Constants.PACKET_BYTE_CMD]; if (BM_errorstate != APStatus.HW_NO_ERROR) return false; return true; }