Click here to Skip to main content
15,912,329 members

Comments by jitsejan (Top 4 by date)

jitsejan 13-Apr-12 8:30am View    
Thank you. That already helps me a bit further. I am not there yet, but at least I have some progress =)
jitsejan 13-Apr-12 6:29am View    
Okay. That is not going to work then unfortunately.
jitsejan 13-Apr-12 5:36am View    
Thanks for your reply. I am not sure what you mean by the loop-plug on the serial line? I am using a USB cable which functions as a serial cable, so I can't measure the pins.
jitsejan 13-Apr-12 5:34am View    
Thanks for your reply. I allocate the memory now beforehand.
<pre lang="c++">
char line[BUFFERLENGTH];
char buffWrite[BUFFERLENGTH];
char buffRead[BUFFERLENGTH+1];
</pre>
but this doesn't change the behaviour. The problem is that I only allocate BUFFERLENGTH+1 for the output of the serial, and since the output contains the '\0\0\0' after each character, the input of length 19 doesn't fit in the buffer of length 19+1. I thought it would require (BUFFERLENGTH*4)-4 characters, but this is too big. I want to correct the null characters afterwards like the following code, by cleaning the 'dirty buffer' into a new string by neglecting the '\0', but also that seems not to be working.

<pre lang="c++">
if(ReadFile(hSerial, buffRead, 4*(BUFFERLENGTH-1), &dwBytesRead, NULL)){
printBuffer(buffRead, dwBytesRead);
}

void printBuffer(char * buffRead, DWORD dwBytesRead){
int j, k = 0;
char outputLine[BUFFERLENGTH];
for(j = 0; j < 4*(BUFFERLENGTH-1); j++){
if(buffRead[j] != '\0' && buffRead[j] != 13){
outputLine[k] = buffRead[j];
k++;
}
}
printf("Output: '%s'\n", outputLine);
}
</pre>