Giter Site home page Giter Site logo

Comments (8)

euantorano avatar euantorano commented on July 19, 2024 2

Async support is here now, in #9 @r3d9u11. I haven't yet tested this on Linux or Mac at all, but have tested on Windows 10 and it's functioning well. Once I test on Mac and Linux later on today I will merge it and tag a new release.

from serial.nim.

euantorano avatar euantorano commented on July 19, 2024 1

from serial.nim.

euantorano avatar euantorano commented on July 19, 2024

You could do it multithreaded by making the serial port instance a shared object (or by passing a pinter to it to your read/write thread). I haven't written any code to do this myself before, but it should be possible. I can try it this weekend and provide an example if I get it working.

Async IO would be the best approach obviously, but I haven't yet implemented that in this library.

from serial.nim.

kvinwang avatar kvinwang commented on July 19, 2024

Sounds workable. I'll have a try. Thanks.

from serial.nim.

kvinwang avatar kvinwang commented on July 19, 2024

The multithreaded way is so tedious in Nim.
Eventually, I chose the async way, with some modification of serial.nim:

  • Add async flag for the open, and add a getFileHandle for SerialPort.
proc test() {.async.} =
  let port = newSerialPort("COM1")
  port.open(57600, Parity.None, 8, StopBits.One, async=true)
  let com = port.getFileHandle().AsyncFd.newAsyncFile()
  while true:
    echo await com.readLine()

waitFor test()

This way seems simpler and more flexible.

from serial.nim.

euantorano avatar euantorano commented on July 19, 2024

from serial.nim.

kvinwang avatar kvinwang commented on July 19, 2024

My app is for Windows, so I tested only on Windows XP so far.
Will test it on macOS and Linux when I am free.

from serial.nim.

R3D9477 avatar R3D9477 commented on July 19, 2024

@LoongW @euantorano Hi!
I tried this code, but compilation was failed :(
Is there any news about this issue?

from serial.nim.

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.