Wednesday, 15 August 2012

c - read more than 8 bytes from the serial port -



c - read more than 8 bytes from the serial port -

i need read info serial port, read() function homecoming 8 bytes or less, how can info c code:

readbytes = read(f, bufptr, sizeof(buffer)); buffer[readbytes]='\0'; printf("number of bytes read %d\n", readbytes); printf("buffer %s\n", buffer);

i seek utilize while, still have same result.

[too long comment]

try code:

char buffer[256]; memset(buffer, 0, 256); size_t bytes_read= 0, bytes_expected = 11; { ssize_t result = read(f, buffer + bytes_read, bytes_expected - bytes_read); if (0 >= result) { if (0 > result) { perror("read()"); } break; } bytes_read+= result; } while (bytes_read < bytes_expected) fprintf(stderr, "read %zu out of %zu expected bytes: `%s`\n", bytes_read, bytes_expected, buffer);

c serial-port

No comments:

Post a Comment