Quantcast

Re: [Beremiz-devel] Creating own functions

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Beremiz-devel] Creating own functions

Beremiz-Devel mailing list
Hello!

I'm not sure is it bug or not: I created own function with input param of ANY type. I try to use it and got the follows:

FUNCTION PRINT_ANY : INT
  VAR_INPUT
    VAR : WORD;
  END_VAR
                     {{
                     printf("value: %u\r\n", (unsigned int) VAR);
                     PRINT_ANY = 1;
                     }}
END_FUNCTION


PROGRAM program0
  VAR
    rez : INT;
    in : INT;
  END_VAR

  in := 1;
  rez := PRINT_ANY(in);
END_PROGRAM


CONFIGURATION config

  RESOURCE resource1 ON PLC
    TASK task1(INTERVAL := T#1s0ms,PRIORITY := 0);
    PROGRAM inst1 WITH task1 : program0;
  END_RESOURCE
END_CONFIGURATION

Matiec crashes when I try to compile it, so I don't get any errors from it.

Does there exist possibility to create own function with input params of ANY type?

Regards,
Vasilij

2017-04-03 4:09 GMT+00:00 yanvasilij yan <[hidden email]>:
Hello, Andrey,

And again you are right - my mistake. Thank you a lot for help!

Regards,
Vasilij

2017-04-02 8:00 GMT+00:00 <[hidden email]>:
Hi,

sorry for not looking close enough at your library code as you posted
it for a first time, because it was wrong as well.



On 17-04-01 07:34, [hidden email] wrote:
> Here it is:
>
> 2017-04-01 6:48 GMT+00:00 <[hidden email]>:
>
> > On 17-04-01 06:13, [hidden email] wrote:
> > > As I said - It doesn't work. Because in ST-code doesn't appear
> > realisation
> > > of Words_To_Real. It works with FB, but not with functions.
> >


> > > >       <pou name="Words_To_Real" pouType="function">
> > > >         <interface>
> > > >           <returnType>
> > > >             <REAL/>
> > > >           </returnType>
> > > >           <inputVars>
> > > >             <variable name="in1">
> > > >               <type>
> > > >                 <WORD/>
> > > >               </type>
> > > >             </variable>
> > > >             <variable name="in2">
> > > >               <type>
> > > >                 <WORD/>
> > > >               </type>
> > > >             </variable>
> > > >           </inputVars>
> > > >         </interface>
> > > >         <body>
> > > >           <ST>
> > > >             <![CDATA[
> > > >
> > > >                      {{
> > > >                      float words_to_real_ll(int, int);
> > > >                      WORDS_TO_REAL = words_to_real_ll(IN1, IN2); }}
> > > > ]]>
> > > >           </ST>
> > > >         </body>
> > > >       </pou>
> > > > ...


>          <pou name="myfunction" pouType="function">
>         <interface>
>           <returnType>
>             <INT/>
>           </returnType>
>           <inputVars>
>           </inputVars>
>         </interface>
>         <body>
>           <ST>
>             <xhtml:p><![CDATA[MYFUNCTION:= {{ myfunction := myRunTimeFunction();}};]]></xhtml:p>
>           </ST>
>         </body>
>       </pou>


So here you have several problems
1. inside of C pragma ({{ .. }}) should be correct C code.
   Don't use := there. You can look how to use C pragma in python example.

2. to access IEC function result value use function name in upper case
(as we found in the last discussion)

3. Missing function definition inside your pragma. Because according
to C89 if you don't have function definition compiler assumes that
function returns int and takes fixed number of arguments. This is not
an error, it can potentially cause problems at runtime.

4. Assigning C pragma to IEC variable looks wrong for me. I think this
is the reason for matiec error message.

Try this code in your library.
<ST>
  <![CDATA[
      {{
            extern int myRunTimeFunction(void);
            MYFUNCTION = myRunTimeFunction();
      }}
  ]]>
</ST>



--
Best regards,
Andrey Skvortsov

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Beremiz-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beremiz-devel




------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Beremiz-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beremiz-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Beremiz-devel] Creating own functions

Beremiz-Devel mailing list
I'm realy sorry, I've posted wrong code. Here the code with ANY type in function:

FUNCTION PRINT_ANY : INT
  VAR_INPUT
    VAR : ANY;
  END_VAR
                     {{
                     printf("value: %u\r\n", (unsigned int) VAR);
                     PRINT_ANY = 1;
                     }}
END_FUNCTION


PROGRAM program0
  VAR
    rez : INT;
    in : INT;
  END_VAR

  in := 1;
  rez := PRINT_ANY(in);
END_PROGRAM


CONFIGURATION config

  RESOURCE resource1 ON PLC
    TASK task1(INTERVAL := T#1s0ms,PRIORITY := 0);
    PROGRAM inst1 WITH task1 : program0;
  END_RESOURCE
END_CONFIGURATION


2017-04-17 7:31 GMT+00:00 yanvasilij yan <[hidden email]>:
Hello!

I'm not sure is it bug or not: I created own function with input param of ANY type. I try to use it and got the follows:

FUNCTION PRINT_ANY : INT
  VAR_INPUT
    VAR : WORD;
  END_VAR
                     {{
                     printf("value: %u\r\n", (unsigned int) VAR);
                     PRINT_ANY = 1;
                     }}
END_FUNCTION


PROGRAM program0
  VAR
    rez : INT;
    in : INT;
  END_VAR

  in := 1;
  rez := PRINT_ANY(in);
END_PROGRAM


CONFIGURATION config

  RESOURCE resource1 ON PLC
    TASK task1(INTERVAL := T#1s0ms,PRIORITY := 0);
    PROGRAM inst1 WITH task1 : program0;
  END_RESOURCE
END_CONFIGURATION

Matiec crashes when I try to compile it, so I don't get any errors from it.

Does there exist possibility to create own function with input params of ANY type?

Regards,
Vasilij

2017-04-03 4:09 GMT+00:00 yanvasilij yan <[hidden email]>:
Hello, Andrey,

And again you are right - my mistake. Thank you a lot for help!

Regards,
Vasilij

2017-04-02 8:00 GMT+00:00 <[hidden email]>:
Hi,

sorry for not looking close enough at your library code as you posted
it for a first time, because it was wrong as well.



On 17-04-01 07:34, [hidden email] wrote:
> Here it is:
>
> 2017-04-01 6:48 GMT+00:00 <[hidden email]>:
>
> > On 17-04-01 06:13, [hidden email] wrote:
> > > As I said - It doesn't work. Because in ST-code doesn't appear
> > realisation
> > > of Words_To_Real. It works with FB, but not with functions.
> >


> > > >       <pou name="Words_To_Real" pouType="function">
> > > >         <interface>
> > > >           <returnType>
> > > >             <REAL/>
> > > >           </returnType>
> > > >           <inputVars>
> > > >             <variable name="in1">
> > > >               <type>
> > > >                 <WORD/>
> > > >               </type>
> > > >             </variable>
> > > >             <variable name="in2">
> > > >               <type>
> > > >                 <WORD/>
> > > >               </type>
> > > >             </variable>
> > > >           </inputVars>
> > > >         </interface>
> > > >         <body>
> > > >           <ST>
> > > >             <![CDATA[
> > > >
> > > >                      {{
> > > >                      float words_to_real_ll(int, int);
> > > >                      WORDS_TO_REAL = words_to_real_ll(IN1, IN2); }}
> > > > ]]>
> > > >           </ST>
> > > >         </body>
> > > >       </pou>
> > > > ...


>          <pou name="myfunction" pouType="function">
>         <interface>
>           <returnType>
>             <INT/>
>           </returnType>
>           <inputVars>
>           </inputVars>
>         </interface>
>         <body>
>           <ST>
>             <xhtml:p><![CDATA[MYFUNCTION:= {{ myfunction := myRunTimeFunction();}};]]></xhtml:p>
>           </ST>
>         </body>
>       </pou>


So here you have several problems
1. inside of C pragma ({{ .. }}) should be correct C code.
   Don't use := there. You can look how to use C pragma in python example.

2. to access IEC function result value use function name in upper case
(as we found in the last discussion)

3. Missing function definition inside your pragma. Because according
to C89 if you don't have function definition compiler assumes that
function returns int and takes fixed number of arguments. This is not
an error, it can potentially cause problems at runtime.

4. Assigning C pragma to IEC variable looks wrong for me. I think this
is the reason for matiec error message.

Try this code in your library.
<ST>
  <![CDATA[
      {{
            extern int myRunTimeFunction(void);
            MYFUNCTION = myRunTimeFunction();
      }}
  ]]>
</ST>



--
Best regards,
Andrey Skvortsov

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Beremiz-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beremiz-devel





------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Beremiz-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beremiz-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Beremiz-devel] Creating own functions

Beremiz-Devel mailing list




 Hi,


 Matiec follows the IEC 61131-3 standard, which says that ANY data types are
not allowed in user code. These data types are only allowed in the standard
functions.

 Matiec therefore is able to parse the ANY data types (i.e. stages 1, 2, and 3
support ANY data types), but is not able to generate C code for these data
types.

 The bug is that it should be printing out an error message instead of
crashing.



 Cheers,

      Mario






On Monday 17 April 2017 08:33:19 [hidden email] wrote:

> I'm realy sorry, I've posted wrong code. Here the code with ANY type in
> function:
>
> FUNCTION PRINT_ANY : INT
>   VAR_INPUT
>     VAR : ANY;
>   END_VAR
>                      {{
>                      printf("value: %u\r\n", (unsigned int) VAR);
>                      PRINT_ANY = 1;
>                      }}
> END_FUNCTION
>
>
> PROGRAM program0
>   VAR
>     rez : INT;
>     in : INT;
>   END_VAR
>
>   in := 1;
>   rez := PRINT_ANY(in);
> END_PROGRAM
>
>
> CONFIGURATION config
>
>   RESOURCE resource1 ON PLC
>     TASK task1(INTERVAL := T#1s0ms,PRIORITY := 0);
>     PROGRAM inst1 WITH task1 : program0;
>   END_RESOURCE
> END_CONFIGURATION
>
> 2017-04-17 7:31 GMT+00:00 yanvasilij yan <[hidden email]>:
> > Hello!
> >
> > I'm not sure is it bug or not: I created own function with input param of
> > ANY type. I try to use it and got the follows:
> >
> > FUNCTION PRINT_ANY : INT
> >
> >   VAR_INPUT
> >  
> >     VAR : WORD;
> >  
> >   END_VAR
> >  
> >                      {{
> >                      printf("value: %u\r\n", (unsigned int) VAR);
> >                      PRINT_ANY = 1;
> >                      }}
> >
> > END_FUNCTION
> >
> >
> > PROGRAM program0
> >
> >   VAR
> >  
> >     rez : INT;
> >     in : INT;
> >  
> >   END_VAR
> >  
> >   in := 1;
> >   rez := PRINT_ANY(in);
> >
> > END_PROGRAM
> >
> >
> > CONFIGURATION config
> >
> >   RESOURCE resource1 ON PLC
> >  
> >     TASK task1(INTERVAL := T#1s0ms,PRIORITY := 0);
> >     PROGRAM inst1 WITH task1 : program0;
> >  
> >   END_RESOURCE
> >
> > END_CONFIGURATION
> >
> > Matiec crashes when I try to compile it, so I don't get any errors from
> > it.
> >
> > Does there exist possibility to create own function with input params of
> > ANY type?
> >
> > Regards,
> > Vasilij
> >
> > 2017-04-03 4:09 GMT+00:00 yanvasilij yan <[hidden email]>:
> >> Hello, Andrey,
> >>
> >> And again you are right - my mistake. Thank you a lot for help!
> >>
> >> Regards,
> >> Vasilij
> >>
> >> 2017-04-02 8:00 GMT+00:00 <[hidden email]>:
> >>> Hi,
> >>>
> >>> sorry for not looking close enough at your library code as you posted
> >>> it for a first time, because it was wrong as well.
> >>>
> >>> On 17-04-01 07:34, [hidden email] wrote:
> >>> > Here it is:
> >>> >
> >>> > 2017-04-01 6:48 GMT+00:00 <[hidden email]>:
> >>> > > On 17-04-01 06:13, [hidden email] wrote:
> >>> > > > As I said - It doesn't work. Because in ST-code doesn't appear
> >>> > >
> >>> > > realisation
> >>> > >
> >>> > > > of Words_To_Real. It works with FB, but not with functions.
> >>> > > >
> >>> > > > >       <pou name="Words_To_Real" pouType="function">
> >>> > > > >      
> >>> > > > >         <interface>
> >>> > > > >        
> >>> > > > >           <returnType>
> >>> > > > >          
> >>> > > > >             <REAL/>
> >>> > > > >          
> >>> > > > >           </returnType>
> >>> > > > >           <inputVars>
> >>> > > > >          
> >>> > > > >             <variable name="in1">
> >>> > > > >            
> >>> > > > >               <type>
> >>> > > > >              
> >>> > > > >                 <WORD/>
> >>> > > > >              
> >>> > > > >               </type>
> >>> > > > >            
> >>> > > > >             </variable>
> >>> > > > >             <variable name="in2">
> >>> > > > >            
> >>> > > > >               <type>
> >>> > > > >              
> >>> > > > >                 <WORD/>
> >>> > > > >              
> >>> > > > >               </type>
> >>> > > > >            
> >>> > > > >             </variable>
> >>> > > > >          
> >>> > > > >           </inputVars>
> >>> > > > >        
> >>> > > > >         </interface>
> >>> > > > >         <body>
> >>> > > > >        
> >>> > > > >           <ST>
> >>> > > > >          
> >>> > > > >             <![CDATA[
> >>> > > > >            
> >>> > > > >                      {{
> >>> > > > >                      float words_to_real_ll(int, int);
> >>> > > > >                      WORDS_TO_REAL = words_to_real_ll(IN1,
> >>> > > > >                      IN2);
> >>>
> >>> }}
> >>>
> >>> > > > > ]]>
> >>> > > > >
> >>> > > > >           </ST>
> >>> > > > >        
> >>> > > > >         </body>
> >>> > > > >      
> >>> > > > >       </pou>
> >>> > > > >
> >>> > > > > ...
> >>> > > > >
> >>> >          <pou name="myfunction" pouType="function">
> >>> >        
> >>> >         <interface>
> >>> >        
> >>> >           <returnType>
> >>> >          
> >>> >             <INT/>
> >>> >          
> >>> >           </returnType>
> >>> >           <inputVars>
> >>> >           </inputVars>
> >>> >        
> >>> >         </interface>
> >>> >         <body>
> >>> >        
> >>> >           <ST>
> >>> >          
> >>> >             <xhtml:p><![CDATA[MYFUNCTION:= {{ myfunction :=
> >>>
> >>> myRunTimeFunction();}};]]></xhtml:p>
> >>>
> >>> >           </ST>
> >>> >        
> >>> >         </body>
> >>> >      
> >>> >       </pou>
> >>>
> >>> So here you have several problems
> >>> 1. inside of C pragma ({{ .. }}) should be correct C code.
> >>>
> >>>    Don't use := there. You can look how to use C pragma in python
> >>>
> >>> example.
> >>>
> >>> 2. to access IEC function result value use function name in upper case
> >>> (as we found in the last discussion)
> >>>
> >>> 3. Missing function definition inside your pragma. Because according
> >>> to C89 if you don't have function definition compiler assumes that
> >>> function returns int and takes fixed number of arguments. This is not
> >>> an error, it can potentially cause problems at runtime.
> >>>
> >>> 4. Assigning C pragma to IEC variable looks wrong for me. I think this
> >>> is the reason for matiec error message.
> >>>
> >>> Try this code in your library.
> >>> <ST>
> >>>
> >>>   <![CDATA[
> >>>  
> >>>       {{
> >>>      
> >>>             extern int myRunTimeFunction(void);
> >>>             MYFUNCTION = myRunTimeFunction();
> >>>      
> >>>       }}
> >>>  
> >>>   ]]>
> >>>
> >>> </ST>
> >>>
> >>>
> >>>
> >>> --
> >>> Best regards,
> >>> Andrey Skvortsov
> >>>
> >>> ------------------------------------------------------------
> >>> ------------------
> >>> Check out the vibrant tech community on one of the world's most
> >>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> >>> _______________________________________________
> >>> Beremiz-devel mailing list
> >>> [hidden email]
> >>> https://lists.sourceforge.net/lists/listinfo/beremiz-devel

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Beremiz-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beremiz-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Beremiz-devel] Creating own functions

Beremiz-Devel mailing list
Hello Mario,

Got it! Thanks for explanation!

Regards,
Vasilij

2017-04-17 8:54 GMT+00:00 <[hidden email]>:




 Hi,


 Matiec follows the IEC 61131-3 standard, which says that ANY data types are
not allowed in user code. These data types are only allowed in the standard
functions.

 Matiec therefore is able to parse the ANY data types (i.e. stages 1, 2, and 3
support ANY data types), but is not able to generate C code for these data
types.

 The bug is that it should be printing out an error message instead of
crashing.



 Cheers,

      Mario






On Monday 17 April 2017 08:33:19 [hidden email] wrote:
> I'm realy sorry, I've posted wrong code. Here the code with ANY type in
> function:
>
> FUNCTION PRINT_ANY : INT
>   VAR_INPUT
>     VAR : ANY;
>   END_VAR
>                      {{
>                      printf("value: %u\r\n", (unsigned int) VAR);
>                      PRINT_ANY = 1;
>                      }}
> END_FUNCTION
>
>
> PROGRAM program0
>   VAR
>     rez : INT;
>     in : INT;
>   END_VAR
>
>   in := 1;
>   rez := PRINT_ANY(in);
> END_PROGRAM
>
>
> CONFIGURATION config
>
>   RESOURCE resource1 ON PLC
>     TASK task1(INTERVAL := T#1s0ms,PRIORITY := 0);
>     PROGRAM inst1 WITH task1 : program0;
>   END_RESOURCE
> END_CONFIGURATION
>
> 2017-04-17 7:31 GMT+00:00 yanvasilij yan <[hidden email]>:
> > Hello!
> >
> > I'm not sure is it bug or not: I created own function with input param of
> > ANY type. I try to use it and got the follows:
> >
> > FUNCTION PRINT_ANY : INT
> >
> >   VAR_INPUT
> >
> >     VAR : WORD;
> >
> >   END_VAR
> >
> >                      {{
> >                      printf("value: %u\r\n", (unsigned int) VAR);
> >                      PRINT_ANY = 1;
> >                      }}
> >
> > END_FUNCTION
> >
> >
> > PROGRAM program0
> >
> >   VAR
> >
> >     rez : INT;
> >     in : INT;
> >
> >   END_VAR
> >
> >   in := 1;
> >   rez := PRINT_ANY(in);
> >
> > END_PROGRAM
> >
> >
> > CONFIGURATION config
> >
> >   RESOURCE resource1 ON PLC
> >
> >     TASK task1(INTERVAL := T#1s0ms,PRIORITY := 0);
> >     PROGRAM inst1 WITH task1 : program0;
> >
> >   END_RESOURCE
> >
> > END_CONFIGURATION
> >
> > Matiec crashes when I try to compile it, so I don't get any errors from
> > it.
> >
> > Does there exist possibility to create own function with input params of
> > ANY type?
> >
> > Regards,
> > Vasilij
> >
> > 2017-04-03 4:09 GMT+00:00 yanvasilij yan <[hidden email]>:
> >> Hello, Andrey,
> >>
> >> And again you are right - my mistake. Thank you a lot for help!
> >>
> >> Regards,
> >> Vasilij
> >>
> >> 2017-04-02 8:00 GMT+00:00 <[hidden email]>:
> >>> Hi,
> >>>
> >>> sorry for not looking close enough at your library code as you posted
> >>> it for a first time, because it was wrong as well.
> >>>
> >>> On 17-04-01 07:34, [hidden email] wrote:
> >>> > Here it is:
> >>> >
> >>> > 2017-04-01 6:48 GMT+00:00 <[hidden email]>:
> >>> > > On 17-04-01 06:13, [hidden email] wrote:
> >>> > > > As I said - It doesn't work. Because in ST-code doesn't appear
> >>> > >
> >>> > > realisation
> >>> > >
> >>> > > > of Words_To_Real. It works with FB, but not with functions.
> >>> > > >
> >>> > > > >       <pou name="Words_To_Real" pouType="function">
> >>> > > > >
> >>> > > > >         <interface>
> >>> > > > >
> >>> > > > >           <returnType>
> >>> > > > >
> >>> > > > >             <REAL/>
> >>> > > > >
> >>> > > > >           </returnType>
> >>> > > > >           <inputVars>
> >>> > > > >
> >>> > > > >             <variable name="in1">
> >>> > > > >
> >>> > > > >               <type>
> >>> > > > >
> >>> > > > >                 <WORD/>
> >>> > > > >
> >>> > > > >               </type>
> >>> > > > >
> >>> > > > >             </variable>
> >>> > > > >             <variable name="in2">
> >>> > > > >
> >>> > > > >               <type>
> >>> > > > >
> >>> > > > >                 <WORD/>
> >>> > > > >
> >>> > > > >               </type>
> >>> > > > >
> >>> > > > >             </variable>
> >>> > > > >
> >>> > > > >           </inputVars>
> >>> > > > >
> >>> > > > >         </interface>
> >>> > > > >         <body>
> >>> > > > >
> >>> > > > >           <ST>
> >>> > > > >
> >>> > > > >             <![CDATA[
> >>> > > > >
> >>> > > > >                      {{
> >>> > > > >                      float words_to_real_ll(int, int);
> >>> > > > >                      WORDS_TO_REAL = words_to_real_ll(IN1,
> >>> > > > >                      IN2);
> >>>
> >>> }}
> >>>
> >>> > > > > ]]>
> >>> > > > >
> >>> > > > >           </ST>
> >>> > > > >
> >>> > > > >         </body>
> >>> > > > >
> >>> > > > >       </pou>
> >>> > > > >
> >>> > > > > ...
> >>> > > > >
> >>> >          <pou name="myfunction" pouType="function">
> >>> >
> >>> >         <interface>
> >>> >
> >>> >           <returnType>
> >>> >
> >>> >             <INT/>
> >>> >
> >>> >           </returnType>
> >>> >           <inputVars>
> >>> >           </inputVars>
> >>> >
> >>> >         </interface>
> >>> >         <body>
> >>> >
> >>> >           <ST>
> >>> >
> >>> >             <xhtml:p><![CDATA[MYFUNCTION:= {{ myfunction :=
> >>>
> >>> myRunTimeFunction();}};]]></xhtml:p>
> >>>
> >>> >           </ST>
> >>> >
> >>> >         </body>
> >>> >
> >>> >       </pou>
> >>>
> >>> So here you have several problems
> >>> 1. inside of C pragma ({{ .. }}) should be correct C code.
> >>>
> >>>    Don't use := there. You can look how to use C pragma in python
> >>>
> >>> example.
> >>>
> >>> 2. to access IEC function result value use function name in upper case
> >>> (as we found in the last discussion)
> >>>
> >>> 3. Missing function definition inside your pragma. Because according
> >>> to C89 if you don't have function definition compiler assumes that
> >>> function returns int and takes fixed number of arguments. This is not
> >>> an error, it can potentially cause problems at runtime.
> >>>
> >>> 4. Assigning C pragma to IEC variable looks wrong for me. I think this
> >>> is the reason for matiec error message.
> >>>
> >>> Try this code in your library.
> >>> <ST>
> >>>
> >>>   <![CDATA[
> >>>
> >>>       {{
> >>>
> >>>             extern int myRunTimeFunction(void);
> >>>             MYFUNCTION = myRunTimeFunction();
> >>>
> >>>       }}
> >>>
> >>>   ]]>
> >>>
> >>> </ST>
> >>>
> >>>
> >>>
> >>> --
> >>> Best regards,
> >>> Andrey Skvortsov
> >>>
> >>> ------------------------------------------------------------
> >>> ------------------
> >>> Check out the vibrant tech community on one of the world's most
> >>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> >>> _______________________________________________
> >>> Beremiz-devel mailing list
> >>> [hidden email]
> >>> https://lists.sourceforge.net/lists/listinfo/beremiz-devel

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Beremiz-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beremiz-devel


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Beremiz-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beremiz-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Beremiz-devel] Creating own functions

Beremiz-Devel mailing list


  It has been some time since I last messed with that part of the code.
Anyway, I have just realised that what I said is not completely true.

 Matiec does not actually support ANY data types directly (i.e., no stage
supports ANY data types). We do have the equivalent of ANY data types in the
standard functions, although we do this differently. In other words, the end
result is the same as an ANY data type, but matiec does not support it
directly.

  Mario.
 

 




On Monday 17 April 2017 10:19:06 [hidden email] wrote:

> Hello Mario,
>
> Got it! Thanks for explanation!
>
> Regards,
> Vasilij
>
> 2017-04-17 8:54 GMT+00:00 <[hidden email]>:
> >  Hi,
> >  
> >  
> >  Matiec follows the IEC 61131-3 standard, which says that ANY data types
> >
> > are
> > not allowed in user code. These data types are only allowed in the
> > standard functions.
> >
> >  Matiec therefore is able to parse the ANY data types (i.e. stages 1, 2,
> >
> > and 3
> > support ANY data types), but is not able to generate C code for these
> > data types.
> >
> >  The bug is that it should be printing out an error message instead of
> >
> > crashing.
> >
> >  Cheers,
> >  
> >       Mario
> >
> > On Monday 17 April 2017 08:33:19 [hidden email]
> >
> > wrote:
> > > I'm realy sorry, I've posted wrong code. Here the code with ANY type in
> > > function:
> > >
> > > FUNCTION PRINT_ANY : INT
> > >
> > >   VAR_INPUT
> > >  
> > >     VAR : ANY;
> > >  
> > >   END_VAR
> > >  
> > >                      {{
> > >                      printf("value: %u\r\n", (unsigned int) VAR);
> > >                      PRINT_ANY = 1;
> > >                      }}
> > >
> > > END_FUNCTION
> > >
> > >
> > > PROGRAM program0
> > >
> > >   VAR
> > >  
> > >     rez : INT;
> > >     in : INT;
> > >  
> > >   END_VAR
> > >  
> > >   in := 1;
> > >   rez := PRINT_ANY(in);
> > >
> > > END_PROGRAM
> > >
> > >
> > > CONFIGURATION config
> > >
> > >   RESOURCE resource1 ON PLC
> > >  
> > >     TASK task1(INTERVAL := T#1s0ms,PRIORITY := 0);
> > >     PROGRAM inst1 WITH task1 : program0;
> > >  
> > >   END_RESOURCE
> > >
> > > END_CONFIGURATION
> > >
> > > 2017-04-17 7:31 GMT+00:00 yanvasilij yan <[hidden email]>:
> > > > Hello!
> > > >
> > > > I'm not sure is it bug or not: I created own function with input
> > > > param
> >
> > of
> >
> > > > ANY type. I try to use it and got the follows:
> > > >
> > > > FUNCTION PRINT_ANY : INT
> > > >
> > > >   VAR_INPUT
> > > >  
> > > >     VAR : WORD;
> > > >  
> > > >   END_VAR
> > > >  
> > > >                      {{
> > > >                      printf("value: %u\r\n", (unsigned int) VAR);
> > > >                      PRINT_ANY = 1;
> > > >                      }}
> > > >
> > > > END_FUNCTION
> > > >
> > > >
> > > > PROGRAM program0
> > > >
> > > >   VAR
> > > >  
> > > >     rez : INT;
> > > >     in : INT;
> > > >  
> > > >   END_VAR
> > > >  
> > > >   in := 1;
> > > >   rez := PRINT_ANY(in);
> > > >
> > > > END_PROGRAM
> > > >
> > > >
> > > > CONFIGURATION config
> > > >
> > > >   RESOURCE resource1 ON PLC
> > > >  
> > > >     TASK task1(INTERVAL := T#1s0ms,PRIORITY := 0);
> > > >     PROGRAM inst1 WITH task1 : program0;
> > > >  
> > > >   END_RESOURCE
> > > >
> > > > END_CONFIGURATION
> > > >
> > > > Matiec crashes when I try to compile it, so I don't get any errors
> > > > from it.
> > > >
> > > > Does there exist possibility to create own function with input params
> >
> > of
> >
> > > > ANY type?
> > > >
> > > > Regards,
> > > > Vasilij
> > > >
> > > > 2017-04-03 4:09 GMT+00:00 yanvasilij yan <[hidden email]>:
> > > >> Hello, Andrey,
> > > >>
> > > >> And again you are right - my mistake. Thank you a lot for help!
> > > >>
> > > >> Regards,
> > > >> Vasilij
> > > >>
> > > >> 2017-04-02 8:00 GMT+00:00 <[hidden email]>:
> > > >>> Hi,
> > > >>>
> > > >>> sorry for not looking close enough at your library code as you
> > > >>> posted it for a first time, because it was wrong as well.
> > > >>>
> > > >>> On 17-04-01 07:34, [hidden email] wrote:
> > > >>> > Here it is:
> > > >>> >
> > > >>> > 2017-04-01 6:48 GMT+00:00 <[hidden email]>:
> > > >>> > > On 17-04-01 06:13, [hidden email] wrote:
> > > >>> > > > As I said - It doesn't work. Because in ST-code doesn't
> > > >>> > > > appear
> > > >>> > >
> > > >>> > > realisation
> > > >>> > >
> > > >>> > > > of Words_To_Real. It works with FB, but not with functions.
> > > >>> > > >
> > > >>> > > > >       <pou name="Words_To_Real" pouType="function">
> > > >>> > > > >      
> > > >>> > > > >         <interface>
> > > >>> > > > >        
> > > >>> > > > >           <returnType>
> > > >>> > > > >          
> > > >>> > > > >             <REAL/>
> > > >>> > > > >          
> > > >>> > > > >           </returnType>
> > > >>> > > > >           <inputVars>
> > > >>> > > > >          
> > > >>> > > > >             <variable name="in1">
> > > >>> > > > >            
> > > >>> > > > >               <type>
> > > >>> > > > >              
> > > >>> > > > >                 <WORD/>
> > > >>> > > > >              
> > > >>> > > > >               </type>
> > > >>> > > > >            
> > > >>> > > > >             </variable>
> > > >>> > > > >             <variable name="in2">
> > > >>> > > > >            
> > > >>> > > > >               <type>
> > > >>> > > > >              
> > > >>> > > > >                 <WORD/>
> > > >>> > > > >              
> > > >>> > > > >               </type>
> > > >>> > > > >            
> > > >>> > > > >             </variable>
> > > >>> > > > >          
> > > >>> > > > >           </inputVars>
> > > >>> > > > >        
> > > >>> > > > >         </interface>
> > > >>> > > > >         <body>
> > > >>> > > > >        
> > > >>> > > > >           <ST>
> > > >>> > > > >          
> > > >>> > > > >             <![CDATA[
> > > >>> > > > >            
> > > >>> > > > >                      {{
> > > >>> > > > >                      float words_to_real_ll(int, int);
> > > >>> > > > >                      WORDS_TO_REAL = words_to_real_ll(IN1,
> > > >>> > > > >                      IN2);
> > > >>>
> > > >>> }}
> > > >>>
> > > >>> > > > > ]]>
> > > >>> > > > >
> > > >>> > > > >           </ST>
> > > >>> > > > >        
> > > >>> > > > >         </body>
> > > >>> > > > >      
> > > >>> > > > >       </pou>
> > > >>> > > > >
> > > >>> > > > > ...
> > > >>> > > > >
> > > >>> >          <pou name="myfunction" pouType="function">
> > > >>> >        
> > > >>> >         <interface>
> > > >>> >        
> > > >>> >           <returnType>
> > > >>> >          
> > > >>> >             <INT/>
> > > >>> >          
> > > >>> >           </returnType>
> > > >>> >           <inputVars>
> > > >>> >           </inputVars>
> > > >>> >        
> > > >>> >         </interface>
> > > >>> >         <body>
> > > >>> >        
> > > >>> >           <ST>
> > > >>> >          
> > > >>> >             <xhtml:p><![CDATA[MYFUNCTION:= {{ myfunction :=
> > > >>>
> > > >>> myRunTimeFunction();}};]]></xhtml:p>
> > > >>>
> > > >>> >           </ST>
> > > >>> >        
> > > >>> >         </body>
> > > >>> >      
> > > >>> >       </pou>
> > > >>>
> > > >>> So here you have several problems
> > > >>> 1. inside of C pragma ({{ .. }}) should be correct C code.
> > > >>>
> > > >>>    Don't use := there. You can look how to use C pragma in python
> > > >>>
> > > >>> example.
> > > >>>
> > > >>> 2. to access IEC function result value use function name in upper
> >
> > case
> >
> > > >>> (as we found in the last discussion)
> > > >>>
> > > >>> 3. Missing function definition inside your pragma. Because
> > > >>> according to C89 if you don't have function definition compiler
> > > >>> assumes that function returns int and takes fixed number of
> > > >>> arguments. This is not an error, it can potentially cause problems
> > > >>> at runtime.
> > > >>>
> > > >>> 4. Assigning C pragma to IEC variable looks wrong for me. I think
> >
> > this
> >
> > > >>> is the reason for matiec error message.
> > > >>>
> > > >>> Try this code in your library.
> > > >>> <ST>
> > > >>>
> > > >>>   <![CDATA[
> > > >>>  
> > > >>>       {{
> > > >>>      
> > > >>>             extern int myRunTimeFunction(void);
> > > >>>             MYFUNCTION = myRunTimeFunction();
> > > >>>      
> > > >>>       }}
> > > >>>  
> > > >>>   ]]>
> > > >>>
> > > >>> </ST>
> > > >>>
> > > >>>
> > > >>>
> > > >>> --
> > > >>> Best regards,
> > > >>> Andrey Skvortsov
> > > >>>
> > > >>> ------------------------------------------------------------
> > > >>> ------------------
> > > >>> Check out the vibrant tech community on one of the world's most
> > > >>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> > > >>> _______________________________________________
> > > >>> Beremiz-devel mailing list
> > > >>> [hidden email]
> > > >>> https://lists.sourceforge.net/lists/listinfo/beremiz-devel
> >
> > ------------------------------------------------------------
> > ------------------
> > Check out the vibrant tech community on one of the world's most
> > engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> > _______________________________________________
> > Beremiz-devel mailing list
> > [hidden email]
> > https://lists.sourceforge.net/lists/listinfo/beremiz-devel

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Beremiz-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beremiz-devel
Loading...