Jump to content
  • 0

USB-1208FS C language


ThomMoun

Question

Hello,

I am experiencing difficulties using the cbw library from Measurement Computing.

I am working with the USB1208FS Plus card, and my current goal is to turn on and off an RGB LED using this card. The LED is connected to a breadboard.

I am using the DevC++ IDE, but I am encountering errors in the makefile during compilation. Do you think I may have imported the library and the cbw.h header file incorrectly? Or is there a specific function that needs to be called before any other to ensure smooth compilation?

I also tried using CodeBlocks, but my header file is either not being detected, or I have an issue with the precompiled file cbw.h.gch.

If anyone can provide me with one or two hints, even if they are small, I would greatly appreciate it.

Thank you in advance,

TM

Link to comment
Share on other sites

9 answers to this question

Recommended Posts

  • 0

Hello,

I have yet to try to use DevC++ IDE or Code: Blocks on Windows. MCC uses Microsoft Visual Studio. I recommend downloading the free Community version of Visual Studio for your project. Create a 32-bit C console project and add to it the cbw.h, cbw32.lib files and your code file. Below is a simple 32-bit C console program that toggles D0 on FirstPortA and D0 or FirstPortB.

#include "stdafx.h"

/* Include files */
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include "cbw.h"


#define MAXNUMDEVS 100

void main()
{
    /* Variable Declarations */

    int ULStat = 0;

    int numberOfDevices = MAXNUMDEVS;
    DaqDeviceDescriptor inventory[MAXNUMDEVS];
    DaqDeviceDescriptor DeviceDescriptor;

    int BoardNum = -1;

    float Rev = (float)CURRENTREVNUM;
    ULStat = cbDeclareRevision(&Rev);
    cbErrHandling(PRINTALL, STOPALL);

    printf("Digital output demonstration\n\n");

    //Ignore InstaCal device discovery
    cbIgnoreInstaCal();

    //locate USB devices
    ULStat = cbGetDaqDeviceInventory(USB_IFC, inventory, &numberOfDevices);
    for (int i = 0; i < numberOfDevices; i++)
    {
        DeviceDescriptor = inventory[i];

        //Product IDs can be found in ULProps.txt located in 
        // C:\Program Files (x86)\Measurement Computing\DAQ

        if (DeviceDescriptor.ProductID == 0xE8) 
        {
            BoardNum = i;
            ULStat = cbCreateDaqDevice(BoardNum, DeviceDescriptor);
            printf("Device Name: %s\n", DeviceDescriptor.ProductName);
            break;
        }

    }

    if (BoardNum < 0)
    {
        printf("USB device not found...press any key to exit\n");
        getch();
        return;
    }

    ULStat = cbDConfigPort(BoardNum, FIRSTPORTA, DIGITALOUT);
    ULStat = cbDConfigPort(BoardNum, FIRSTPORTB, DIGITALOUT);

    unsigned short dataValue = 0;

    while (!_kbhit())
    {
        ULStat = cbDOut(BoardNum, FIRSTPORTA, dataValue);
        ULStat = cbDOut(BoardNum, FIRSTPORTB, dataValue);
        dataValue = 1;
        ULStat = cbDOut(BoardNum, FIRSTPORTA, dataValue);
        ULStat = cbDOut(BoardNum, FIRSTPORTB, dataValue);
        dataValue = 0;


        if (ULStat != 0){
            printf("Digital IO error\n");
            break;
        }

    }


    cbReleaseDaqDevice(BoardNum);

    printf("Completed...press any key to exit\n");
    getch();
}


 

Link to comment
Share on other sites

  • 0

Hello,

How can i use more than 2 ports as a digital output ? I am currently using FIRSTPORTA and FIRSTPORTB to turn on blue and green but as soon as i try using SECONDPORTA or B to turn on red color (config + out), a mistake appears (digital port number error). I noticed that on Instacal i can only test those two first ports, is it related ? How can i activate the others ?

Respectfully

 

TM

Link to comment
Share on other sites

  • 0

Hello,

Your device has two 8-bit ports, FIRSTPORTA and FIRSTPORTB, or 16 bits altogether. In my example code, the following two lines set D0 on FIRSTPORTA. 

dataValue = 1;
ULStat = cbDOut(BoardNum, FIRSTPORTA, dataValue);

dataValue is 0-255, depending on which bits you want to set. Using 128 will turn on D7, and 129 will turn on D0 & D7. 

You could use the cbDBitOut function instead. It uses only FIRSTPORTA, a bit number, and a bit level (0 or  1). Bit numbers are 0 to 15.

Best regards,

John

Link to comment
Share on other sites

  • 0

Hello,

Thanks, it works better with cbDBitOut !

Now am trying with analog sensors. By reading the datasheet i understand that it is not necessary to use a function as cbDConfigPort to prepare an analog port and i can directly use cbAOut and cbAIn. My sensor is a temperature sensor with 3 pins (adj, +, -), to collect its data i connected it to an anolog output to power it with 5V, and to an analog input to receive the voltage given back by the sensor. This solution does not work, so i think there are errors in my code or in my hardware configuration.

 

#define RANGE BIP5VOLTS

        ULStat = cbAOut(BoardNum, ADDA1, RANGE, 5);
        ULStat = cbAOut(BoardNum, ADDA2, RANGE, 1);

        ULStat = cbAIn(BoardNum, CHANNEL, RANGE, &temperature);

        if (ULStat != 0) {
            printf("Erreur lors de la lecture des données analogiques.\n");
            return 1;

i have the same issue with the distance sensor.

the temperature sensor  :

https://www.ti.com/lit/ds/symlink/lm335.pdf?ts=1685441744173&ref_url=https%3A%2F%2Fwww.ti.com%2Fproduct%2FLM335%2Fpart-details%2FLM335Z%2FNOPB%3Futm_source%3Dgoogle%26utm_medium%3Dcpc%26utm_campaign%3Docb-tistore-promo-asc_opn_en-cpc-storeic-google-wwe%26utm_content%3DDevice%26ds_k%3DLM335Z%2FNOPB%26DCM%3Dyes%26gclid%3DCjwKCAjwvdajBhBEEiwAeMh1U3xNuSXuxXPB2xmvuas6gYn7MyloL68uug54Y-4jCJYOqjNNP8sRTBoCuZoQAvD_BwE%26gclsrc%3Daw.ds

Link to comment
Share on other sites

  • 0

Hello,

I'm unfamiliar with the LM135 temperature sensor, but I did look at the datasheet. It would be better to power it with the +VO pin 30, which is +5 volts. The datasheet suggests powering it with the lowest possible current, and the application diagram suggests using a current-limiting resistor. For example, putting a 4.7k  ohm resistor in series with the +VO power will limit the current to just over one mA. It also suggests using a trim potentiometer for calibration, but you could devise a scheme to calibrate in software. 

Best regards,
John

Link to comment
Share on other sites

  • 0

Do you have the sensor's reference connected to the USB-1208FS-Plus ground pin, and is the output signal connected to CH0H (pin 1)? If I assume this is how you connect it, add the function cbAInputMode(BoardNum, SINGLE_END) before you drop into a loop to read the voltage.  Review the following code:

#include "stdafx.h"
/* Include files */
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include "cbw.h"


#define MAXNUMDEVS 100

void main()
{
    /* Variable Declarations */

    int ULStat = 0;

    int numberOfDevices = MAXNUMDEVS;
    DaqDeviceDescriptor inventory[MAXNUMDEVS];
    DaqDeviceDescriptor DeviceDescriptor;

    int BoardNum = -1;

    float Rev = (float)CURRENTREVNUM;
    ULStat = cbDeclareRevision(&Rev);
    cbErrHandling(PRINTALL, STOPALL);

    printf("Digital output demonstration\n\n");

    //Ignore InstaCal device discovery
    cbIgnoreInstaCal();

    //locate USB devices
    ULStat = cbGetDaqDeviceInventory(USB_IFC, inventory, &numberOfDevices);
    for (int i = 0; i < numberOfDevices; i++)
    {
        DeviceDescriptor = inventory[i];

        //Product IDs can be found in ULProps.txt located in 
        // C:\Program Files (x86)\Measurement Computing\DAQ

        if (DeviceDescriptor.ProductID == 0xE8) 
        {
            BoardNum = i;
            ULStat = cbCreateDaqDevice(BoardNum, DeviceDescriptor);
            printf("Device Name: %s\n", DeviceDescriptor.ProductName);
            break;
        }

    }

    if (BoardNum < 0)
    {
        printf("USB device not found...press any key to exit\n");
        getch();
        return;
    }

    float temp = 0.0f;
    cbAInputMode(BoardNum, SINGLE_ENDED);

    ULStat = cbDConfigPort(BoardNum, FIRSTPORTA, DIGITALOUT);
    ULStat = cbDConfigPort(BoardNum, FIRSTPORTB, DIGITALOUT);

    unsigned short dataValue = 0;

    while (!_kbhit())
    {
        ULStat = cbDOut(BoardNum, FIRSTPORTA, dataValue);
        ULStat = cbDOut(BoardNum, FIRSTPORTB, dataValue);
        dataValue = 1;
        ULStat = cbDOut(BoardNum, FIRSTPORTA, dataValue);
        ULStat = cbDOut(BoardNum, FIRSTPORTB, dataValue);
        dataValue = 0;


        if (ULStat != 0){
            printf("Digital IO error\n");
            break;
        }

        cbVIn(BoardNum, 0, BIP10VOLTS, &temp, 0);
        printf("%2.3f\n", temp);
        Sleep(100);

    }


    cbReleaseDaqDevice(BoardNum);

    printf("Completed...press any key to exit\n");
    getch();
}


 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...