I am trying to get a simple userspace component working, following the
instructions in docs/src/hal/comp.txt. Source (below) is saved as
testrand.comp. 

I have run into a few issues so far. If there is a better process for reporting 
these,
please let me know (and forgive this long email!)


(1) it is not clear from "docs/src/hal/comp.txt" or the HAL user manual
how to build a userspace component. 

What is unclear:
(a) Placing a "comp" in src/hal/user_comps, Make will not build it 
automatically 
(though it will for an RT component in src/hal/components)
(b) Placing it in src/hal/components, Make will find it but build it 
incorrectly 
(as if it was a RT component)
(c) The Makefile instructions at 
http://wiki.linuxcnc.org/cgi-bin/wiki.pl?MakefileDeMystified
do not give instructions how to add a simple .comp userspace file to the 
process.
(d) I placed it in src/hal/user_comps and ran 
"comp --install src/hal/user_comps/testrand.comp". That worked.
(e) However, "comp --install src/hal/user_comps/testrand.c" to compile the 
equivalent 
C file does NOT work; (it builds a .so file as if it were a RT component) 
Adding the userspace option is necessary
"comp --install --userspace src/hal/user_comps/testrand.c"

Summary : I have wasted about a day navigating the twisty winding passages. 

Improvements: 
(a) An example in "comp.txt" or the HAL user manual would clarify this
(b) Maybe improve the Make process to cover user comps correctly?


(2) In "halrun", the "loadrt" command allows loading multiple components as
loadrt wcomp count=6

However the "loadusr" command does not!
loadusr testrand count=6
(1 component added!)
Improvements:
(a) fix loadusr command, or
(b) document this to avoid head scratching! (if this is already documented, I'd 
appreciate knowing where...

This is clearly not a fundamental limit on user components, because both other 
approaches work:
option count_function yes;
or
option default_count 3;

(3) Attempting to read the command line args results in a segfault (the 
following source will reproduce this)
Traced to bug in /home/brian/Projects/cnc/linuxcnc-dev/bin/comp lines 843-849

    if options.get("userspace"):
        print >>f, "static void user_mainloop(void);"
        if options.get("userinit"):
            print >>f, "static void userinit(int argc, char **argv);"
        print >>f, "int argc=0; char **argv=0;"
        print >>f, "int main(int argc_, char **argv_) {"    
-        print >>f, "    argc = argc_; argv = argv;"
+        print >>f, "    argc = argc_; argv = argv_;"

Apart from these, I am quite impressed with the system so far.

- Brian


---- testrand.comp ( modified from comp.txt) ----
component testrand "Random component";
option userspace yes;
option count_function yes;
//option default_count 3;


pin out float out;
license "GPLv2 or later";
;;
#include <unistd.h>

void user_mainloop(void) {
    rtapi_print_msg(RTAPI_MSG_ERR, "Cmdline, argc=%d, arg0 = %s\n", 
                argc, argv[0]);         // segfaults!
    // rtapi_print_msg(RTAPI_MSG_ERR, "Cmdline, argc=%d\n", 
    //          argc);                  // OK
    while(1) {
        usleep(1000);
        FOR_ALL_INSTS() out = drand48();
    }
}

int get_count(void) {
    return 5;
}
---- end source ----




------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Emc-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-developers

Reply via email to