Skip to content

Conversation

@Vrong
Copy link
Contributor

@Vrong Vrong commented Jul 18, 2017

This bug was causing sweep object creation to hang when trying to read the returned value from serial port. ==> Issue #72

Bitrate of the serial communication was badly set during the creation of the sweep object when using the libsweep library on Linux.

cfsetispeed(...) and cfsetospeed(...) both take a termios bitrate constant and not the bitrate directly. So should the get_baud(115200) call return the B115200 value defined in termios.h.

The fix seems to have a limitation when compiling on some MAC OS X computers. Termios constants like B115200 doesn't seem to be always defined. That's why the code uses a #ifdef as a workaround for MAC.

Thanks.

}

// translate human readable bitrate to termios bitrate
if (bitrate == 115200)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conditional branch is redundant given the if (bitrate != 115200) above, which results in an error. Maybe just

// if defined, translate human readable bitrate to termios bitrate
#ifdef B115200
    return B115200
#endif
return bitrate;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well ok, I was supposing that more bitrates would be supported in the future.

// translate human readable bitrate to termios bitrate
if (bitrate == 115200)
{
#ifdef B115200
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you clang format as well. Format file included in the main repo. If not, let me know and I'll clean it up before merging.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not use to it but I can figure out how it works

@dcyoung
Copy link

dcyoung commented Jul 18, 2017

Thanks for this second PR. Even if a more robust and elegant portability fix can't be resolved just yet, the library is currently broken.... so I'd like to get this merged ASAP!!

@Vrong
Copy link
Contributor Author

Vrong commented Jul 18, 2017

Done

@dcyoung
Copy link

dcyoung commented Jul 18, 2017

I'll do one more final check on mac and get this merged! Thanks so much.

@dcyoung dcyoung merged commit 3c6738e into scanse:master Jul 18, 2017
@daniel-j-h
Copy link
Collaborator

Urgh thanks for the deep dive here and fixing the bug.

I think we hit this last week when playing with Haskell bindings in #115 but didn't look further (since struggling with Haskell was already enough for the evening 😅).

throw error{"reading from serial device failed"};
}
} else if(ret == 0){
} else if (ret == 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should check for feof (?)

// translate human readable bitrate to termios bitrate
#ifdef B115200
return B115200;
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good quick-fix but we should refactor the function (or how we allow for bitrates here).

We take a bitrate argument but in case we hit the branch here the argument is never used.

@Vrong
Copy link
Contributor Author

Vrong commented Jul 22, 2017

The first fix I made was actually including a condition testing the bitrate before setting a constant, but this one was not merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants