beremiz

py_ext: fix CSV Writer

18 months ago, Edouard Tisserant
d2f5eb3c7d6e
py_ext: fix CSV Writer

fix POU logic :
- SAVE is a BOOL
- invocation of py_eval on rising edge of SAVE
- remove save python argument

fix python:
- use no encoding for file open (python2)
- re-use detected dialect if any
- use no "rt+" and truncate since no need to re-sniff dialect for output file
- return "OK" instead of "#SUCCESS", preventing POU logic to ACK result
- support creating new line if writing just after last line
- support appending data on short rows

fix example:
- use a HMI:Button to trigger CSV write instead of HMI:Input +1
- reload CSVs on on each new CSV opened in file browser
- add display of CSV write output
<?xml version='1.0' encoding='utf-8'?>
<project xmlns:ns1="http://www.plcopen.org/xml/tc6_0201" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.plcopen.org/xml/tc6_0201">
<fileHeader companyName="Unknown" productName="Unnamed" productVersion="1" creationDateTime="2022-09-05T09:02:48"/>
<contentHeader name="Unnamed" modificationDateTime="2022-10-04T10:59:24">
<coordinateInfo>
<fbd>
<scaling x="5" y="5"/>
</fbd>
<ld>
<scaling x="0" y="0"/>
</ld>
<sfc>
<scaling x="0" y="0"/>
</sfc>
</coordinateInfo>
</contentHeader>
<types>
<dataTypes/>
<pous>
<pou name="program0" pouType="program">
<interface>
<localVars>
<variable name="LocalVar0">
<type>
<INT/>
</type>
</variable>
<variable name="PLCHMIVAR">
<type>
<derived name="HMI_INT"/>
</type>
</variable>
</localVars>
</interface>
<body>
<FBD>
<inVariable localId="31" executionOrderId="0" height="25" width="85" negated="false">
<position x="175" y="290"/>
<connectionPointOut>
<relPosition x="85" y="10"/>
</connectionPointOut>
<expression>PLCHMIVAR</expression>
</inVariable>
<outVariable localId="30" executionOrderId="0" height="25" width="85" negated="false">
<position x="330" y="290"/>
<connectionPointIn>
<relPosition x="0" y="10"/>
<connection refLocalId="31">
<position x="330" y="300"/>
<position x="260" y="300"/>
</connection>
</connectionPointIn>
<expression>LocalVar0</expression>
</outVariable>
</FBD>
</body>
</pou>
</pous>
</types>
<instances>
<configurations>
<configuration name="config">
<resource name="resource1">
<task name="task0" priority="0" interval="T#20ms">
<pouInstance name="instance0" typeName="program0"/>
</task>
</resource>
</configuration>
</configurations>
</instances>
</project>