Experimental Physics and Industrial Control System
Sorry I'm a bit late to the party ;-) ...christmas holidays...
Am Donnerstag, 20. Dezember 2012, 04:23:23 schrieb Mark Rivers:
> It needs to be outside the block. All C functions need to be escaped with
> a single block of %{ }%, as in the example below from one of my SNL
> programs.
In seq-2.1.x it is not necessary to place all the C code in one escape block.
It is also not strictly necessary that it is at the end of the program.
However, C function definitions must be at the top-level, i.e. outside any SNL
blocks. And they must be at the end if they access global SNL variables, since
C code blocks in the definition section are placed /before/ SNL global
variables.
> Note that it is usually a good idea to build the program with the +r option
> so that multiple instances of the SNL program can be run:
>
> /* This program must be compiled with the recursive option */
> option +r;
>
> In that case if your C code uses variables from the SNL code it needs to
> reference them with the pVar structure pointer, also shown below.
>
>
> /* C functions */
> %{
>
> /* getMotorPositions returns the positions of each motor.
> * It reads the positions from the controller, and then converts to
> * EPICS motor user coordinates */
> static int getMotorPositions(SS_ID ssId, struct UserVar *pVar, double *pos)
> {
> int status;
> int j;
> int dir;
>
> /* Read the current positions of all the axes */
>
> status = GroupPositionCurrentGet(pVar->positionSocket,
> pVar->groupName,pVar->numAxes,pos);
> if (status != 0)
> printMessage("Error performing GroupPositionCurrentGet%i\n",
> status); /* Convert from XPS units (which are EPICS motor dial units) to
> user units */ for (j=0; j<pVar->numAxes; j++) {
> if (pVar->epicsMotorDir[j] == 0) dir=1; else dir=-1;
> pos[j] = pos[j]*dir + pVar->epicsMotorOff[j];
> }
>
> return(status);
> }
>
>
> ...
>
> static void printMessage(const char *pformat, ...)
> {
> va_list pvar;
> FILE *fp = stdout;
> epicsTimeStamp now;
> char nowText[40];
>
> epicsTimeGetCurrent(&now);
> nowText[0] = 0;
> epicsTimeToStrftime(nowText,sizeof(nowText),
> "%Y/%m/%d %H:%M:%S.%03f",&now);
> fprintf(fp,"%s ",nowText);
> va_start(pvar, pformat);
> vfprintf(fp,pformat,pvar);
> va_end(pvar);
> fflush(fp);
> }
>
> }%
>
>
> Cheers,
> Mark
>
>
> ________________________________
> From: [email protected] [[email protected]] on
> behalf of Pierrick Hanlet [[email protected]] Sent: Wednesday, December 19,
> 2012 6:37 PM
> To: Zelazny, Michael Stanley
> Cc: [email protected]
> Subject: Re: SNL with C
>
> Great! Thank you and Mark.
>
> Another question: if I want to write a C function, I understand that it
> needs to be after the last SNL statement. Does it belong outside of the
> ss SS1 {} block, or is it after the last statement within the block. Is
> it true that this code would also need to be escaped %{ short myFunc() {}
> }%?
> Best regards,
> Pierrick
>
>
> On 12/19/2012 06:11 PM, Zelazny, Michael Stanley wrote:
>
> try putting your statement in an "entry" block. And, as Mark says, the
> "%%" probably isn't necessary.
>
> ss SS1 {
>
> state Offline {
> /* Get PV relevent PV information */
> when (SS1mon == 1) {
> SS1state = 1;
> pvPut(SS1state);
> } state Pumping
> }
>
> state Pumping {
> /* Get PV relevent PV information */
> entry {
> %%if (StateReadCDB()) printf("SS1-Pumping: success\");
> }
> when (SS1vac <= 1.0e-4) {
> SS1state = 2;
> pvPut(SS1state);
> } state Pumped_Warm
> }
> ... continued
> }
> ________________________________________
> From: [email protected]<mailto:[email protected]>
> [[email protected]<mailto:[email protected]>] On
> Behalf Of Pierrick M Hanlet [[email protected]<mailto:[email protected]>]
> Sent: Wednesday, December 19, 2012 3:59 PM
> To: [email protected]<mailto:[email protected]>
> Subject: SNL with C
>
> Hi,
> I a newcomer to SNL.
>
> I have a library to which I link my snl. In a global entrance block, I can
> successfully call one of the functions. Later I added the use of another
> function in a state set and now I can no longer compile.
>
> ss SS1 {
>
> state Offline {
> /* Get PV relevent PV information */
> when (SS1mon == 1) {
> SS1state = 1;
> pvPut(SS1state);
> } state Pumping
> }
>
> state Pumping {
> /* Get PV relevent PV information */
> %%if (StateReadCDB()) printf("SS1-Pumping: success\");
> when (SS1vac <= 1.0e-4) {
> SS1state = 2;
> pvPut(SS1state);
> } state Pumped_Warm
> }
> ... continued
> }
>
>
> The error at compilation/linking is:
> converting ../sncMICEStates.stt
> /home/epics/epics/Support/seq/bin/linux-x86/snc +r ../sncMICEStates.stt
> -o sncMICEStates.c.tmp syntax error: line no. 96 (../sncMICEStates.stt)
> state option list
> make[3]: *** [sncMICEStates.c] Error 1
> make[3]: Leaving directory
> `/home/epics/epics/iocTops/MICEStates/MICEStatesApp/src/O.linux-x86'
> make[2]: *** [install.linux-x86] Error 2
> make[2]: Leaving directory
> `/home/epics/epics/iocTops/MICEStates/MICEStatesApp/src' make[1]: ***
> [src.install] Error 2
> make[1]: Leaving directory
> `/home/epics/epics/iocTops/MICEStates/MICEStatesApp' make: ***
> [MICEStatesApp.install] Error 2
>
> where line no. 96 is the escaped call to the library function in my Pumping
> state. The error "state option list" doesn't tell me anything.
--
Ben Franksen
() ascii ribbon campaign - against html e-mail
/\ www.asciiribbon.org - against proprietary attachments
________________________________
Helmholtz-Zentrum Berlin für Materialien und Energie GmbH
Mitglied der Hermann von Helmholtz-Gemeinschaft Deutscher Forschungszentren e.V.
Aufsichtsrat: Vorsitzender Prof. Dr. Dr. h.c. mult. Joachim Treusch, stv. Vorsitzende Dr. Beatrix Vierkorn-Rudolph
Geschäftsführung: Prof. Dr. Anke Rita Kaysser-Pyzalla, Thomas Frederking
Sitz Berlin, AG Charlottenburg, 89 HRB 5583
Postadresse:
Hahn-Meitner-Platz 1
D-14109 Berlin
http://www.helmholtz-berlin.de
- References:
- SNL with C Pierrick M Hanlet
- Re: SNL with C Pierrick Hanlet
- RE: SNL with C Mark Rivers
- Navigate by Date:
- Prev:
Re: streamDevice: how to read a value as fast as possible? Martin Konrad
- Next:
Error in installing asyn driver nalaka samarasinghe
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
<2012>
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
- Navigate by Thread:
- Prev:
RE: SNL with C Mark Rivers
- Next:
Record processing: periodic vs. push vs. pull jon
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
<2012>
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024