Edit on GitHub

Introduction

Zigbee SDK is a standard programming library to develop S/W communicates with RoboPlus Task with RoboPlus Task code. The characteristics of Zigbee SDK are as below.

API Reference

Device Control Method

Functions to control the communication devices

zgb_initialize

It initializes the communication devices and makes ready status.

int zgb_initialize( 
  int devIndex , 
);

Parameters

Return Values

Example

It shows how to initialize in Windows environment using COM3 port.

#define DEFAULT_PORTNUM 3   // COM3 

int result; 
result =  dxl_initialize( DEFAULT_PORTNUM); 

if( result == 1) 
{ 
  // Succeed to open Zig2Serial
}
else if( result == 0 )
{
  // Failed to open Zig2Serial
}

zgb_terminate

It terminates the communication devices.

void zgb_terminate();

Parameters

Return Values

Example

zgb_terminate();

Communication Method

Functions to transmit and receive the packet

zgb_tx_data

It initializes the communication devices and makes ready status.

int zgb_tx_data( 
  int data , 
);

Parameters

Value Name Contents
1 RC100_BTN_U Pressed value- U Button
2 RC100_BTN_D Pressed value- D Button
4 RC100_BTN_L Pressed value- L Button
8 RC100_BTN_R Pressed value- R Button
16 RC100_BTN_1 Pressed value- Button 1
32 RC100_BTN_2 Pressed value- Button 2
64 RC100_BTN_3 Pressed value- Button 3
128 RC100_BTN_4 Pressed value- Button 4
256 RC100_BTN_5 Pressed value- Button 5
512 RC100_BTN_6 Pressed value- Button 6

Return Values

Example

int TxData; 
int result 
TxData = 1; 
  
result = zgb_tx_data(TxData); 
  
if( result == 0) 
{ 
   // Failed to transmit 
} 
  
else if( result ==1) 
{ 
   // Succeed to transmit 
}

zgb_rx_check

It checks whether the data is arrived to the communication devices or not.

int zgb_rx_check();

Parameters

Return Values

Example

int resut;
result = zgb_rx_check();
if( result == 1 )
{
  // Succeed to data recieved
}
else if( result == 0 )
{
  // Failed to data recieved
}

zgb_rx_data

It receives data from the communication devices. First of all, the data reception must be chacked using zgb_rx_check in order to receive the latest data.

int zgb_rxdata( );

Parameters

Return Values

Value Name Contents
1 RC100_BTN_U Pressed value- U Button
2 RC100_BTN_D Pressed value- D Button
4 RC100_BTN_L Pressed value- L Button
8 RC100_BTN_R Pressed value- R Button
16 RC100_BTN_1 Pressed value- Button 1
32 RC100_BTN_2 Pressed value- Button 2
64 RC100_BTN_3 Pressed value- Button 3
128 RC100_BTN_4 Pressed value- Button 4
256 RC100_BTN_5 Pressed value- Button 5
512 RC100_BTN_6 Pressed value- Button 6

Example

int RxData;
 
if(zgb_rx_check() == 1)
{
  // Get data verified
  RxData = zgb_rx_data();
}

Platform Porting

Zigbee SDK provides sources so that the users can perform porting to various platforms.

The Structure of Source

If you want to do Porting, you must actualize the following functions depending on each platform.

zgb_hal_open

It actualizes the available routine by initializing the communication devices.
zgb_initialize activates the communication devices through zgb_hal_open.

int zgb_hal_open( 
  int devIndex, float baudrate 
)

Parameters

Return Values

zgb_hal_close

It actualizes the routine that let other application programs use by terminating the communication devices.
zgb_terminate terminates the communication devices through this function.

void zgb_hal_close();

Parameters

Return Values

zgb_hal_tx

It actualizes the routine that transmits packet through the communication devices.

int zgb_hal_tx( 
  unsigned char *pPacket, int numPacket 
);

Parameters

Return Values

zgb_hal_rx

It actualizes the routine that takes out packet from the received buffers of the communication devices.

int zgb_hal_rx( 
  unsigned char *pPacket, int numPacket 
);

Parameters

Return Values

ZIG2Serial

For Windows

System Requirements

Composing Folder

Setting Environment Variables

If you want to execute a program developed by Zigbee SDK, zigbee.dll is required.
zigbee.dll is included in bin folder of Zigbee SDK.
If you register the location of zigbee.dll as an environment variable for Windows, dll is not necessary when the program is executed.
If you do not want to register the location of dll as environment variables, the program and dll must be distributed together.

  1. If you go into Control Panel - System - Advanced, you can find Environment Variables button as below.

  2. Find Path category in System Variables, and then click Edit button.

  3. As the example below, add bin folder with semicolon to the end of existing variable values. Please be careful not to change or delete the existing variable values. The example shows the things are added, assuming the location of DLL file is C:\Project\bin.

For Linux

System Requirements

Composing Folder

Zigbee SDK Build

If library is built by “make” command in ZigbeeSDK/src folder, it is automatically copied to ZigbeeSDK/lib.

Visual C++

This is an example for Visual C++. This example has been tested in Visual Studio 2005.

Setting Environment

The environment must be set in C++ to execute the examples.

Registering the Path

The location of Zigbee SDK must be registered in Visual Studio.

  1. Select Tools -> Options in the menu.

  2. Click Project & Solution -> VC++ Directory.

  3. Change the “Directory mark of the next file” part as “Include File,” and then add the ZigbeeSDK-installed folder by clicking the icon where “2” is marked. (For example, C:\ZigbeeSDK\import)

  4. Change the “Directory mark of the next file” part as “Library File,” and then add the ZigbeeSDK-installed folder by clicking the icon where “2” is marked. (For Example, C:\ZigbeeSDK\import)

Using Zigbee SDK

  1. Include Header file. Add #include “zigbee.h” on source file.
  2. Include Library file. Add #pragma comment(lib, “zigbee.lib”) on source file, or add zigbee.lib on the module of Link tap’s input in project characteristics.
  3. Use functions.

Call the necessary functions from the source. Please refer to API Reference on the usage of each function.

Send/Receive Example

Preparation

Used Zigbee modules are set to 1:1 communication for each other.
Download tsk file appropriate to the controller type so that the controller can respond.

Source

Initialization
// Open device
if( zgb_initialize(DEFAULT_PORTNUM) == 0 )
{
  printf( "Failed to open Zig2Serial!\n" );
}
else
{
  printf( "Succeed to open Zig2Serial!\n" );
}

The source above checks whether the initialization is done properly or not.
Since the initialization is succeeded, 1 is returned and if it is failed, 0 is returned, the failed source is included in “If” sentence, and the succeeded source goes to “Else” sentence. zgb_initialize is called from Zigbee API.
DEFAULT_PORTNUM means the number of a connected device.
DEFAULT_PORTNUM must be set depending on the user’s system status, and it is originally set to COM3.

Termination
// Close device
zgb_terminate();

The source above terminates communication with the controller’s communication device. zgb_terminate is called from Zigbee API.

Tramsmitting Pakcet
if (zgb_tx_data(TxData) == 0)
{
  printf( "Failed to transmit\n" );
}

The source above makes Zigbee module to transmit the packet to the controller.
Using zgb_tx_data function among Zigbee API, the users transmit packets and the results are returned.
If the returned value is 1, the transmission is successful, and if it is 0, it means transmission failure.
TxData means the value users transmit to the controller.

Receiving Packet
for( i=0; i < TIMEOUT_TIME; i++)
{
  // Verify data recieved
  if(zgb_rx_check() == 1)
  {
    // Get data verified
    RxData = zgb_rx_data();
    printf( "Recieved: %d\n", RxData );
    break;
  }
  Sleep(1);
}

The source above makes Zigbee module to receive the packet from the controller.
Using zgb_rx_check function, the users check whether the packet is received or not.
If the returned value is 1, the reception is successful, and if it is 0, it means the reception failure.
If the packet is received (if the returned value is 1), using zgb_rx_data function, the received data is saved in RxData variable.
If the packet is not received, it spins the loop as much as the TIMEOUT_TIME using Sleep() function after providing the delay time of 1ms.
TIMEOUT_TIME is initially set to 1000, and the packet is waited for 1 second in this example source.

Visual Basic

This is an example for Visual Basic. This example has been tested in Visual Studio 2005.

Setting Environment

The environment must be set in Visual Basic to execute the examples.

Using Zigbee SDK

  1. In the Solution Browser, selcect Add -> Existing Category by clicking the right button of the mouse on the Projct File name.

  2. Add zigbee.vb file. zigbee.vb is in the import folder where ZigbeeSDK is saved. (For example, C:\ZigbeeSDK\import\zigbee.vb)

  3. Check whether the zigbee.vb is added or not.

  4. Use ZigbeeAPI functions. Please refer to API Reference on the usage of each function.

Send/Receive Example

Preparation

Used Zigbee modules are set to 1:1 communication for each other. Download tsk file appropriate to the controller type so that the controller can respond.

Source

Initialization
'Open device
If (zgb_initialize(DEFAULT_PORTNUM) = 0) Then
  Console.WriteLine("Failed to open Zig2Serial!")
  Exit Sub
Else
  Console.WriteLine("Succeed to open Zig2Serial!")
End If

The source above checks whether the initialization is done properly or not.
Since the initialization is succeeded, 1 is returned and if it is failed, 0 is returned, the failed source is included in “If” sentence, and the succeeded source goes to “Else” sentence.
zgb_initialize is called from Zigbee API.
DEFAULT_PORTNUM means the number of a connected device.
DEFAULT_PORTNUM must be set depending on the user’s system status, and it is originally set to COM3.

Termination
'Close device
zgb_terminate()

The source above terminates communication with the controller’s communication device. zgb_terminate is called from Zigbee API.

Transmitting Packet
If (zgb_tx_data(TxData) = 0) Then
  Console.WriteLine("Failed to transmit")
End If

The source above makes Zigbee module to transmit the packet to the controller.
Using zgb_tx_data function among Zigbee API, the users transmit packets and the results are returned.
If the returned value is 1, the transmission is successful, and if it is 0, it means transmission failure.
TxData means the value users transmit to the controller.

Receiving Packet
For i = 1 To TIMEOUT_TIME
  'Verify data recieved
  If (zgb_rx_check() = 1) Then
    'Get data verified
    RxData = zgb_rx_data()
    Console.WriteLine("Recieved: " & RxData & "")
    Exit For
  End If
  Sleep(1)
Next i

The source above makes Zigbee module to receive the packet from the controller.
Using zgb_rx_check function, the users can check whether the packet is received or not.
If the returned value is 1, the reception is successful, and if it is 0, it means reception failure.
If the packet is received (if the returned value is 1), using zgb_rx_data function, the received data is saved in RxData variable.
If the packet is not received, it spins the loop as long as the Timeout_Time using Sleep() function after providing the delay time of 1ms.
TIMEOUT_TIME is initially set to 1000, and the packet is waited for 1 second in this example source.

Visual C Sharp(#)

This is an example for Visual C#. This example has been tested in Visual Studio 2005.

Setting Environment

The environment must be set in Visual C# to execute the examples.

Using Zigbee SDK

  1. In the Solution Browser, select Add -> Existing Category by clicking the right button of the mouse on the Project File name.

  2. Add Zigbee.cs file. Zigbee.cs is in the import folder where ZigbeeSDK is saved. (For example, C:\ZigbeeSDK\import\Zigbee.cs)

  3. Check whether the Zigbee.cs is added or not.

  4. Add using ROBOTIS, and then use ZigbeeAPI funcitons. Please refer to API Reference on the usage of each function.

Send_Receive

Preparation

Used Zigbee modules are set to 1:1 communication for each other. Download tsk file appropriate to the controller type so that it can respond.

Source

Initialization
// Open device
if (zigbee.zgb_initialize(DEFAULT_PORTNUM) == 0)
{
  printf( "Failed to open Zig2Serial!\n" );
}
else
{
  printf( "Succeed to open Zig2Serial!\n" );
}

The source above checks whether the initialization is done properly or not.
Since the initialization is succeeded, 1 is returned and if it is failed, 0 is returned, the failed source is included in “If” sentence, and the succeeded source goes to “Else” sentence.
zgb_initialize is called from Zigbee API.
DEFAULT_PORTNUM means the number of a connected device.
DEFAULT_PORTNUM must be set depending on the user’s system status, and it is originally set to COM3.

Termination
// Close device
zigbee.zgb_terminate();

The source above terminates communication with the controller’s communication device. zgb_terminate is called from Zigbee API.

Transmitting Packet
if (zigbee.zgb_tx_data(TxData) == 0)
{
  Console.WriteLine("Failed to transmit");
}

The source above makes Zigbee module to transmit the packet to the controller.
Using zgb_tx_data function among Zigbee API Functions, the users transmit packets and the results are returned.
If the returned value is 1, the transmission is successful, and if it is 0, it means transmission failure.
TxData means the value users transmit to the controller.

Receiving Packet
for( i=0; i < TIMEOUT_TIME; i++)
{
  // Verify data recieved
  if(zigbee.zgb_rx_check() == 1)
  {
    // Get data verified
    RxData = zigbee.zgb_rx_data();
    Console.WriteLine("Recieved: {0:d}", RxData);
    break;
  }
  Thread.Sleep(1);
}

The source above makes Zigbee module to receive the packet from the controller.
Using zgb_rx_check function, the users check whether the packet is received or not.
If the returned value is 1, the reception is successful, and if it is 0, it means reception failure.
If the packet is received (if the returned value is 1), using zgb_rx_data function, the received data is saved in RxData variable.
If the packet is not received, it spins the loop as much as the Timeout_Time using Sleep() function after providing the delay time of 1ms.
TIMEOUT_TIME is initially set to 1000, and the packet is waited for 1 second in this example source.

gcc

Linux gcc used for this example.

Setting Environment

Using Zigbee API

  1. Designate header file. Add #include <zigbee.h> to source file.
  2. Call functions. Call necessary functions for the source. Please refer to API Reference on the usage of each function.

Send/Receive Example

Preparation

Zig2Serial and ZIG-100 must be connected to USB2DYNAMIXEL.
Also, there must be the controller or other communication device which can communicatte with ZIG-100 communication module connected to Zig2Serial.

Source

Initialization
if( zgb_initialize(DEFAULT_DEVICEINDEX) == 0 )
{
  printf( "Failed to open Zig2Serial!\n" );
  printf( "Press any key to terminate...\n" );
  getchar();
  return 0;
}
else
  printf( "Succeed to open Zig2Serial!\n" );

The source above checks whether the initialization is done properly or not.
Since the initialization is succeeded, 1 is returned and if it is failed, 0 is returned, the failed source is included in “If” sentence, and the succeeded source goes to “Else” sentence.
zgb_initialize is called from zigbee API.
DEFAULT_DEVICEINDEX is the device index of Linux communication devices; the basic value is 1.
DEFAULT_DEVICEINDEX must be set appropriately to the users’ status.
Baud Rate is fixed to 57600.

Termination
// Close device
zgb_terminate();

The source is for termination. The connection is terminated by calling zgb_teminate function from zigbee API.

Transmitting Data
// Wait user's input
printf( "Input number to transmit: " );
if(scanf("%d", &TxData));
  // Transmit data
if(zgb_tx_data(TxData) == 0)
  printf( "Failed to transmit\n" );

The source above is to transmit the inputted values by users through zigbee. zgb_tx_data function is called form zigbee API.

Receiving Data
for( i=0; i < TIMEOUT_TIME; i++)
{
  // Verify data recieved
  if(zgb_rx_check() == 1)
  {
    // Get data verified
    RxData = zgb_rx_data();
    printf( "Recieved: %d\n", RxData );
    break;
  }
  sleep(1);
}

The source above is to receive data before the set TIMEOUT. zgb_rx_check and zgb_rx_data functions are called from zigbee API.

CM-510/700

Zigbee SDK for CM-510/700 is included in Embedded C.
Please refer to RC100/ZigBee