amit.user105387
amit.user105387

Reputation: 76

Running libserialport in any event loop

I am trying to integrate libserialport library to a solution which can use poll, libev and libuv.

While it's relatively easy to get the fd for the serial port file from libserialport and watch it using libev or libuv,

uv_poll_init(loop, &poller, serial_port_fd);
uv_poll_start(&poller, UV_READABLE /*| UV_PRIORITIZED*/, cb);

I do not know how to get it working using the default loop using poll. The main loop is like:

while(!interrupted){
    interrupted = service_one_loop();
    //// THIS IS ONE PLACE TO poll (serial_port_fd) CODE and call callback function for serial
}

Is there any other way? Something like:

while(!interrupted){
    interrupted = service_one_loop();
    read_size = sp_nonblocking_read(machine_port, read_buffer, read_buffer_size);
    if (read_size >= 0) {
        cb();
    }
}

Upvotes: 2

Views: 334

Answers (0)

Related Questions