Click here to Skip to main content
15,885,216 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Using fstream with USB Serial Port Pin
Jochen Arndt10-Jul-18 3:31
professionalJochen Arndt10-Jul-18 3:31 
GeneralRe: Using fstream with USB Serial Port Pin
OscardelaGrouch10-Jul-18 9:53
OscardelaGrouch10-Jul-18 9:53 
GeneralRe: Using fstream with USB Serial Port Pin
OscardelaGrouch10-Jul-18 18:43
OscardelaGrouch10-Jul-18 18:43 
GeneralRe: Using fstream with USB Serial Port Pin
Jochen Arndt10-Jul-18 21:09
professionalJochen Arndt10-Jul-18 21:09 
GeneralRe: Using fstream with USB Serial Port Pin
OscardelaGrouch11-Jul-18 17:40
OscardelaGrouch11-Jul-18 17:40 
GeneralRe: Using fstream with USB Serial Port Pin
Jochen Arndt11-Jul-18 21:16
professionalJochen Arndt11-Jul-18 21:16 
GeneralRe: Using fstream with USB Serial Port Pin
OscardelaGrouch12-Jul-18 18:42
OscardelaGrouch12-Jul-18 18:42 
GeneralRe: Using fstream with USB Serial Port Pin
Jochen Arndt12-Jul-18 20:59
professionalJochen Arndt12-Jul-18 20:59 
The source is probably here:
read(hComPort, &c, 1);
if ((c >= 0x20) && (c <= 0x7E)) data[cnt++] = c;
See read(2): read from file descriptor - Linux man page[^]:
Quote:
Return Value
On success, the number of bytes read is returned (zero indicates end of file), and the file position is advanced by this number. It is not an error if this number is smaller than the number of bytes requested; this may happen for example because fewer bytes are actually available right now (maybe because we were close to end-of-file, or because we are reading from a pipe, or from a terminal), or because read() was interrupted by a signal. On error, -1 is returned, and errno is set appropriately. In this case it is left unspecified whether the file position (if any) changes.
read() will return zero when there are no data available. So you have either to clear your c variable before, or - better - check the return value:
int received = read(hComPort, &c, 1);
if (received == 1 && c >= 0x20 && c <= 0x7E) 
    data[cnt++] = c;
else if (received < 0)
    // handle error here
Another option is setting blocking mode (attributes c_cc[VMIN] to non zero and c_cc[VTIME] to the timeout value). Then you will not get zero return values but still have to check for negative return values indicating timeout or other errors.
GeneralRe: Using fstream with USB Serial Port Pin
OscardelaGrouch14-Jul-18 7:51
OscardelaGrouch14-Jul-18 7:51 
GeneralRe: Using fstream with USB Serial Port Pin
Jochen Arndt14-Jul-18 8:36
professionalJochen Arndt14-Jul-18 8:36 
GeneralRe: Using fstream with USB Serial Port Pin
OscardelaGrouch14-Jul-18 8:38
OscardelaGrouch14-Jul-18 8:38 
GeneralRe: Using fstream with USB Serial Port Pin
Jochen Arndt14-Jul-18 8:43
professionalJochen Arndt14-Jul-18 8:43 
GeneralRe: Using fstream with USB Serial Port Pin
OscardelaGrouch14-Jul-18 9:40
OscardelaGrouch14-Jul-18 9:40 
GeneralRe: Using fstream with USB Serial Port Pin
Jochen Arndt14-Jul-18 12:49
professionalJochen Arndt14-Jul-18 12:49 
QuestionWhich do I use ide for learn c ++ Pin
Onur Çil6-Jul-18 2:33
Onur Çil6-Jul-18 2:33 
AnswerRe: Which do I use ide for learn c ++ Pin
Richard MacCutchan6-Jul-18 2:54
mveRichard MacCutchan6-Jul-18 2:54 
AnswerRe: Which do I use ide for learn c ++ Pin
CPallini7-Jul-18 11:06
mveCPallini7-Jul-18 11:06 
GeneralRe: Which do I use ide for learn c ++ Pin
Daniel Pfeffer8-Jul-18 1:49
professionalDaniel Pfeffer8-Jul-18 1:49 
GeneralRe: Which do I use ide for learn c ++ Pin
CPallini8-Jul-18 20:56
mveCPallini8-Jul-18 20:56 
Questionfree pointer to pointer Pin
Diprom3-Jul-18 4:10
Diprom3-Jul-18 4:10 
AnswerRe: free pointer to pointer Pin
Richard MacCutchan3-Jul-18 4:23
mveRichard MacCutchan3-Jul-18 4:23 
AnswerRe: free pointer to pointer Pin
CPallini3-Jul-18 10:25
mveCPallini3-Jul-18 10:25 
GeneralRe: free pointer to pointer Pin
Richard MacCutchan3-Jul-18 21:38
mveRichard MacCutchan3-Jul-18 21:38 
GeneralRe: free pointer to pointer Pin
CPallini3-Jul-18 21:41
mveCPallini3-Jul-18 21:41 
GeneralRe: free pointer to pointer Pin
Richard MacCutchan3-Jul-18 21:53
mveRichard MacCutchan3-Jul-18 21:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.