This shows you the differences between two versions of the page.
| — | sdk:hex2serial [2017/11/23 16:16] (current) – created juraschek | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Hex Values over Serial ====== | ||
| + | |||
| + | This Script can be used to send non ascii strings over the serial interface. This is ussually made to talk to external devices for managment or configuration. | ||
| + | |||
| + | The Big diffrence is to define the non ascii String as follows | ||
| + | |||
| + | <code c> | ||
| + | get_status=" | ||
| + | set_power_mode=" | ||
| + | </ | ||
| + | |||
| + | and use the write() function to send them over the serial port | ||
| + | |||
| + | | ||
| + | ===== The Script ===== | ||
| + | |||
| + | |||
| + | <code c> | ||
| + | |||
| + | /* Serial Baud Rate 9600, 19200, 38400, 57600, 115200 */ | ||
| + | SER_SPEED=115200; | ||
| + | /* number of data bits (5, 6, 7, 8) */ | ||
| + | SER_DATABIT=8; | ||
| + | /* number of stop bits (1, 2) */ | ||
| + | SER_STOPBIT=1; | ||
| + | /* parity (0=no parity, 1=odd parity, 2=even parity) */ | ||
| + | SER_PARITY=0; | ||
| + | /* flow control (0=none, 1=xon/xoff, 2=hardware) */ | ||
| + | SER_FLOW=0; | ||
| + | /* name of the Serial Interface (Only changed if your device has more then one serial Interface (NB3710) */ | ||
| + | DEV = " | ||
| + | |||
| + | rc = nb_serial_setattr(DEV, | ||
| + | if (rc != 0) { | ||
| + | nb_syslog(" | ||
| + | return -1; | ||
| + | } | ||
| + | |||
| + | /* open serial port */ | ||
| + | serial_fd = nb_serial_open(DEV); | ||
| + | if (fd < 0) { | ||
| + | return -1; | ||
| + | } | ||
| + | | ||
| + | |||
| + | |||
| + | get_status=" | ||
| + | set_power_mode=" | ||
| + | |||
| + | data=get_status; | ||
| + | len=strlen(data); | ||
| + | if (len > 0) { | ||
| + | sent = write(serial_fd, | ||
| + | if (sent != len) { | ||
| + | nb_syslog(" | ||
| + | } | ||
| + | } | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | </ | ||