/* DESC: This script will write to and read from the serial port. * Copyright (C) 2012 NetModule AG, Switzerland */ DEV = "SERIAL1"; /* check serial port config */ st = nb_config_get("serial.0.status"); if (st != "2") { printf("Serial port is not enabled for us\n"); exit(1); } /* set attributes first */ ret = nb_serial_setattr(DEV, 115200, 8, 1, 0, 0); if (ret != 0) { printf("Could not set serial attributes\n"); exit(1); } if (nb_serial_write(DEV, "hello world\n") == -1) { printf("Could not write to serial port\n"); } while (1) { msg = nb_serial_read(DEV); if (msg) { printf("read: %s\n", msg); } else { sleep(1); } } exit(0);