Custom Data Links

A custom data link can be implemented to create a communications link between a Windows PC and an embedded microcontroller device. The data link component handles all of the application specific messaging protocol for both the device and the PC application. The data link can use any of the following transport interfaces.

  • USB
    A native USB connection that uses the USB device stack within the microcontroller device. The PC application uses the USBDevice class provided by the DZX.Devices.dll library for communications.
  • FTDI D2XX
    A USB-to-Serial connection that uses the UART driver within the microcontroller device. The PC application uses the FTDIDevice class provided by the DZX.Devices.dll for communications.
  • Standard Serial Port
    A serial connection that uses the UART driver within the microcontroller device. The PC application uses the standard SerialPort class from the .NET framework for communications.

The following steps describe how to implement a custom data link.

Step 1. Define the Protocol

Begin by using the Data Link Editor tool to define a messaging protocol for the data link. The tool will generate code files for both the device and the PC software for the data link.

Step 2. MCU Device Implementation

Add the following code files to your embedded software project:

  • datalink.c/.h
    Add these files to provide the base support for any data link. These files are found within the '<SDK>/Source/DataLink' directory.
  • datalink_usb.c/.h
    Add these files if using the data link over a native USB interface. These files provide a basic implementation of a data link over native USB. These files are found within the '<SDK-Archive>/Source/DataLink' directory.
  • datalink_uart.c/.h
    Add these files if using the data link over a UART interface. These files provide a basic implementation of a data link over a UART. These files are found within the '<SDK>/Source/DataLink' directory.
  • datalink_app.c/.h
    Add these files for support of the custom messaging protocol. These files are generated by the Data Link Editor tool.

Code will need to be added to initialize and open the data link for communications.

If the data link is using the native USB interface, the data link will use a pair of endpoints, one for transmitting and the other for receiving. The code below illustrates how to initialize and open a USB data link.

#include "DataLink/datalink_usb.h"
#include "datalink_app.h"
#include <assert.h>


static USBLINK link;                                /* Allocate an instance of a USB data link */

void APP_Example(void)
{
    STATUS status;


    status = USBLINK_Create(&link,                  /* Create and initialize an instance of the data link over USB */
                            DATALINK_CreateApp,     /* Function to initialize the application specific data link */
                            0,                      /* USB port number */
                            0x0000,                 /* USB vendor ID */
                            0x0010,                 /* USB product ID */
                            1);                     /* USB endpoint number */

    assert(status == SUCCESS);

    status = USBLINK_Open(&link);                   /* Open and start communications on the USB data link */
    assert(status == SUCCESS);
}

If the data link is using a UART interface, the data link will use an instance of the UART driver. The code below illustrates how to initialize and open a UART data link.

#include "DataLink/datalink_uart.h"
#include "datalink_app.h"
#include <assert.h>


static UARTLINK link;                               /* Allocate an instance of a UART data link */

void APP_Example(void)
{
    STATUS status;


    status = UARTLINK_Create(&link,                 /* Create and initialize an instance of the data link over USB */
                            DATALINK_CreateApp);    /* Function to initialize the application specific data link */

    assert(status == SUCCESS);

    status = UARTLINK_Open(&link,                   /* Open and start communications on the USB data link */
                           0,                       /* UART port number */
                           115200);                 /* UART baud rate */
                  
    assert(status == SUCCESS);
}

With the link initialized and open, the link will automatically process any received data and will call the respective handers for each message. Handler functions need to be added within the MCU application to handle each message that can be received by the device.

For convenience, use the embedded handlers dialog within the Data Link Editor to generate a function template for each of the possible handler functions. The handler function templates can be pasted anywhere into the MCU application. The prototypes for the handler functions are automatically generated and placed within the header file (e.g. datalink_app.h).

At this point, the MCU application can be built and loaded into the target device.

Step 3. Testing and Visualization

You can visualize and transfer messages to the device using the USB Terminal tool. The USB Terminal can load and interpret the custom data link definition to properly format messages transferred to or from the device.

See the Data Link View topic within the USB Terminal.

Step 4. Custom PC Application

The Data Link Editor tool also generates the code required to make a custom .NET application. The code will be in a single file that is named after the data link (e.g. DataLinkApp.cs). The generated code will contain all of the methods required for transmitting each of the messages that can be sent from the application. The code will also contain events for each of the messages that can be received by the application.

See the .NET Data Link topic for more information about using the .NET data link software.