Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

6533 Board - setting all the ports in a group of two ports

Hello,
 
I am using a 6533 Board with the I/O Ports configured into 2 Groups - one for Input one for Output. (The two groups are externally connected together for testing reasons).
To output data I use DIG_Block_Out, which uses a i16 buffer.
When I try to load the buffer with 0xFFFF (set all lines in the group) it causes an overflow in the buffer (i16 ranging max till 32,767). And when I read the input group in the input buffer (also i16) I receive -193 instead of the 65,535 I would expect.
Can anyone please tell me how can I correctly set all the lines in a Group?
 
Thank you very much,
Alexandra
Message 1 of 9
(7,448 Views)

Hi Alexandra,

I hope all is well with you.  From my understanding you are using Traditional NI-DAQ, Measurement Studio (Visual C++) to do digital write and read on your NI 6533.  You mentioned that you have connected your digital output to your digital input to read in what you wrote out.  I am assuming that you are using windows XP.

I would like to give a brief description of the DIG_Block_out function that you are using.  If you would like more information on it, you can find it in the Traditional NI-DAQ C Function Help.  You can get to this help by going to Start>>Programs >>National Instruments>>NI-DAQ>>Traditional NI-DAQ Function Help.

DIG_Block_Out
DIG_Block_Out initiates an asynchronous transfer of data from your buffer to a specified group. The hardware is responsible for the handshaking details. Call DIG_Grp_Config for the DIO-32F and 653X devices, or DIG_SCAN_Setup for the other devices at least once before calling DIG_Block_Out to select the group configuration for handshaking.

In other words, DIG_Block_Out takes an specified amount of data, and throws it out using the current setup of the board, once initiated, the call to the driver returns, and program flow continues.

It sounds like you are developing code for this application.  My suggestion is for you to upgrade to the current driver for your hardware.  It is much easier to develop in and there are already examples that do what you are trying to do.  You can download the DAQmx driver for free online and use it with Measurement studio and your 6533.

What value to you get when you write just $FF?

 

 

Regards,

Ima
Applications Engineer
National Instruments
LabVIEW Introduction Course - Six Hours
Getting Started with NI-DAQmx
0 Kudos
Message 2 of 9
(7,434 Views)

Hello,

Sorry for the delay, but I had something else to work on.

When I write 0x00FF it receives back 0x00FF. So that works. But for 0xFF00 I don't receive 0xFF00.

But if the board has the option to group the ports in order to be able to send 16b or even 32b, then it should be able to be done. However, the functions avaiable for sending/receiving data use i16 (a signed type) which inables me to set all the bits of the grouped ports.

Here is the pice of code I use:

iStatus = 0;
iDevice = 4;

 for (i=0;i<200000;i++)
 {
  piBuffer[i] = 0;
  outputBuffer[i] = 0;
 }

 ulCount = 200000;
 numdone = 1;

    iGroupSize = 2;
    iPgConfig =1;
    iReqSource = 2;
    iPgTB =1;
    iReqInt = 10;
    iExtGate = 0;
    iIgnoreWarning = 0;
    iYieldON = 1;
    iGroupOut = 1;
    iGroupIn = 2;
    iPortOut = 0;
    iPortIn = 2;
    iDirIn = 0;
    iDirOut = 1;
    iDeviceCode;
    iReqSourceOut = 0;
    wordTransferCount = 200000;
    iModeOn = 1;
    iOldDataStop = 0;
    iPartialTransfers = 1;
    iNchanges = 2;  

    iStatus = Init_DA_Brds(iDevice, &iDeviceCode);
    iRetVal = NIDAQErrorHandler(iStatus, "Init_DA_Brds", iIgnoreWarning);
   

// Configure port 0 as group 1 and as an output port
//
    iStatus = DIG_Grp_Config(iDevice, iGroupOut, iGroupSize, iPortOut, iDirOut);
    iRetVal = NIDAQErrorHandler(iStatus, "DIG_Grp_Config", iIgnoreWarning);

// Configure internally timed pattern generation with timebase -3,
// interval 20 ( final clock = 20 MHZ), and no external gating.
//
    iStatus = DIG_Block_PG_Config(iDevice, iGroupOut, 0, iReqSourceOut, iPgTB, iReqInt, iExtGate);
    iRetVal = NIDAQErrorHandler(iStatus, "DIG_Block_PG_Config", iIgnoreWarning);

    iStatus = DIG_DB_Config(iDevice, iGroupOut, 1,0,1);
    iRetVal = NIDAQErrorHandler(iStatus, "DIG_DB_Config", iIgnoreWarning);
          
    iStatus = Set_DAQ_Device_Info(iDevice, ND_DATA_XFER_MODE_DIO_GR2, ND_INTERRUPTS);
    iRetVal = NIDAQErrorHandler(iStatus, "Set_DAQ_Device_Info", iIgnoreWarning);


    /* Clear all messages */
    iStatus = Config_DAQ_Event_Message (iDevice, 0, "DIGRP2", 1, 1, 0, 0, 0, 0, 0, 0, (DWORD)MyMessage);
  
    iRetVal = NIDAQErrorHandler(iStatus, "Config_DAQ_Event_Message", iIgnoreWarning);
 
    /* Configure the group for port assignment (2) and direction (input) */
    iStatus = DIG_Grp_Config(iDevice, iGroupIn, iGroupSize, iPortIn,  iDirIn);
    iRetVal = NIDAQErrorHandler(iStatus, "DIG_Grp_Config", iIgnoreWarning);

    /* Configure for Change Detection */
    iStatus = DIG_Block_PG_Config(iDevice, iGroupIn, iPgConfig,iReqSource, iPgTB, iReqInt, iExtGate);
    iRetVal = NIDAQErrorHandler(iStatus, "DIG_Block_PG_Config",iIgnoreWarning);
    
    /* Configure for double buffering */
    iStatus = DIG_DB_Config(iDevice, iGroupIn, iModeOn, iOldDataStop, iPartialTransfers);
    iRetVal = NIDAQErrorHandler(iStatus, "DIG_DB_Config", iIgnoreWarning);
     
    
 iStatus = Config_DAQ_Event_Message (iDevice, 1, "DIGRP2", 1, iNchanges, 1, 0, 0, 0, 0, 0, (DWORD)MyMessage);
    iRetVal = NIDAQErrorHandler(iStatus, "Config_DAQ_Event_Message", iIgnoreWarning); 

}

Send_Receive::Send(i16 msg)
{
 outputBuffer[0] = msg;
 iStatus = DIG_Block_Out(iDevice, iGroupOut, outputBuffer, wordTransferCount);
    iRetVal = NIDAQErrorHandler(iStatus, "DIG_Block_Out", iIgnoreWarning);
 iStatus = DIG_Block_Clear(iDevice, iGroupOut);
}

Send_Receive::Receive()
{
 int i;
 unsigned long time;

 for (i=0;i<32;i++)
  piBuffer[i] = 0;

 iStatus = DIG_Block_In(iDevice, iGroupIn, piBuffer, ulCount);
 iRetVal = NIDAQErrorHandler(iStatus, "DIG_Block_In", iIgnoreWarning); 
 for (i=0;i<32;i++)
  printf("%d",piBuffer[i]);
 printf("\n");
 iStatus = DIG_Block_Clear(iDevice, iGroupIn);
}

Thank you for the support,

Alexandra Mazilu

0 Kudos
Message 3 of 9
(7,390 Views)
Hi Alexandra,

It sounds like your data type is a signed integer which would mean that -193 = xFFFFFFFFFFFFFF3F. 

If that is the case, it looks like you are reading the correct values from the lines in the group.  Here is a wikipedia article talking about signed and unsigned integers.

Is this the expected value that you want?

Thank You,

Nick F.
Applications Engineer
0 Kudos
Message 4 of 9
(7,373 Views)
Hello,

Well I don't doubt that the pins get the right data, but the functions available for reading the ports use this type of data (i16) which is a signed type. In order to read the 16 bits of a group of 2 ports I need an unsigned 16 bits type.
Or maybe I need to shift the received data with 8bits...I will try this...

Alexandra

Message Edited by ale_m on 11-28-2007 11:23 AM
0 Kudos
Message 5 of 9
(7,371 Views)

Hi Alexandra,

You do not mention what exactly you get when you enter xFF00.  Do you receive the -193 and a buffer overflow?  I believe the problem is with the grouping of the channels since FF works but FFFF does not.  I would like you to also try entering 5555 and then post back the result.

Regards,

Ima
Applications Engineer
National Instruments
LabVIEW Introduction Course - Six Hours
Getting Started with NI-DAQmx
0 Kudos
Message 6 of 9
(7,346 Views)

Hello,

For 0xFF00 I get -256.

The thing is I haven't connected 2 pins (PortA pins 6,7 with PortC pins 6,7), because I run out of wire :P. That means that for 0x00FF I receive 63 = 0x003F (for 0x0FFF I get 0x0F3F). And that's probably why I receive -193. If I convert this number using the Windows Calculator, from decimal to hexadecimal, it look like this: 0xFF3F, which is correct.

So the result read is correct, only the way it is displayed is not ok. I'll try some bit shifting.

Thanks,

Alexandra

0 Kudos
Message 7 of 9
(7,341 Views)

OK, I've solved the problem.

I used an additional u16 variable:

u16 x;

x = piBuffer[i];

And now x contains the proper value!

Thanks,

Alexandra

0 Kudos
Message 8 of 9
(7,340 Views)

Hi Alexandra,

I am glad to hear that everything is working.  Thank you for posting the solution for the benefit of others.

I wish you the best on your application. Smiley Happy

Regards,

Ima
Applications Engineer
National Instruments
LabVIEW Introduction Course - Six Hours
Getting Started with NI-DAQmx
0 Kudos
Message 9 of 9
(7,310 Views)