API
zb_serial.c File Reference
#include <string.h>
#include <stdio.h>
#include <stdint.h>
#include <limits.h>
#include "zb_serial.h"
Include dependency graph for zb_serial.c:

Go to the source code of this file.

Functions

void zb_set_verbose (int value)
 
int zb_encode (uint8_t *destination, uint8_t device_number, uint8_t command_number, int32_t data)
 
int zb_decode (int32_t *destination, const uint8_t *reply)
 

Variables

static int zb_verbose = 1
 

Function Documentation

◆ zb_decode()

int zb_decode ( int32_t *  destination,
const uint8_t *  reply 
)

Decodes the last 4 bytes of a 6-byte (complete) reply.

This function wraps the last four bytes of the reply into a 32-bit integer matching the architecture of the compilation target (typically the machine which compiled the code, unless otherwise specified).

This function only writes the "data" portion of a reply (the last four bytes) into destination. You will still need to manually read the first two bytes of your reply to get the device and command IDs.

This function does not support the decoding of Message IDs. If your device does have Message IDs enabled, the data decoded by this function will be incorrect and should be considered undefined.

Parameters
[out]destinationa pointer to a 32-bit integer to which to write the reply's data.
[in]replya pointer to an array containing a 6-byte reply message.
Returns
Z_SUCCESS on success, or Z_ERROR_NULL_PARAMETER if destination or reply is NULL.

Definition at line 48 of file zb_serial.c.

◆ zb_encode()

int zb_encode ( uint8_t *  destination,
uint8_t  device_number,
uint8_t  command_number,
int32_t  data 
)

Encodes a command according to Zaber's Binary Protocol Manual.

This function performs the necessary transposition of data bytes for transmission to Zaber devices using the binary protocol.

This function does not support the encoding of Message IDs.

Parameters
[out]destinationa pointer to an array to which to write the encoded command. Assumed to be at least 6 bytes long.
[in]device_numberthe number of the device to which to send the command.
[in]command_numberthe number of the command to be sent.
[in]datathe data to be sent along with the command. The contents of this field depend on the command number being sent. See the Binary Protocol Manual for info on specific commands.
Returns
Z_SUCCESS on success, or Z_ERROR_NULL_PARAMETER if destination is NULL.

Definition at line 25 of file zb_serial.c.

◆ zb_set_verbose()

void zb_set_verbose ( int  value)

Sets whether errors and extra info are reported to stderr.

Set value to 0 to disable all output. Additionally, you can compile this library with the macro NDEBUG defined, which will disable all output and skip checks to "verbose" altogether in the compiled code.

Parameters
[in]valuewhether (1) or not (0) the program should output error messages and info to stderr.

Definition at line 20 of file zb_serial.c.

Variable Documentation

◆ zb_verbose

int zb_verbose = 1
static

Definition at line 18 of file zb_serial.c.

Referenced by zb_set_verbose().