Saturday, 15 May 2010

c - Transferring data from a serial Port to a text file -



c - Transferring data from a serial Port to a text file -

i'm using debian , have transfer info serial port text file read database. think how im setting port wrong, , maintain stumbling across many different examples, current code (below) keeps giving me 3 warnings, "assignment makes pointer integer without cast" think has values beingness returned, did reading on pointers return, wasn't clear me, wondering if give insight on issue, or if there glaringly obvious issues missing. suggestions much appreciated.

#include <stdio.h> #include <fcntl.h> #include <sys/stat.h> #include <termios.h> #include <string.h> #define baudrate b115200 #define modemdevice "/dev/ttys0" main() { int n; file *file; file = open(modemdevice, o_rdwr, o_noctty); if(file == null){ printf("initiation error. \n"); homecoming 1; } file *fp; fp = open("testfile.txt", o_rdwr); while(1){ file = scanf("%d", &n); fprintf(fp, "%d", n); fclose(fp); } fclose(file); }

so think does, or intend @ to the lowest degree set file read info port, , store values in n, printed in text file.

this:

file *fp; fp = open("testfile.txt", o_rdwr);

is wrong, meant fopen() on lastly line, don't confuse raw i/o c runtime library's buffered functions.

this 1 reason error, since file descriptor (not pointer) returned open() integer (see open() manual page , compare fopen()'s).

update: fail understand you're trying scanf() line.

if want read integer file *, should utilize fscanf(). homecoming value number of successful conversions, used in error-checking:

if(fscanf(file, "%d", &n) == 1) fprintf(fp, "%d", n);

that read integer serial port file, , if successful print out output file fp.

c file serial-port scanf

No comments:

Post a Comment