Inkcut
search
  • chevron_right Threads
  • label General

supporting inter-byte timing for a device with RS232 timing requirements

rsaxvc
Nov. 28, 2021
chat_bubble_outline 5
  • link
    rsaxvc
    Members 3 posts
    Nov. 28, 2021, 6:25 p.m. Nov. 28, 2021, 6:25 p.m.
    link

    I'm working on adding support for a binary-protocol plotter that has only a single byte RX FIFO and no flow control - it works reliably if a 1 millisecond delay is added between transmitted bytes. I've got the protocol sketched out, and added 1ms delays, but when I try to have inkcut run it, it fails. I replaced the plotter with a null-modem cable with a hex-terminal on the other side, it seems twisted/serial buffers up the data and writes it to the serial port in blocks, which skips past the delays.

    I need to learn how to use reactor. I tried using reactor.callFromThread() to send the data, but that seems to just pend execution again until later, where it's again buffered and sent.

    Is there a way to make the protocol-write wait for the underlying transport/connection finish writing? Is there a better way to approach this?

  • link
    rsaxvc
    Members 3 posts
    Nov. 28, 2021, 6:57 p.m. Nov. 28, 2021, 6:57 p.m.
    link

    Looks like writeSomeData() might do the trick, provided there's always enough buffering available.

  • link
    frmdstryr
    Team 127 posts
    Nov. 28, 2021, 7:12 p.m. Nov. 28, 2021, 7:12 p.m.
    link

    Pyserial has an inter byte timeout option, im unsure if it works with twisted.

    You can override the write function of the serialport transport to do one at a time and sleep but it may make the ui unresponsive

  • link
    frmdstryr
    Team 127 posts
    Nov. 28, 2021, 7:13 p.m. Nov. 28, 2021, 7:13 p.m.
    link

    Another option would be to try a very low baud rate.

  • link
    rsaxvc
    Members 3 posts
    Nov. 28, 2021, 7:48 p.m. Nov. 28, 2021, 7:48 p.m.
    link
    @frmdstryr

    Another option would be to try a very low baud rate.

    Sadly, the plotter baud-rate is not adjustable.

    @frmdstryr

    You can override the write function of the serialport transport to do one at a time and sleep but it may make the ui unresponsive

    I've done so, and as you predicted, it does make the UI unresponsive.

  • link
    frmdstryr
    Team 127 posts
    Nov. 28, 2021, 8:40 p.m. Nov. 28, 2021, 8:40 p.m.
    link

    Using this may work github.com/inkcut/inkcut/blob/d3dea58e13de9f9babb5ed9b562c7326b4efdcd7/inkcut/core/utils.py#L111

    I think the write needs to use inlineCallbacks. Inkcut should be changed to use asyncio at some point

    rsaxvc likes this.

    favorite 1

arrow_upward Go to top
  • Privacy policy
powered by misago