Menu

opendmx mac c source problems

gabor papp
2007-06-25
2013-04-23
  • gabor papp

    gabor papp - 2007-06-25

    dear opendmx usb users,

    i'm trying to use an opendmx on a mac osx intel computer. i was not able to find any documentation on the subject apart from some sample code for windows that i have tried to port (http://prdownloads.sourceforge.net/opendmxusb/bc5_dmxusb_soft_141.zip?download). it uses the ftd2xx library, which also exists on mac, but the sample uses some win32 specific calls that i'm not sure how to port.

    // set RS485 for sendin
    FT_W32_EscapeCommFunction(ftHandle,CLRRTS);

    FT_W32_SetCommBreak(ftHandle);
    FT_W32_ClearCommBreak(ftHandle);

    i also attached the non-working code. opening the device seems to work, but i had no luck sending data. the lights turn on when my program is running, and turn off when it ends.

    any help would be appreciated.

    thanks in advance,
    gabor

    ------
                                                                                                                      #include <stdio.h>
    #include <stdarg.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include "ftd2xx.h"

    void panic(const char *panicstr, ...)
    {
        char msgbuf[256];
        va_list args;

        va_start(args, panicstr);
        vsnprintf(msgbuf, 256, panicstr, args);
        va_end(args);

        fprintf(stderr, "*panic: %s\n", msgbuf);
        exit(1);
    }

    FT_HANDLE opendmx_open(void)
    {
        FT_HANDLE fthandle;
        FT_STATUS ftstatus;
        char buf[512];

        ftstatus = FT_ListDevices(0, buf, FT_LIST_BY_INDEX | FT_OPEN_BY_DESCRIPTION);
        if (ftstatus != FT_OK)
            panic("FT_ListDevices %d", ftstatus);
       
        ftstatus = FT_Open(0, &fthandle);
        if (ftstatus != FT_OK)
            panic("FT_Open %d", ftstatus);

        ftstatus = FT_SetBaudRate(fthandle, 250000);
        if (ftstatus != FT_OK)
            panic("FT_SetBaudRate %d", ftstatus);

        ftstatus = FT_SetDataCharacteristics(fthandle, FT_BITS_8,
            FT_STOP_BITS_2, FT_PARITY_NONE);
        if (ftstatus != FT_OK)
            panic("FT_SetDataCharacteristics %d", ftstatus);   
       
        return fthandle;
    }

    void opendmx_send_frame(FT_HANDLE fthandle, unsigned numchannels,
        uint8_t *buf)
    {
        FT_STATUS ftstatus;
        DWORD num;
        int startcode = 0;
       
        ftstatus = FT_ClrRts(fthandle);
        if (ftstatus != FT_OK)
            panic("CrlRts %d", ftstatus);
       
        ftstatus = FT_SetBreakOn(fthandle);
        if (ftstatus != FT_OK)
            panic("SetBreakOn %d", ftstatus);
       
        ftstatus = FT_SetBreakOff(fthandle);
        if (ftstatus !=FT_OK)
            panic("SetBreakOff %d", ftstatus);
       
        ftstatus = FT_Write(fthandle, &startcode, 1, &num);
        if ((ftstatus != FT_OK) || (num != 1))
            panic("FT_Write %d %d", ftstatus, num);    
       
        ftstatus = FT_Write(fthandle, buf, numchannels, &num);
        if ((ftstatus != FT_OK) || (num != numchannels))
            panic("FT_Write %d %d", ftstatus, num);
    }

    void opendmx_close(FT_HANDLE fthandle)
    {
        FT_Close(fthandle);
    }

    int main(void)
    {
        FT_HANDLE h;
        uint8_t buf[512];
       
        h = opendmx_open();

        for (int i=0; i<256; i++)
        {
            buf[0] = 0;
            for (int j=1; j<512; j++)
            {
                buf[j] = i;
            }
            opendmx_send_frame(h, 512, buf);
        }

            opendmx_close(h);
        return 0;
    }

     
    • Nobody/Anonymous

      gabor,

      The header fie "ftd2xx.h" included in bc5_dmxusb_soft_141.zip is stale.
      Get the latest D2XX library (Universal D2XX0.1.0.dmg) from FTDI site, then install the library and use D2XX/bin/ftd2xx.h instead.
      HTH,

      yoshi

       

Log in to post a comment.