Linux Users

cancel
Showing results for 
Search instead for 
Did you mean: 

Daemonize a process and manage USB-6501

Successfully installed NI-DAQmxBase 3.3 on Red Hat EL4

I am trying to write a standard linux daemon program talking with USB-6501 card. If I run this program as simple background process, it works well.

If I daemonize the process in the standard way (fork() and terminate parent), it does not work. The process aborts the first time it attempts to talk with the card.

My hypothesis is that the problem is related to lack of multithread support in NI-DAQmxBase, what do you think ?

Following is the piece of code that daemonize/not_daemonize the process

if ( DAEMONIZE == 1 ) {
     if(getppid()==1) return; /* already a daemon */
     i=fork();
     if (i<0) exit(1); /* fork error */
     if (i>0) exit(0); /* parent exits */
     /* child (daemon) continues */
     setsid(); /* obtain a new process group */
}


Many thanks,

Pino

0 Kudos
Message 1 of 9
(7,015 Views)

Unfortunately NI Core driver component that DAQ depends on does not work with fork() due to the way the driver works. We do support multi-threading, but fork() creates another process container without notifying the driver and our driver gets confused. If you want to do fork(), call it before loading NI driver stack.

0 Kudos
Message 2 of 9
(4,515 Views)

Some correction actually.  With using DAQmx Base for USB devices it just uses the user-mode USB interface and does not actually go down and hit the NI Core driver component.  So I don't know why you are hitting the issue to help you out, but is at least not exactly what Irwan is pointing out.

Hopefully somebody who has tried this with VISA could say better...

0 Kudos
Message 3 of 9
(4,515 Views)

First of all, many thanks for your replies. I was able to see them only opening the RSS link and I do not know why, but this is another issue related to this forum tool.

Back to my question.

If you want to do fork(), call it before loading NI driver stack

Do you mean initialize NI device after the fork() ? I tried it but it did not work. It is possibile that I made some other mistake, I will check better.

Hopefully somebody who has tried this with VISA could say better

As you probably have understood, this is my first use of NI device. Could you please help me to find my bearings ? ... What is VISA ?

Best regards,

Pino

0 Kudos
Message 4 of 9
(4,515 Views)

picolu wrote:


As you probably have understood, this is my first use of NI device. Could you please help me to find my bearings ? ... What is VISA ?


Hi Pino,

There's a good overview of what VISA is here:  http://cnx.org/content/m12288/latest/

And a tutorial here:  https://www.ni.com/support/visa/vintro.pdf

---------------------
Patrick Allen: FunctionalityUnlimited.ca
0 Kudos
Message 5 of 9
(4,515 Views)

Thanks,

Pino

0 Kudos
Message 6 of 9
(4,515 Views)

And as a further clarification for relevance to this discussion.  I mentioned VISA because that is what DAQmx Base uses for the operations you are doing.  Really, it could be in DAQmx Base or VISA causing this problem.

0 Kudos
Message 7 of 9
(4,515 Views)

Looks like I was wrong and you're not actually using NI Core Driver.. But for what it's worth, what I meant by:

If you want to do fork(), call it before loading NI driver stack

is to call fork() even before the process loads any of NI driver shared library. Potentially this means that you need to bundle your app in another shared lib, that's called by a wrapper executable that does fork() before loading your main shared lib and execute whatever you need to do.

0 Kudos
Message 8 of 9
(4,515 Views)

Hello,

Sorry for disturbing this thread but it's very interresting for my own problem, when i bundle my working code into a shared library, DAQmxBaseReadAnalogF64 never update samplesNread, so you dont know how many sample be readed !!! Here is a sample to reproduce the probleme over 4th OS : https://decibel.ni.com/content/message/24454

I need help.

Thanks in advance

Rom1nux

0 Kudos
Message 9 of 9
(4,515 Views)