This shows you the differences between two versions of the page.
| — | sdk:scripts:serial-write [2015/05/05 15:04] (current) – created - external edit 127.0.0.1 | ||
|---|---|---|---|
| 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(" | ||
| + | exit(1); | ||
| + | } | ||
| + | |||
| + | if (argc < 2) { | ||
| + | usage(); | ||
| + | } | ||
| + | |||
| + | DEV = " | ||
| + | MSG = argv[1]; | ||
| + | |||
| + | |||
| + | /* check serial port config */ | ||
| + | st = nb_config_get(" | ||
| + | if (st != " | ||
| + |     printf(" | ||
| + | exit(1); | ||
| + | } | ||
| + | |||
| + | ret = nb_serial_setattr(DEV, | ||
| + | if (ret != 0) { | ||
| + |     printf(" | ||
| + | exit(1); | ||
| + | } | ||
| + | |||
| + | fd = nb_serial_open(DEV); | ||
| + | if (fd < 0) { | ||
| + |     printf(" | ||
| + | exit(1); | ||
| + | } | ||
| + | |||
| + | message = strcat(MSG, " | ||
| + | ret = write(fd, message, strlen(message)); | ||
| + | if (ret> 0) { | ||
| + |     printf(" | ||
| + | } else { | ||
| + |     printf(" | ||
| + | } | ||
| + | close(fd); | ||
| + | |||
| + | exit(0); | ||
| + | |||
| + | </ | ||