Originally Posted by
jimblumberg
Where are you clearing your buffer? I'm not talking about your character buffer, I'm talking about the "hardware" buffer. You do know that both the operating system and the hardware usually buffer this port, right? To clear these buffers after you initialize the port you call tcflush().
Code:
tcflush(fd, TCIOFUSH); // Clear both the input and output buffers.
What's new to comment about? You haven't changed anything. You're still not checking if read() actually read anything. Please note this quote from this tutorial:
Serial Programming Guide for Linux
What is this supposed to mean? You'll need to provide much more information. Does your external hardware have a method of outputting a predetermined string so you can check the communications? Can you tell us what type of hardware your trying to interface to? The manufacturer, and if the board is mass produced the model and part number of the device you're using?
Jim
Hello jim, the problem seems to be solved already. I did the input and output clear buffer and its settled. Now i have another problem, below is my code to print the output from the device into a text file:
Code:
fp = fopen("results_eigenvalue.txt", "w"); /*open and write into existing file*/
for(i=0;i<207;i++)
{
result = read(mainfd, &chout, sizeof(chout)); /* Read character from ABU (Auto buffering Unit) */
if ( result == -1 ) { perror("error: read"); }
if ( i >= 8){
fprintf(fp,"%02x ",chout); }
}
Problem is the result i get is below:
f5 23 00 c4 00 00 e7 f5 f5 00 00 00 29 (for example)
What i need is some thing like below:
\xf5\x23\xc4\x00\x00\xe7\xf5\xf5\x00\x00\x00\x29
==> I tried to do this "fprintf(fp,"\x%02x ",chout);", but i get this error below:
error: \x used with no following hex digits
Any suggestion?