LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

NI Loader or Configuration Manager as ready indicator

After a reboot of my computer, the PCI multi I/O board seems to have undefined digital lines. A shutter connected to a digital out line starts to switch rapidly open and close. If nobody is available or alert, this becomes a hardware lifetime test.

 

With a Windows service (automatic started after boot) I want to define the digital lines. I know that the NIDAQmx device is available as dev1. However when my service is too fast, it gets stuck. Probably the NI software that configures the devices and their names has not started or finished yet.

 

One solution is a (long) delay. However I prefer to check if the appropriate NI software/service is available. And if needed, wait a short delay after this has started. When looking for such a service, what is the best one as indicator before sending NIDAQmx commands to dev1 ?

- service display name "NI Device Loader", or

- service name "nidevldu", or

- service display name "NI Configuration Manager", or

- service name "mxssvr", or

- ????? ????

 

Regards, Jos

 

0 Kudos
Message 1 of 4
(3,673 Views)

I do not see yet a reply with the magic trick. Maybe I have to elaborate on my question.

 

Commonly, my application defines the digital I/O port for four input lines and four output lines. This is done by creating a DAQmx task for input, creating four digital input lines, and starting this task. The same is done for an output task. (The port name in the code below will be Dev1).

/* clean up old tasks */
NIDAQPC_CleanUpGlobalTask();
DAQmxErrChk (DAQmxCreateTask("",&NIDAQPC_TaskHandleInput));
for (i = 0; i < NIDAQPC_CONFIG_LINENUMBERINPUT; i++)
{
   sprintf(LineName, "%s/line%0d", NIDAQPC_Devices[Device].DigitalPortName, i);
   DAQmxCreateDIChan (NIDAQPC_TaskHandleInput, LineName, "", DAQmx_Val_ChanPerLine);
}  
DAQmxErrChk (DAQmxStartTask(NIDAQPC_TaskHandleInput));
DAQmxErrChk (DAQmxCreateTask("",&NIDAQPC_TaskHandleOutput));
for (i = NIDAQPC_CONFIG_LINENUMBERINPUT; i < NIDAQPC_CONFIG_LINENUMBERINPUT + NIDAQPC_CONFIG_LINENUMBEROUTPUT; i++)
{
   sprintf(LineName, "%s/line%0d", NIDAQPC_Devices[Device].DigitalPortName, i);
   DAQmxCreateDOChan (NIDAQPC_TaskHandleOutput, LineName, "", DAQmx_Val_ChanPerLine);
}  
DAQmxErrChk (DAQmxStartTask(NIDAQPC_TaskHandleOutput));

If my computer restarts and nobody is there to log-on, the state of the digital lines seem undefined. And the shutter that is connected to one of the digital output lines, starts to open and close rapidly.

From the Windows SDK help and from some examples, I found how to make a simple Windows Service. I have installed this service so that it starts automatic after boot. Inside the service, I send a call to my function that defines the input and output tasks. And I stop the service because I do not need it anymore.

void WINAPI ServiceStart (DWORD argc, LPTSTR *argv)
{
   HANDLE Events[2] = {NULL, NULL};
   if (!ServiceStatusToManager(SERVICE_START_PENDING,NO_ERROR,100)) goto CleanUp;
   ServerStopEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
   if ( ServerStopEvent == NULL) goto CleanUp;
   Events[0] = ServerStopEvent;
   if (!ServiceStatusToManager(SERVICE_START_PENDING,NO_ERROR,100)) goto CleanUp;
   if (!ServiceStatusToManager(SERVICE_RUNNING,NO_ERROR,0))goto CleanUp;
   // End of initialization
   ////////////////////////////////////////////////////////
   // Service is now running, perform work until shutdown
   Delay(30.0);
   SHUTTER_Init();
   SHUTTER_Set(-1L, SHUTTER_Closed);
   ServiceStop();
CleanUp:
   if (ServerStopEvent) CloseHandle(ServerStopEvent);
}

Without the delay of 30 seconds, the service gets stuck when initializing the digital lines i.e. the call to SHUTTER_Init does not return. I know this because I added print-statements before each function call that gets stored in a log-file. With the delay of 30 seconds in ServiceStart, I get (tested 5 times) successful definition of the ditigal I/O lines without the need to log-on.

I assume that one or multiple of the NI services are needed before I can start a task. Specific I expect that a NI service builds an inventory of all the devices and their names.
 

I like to know how to check when I can start a task. So my next step was to look which services do exist after 10 seconds delay:
Delay(10.0);
hSCM = OpenSCManager(NULL,NULL,SC_MANAGER_ENUMERATE_SERVICE | SC_MANAGER_CONNECT);
if (hSCM != NULL)
{
   EnumServicesStatusEx(hSCM,SC_ENUM_PROCESS_INFO,SERVICE_WIN32,
              SERVICE_STATE_ALL,NULL,dwBufSize, &dwBufNeed,&dwNumberOfService,NULL,NULL);
   if (dwBufNeed > 0)
   {
      dwBufSize = dwBufNeed + 0x10;
      pBuf  = (PUCHAR) malloc(dwBufSize);
      if (pBuf != NULL)
      {
         EnumServicesStatusEx(hSCM,SC_ENUM_PROCESS_INFO,SERVICE_WIN32,
                  SERVICE_ACTIVE,pBuf,dwBufSize, &dwBufNeed,&dwNumberOfService,NULL,  NULL);
         pInfo = (LPENUM_SERVICE_STATUS_PROCESS)pBuf;
         for (i=0;i<dwNumberOfService;i++)
         {
            //pInfo[i].lpDisplayName
            //pInfo[i].lpServiceName
            //pInfo[i].ServiceStatusProcess.dwProcessId
         }
         free(pBuf);
      }
   }
   CloseServiceHandle(hSCM);
}

The list does include a few NI services. To repeat my original question: can I use the active-status of any of the NI services (with optional a short delay) as an indicator that I can define a DAQmx task before log-on?

Regards, Jos

 

0 Kudos
Message 2 of 4
(3,643 Views)

i am sorry, i can't tell which service has to be started before trying to configure a DAQmx task.

 

however, when defining a service, it is possible to specify which other services this new service depends on. the CreateService() function of the Windows SDK includes a "lpDependencies" arguments in order to achieve this. this means that the service will not be started before the service it depends on. i advise you to use this feature, since it will avoid a hard coded delay: your delay is fixed but the time it takes for a service to start is dependent on a number of factors not in your control, like processor speed or number of service to start, thus it may vary greatly from one machine to another. also, using this feature will allow you to perform your action at the right time, without much delay.

0 Kudos
Message 3 of 4
(3,630 Views)

Thanks for you contribution.

 

The dependency-option is excactly what I tried to do with my own inventory of active services. While I do not use CreateService (I hardly use SDK, I am not familiar with services, and I did use sc.exe to install the service), I can add the dependency option direct in the registry.

 

Still I need to know which service to check for. And probably I need a small delay in my own service if that particular NI service needs some time to finish its start-up routine e.g. to finish a hardware inventory.

 

Regards, Jos

 

0 Kudos
Message 4 of 4
(3,613 Views)