Hal component cannot assign variable to output ?

More
12 Dec 2021 23:42 - 12 Dec 2021 23:45 #228963 by deroj
Hi.
I am just trying to build a component for my VFD.
So I am playing arround with the mesa_uart.comp

the examle shows how to use send and receive with UART.

here is my problem.

in the beginning there are some declarations for the pins.....

pin in u32 tx-data-##[16] "Data to be transmitted";
pin out u32 rx-data-##[16] "Data received";
pin in s32 tx-bytes "Number of bytes to transmit";
pin out s32 rx-bytes "Number of Bytes received";

I have access to all of these pins. But here comes the weird thing.

FUNCTION(receive){/* This function uses the hm2_uart_send function to transmit data.See man hm2_uart_send for more information. 16 bytes in the Rx buffer*/ 
int i;unsigned char data[16];
rx_bytes = hm2_uart_read(name, data);
for (i = 0 ; i < rx_bytes ; i++){rx_data(i) = data;}}

 This function also does as aspected.


But the pin hm2_5i25.0.uart.0.rx-bytes shows "0" all the time and not the number of bytes received.
Always, when I assign a variable to rx_bytes, the output is "0".
When I say rx_bytes = 10; it will show 10 or 0x0A.
When I say
int test = 10;
rx_bytes = test;

the pin will show 10 (0x0A).

What am I missing?
I really want to generate an "variable" output....
 
Last edit: 12 Dec 2021 23:45 by deroj.

Please Log in or Create an account to join the conversation.

More
13 Dec 2021 00:19 #228969 by deroj
And when I do this:

    int i;
    unsigned char data[16];
    
    rx_bytes = hm2_uart_read(name, data);
       
    for (i = 0 ; i < rx_bytes ; i++){
         rx_data(i) = data;
        
    }
    rx_data(i) = rx_bytes;

the rx-data-00 is "0" (overwritten?)
rx-data-01, 02, etc keep the values from UART
and the additional rx-data- keeps the rx_byte value...

I really don't get it

Please Log in or Create an account to join the conversation.

More
13 Dec 2021 02:29 #228985 by cmorley
Did you addf servo-thread the component?

Please Log in or Create an account to join the conversation.

More
13 Dec 2021 07:19 #228997 by deroj
not to servo, but to another thread with 1 sec period.
yesterday I tested this only in terminal with halrun and a test.hal

I checked it today in LinuxCnc and guess what.
The rx-bytes Pin get the output, but just for a second (period) and after it get zero again.
In halrun I just were to slow to see it with "show pin".
Think this is normal behaviour for the UART when there aren't new bytes in RX buffer?
This is no problem for me, I just got mad yesterday not being able to set an output :silly:

Please Log in or Create an account to join the conversation.

Time to create page: 0.210 seconds
Powered by Kunena Forum