EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  <20112012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  <20112012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: Re: Combing Two State Sets into One
From: Eric Norum <[email protected]>
To: Bradley Pietrzak <[email protected]>
Cc: EPICS Tech Talk <[email protected]>
Date: Thu, 29 Sep 2011 10:08:08 -0700
The
float i;
line is a SNL statement, not a C statement.
SNL doesn't provide a mechanism for variables to be statically initialized.

Taking a look at the generated C code for the working example might provide you some insight into what's happening 'under the hood'.

On Sep 29, 2011, at 9:58 AM, Bradley Pietrzak wrote:

Thanks again for the help.  I have found another issue, though, and I sincerely apologize if it is yet another fundamental C error.  Can anybody shed any light on why Program 1 shown below does work while Program 2 does not even successfully compile?  I have highlighted the only differences between the two programs with "***************".

Program 1:

/* Sample Program */
program sncExample

option +r; /* reentrant */

float i;   ***********

float pv;
assign pv to "testioc:magnet{mag}";

%{

    void helloWorld(SS_ID ssId, struct UserVar *pVar) {
        pVar->i = 1;   ****************
        printf("Hello World! You have just called a C function, and the variable i is %5.1f \n", pVar->i);
    }

}%

ss ss1 {

   state one {
       when() {
       %% helloWorld(ssId, pVar);
       pv = 1;
       pvPut(pv);
       sleep(1);
       } state two
   }

   state two {
       when () {
       %% helloWorld(ssId, pVar);
       pv = 2;
       pvPut(pv);
       sleep(1);
       } state one
   }

}



Program 2:

/* Sample Program */
program sncExample

option +r; /* reentrant */

float i = 1; ****************

float pv;
assign pv to "testioc:magnet{mag}";

%{

    void helloWorld(SS_ID ssId, struct UserVar *pVar) {
        printf("Hello World! You have just called a C function, and the variable i is %5.1f \n", pVar->i);
    }

}%

ss ss1 {

   state one {
       when() {
       %% helloWorld(ssId, pVar);
       pv = 1;
       pvPut(pv);
       sleep(1);
       } state two
   }

   state two {
       when () {
       %% helloWorld(ssId, pVar);
       pv = 2;
       pvPut(pv);
       sleep(1);
       } state one
   }

}


The error message displayed upon compiling program 2 is :

./../sncExample.stt: In function ‘helloWorld’:
./../sncExample.stt:15: error: ‘struct UserVar’ has no member named ‘i’
./../sncExample.stt: In function ‘A_ss1_one’:
./../sncExample.stt:24: error: ‘struct UserVar’ has no member named ‘pv’
./../sncExample.stt:26: warning: implicit declaration of function ‘sleep’
./../sncExample.stt: In function ‘A_ss1_two’:
./../sncExample.stt:33: error: ‘struct UserVar’ has no member named ‘pv’
./../sncExample.stt: At top level:
./../sncExample.stt:50: error: ‘struct UserVar’ has no member named ‘pv’


Thanks everybody!

Brad Pietrzak




On Mon, Sep 26, 2011 at 6:02 PM, J. Lewis Muir <[email protected]> wrote:
On 9/26/11 4:39 PM, Bradley Pietrzak wrote:
> Thank you again for your responses.  Unfortunately, I have encountered
> another problem, this time involving code that has been escaped to C.  The
> new version of my program is shown below.  Without the re-entrant option,
> the code runs perfectly fine.  With the re-entrant option, however, I am met
> with several errors. The SNL user's manual says that the SNC automatically
> refers to variables in the struct UserVar by running the code " pVar->xxx",
> but that such references have to be handled manually for escaped C code. How
> do I handle such situations manually?

Hi, Brad.

In your example, you would need to do:

 %% helloWorld(pVar->i);

Or, if you are wanting to do more things within your helloWorld
function, you could call it like this:

 %% helloWorld(ssId, pVar);

with the function changed to:

 void helloWorld(SS_ID ssId, struct UserVar *pVar) {
   printf("Hello World! You have just called a C function, "
     "and the variable i is %5.1f \n", pVar->i);
 }

Lewis


-- 
Eric Norum
[email protected]





References:
Re: Combing Two State Sets into One Bradley Pietrzak
Re: Combing Two State Sets into One Ned Arnold
Re: Combing Two State Sets into One Bradley Pietrzak
Re: Combing Two State Sets into One J. Lewis Muir
Re: Combing Two State Sets into One Bradley Pietrzak

Navigate by Date:
Prev: Re: Combing Two State Sets into One Bradley Pietrzak
Next: Re: Transform Record no_inlink test Tim Mooney
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  <20112012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Re: Combing Two State Sets into One Bradley Pietrzak
Next: Asub record problems to update waveforms of string-type Perrier Pierre
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  <20112012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 18 Nov 2013 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·