Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first byte choked when reading again after a read time-out #9

Open
volkers opened this issue Apr 3, 2020 · 0 comments
Open

first byte choked when reading again after a read time-out #9

volkers opened this issue Apr 3, 2020 · 0 comments

Comments

@volkers
Copy link
Contributor

volkers commented Apr 3, 2020

Hi, I run into following problem (on Windows 10, sbcl):
After a timeout when reading, the next byte/character is missing when reading the next bytes. I made a simple test with a loopback device:

(ql:quickload 'cserial-port)
(defvar *device* "COM3")
(defvar *serial-stream* nil)


(defun open-serial-stream ()
  (unless *serial-stream*
    (setq *serial-stream*
          (cserial-port:open-serial *device*
                                    ;;:baud-rate 38400
                                    :baud-rate 9600
                                    :data-bits 8
                                    :stop-bits 1
                                    :parity :none)
          )))

(defun close-serial-stream ()
  (when *serial-stream*
    (cserial-port:close-serial *serial-stream*)
    (setq *serial-stream* nil)))

(defun send-x (b)
  (cserial-port:write-serial-byte b *serial-stream*))

(defun read-x ()
  (handler-case 
      (cserial-port:read-serial-byte *serial-stream* :timeout-ms 10)
    (CSERIAL-PORT:TIMEOUT-ERROR () nil)))


;; test

(open-serial-stream)
(pprint "Write 117 followed by 118 and read them back")
(send-x 117)
(send-x 118)
(sleep 0.01)
(pprint (read-x))
(pprint (read-x))

(pprint "Read again, timeout:")
(pprint (read-x))

(sleep 0.01)

(pprint "Write 117 followed by 118 and read them back")
(send-x 117)
(send-x 118)
(sleep 0.01)
(pprint (read-x))
(pprint "first byte missing!")
;; (pprint (read-x))

(pprint "Write 117 followed by 118 and read them back")
(send-x 117)
(send-x 118)
(sleep 0.5)
(pprint (read-x))
(pprint (read-x))
(pprint "Works correctly again")

(close-serial-stream)

Following output:

"Write 117 followed by 118"
117
118
"Read again, timeout:"
NIL
"Write 117 followed by 118"
118
"first byte missing!"
"Write 117 followed by 118"
117
118
"Works correctly again"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant