0

I'm trying to write some code to read data from a serial port continuously in a loop and write it to a file. I'm a beginner programmer.

I gather I can use fopen() to open a "file" to the serial port, which is what this code does.

My question is how would you read it continuously and write it to a file. The baud rate is 115200 and there are line feeds and carriage returns. How do you specify this parameters?

  FILE *fp = fopen("/dev/ttyUSB1", "r");
    if (!fp) {
        perror("open failed");
        exit(1);
    } else {
        // read from file

    }

If I open the serial port with minicom this is what the data looks like:

Starting Contiki-1cb08a4
With DriverLib v0.44336
TI SmartRF06EB + CC26xx EM
 Net: sicslowpan
 MAC: TSCH2
 RDC: nordc
 RF: Channel 25
[node] id=0, role=6ln
Starting Contiki-1cb08a4
With DriverLib v0.44336
TI SmartRF06EB + CC26xx EM
 Net: sicslowpan
 MAC: TSCH2
 RDC: nordc
 RF: Channel 25
[node] id=0, role=6ln
artic sol
  • 349
  • 6
  • 18

0 Answers0