tests/python/c_code@c_ext/cfile.xml
author Laurent Bessard
Mon, 10 Jun 2013 23:48:08 +0200
changeset 1242 ec2c415fc65e
parent 1125 1b1472e76f07
child 1401 611fded24ce4
permissions -rw-r--r--
Rewrite FBDBlockDialog and BlockPreviewDialog
734
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
     1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
1125
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
     2
<CFile>
734
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
     3
  <includes>
1125
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
     4
<![CDATA[
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
     5
]]>
734
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
     6
  </includes>
859
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
     7
  <variables>
1099
d9c28879e55b Updated python test
Laurent Bessard
parents: 1086
diff changeset
     8
    <variable name="TestInput" type="SINT" initial="0"/>
d9c28879e55b Updated python test
Laurent Bessard
parents: 1086
diff changeset
     9
    <variable name="TestOutput" type="SINT"/>
859
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    10
  </variables>
734
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    11
  <globals>
1125
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    12
<![CDATA[
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    13
volatile long Lock=0;
859
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    14
volatile char PtoC=1,CtoP=2;
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    15
1086
b566ab5556ab Fixed warnings in python test
Laurent Bessard
parents: 953
diff changeset
    16
extern long AtomicCompareExchange(long*,long, long);
b566ab5556ab Fixed warnings in python test
Laurent Bessard
parents: 953
diff changeset
    17
859
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    18
int Simple_C_Call(int val){
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    19
  return val+1;
734
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    20
}
859
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    21
862
bb59865db6e6 Introduced FBID in tests/python example. Fixed type error leading to segfault
Edouard Tisserant
parents: 860
diff changeset
    22
int Python_to_C_Call(char toC, char *fromC){
859
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    23
  /* Code called by python should never touch to 
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    24
     variables modified by PLC thread directly
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    25
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    26
     AtomicCompareExchange comes from 
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    27
     beremiz' runtime implementation */
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    28
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    29
  int res = 0;
1086
b566ab5556ab Fixed warnings in python test
Laurent Bessard
parents: 953
diff changeset
    30
  if(!AtomicCompareExchange((long*)&Lock, 0, 1)){
859
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    31
    PtoC=toC;
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    32
    *fromC=CtoP;
1086
b566ab5556ab Fixed warnings in python test
Laurent Bessard
parents: 953
diff changeset
    33
    AtomicCompareExchange((long*)&Lock, 1, 0);
859
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    34
    res=1;
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    35
  }
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    36
  printf("C code called by Python: toC %d fromC %d\n",toC,*fromC);
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    37
  return res;
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    38
}
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    39
862
bb59865db6e6 Introduced FBID in tests/python example. Fixed type error leading to segfault
Edouard Tisserant
parents: 860
diff changeset
    40
int PLC_C_Call(char fromPLC, char *toPLC){
859
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    41
  /* PLC also have to be realy carefull not to 
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    42
     conflict with asynchronous python access */
1086
b566ab5556ab Fixed warnings in python test
Laurent Bessard
parents: 953
diff changeset
    43
  if(!AtomicCompareExchange((long*)&Lock, 0, 1)){
859
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    44
      CtoP = fromPLC;
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    45
      *toPLC = PtoC;
1086
b566ab5556ab Fixed warnings in python test
Laurent Bessard
parents: 953
diff changeset
    46
      AtomicCompareExchange((long*)&Lock, 1, 0);
859
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    47
      return 1;
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    48
  }
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    49
  return 0;
1125
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    50
}
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    51
]]>
734
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    52
  </globals>
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    53
  <initFunction>
1125
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    54
<![CDATA[
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    55
]]>
734
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    56
  </initFunction>
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    57
  <cleanUpFunction>
1125
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    58
<![CDATA[
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    59
]]>
734
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    60
  </cleanUpFunction>
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    61
  <retrieveFunction>
1125
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    62
<![CDATA[
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    63
]]>
734
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    64
  </retrieveFunction>
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    65
  <publishFunction>
1125
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    66
<![CDATA[
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    67
if(!AtomicCompareExchange((long*)&Lock, 0, 1)){
860
8a51046010d7 Even more pedagogical tests/python. Renaming will not help
Edouard Tisserant
parents: 859
diff changeset
    68
    TestInput = CtoP + PtoC + TestOutput;
1086
b566ab5556ab Fixed warnings in python test
Laurent Bessard
parents: 953
diff changeset
    69
    AtomicCompareExchange((long*)&Lock, 1, 0);
1125
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    70
}
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    71
]]>
734
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    72
  </publishFunction>
1125
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    73
</CFile>