LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

PCI 6528 Digital output

Hi,
I am a beginner in this field. Sorry for my lack of knowledge.
I want to control the Digital output through the binary switch in application software Labwindows/CVI. Is the following flow right?
1. get the attribute value of binary switch (1 or 0)
GetCtrlVal(panel,PANEL_BINARYSWITCH,&data);
2. create task
DAQmxCreateTask("BINARY",&TaskHandle)
3. creat channel
 DAQmxCreateDOChan (TaskHandle, "Dev1/port3/line0", "binary", DAQmx_Val_ChanPerLine);  
 4. write value to line
 DAQmxWriteDigitalU8 (TaskHandle, 1, 1, 10.0, DAQmx_Val_GroupByChannel, data, , NULL);  

Do I need to do anything in MAX?
Thanks,
Joyce
0 Kudos
Message 1 of 8
(4,644 Views)
Hi Joyce,
 
Since you are writing a single static value to the digital line I'd recommend you to use DAQmxWriteDigitalScalarU32.
Why bother with parameters like # samples per channel, data layout, etc. ?
 
You can use MAX to be sure about the name of your device, "Dev1" in your case. Otherwise your code would be sufficient.
 
Btw, it is not a must to give names to channels you can use an empty string ("") instead of  "binary" unless you really to name them.
 
Hope this helps,
S. Eren BALCI
IMESTEK
0 Kudos
Message 2 of 8
(4,637 Views)
Thanks for your reply.
I don't have device connected to my computer.  Can't I control the simulated device through the following code?
    /*********************************************/                                
    // DAQmx Configure Code                                                        
    /*********************************************/                                
    DAQmxCreateTask("",&taskRF);                                                   
    DAQmxCreateDOChan (taskRF, "Dev1/port3/line3", "", DAQmx_Val_ChanPerLine);     
                                                                                   
    /*********************************************/                                
    // DAQmx Start Code                                                            
    /*********************************************/                                
    DAQmxStartTask(taskRF);                                                        
    /*********************************************/                                
    // DAQmx Write Code                                                            
    /*********************************************/                                
    DAQmxWriteDigitalScalarU32 (taskRF, 1, 10.0, RFswitch, 0) ;                    
  
When I tried to switch the binary switch, the error came out: Function DAQmxStartTask: (return value==-200587 [0xfffcf075]).
Is it because I don't have the device connected?

Thanks,
Joyce
                                                                                

0 Kudos
Message 3 of 8
(4,629 Views)

Hi,

Your code seems sufficient to operate the digital output according to the position of the switch provided that you called GetCtrlVal to get the position of the switch before the DAQmx code.
The second parameter to function DAQmxWriteDigitalScalarU32 is 1, which means you do not need to call DAQmxStartTask separately.

The error code means: "digital lines are reserved or unavailable". You can search your error code in the daqmx.h file to get a quick info on any error or warning (which are positive). This error is probably because "Dev1/port3/line3" is not a valid channel name without a hardware.

Hope this helps,

S. Eren BALCI
IMESTEK
Message 4 of 8
(4,625 Views)
Hi,  Balci (Is this your last name?),
Thanks for your prompt reply. I try to use binary switch function to control digital output. I found that the previous problem was gone if I add "DAQmxStopTask(taskRF);                                                                   
DAQmxClearTask(taskRF);"
in the end of the case. So I think the error comes because the second task starts while the first task is not stopped.
However, When I connected the device to the computer, the following code can only work in the first event and it keeps the same state if I click the binary switch again.
I used DAQmxReadDigitalScalarU32 and printf to check the digital output status. I found that the the state is always 0.
Why?
Here is the code:
---------------------------------------------------------------------------------------------------------------------------------
int CVICALLBACK RFcontrol (int panel, int control, int event,           //binary switch function
        void *callbackData, int eventData1, int eventData2)            
{                                                                      
    switch (event)                                                     
     case EVENT_COMMIT:                                                                                                                                                             
    GetCtrlVal (panelHandle, PANEL_BINARYSWITCHRF, &RFswitch);                               
   
        DAQmxCreateTask("",&taskRF);                                                         
        DAQmxCreateDOChan (taskRF, "Dev1/port3/line3", "", DAQmx_Val_ChanPerLine);                        
        DAQmxWriteDigitalScalarU32 (taskRF, 1, 10.0, RFswitch, 0) ;                       
                                                                                                    
    DAQmxReadDigitalScalarU32 (taskRF, 10.0, &RFstatus, 0);                                     
    printf("%d\n",RFstatus);                                                                 
    DAQmxStopTask(taskRF);                                                                   
    DAQmxClearTask(taskRF);                                                                  
    break;                                                                                   
-------------------------------------------------------------------------------------------------------------------------------------------
Thanks,
Joyce
0 Kudos
Message 5 of 8
(4,619 Views)

Hi Joyce,

My first name is Eren. Balci is the last name 🙂

Could you paste the following lines in your code and tell me what happens?:

     DAQmxCreateDOChan (taskRF, "Dev1/port3", "", DAQmx_Val_ChanForAllLines); //use the port as a whole
     DAQmxStartTask (taskRF); //start task
     DAQmxReadDigitalScalarU32 (taskRF, 10.0, &RFstatus, 0); //read current value
     DAQmxWriteDigitalScalarU32 (taskRF, 0, 10.0, (RFswitch == 1) ? (0x08 | RFstatus)  : (0xF7 & RFstatus), 0) ;

This uses the port as a whole and sets or clears the bit corresponding to line-3 only and leaves other bits unchanged.

Message Edited by ebalci on 08-13-2007 12:59 PM

S. Eren BALCI
IMESTEK
Message 6 of 8
(4,613 Views)
Hi, Eren,

Wow~~ It works now. Thank you very much.
Though I have a question. If I want to use 2 lines in the same port3, e. g., I want to use line4 for another binary switch, will this code intervene the other line?
0 Kudos
Message 7 of 8
(4,594 Views)
You may extend the code as you wish. For controlling line-4 from another UIR switch;
 
     DAQmxReadDigitalScalarU32 (taskRF, 10.0, &portval, 0); //read current value
     DAQmxWriteDigitalScalarU32 (taskRF, 0, 10.0, (other_switch == 1) ? (0x10 | portval)  : (0xEF & portval), 0) ;
 
Actually, you need to read the current port status just once and then modify as many bits as necessary (using UIR switch values for your case) and write the new value back to the port.
S. Eren BALCI
IMESTEK
Message 8 of 8
(4,584 Views)