Differences

This shows you the differences between two versions of the page.

Link to this comparison view

sdk:scripts:serial-write [2015/05/05 15:04]
sdk:scripts:serial-write [2015/05/05 15:04] (current)
Line 1: Line 1:
 +====== SDK Script serial-write.are ======
 +<code c serial-write.are>​
 +/* DESC: This script can be used to write a message to the serial port.
 + * Copyright (C) 2012 NetModule AG, Switzerland
 + */
 +
 +void usage()
 +{
 +    printf("​usage:​ serial-write.are <​msg>​\n"​);​
 +    exit(1);
 +}
 +
 +if (argc < 2) {
 +    usage();
 +}
 +
 +DEV = "​SERIAL1";​
 +MSG = argv[1];
 +
 +
 +/* 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);
 +}
 +
 +ret = nb_serial_setattr(DEV,​ 115200, 8, 1, 0, 0);
 +if (ret != 0) {
 +    printf("​Could not set serial attributes: %i \n",​ret);​
 +    exit(1);
 +}
 +
 +fd = nb_serial_open(DEV);​
 +if (fd < 0) {
 +    printf("​Unable to open %s\n", DEV);
 +    exit(1);
 +}
 +
 +message = strcat(MSG, "​\r\n"​);​
 +ret = write(fd, message, strlen(message));​
 +if (ret> 0) {
 +    printf("​Wrote %d bytes to %s\n", ret, DEV);
 +} else {
 +    printf("​Unable to write to %s\n", DEV);
 +}
 +close(fd);
 +
 +exit(0);
 +
 +</​code>​