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  2011  2012  2013  <20142015  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  2011  2012  2013  <20142015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: Re: Accessing SNL Function and global Pvs from C
From: Benjamin Franksen <[email protected]>
To: <[email protected]>
Date: Wed, 26 Feb 2014 17:40:22 +0100
Since you asked for example/tutorial (which I don't have ready), let me
state some simple rules. Following them is not striclty required but
increases the likelyhood of things working without surprises:

(1) always escape #include and other preprocessor directives with %%
(2) place #include directives before the first state set
(3) add function prototypes and place them before the first state set
(4) place function definitions after the last state set

Cheers
Ben

On Wednesday, February 26, 2014 17:05:08 Benjamin Franksen wrote:
> On Monday, February 24, 2014 22:45:19 Ganesh Jangir wrote:
> > Dear All,
> >
> >  Facing problem in calling/accessing SNL Function and global Pvs
> >  from
> >
> > C. Here is the example I  tried.
> >
> >  _________________________________________________________________
> >
> >
> >  program cmcseq
> >
> >
> >  string CMC_STATUS;
> >  assign CMC_STATUS to "CMC_STATUS";
> >
> > foreign ssId;
> >
> >  // No monitoring
> >  // No options
> >  ....
> >
> >
> >  ss ss1 {
> >  state initial{
> >  when(delay(5)){
> >
> >  	  printf("Calling cmcStatus... \n");
> >  	  cmcStatus(ssId,"Hello",pvIndex(CMC_STATUS));
> >
> >  	  printf("Received status is %s\n", CMC_STATUS);
> >
> >  	 }state default
> >
> >             }
> >
> >  ....
> >  }
> >
> >
> >  C Function is
> >  %%#include <stdio.h>
> >  %%#include <string.h>
> >  %%#include <stdlib.h>
> >  %{
> >
> >  void cmcStatus(SS_ID ssId,string msg, VAR_ID pvCmcStatus) {
> >
> >  	strcpy(pvCmcStatus,msg);
> >  	seq_pvPut(ssId,pvCmcStatus, ASYNC);
> >  	}
> >
> >  }%
>
> Try to move the #include stuff (and a prototype for your function) to
> the top:
>
> program cmcseq
>
> %%#include <stdio.h>
> %%#include <string.h>
> %%#include <stdlib.h>
> %%void cmcStatus(SS_ID ssId,string msg, VAR_ID pvCmcStatus);
>
> The relevant section in the manual is http://www-
> csr.bessy.de/control/SoftDist/sequencer/Reference.html#defining-c-
> functions-within-the-program where it says:
>
> """
> It matters where the function is defined: if it appears at the end of
> the program, it can see all the variable and type definitions
> generated by the SNL compiler, so if your C function accesses a
> global SNL variable, you must place its definition at the end.
> However, this means that the generated code for the SNL program does
> not see the C function definition, so you might want to place a
> separate prototype for the function in the definitions section (i.e.
> before the state sets). """
>
> Cheers
> Ben
>
> >  During Make Warnings are
> >  ;
> >
> >      ^
> >
> >  ../cmcseq.stt:49:4: warning: implicit declaration of function
> >
> > &#8216;cmcStatus&#8217; [-Wimplicit-function-declaration]
> > cmcStatus("ss1","Hello",CMC_STATUS);
> >
> >      ^
> >
> >  .
> >  .
> >  .
> >  ../cmcseq.stt:149:6: warning: conflicting types for
> >
> > &#8216;cmcStatus&#8217; [enabled by default] void cmcStatus(SS_ID
> > ssId,string msg, VAR_ID pvCmcStatus) { ^
> >
> >  ../cmcseq.stt:49:4: note: previous implicit declaration of
> >
> > &#8216;cmcStatus&#8217; was here
> > cmcStatus("ss1","Hello",CMC_STATUS);
> >
> >      ^
> >
> >  ../cmcseq.stt: In function &#8216;cmcStatus&#8217;:
> >  ../cmcseq.stt:151:3: warning: passing argument 1 of
> >
> > &#8216;strcpy&#8217; makes pointer from integer without a cast
> > [enabled by default] strcpy(pvCmcStatus,msg);
> >
> >     ^  printf("checking if all are connected USE pvConnecetd Count
> >
> > Function, Wait UNTIL lISTED PVS are c  printf("checking if all are
> > connected USE pvConnecetd Count Function, Wait UNTIL lISTED PVS are
> > connected  \n"); /*  configure(&seq,&version);
> >
> >  	  printf("Read Configuration parameter here, Calling File Read
> >
> > function %d %f \n", seq, version); */onnected  \n");
> >
> >  	/*  configure(&seq,&version);
> >
> >  	  printf("Read Configuration parameter here, Calling File Read
> >
> > function %d %f \n", seq, version); */
> >
> >  In file included from cmcseq.c:4:0:
> >  /usr/include/string.h:125:14: note: expected &#8216;char *
> >
> > __restrict__&#8217; but argument is of type &#8216;VAR_ID&#8217;
> > extern char *strcpy (char *__restrict __dest, const char *__restrict
> > __src) ^
> >
> >  /usr/bin/ar -rc   libCMC_SEQSupport.a        initTrace.o cmcseq.o
> >  /usr/bin/ranlib libCMC_SEQSupport.a
> >
> >
> >
> >
> >  The error during run time is .
> >  seq cmcseq,
> >  Sequencer release 2.1.16, compiled Sat Feb 22 20:11:22 2014
> >  Spawning sequencer program "cmcseq", thread 0xd939e0: "cmcseq"
> >  cmcseq[0]: all channels connected & received 1st monitor
> >  epics> Calling cmcStatus...
> >  Segmentation fault (core dumped)
> >
> >
> >
> >
> >
> >
> >  Also, Where can I found  sequencer Examples /tutorial, for
> >  accessing
> >
> > SNL_Function and Pvs in C. I am referring to Sequencer User Guide
> > 2.1.16,already.
> >
> >
> > Thanks and Regards
> >
> > Ganesh Jangir
> >
> > =====-----=====-----====> > Notice: The information contained in this e-mail
> > message and/or attachments to it may contain
> > confidential or privileged information. If you are
> > not the intended recipient, any dissemination, use,
> > review, distribution, printing or copying of the
> > information contained in this e-mail message
> > and/or attachments to it are strictly prohibited. If
> > you have received this communication in error,
> > please notify us by reply e-mail or telephone and
> > immediately and permanently delete the message
> > and any attachments. Thank you
--
"Make it so they have to reboot after every typo." ― Scott Adams

Attachment: signature.asc
Description: This is a digitally signed message part.


References:
Accessing SNL Function and global Pvs from C Ganesh Jangir
Re: Accessing SNL Function and global Pvs from C Benjamin Franksen

Navigate by Date:
Prev: Re: Accessing SNL Function and global Pvs from C Benjamin Franksen
Next: Re: Error in building epics base-3.15.0.1 on windows XP (32 bit) using mingw Johnson, Andrew N.
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  <20142015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Re: Accessing SNL Function and global Pvs from C Benjamin Franksen
Next: Error in building epics base-3.15.0.1 on windows XP (32 bit) using mingw Anindya Roy
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  <20142015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 17 Dec 2015 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·