get channel number from real time thread  function

Dear Alex and John:

Many thanks for your suggestions. Finally, I came out with a solution.
As I only need the index of a channel, I don't want to change to data
structure. I made a few line in the function, I now can get the index
.

calc_pid(void* arg, long period){
pid=arg;
**********************
 for(i=0;i<num_chan;i++){
     if(pid == (pid_array+i)){
                chan = i;
                break;
        }
 }
***********************
}

regards
Xuecheng

> The idea is that you only pass the address of the current channel data
> structure:
>     &(pid_array[num])
>
> e.g. &(pid_array[0]) then &(pid_array[1]), etc
>
> This way each function will only access it's own data.
>
> If you need to access some other data then you need to pass
> &(pid_array), and handle the channel number in some other way.
>
> Regards,
> Alex
>

> pid_array is an array of structures, each with all the data needed for
> a PID loop.  Each function gets a pointer to one structure with the
> data it needs, and is unaware of the other structures.  If you are
> writing a HAL component, you are the one who defines that structure.
> You can have any fields you want in that structure, not just HAL pins
> and parameters.  (See stepgen for an example of a large struct with lots
> of data in it).  For your situation, you can add a "channel_num" field
> to the structure, and initialize it before you call export_funct during
> startup.
>
> Regards,
>
> John Kasunich
>

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Emc-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-developers

Reply via email to