author | Edouard Tisserant |
Sat, 02 Feb 2013 16:01:02 +1100 | |
changeset 921 | a8db48ec2c31 |
parent 862 | bb59865db6e6 |
child 953 | 1fb6cf5a4c4d |
permissions | -rw-r--r-- |
734 | 1 |
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
2 |
<CFile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.w3.org/2001/XMLSchema" xsi:schemaLocation="cext_xsd.xsd"> |
|
3 |
<includes> |
|
4 |
<![CDATA[]]> |
|
5 |
</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
|
6 |
<variables> |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
7 |
<variable name="TestInput" type="SINT" class="input"/> |
860
8a51046010d7
Even more pedagogical tests/python. Renaming will not help
Edouard Tisserant
parents:
859
diff
changeset
|
8 |
<variable name="TestOutput" type="SINT" class="output"/> |
859
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
9 |
</variables> |
734 | 10 |
<globals> |
859
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
11 |
<![CDATA[volatile long Lock=0; |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
12 |
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
|
13 |
|
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
14 |
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
|
15 |
return val+1; |
734 | 16 |
} |
859
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
17 |
|
862
bb59865db6e6
Introduced FBID in tests/python example. Fixed type error leading to segfault
Edouard Tisserant
parents:
860
diff
changeset
|
18 |
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
|
19 |
/* 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
|
20 |
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
|
21 |
|
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
22 |
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
|
23 |
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
|
24 |
|
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
25 |
int res = 0; |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
26 |
if(!AtomicCompareExchange(&Lock, 0, 1)){ |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
27 |
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
|
28 |
*fromC=CtoP; |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
29 |
AtomicCompareExchange(&Lock, 1, 0); |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
30 |
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
|
31 |
} |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
32 |
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
|
33 |
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
|
34 |
} |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
35 |
|
862
bb59865db6e6
Introduced FBID in tests/python example. Fixed type error leading to segfault
Edouard Tisserant
parents:
860
diff
changeset
|
36 |
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
|
37 |
/* 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
|
38 |
conflict with asynchronous python access */ |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
39 |
int res; |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
40 |
if(!AtomicCompareExchange(&Lock, 0, 1)){ |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
41 |
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
|
42 |
*toPLC = PtoC; |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
43 |
AtomicCompareExchange(&Lock, 1, 0); |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
44 |
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
|
45 |
} |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
46 |
return 0; |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
47 |
}]]> |
734 | 48 |
</globals> |
49 |
<initFunction> |
|
50 |
<![CDATA[]]> |
|
51 |
</initFunction> |
|
52 |
<cleanUpFunction> |
|
53 |
<![CDATA[]]> |
|
54 |
</cleanUpFunction> |
|
55 |
<retrieveFunction> |
|
56 |
<![CDATA[]]> |
|
57 |
</retrieveFunction> |
|
58 |
<publishFunction> |
|
860
8a51046010d7
Even more pedagogical tests/python. Renaming will not help
Edouard Tisserant
parents:
859
diff
changeset
|
59 |
<![CDATA[if(!AtomicCompareExchange(&Lock, 0, 1)){ |
8a51046010d7
Even more pedagogical tests/python. Renaming will not help
Edouard Tisserant
parents:
859
diff
changeset
|
60 |
TestInput = CtoP + PtoC + TestOutput; |
8a51046010d7
Even more pedagogical tests/python. Renaming will not help
Edouard Tisserant
parents:
859
diff
changeset
|
61 |
AtomicCompareExchange(&Lock, 1, 0); |
8a51046010d7
Even more pedagogical tests/python. Renaming will not help
Edouard Tisserant
parents:
859
diff
changeset
|
62 |
}]]> |
734 | 63 |
</publishFunction> |
64 |
</CFile> |