Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  <20062007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  <20062007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017 
<== Date ==> <== Thread ==>

Subject: Re: Sequencer embedded C code question
From: Eric Norum <norume@aps.anl.gov>
To: Jiro Fujita <jiro.fujita@gmail.com>
Cc: tech-talk@aps.anl.gov
Date: Thu, 29 Jun 2006 17:07:19 -0500
There are quite a few problems here:

On Jun 29, 2006, at 4:28 PM, Jiro Fujita wrote:

Eric,
Here is what the code looks like right now:

program snchygrometer

%%#include <ctype.h>
%%#include <stdlib.h>
%%#include <stdio.h>

 %%char rob[10] ;
 char *roba;
 assign roba to "rawdata" ;     <<<< You should assign a 'string' variable to a stringin record.  Assigning a char * variable is not likely to do what you want.    You then also sync this variable to an event flag.   In your state set you then have  when(efTestAndClear(evFlag_name)) statement befoe the code you wish to run when the stringin record is processed.
 monitor roba ;
 float ch1 ;
 float ch2 ;
 float ch3 ;
 float ch4 ;
 float ch5 ;
 assign ch1 to "PV1";
 assign ch2 to "PV2";
 assign ch3 to "PV3";
 assign ch4 to "PV4";
 assign ch5 to "PV5";

  %%int v ;
  %%int z ;
  %%extern char *wa1 ;
  %%char *sign="+-" ;

%{
when()   <<<<< As you discovered, you can't place an SNL when statement out in the middle of nowhere like this.  Since this is escaped C code and outside any state set what you've done is declare a C function when().  This causes all sorts of other strange things to happen as described below.
{
  rob=&roba; /*i dont know how to do this & wont work w/ roba as just rob*/     <<<<<<<< These statements are not treated as assignment expressions, rather they declare local variables to this function -- since no type is specified the C compiler assumes 'int' which is why you're getting the warnings (a) about default type declarations and (b) about assigning a pointer to an integer.
  v=rob[0];                /*Get first char from string*/
  wa1=strpbrk(rob, "+-");  /*Break string at +-,rest is wa1*/
  z=(float)wa1;            /*convert string to float z*/

ss ss1 {    <<<<<<< You can't do this in escaped C code
  state state1 {
     when (    v==1) {
         ch1 = z; pvPut(ch1);
     } state state2
  }
  state state2 {
     when (    v==2) {
         ch2 = z; pvPut(ch2);
     } state state3
  }
  state state3 {
     when (    v==3) {
         ch3 = z; pvPut(ch3);
     } state state4
  }
  state state4 {
     when (    v==4) {
         ch4 = z; pvPut(ch4);
     } state state5
  }
  state state5 {
     when (    v==5) {
         ch5 = z; pvPut(ch5);
     } state state1
  }
}


(This is the entire code).
and here is the error we are getting:

make[3]: Entering directory
`/home/sysuser/epics3.14.8.2/hygrometerApp/hygrometerApp/src/O.linux-x86'
/usr/bin/gcc -c   -D_POSIX_C_SOURCE=199506L -D_POSIX_THREADS
-D_XOPEN_SOURCE=500        -D_X86_  -DUNIX  -D_BSD_SOURCE -Dlinux
-D_REENTRANT -ansi  -O3  -Wall          -g  -I. -I..
-I../../../include/os/Linux -I../../../include
-I/home/sysuser/epics3.14.8.2/base-3.14.8.2/../modules/soft/seq-2.0.11/include/os/Linux
-I/home/sysuser/epics3.14.8.2/base-3.14.8.2/../modules/soft/seq-2.0.11/include
-I/home/sysuser/epics3.14.8.2/base-3.14.8.2/include/os/Linux
-I/home/sysuser/epics3.14.8.2/base-3.14.8.2/include
-I/home/sysuser/epics3.14.8.2/modules/soft/asyn/4-6/include/os/Linux
-I/home/sysuser/epics3.14.8.2/modules/soft/asyn/4-6/include
sncProgram.c
../sncExample.stt:35: warning: return type defaults to `int'
../sncExample.stt: In function `when':
../sncExample.stt:36: `roba' undeclared (first use in this function)
../sncExample.stt:36: (Each undeclared identifier is reported only once
../sncExample.stt:36: for each function it appears in.)
../sncExample.stt:39: pointer value used where a floating point value
was expected
make[3]: *** [sncProgram.o] Error 1
make[3]: Leaving directory
`/home/sysuser/epics3.14.8.2/hygrometerApp/hygrometerApp/src/O.linux-x86'
make[2]: *** [install.linux-x86] Error 2
make[2]: Leaving directory
`/home/sysuser/epics3.14.8.2/hygrometerApp/hygrometerApp/src'
make[1]: *** [src.install] Error 2
make[1]: Leaving directory
`/home/sysuser/epics3.14.8.2/hygrometerApp/hygrometerApp'
make: *** [hygrometerApp.install] Error 2

What we are wondering is, why does it think rob is defaulting to int,
when we are setting it as char??  Obviously, there is something wrong
with array vs pointer (this is what I have been telling to my
students), but this seems to compile without any issues outside of
EPICS (well, the original ones we started out did, anyway).


-- 
Eric Norum <norume@aps.anl.gov>
Advanced Photon Source
Argonne National Laboratory
(630) 252-4793



References:
Re: Sequencer embedded C code question Jiro Fujita
RE: Sequencer embedded C code question Laznovsky, Michael
Re: Sequencer embedded C code question Jiro Fujita
Re: Sequencer embedded C code question Eric Norum
Re: Sequencer embedded C code question Jiro Fujita

Navigate by Date:
Prev: Re: Sequencer embedded C code question Pete Jemian
Next: Re: Sequencer embedded C code question Jiro Fujita
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  <20062007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017 
Navigate by Thread:
Prev: Re: Sequencer embedded C code question Jiro Fujita
Next: RE: Sequencer embedded C code question Laznovsky, Michael
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  <20062007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017 
ANJ, 02 Sep 2010 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·