How to access rt pins in user space

More
1 year 8 months ago #322430 by RushA
Hi,
    I create some pins in the RT module, now I want to read and write pins' value in user space.I use the following code,but it failed.Is there any way to access RT module pins in the user space? The environment is Ubuntu20.04+xenomai3.1+linuxcnc2.9.Thanks!
    int compId;
    int ret;
    hal_float_t *pin_value;
    // init HAL
    compId = hal_init("user_program");
    if (compId < 0) {
        rtapi_print("HAL init failed\n");
        return -1;
    }
    pin_value = (hal_float_t*)hal_malloc(sizeof(hal_float_t));
    ret = hal_pin_float_new("kernel_pin", HAL_IN, &pin_value, compId);
    if (ret < 0) {
        rtapi_print("getting or creating pin failed!\n");
        hal_exit(compId);
        return -1;
    }

    ret = hal_link("user_program.kernel_pin", "ALT.I2600");
    if (ret < 0) {
        fprintf(stderr, "cann't bind signal!\n");
        hal_exit(compId);
        return -1;
    }
    hal_ready(compId);
    
    //*pin_value = 123.45;
    //rtapi_print("value is: %f\n", *pin_value);
    hal_exit(compId);

It prints some messages:
HAL: initializing hal_lib
HAL: initializing component 'user_program'
HAL: component 'user_program' initialized, ID = 28
smalloc_up: shmem available 1386552
HAL: ERROR: pin_new(kernel_pin) called with already-initialized memory
HAL: creating pin 'kernel_pin'
HAL: ERROR: data_ptr_addr not in shared memory

Please Log in to join the conversation.

More
1 year 7 months ago #323156 by andypugh
One option might be to create complementary pins in your userspace module and link them in the HAL layer.

Can you give more details about what you are trying to do? There are a few examples of existing drivers with realtime and userspace pairs. These tend to communicate with private shared memory.

linuxcnc.org/docs/stable/html/man/man1/halsampler.1.html
linuxcnc.org/docs/stable/html/man/man9/sampler.9.html
For example.

Please Log in to join the conversation.

More
1 year 6 months ago #325501 by RushA
hi,thank you for your reply!
I have two modules running in realtime space. One is ethercat module, the other is shared memory module. The ethercat module tranfers data to shared memory module through pins, and I want to get these data from shared memory module in user space.

Please Log in to join the conversation.

More
1 year 6 months ago #325502 by RushA
Can you give me some examples? Code or something.

Please Log in to join the conversation.

More
1 year 6 months ago #325504 by Aciera

Please Log in to join the conversation.

More
1 year 6 months ago #325563 by RushA
That's great, thank you!

Please Log in to join the conversation.

More
1 year 6 months ago #325569 by cmorley
The HAL python module allows reading or arbitrary pins and signals without connecting to them.
It's written in C++ but shows the process and borrows C code from HAL cmd.

Please Log in to join the conversation.

More
1 year 6 months ago #325586 by RushA
hi,here's another question. I want to read from and write to the module (for example the shared memory module in realtime space) through pins in user space.How can I solve the problem? Is there any code about this?

Please Log in to join the conversation.

More
1 year 6 months ago #325587 by RushA
hi, thanks!
Is there any code or links to refer to?

Please Log in to join the conversation.

Time to create page: 0.101 seconds
Powered by Kunena Forum