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
#!/bin/bash
rm -f ./PLC_OK ./CLI_OK
# Run C runtime
$BEREMIZPATH/C_runtime/beremiz_runtime -v -t tcp -p 61131 -h localhost > >(
echo "Start PLC stdout reader loop"
while read line; do
# Wait for server to print modified value
echo "PLC>> $line"
if [[ "$line" == "C runtime OK #3" ]]; then
echo "$line"
touch ./PLC_OK
fi
done
echo "End PLC stdout reader loop"
) &
PLC_PID=$!
# Start PLC with C runtime test
setsid $BEREMIZPYTHONPATH $BEREMIZPATH/Beremiz_cli.py -k \
--project-home $BEREMIZPATH/tests/projects/c_runtime build transfer run > >(
echo "Start CLI loop"
while read line; do
# Wait for CLI to output expected PLC log message on stdout
echo "CLI>> $line"
if [[ $line =~ .*C\ runtime\ log\ OK\ #3$ ]]; then
echo "$line"
touch ./CLI_OK
fi
done
echo "End CLI loop"
) &
CLI_PID=$!
echo all subprocess started, start polling results
res=110 # default to ETIMEDOUT
c=45
while ((c--)); do
if [[ -a ./PLC_OK && -a ./CLI_OK ]]; then
echo got results.
res=0 # OK success
break
else
echo waiting.... $c
sleep 1
fi
done
# Kill PLC and subprocess
echo will kill CLI:$CLI_PID and PLC:$PLC_PID
pkill -s $CLI_PID
kill $PLC_PID
exit $res