Advertisement
Guest User

Untitled

a guest
Jul 24th, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.97 KB | None | 0 0
  1. /*
  2.  * DEMO.CPP - Demo code on how to use the vusbdmx.dll with load-time
  3.  * dynamic linking. If the dll is not present this demo will not start.
  4.  * Link you code against vusbdmx.lib.
  5.  *
  6.  * This file is provided as is to allow an easy start with the
  7.  * vusbdmx driver and dll.
  8.  *
  9.  * In case of trouble please contact driver@lighting-solutions.de or
  10.  * call +49/40/600877-51.
  11.  */
  12.  
  13. #define WIN32_LEAN_AND_MEAN
  14. #include <windows.h>
  15. #include <stdio.h>
  16. #include <conio.h>
  17.  
  18. /* the vusbdmx include file with all function definitions */
  19. #include "vusbdmx.h"
  20.  
  21. /*
  22.  * Send a DMX512 frame
  23.  *
  24.  * slots is the number of slots to send incl. startcode
  25.  * buffer contains the dmx512 frame to send incl. startcode
  26.  */
  27. static void tx_dmx(const HANDLE h, const USHORT slots, const PUCHAR buffer)
  28. {
  29.     UCHAR  status;  // return status of the sending process
  30.  
  31.     if (   h == INVALID_HANDLE_VALUE
  32.         || slots > 513)
  33.         return;
  34.  
  35.     /* send a DMX512 frame with 200us break and 20us MaB */
  36.     if (!vusbdmx_tx(h, 0, slots, buffer, VUSBDMX_BULK_CONFIG_BLOCK, 100e-3,
  37.                     200e-6, 20e-6, 0, &status))
  38.         printf("ERROR: vusbdmx_tx() error\n");
  39.     /* check transaction status, see usbdmx.h for details */
  40.     else if (!VUSBDMX_BULK_STATUS_IS_OK(status))
  41.         printf("ERROR: vusbdmx_tx(): status = 0x%02x\n", status);
  42. }
  43.  
  44. /*
  45.  * Send a special frame with 57600 baud and trailing break
  46.  *
  47.  * slots is the number of slots to send
  48.  * buffer contains the frame to send
  49.  */
  50. static void tx_special(const HANDLE h, const USHORT slots, const PUCHAR buffer)
  51. {
  52.     UCHAR  status;  // return status of the sending process
  53.  
  54.     if (   h == INVALID_HANDLE_VALUE
  55.         || slots > 513)
  56.         return;
  57.  
  58.     /****
  59.      * 1. send frame without break and mab, send data with 57600 baud */
  60.     if (!vusbdmx_tx(h, 0, slots, buffer, VUSBDMX_BULK_CONFIG_BLOCK | VUSBDMX_BULK_CONFIG_SPEED | VUSBDMX_BULK_CONFIG_NORETX, 100e-3,
  61.                     0e-6, 0e-6, 0, &status))
  62.         printf("ERROR (data): usbdmx_tx() error\n");
  63.     /* check transaction status, see usbdmx.h for details */
  64.     else if (!VUSBDMX_BULK_STATUS_IS_OK(status))
  65.         printf("ERROR (data): vusbdmx_tx(): status = 0x%02x\n", status);
  66.  
  67.     /****
  68.      * 2. send 500us break */
  69.     if (!vusbdmx_tx(h, 0, 0, buffer, VUSBDMX_BULK_CONFIG_BLOCK | VUSBDMX_BULK_CONFIG_SPEED | VUSBDMX_BULK_CONFIG_NORETX, 100e-3,
  70.                     500e-6, 0e-6, 0, &status))
  71.         printf("ERRUR (berak): usbdmx_tx() error\n");
  72.     /* check transaction status, see usbdmx.h for details */
  73.     else if (!VUSBDMX_BULK_STATUS_IS_OK(status))
  74.         printf("ERROR (break): vusbdmx_tx(): status = 0x%02x\n", status);
  75. }
  76.  
  77. /*
  78.  * main demo entry: open a Rodin1 and send some data
  79.  */
  80. int main(int argc, char* argv[])
  81. {
  82.     HANDLE h;               /* handle to one interface */
  83.     UCHAR  bufnew[0x201];   /* buffer for one dmx512 frame incl. startcode */
  84.     USHORT version;         /* version number in BCD */
  85.     WCHAR  product[64];     /* product string */
  86.  
  87.     /* verify VUSBDMX dll version */
  88.     if (!VUSBDMX_DLL_VERSION_CHECK())
  89.     {
  90.         printf("VUSBDMX.DLL version does not match, giving up!\n");
  91.         printf("found %i, expected %i\n", vusbdmx_version(), VUSBDMX_DLL_VERSION);
  92.         return 1;
  93.     }
  94.  
  95.     printf("Using VUSBDMX.DLL version 0x%x\n\n", vusbdmx_version());
  96.  
  97.     /* open the first devices (number 0) */
  98.     if (!vusbdmx_open(0, &h))
  99.     {
  100.         printf("no usbdmx-interface available, giving up!\n");
  101.         return 1;
  102.     }
  103.  
  104.     if (!vusbdmx_product_get(h, product, sizeof(product)))
  105.         printf("ERROR: reading product string failed\n");
  106.  
  107.     vusbdmx_device_version(h, &version);
  108.  
  109.     /* identify the interface */
  110.     printf("The interface found is a %ws version 0x%04x\n", product, version);
  111.     putchar('\n');
  112.  
  113.     // prepare the buffer with all 0
  114.     memset(bufnew, 0, sizeof(bufnew));
  115.  
  116.     printf("press any key to quit demo\n");
  117.  
  118.     while (!_kbhit())
  119.     {
  120.         /*
  121.          * send a dmx512 frame with 513 slots (incl. startcode)
  122.          */
  123.         tx_dmx(h, 513, bufnew);
  124.  
  125.         /*
  126.          * send special frame with 100 slots
  127.          */
  128.         tx_special(h, 100, bufnew);
  129.     }
  130.  
  131.  
  132.     /* close the interface */
  133.     vusbdmx_close(h);
  134.  
  135.     printf("demo code finished\n");
  136.  
  137.     getchar();
  138.     return 0;
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement