Code Monkey home page Code Monkey logo

arduino-serial's Introduction

arduino-serial's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arduino-serial's Issues

Resource temporarily unavailable error?

I am using arduino-serial for a cross platform application. It worked successfully on OS X, but when I compile it on Windows 7 with Cygwin and try to connect to the arduino with the command

$ ./arduino-serial -b 115200 -p /dev/ttyS2 -r

I am met with the error "Device disconnected. : Resource temporarily unavailable". I am sure the baud rate is correct and the Arduino is connected to COM3, which I found translates to /dev/ttyS2 for cygwin. The only changes I made to the code itself was encapsulating the '-r' (read from serial) functionality in a while loop so it would continuously print output from serial. Any suggestions?

reading continuous data

I have problems reading continuous data stream. I'm not getting the whole line who was send but only a fraction of it, depending on the time the command was send. Is there a workaround/command that only displays the read string params between two newlines?

license?

There isn't a COPYING or LICENSE file in this repo, so technically, this is not really open source even though it's available for people to see. Would you be willing to release this code under an open source license like MIT, BSD or LGPL so people can legally use and redistribute it?

Review sleep(2) in flush (Correction suggest)

Hi,

Problem

I use this lib to do some tasks and this next line give me lot of problems :

sleep(2); //required to make flush work, for some reason

  • Blocking code too long
  • Overflow in serial port (without this sleep)

Why ?

Only because write() method on my posix system (RPi 3 - Linux 3 - Raspbian 8) is asynchrone and doesn't wait entire writing of string on serial port (seem legit). The reason of flush()

Solution

The solution is easy, program should wait entire writing (some milliseconds) :

millisecondsToWait = ceil( totalBytes * protocolBitsLength / baudsSpeed / 1000 )
  • millisecondsToWait : Result, that should use as usleep( millisecondsToWait ); instead of sleep 2;
  • totalBytes : Trame length, 23bytes in case of Arduino with MySensors in serial gateway mode,
  • protocolBitsLength : Linked to parity, stop bits, frame length, for example 8N1 = 10 bits,
  • baudsSpeed : Your speed : 9600, 38400, 115200, ...

That give waiting of 6 milliseconds for a MySensors gateway with a speed of 38400 bauds.

This really works ?

Yeah, tested with sniffing our serial port from hardware, without sleep()

  • Before : writing 2 messages gives an unexpected 95% of time,
  • After : no error in one week of test.

\n character substituted with \r character

In some distribution the \n character is substituted with \r character in the input stream beacause the INLCR and ICRNL are not disabled in thetoptions.c_iflag in theint serialport_init(const char* serialport, int baud) function.
The correction is to change the line 74 in arduino-serial-lib.c:

toptions.c_iflag &= ~(IXON | IXOFF | IXANY); // turn off s/w flow ctrl

whith this line

toptions.c_iflag &= ~(IXON | IXOFF | IXANY | INLCR | ICRNL); // turn off s/w flow ctrl

Detect disconnect.

Is there any way to detect disconnection of device? Right now, I can't see any way library offers this, so there is no way to distinguish between disconnection and timeout. I thought that if( n==-1) return -1; // couldn't read at line 127 of the library would fire when device is disconnected, but no luck with that - read returns 0 in that case.

First command working second not registering.

I have row of led if I use

screen /dev/tty.usbmodem1411 9600
type my commands either
g, r, f
it works

But if I type
./arduino-serial -b 9600 -p /dev/tty.usbmodem1411 -s g
lights turn green
./arduino-serial -b 9600 -p /dev/tty.usbmodem1411 -s r

Lights do nothing or anything.

Thank you

serial_manage.txt

Bug fix for char and overflow

serialport_read_until() method needs some optimization, in particular these 2 fixes!

  1. More proper way to declare char:

char b[1]; change to char b;
int n = read(fd, b, 1); change to int n = read(fd, &b, 1);
buf[i] = b[0]; change to buf[i] = b;
while( b[0] != until ... change to while( b != until ...

  1. Overflow problem

while( ... && i < buf_max ... change to while( ... && i+1 < buf_max ...

Unless the documentation says that buf_max should be one less than the size of the buffer (which would be counterintuitive and error-prone)

Also, since i is checked at the end, even with this fix, the code will still store one byte if you pass in buf_max == 0 (but without the fix it will store two bytes). So that's another bug.

Compilation on c++

Sorry to border you here, while you lib works amazingly well, it has a small compilation problem if you compile on a c++ code/compiler. May a suggest to warp the function signatures around a:

ifdef __cplusplus

extern "C" {

endif

.
.
.

ifdef __cplusplus

}

endif

Except for that, your library is perfect and really solved my serial communication problems with Arduino, so thank you for that.

PS: without the extern "C", the code will not compile/link, but the proposed solution removes all the problems

flag -q not always work correct

Hello,

Flag -q fully minimize output only if it first parameter in cmd-string.

for example:

correct: root@raspberrypi:/home/trash/arduino-serial-master# ./arduino-serial -q -p /dev/ttyACM0 -S extHumidity01 -r
11.00

incorrect root@raspberrypi:/home/trash/arduino-serial-master# ./arduino-serial -p /dev/ttyACM0 -S extHumidity01 -r -q
opened port /dev/ttyACM0
send string:extHumidity01

read string:11.40

Thank you,
Alexander

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.