Giter VIP home page Giter VIP logo

Comments (4)

tarm avatar tarm commented on August 17, 2024

Hi @tiziano88,

I often end up wrapping the serial port in channel code like that as well, so it is likely a common need.

I think an API like that would be interesting and I'd be happy to review/merge a new API. Please send it when you have a chance.

from serial.

wichert avatar wichert commented on August 17, 2024

@tiziano88 Have you made any progress on this?

from serial.

tiziano88 avatar tiziano88 commented on August 17, 2024

No, sorry, haven't worked on this for a long time, feel free to pick it up

from serial.

tarm avatar tarm commented on August 17, 2024

I've been thinking about it more and I don't think it's the right API.

It's certainly convenient initially, but if you want to have timeouts, handle error, and do retries then a channel API does not work as well.

Here's a quick example:
https://play.golang.org/p/zk_03P071w

I annotated that example with comments about some of the issues. By the time you add bidirectional communication (errors, closing of connections, reusing of buffers), then a blocking Read()/Write() api often ends up being simpler.

I recently refactored a bunch of my code to STOP using a pattern like that because I wanted better error handling.

The pattern I am moving towards is having a dedicated goroutine (or 2 if needed) per device. That goroutine does blocking Read()s, handles errors and retries, and then there is a higher level API to communicate with the device. The way I have it, a single goroutine does not handle bytes from multiple devices so no select or channels are needed.

from serial.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.