06-08-2018 01:28 AM - edited 06-08-2018 01:31 AM
Due to this info:
http://digital.ni.com/public.nsf/allkb/195B4C4A7B559E4586257062006F95A0?OpenDocument
citation: „…whenever you reconfigure any one of the three adjacent ports ... all adjacent output ports go to the initial value of zero…“
I am very interested for an example code which shows how to see pseudo code
OR
or at least rough feasibility check
portCtrl(bool InitCfg, bool Read, bool Write, char acChanFALines, int whichPort .....)
{
// static so that after the config the handle will still be initialized
static taskHanleINPort0, ....Port1.....;
if(InitCfg)
{
// Hope this is the function where the ports are just configured
DAQmxCreateDIChan (taskHandleINCorresponding Port to Param whichPort, acChanFALines, "INPUT", DAQmx_Val_ChanForAllLines)
}
else if(Read)
{
DAQmxReadDigitalU8(taskHandleINCorresponding Port to Param whichPort,1,0,DAQmx_Val_GroupByScanNumber,uiaRd,8,&samps,0);
}
else if(Write)
{
DAQmxWriteDigitalU8 (taskHandleINCorresponding Port to Param whichPort, 1, 1, 0, DAQmx_Val_GroupByScanNumber, uiaWr,&samps , 0)
}
}
I would be very glad and thankful for some expert opinions, - I had enough of primitive testing, searching for example code and docu.
The AIM of this whole stuff is to be able to have such configuration e.g.
Port0 IN, Port1 OUT, Port2 In
and
Cfg Ports
code..
code..
read Ports
code..
code..
set Ports
...
06-15-2018 11:11 AM
Hi G4Bandit,
Just to make sure, you wanted to see Pseudocode and suggestions to the current code.
1.) Suggestion: One thing I noticed was that you will need a DAQmxCreateDOChan within your InitCfg if statement since you intended to do a digital write.
2.) Suggestion: I also like to place the taskHandles with a global scope in case you would like to write through that port again. If not, you can initialize, write to it and discard it, but I am open to what other community members have to say regarding taskHandles being global.
3.) Suggestion: I believe that what you posted is likely not completed yet, but you will want to figure out what you want to do with the data read from DAQmxReadDigitalU8 before it gets erased by another read. I personally have never seen the above function and generally use DAQmxReadDigitalLines.
Regards,
Vincent
06-18-2018 04:36 AM - edited 06-18-2018 04:38 AM
Hi VincentTang,
regaring:
1.) Yes, completly right. Need also to call this function to make the calling function fully functional.
2.) like you stated, - I am curious what other community members say regarding global taskHandles.
3.) well the pseudo code is not complete yet, but from now I have to expand it to parameters ReadBuf and WriteBuf
like this prototype:
portCtrl(bool InitCfg, bool Read, bool Write, char acChanFALines, int whichPort, ReadBuf, WriteBut);
The main issue of this post is to correctly avoid some unwanted resettings of some OUTDefined Ports.
As a "Plan B" I could design my wiring like
Group A Port A(a 8Bit), B, C = OUT
Group B Port A(a 8Bit), B, C = IN
Group C Port A(a 8Bit), B, C = IN
Group D Port A(a 8Bit), B, C = OUT
But of course I prefer to know not just to "feel" that "Plan A" is in general not working.
Maybe I need to test Plan A.
Hope some experts 🙂 could help me to avoid unnecessary testing time.