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
/*
Written by Edouard TISSERANT (C) 2024
This file is part of Beremiz runtime and IDE
See COPYING.Runtime and COPYING file for copyrights details.
*/
program erpc_PLCObject
struct PSKID {
string ID;
string PSK;
};
enum PLCstatus_enum {
Empty
Stopped,
Started,
Broken,
Disconnected
}
struct PLCstatus {
PLCstatus_enum PLCstatus;
uint32[4] logcounts;
};
struct trace_sample {
uint32 tick;
binary TraceBuffer;
};
struct TraceVariables {
PLCstatus_enum PLCstatus;
list<trace_sample> traces;
};
struct extra_file {
string fname;
binary blobID;
};
struct trace_order {
uint32 idx;
binary force;
};
struct log_message {
string msg;
uint32 tick;
uint32 sec;
uint32 nsec;
};
interface BeremizPLCObjectService {
AppendChunkToBlob(in binary data, in binary blobID, out binary newBlobID) -> uint32
GetLogMessage(in uint8 level, in uint32 msgID, out log_message message) -> uint32
GetPLCID(out PSKID plcID) -> uint32
GetPLCstatus(out PLCstatus status) -> uint32
GetTraceVariables(in uint32 debugToken, out TraceVariables traces) -> uint32
MatchMD5(in string MD5, out bool match) -> uint32
NewPLC(in string md5sum, in binary plcObjectBlobID, in list<extra_file> extrafiles, out bool success) -> uint32
PurgeBlobs() -> uint32
RepairPLC() -> uint32
ResetLogCount() -> uint32
SeedBlob(in binary seed, out binary blobID) -> uint32
SetTraceVariablesList(in list<trace_order> orders, out int32 debugtoken) -> uint32
StartPLC() -> uint32
StopPLC(out bool success) -> uint32
ExtendedCall(in string method, in binary argument, out binary answer ) -> uint32
}