From 3747d8ce4130388f75a6545a0c81957423a4147f Mon Sep 17 00:00:00 2001 From: Ariejan de Vroom Date: Thu, 21 Aug 2014 10:02:04 +0200 Subject: [PATCH] Acia Tx return nothing when there is no new data --- acia6551.go | 12 ++++++++---- acia6551_test.go | 12 ++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/acia6551.go b/acia6551.go index a264a9a..5386713 100644 --- a/acia6551.go +++ b/acia6551.go @@ -95,10 +95,14 @@ func (a *Acia6551) statusRegister() byte { // Implements io.Reader, for external programs to read TX'ed data from // the serial output. func (a *Acia6551) Read(p []byte) (n int, err error) { - a.txEmpty = true - copy(p, []byte{a.tx}) - // TODO: Handle txInterrupt - return 1, nil + if a.txEmpty { + return 0, nil + } else { + a.txEmpty = true + copy(p, []byte{a.tx}) + // TODO: Handle txInterrupt + return 1, nil + } } // Implements io.Writer, for external programs to write to the diff --git a/acia6551_test.go b/acia6551_test.go index 8ce4889..54d5062 100644 --- a/acia6551_test.go +++ b/acia6551_test.go @@ -36,6 +36,18 @@ func TestAciaReset(t *testing.T) { assert.Equal(t, 0, a.controlData) } +func TestAciaReaderWithTxEmpty(t *testing.T) { + a := AciaSubject() + + // Nothing to read + assert.True(t, a.txEmpty) + + value := make([]byte, 1) + bytesRead, _ := a.Read(value) + + assert.Equal(t, 0, bytesRead) +} + func TestAciaWriteByteAndReader(t *testing.T) { a := AciaSubject()