1

I'm trying to improve another abstraction of the serial port. The project involved often needs to check one of the single control signals CTS and DSR. This is currently done by a call to GetCommModemStatus, that's very wordy: a variable is needed and a binary AND operation, GetComModemStatus can also fail (this is more theoretically, but where to check this otherwise...)

I wish to expand the "abstraction" in question by getters for CTS and DSR. And I need help in the decision to make them return bool or int and if the prefix get wouldn't make the resulting code harder to read? Should I use full capitalization?

Here follow some examples of code that would use the new API:

1) with prefix get and boolean result

if (sp.getCts()) {
    // CTS is ON
}

if (!sp.getCts()) {
    // CTS is OFF, in my eyes this looks like getting CTS has failed
}

2) no get prefix with integer result

if (sp.Cts()==1) {
    // CTS is ON
}

if (sp.Cts()==0) {
    // CTS is OFF
}

3) with capitalized CTS (again, no get with bool result)

if (sp.CTS()) {
    // CTS is ON
}

if (!sp.CTS()) {
    // CTS is OFF
}

...this is just to illustrate what I tried in mind; maybe there is even a better solution I left out?