connectors/ERPC_dialog.py
author Edouard Tisserant <edouard@beremiz.fr>
Thu, 05 Dec 2024 13:56:59 +0100
changeset 4060 d2f5eb3c7d6e
parent 4038 4b47b4ce0f12
permissions -rw-r--r--
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
3884
34da877021d5 Replace PYRO with ERPC. Work In Progress.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/env python
34da877021d5 Replace PYRO with ERPC. Work In Progress.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
34da877021d5 Replace PYRO with ERPC. Work In Progress.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
     3
34da877021d5 Replace PYRO with ERPC. Work In Progress.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
     4
# See COPYING file for copyrights details.
34da877021d5 Replace PYRO with ERPC. Work In Progress.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
     5
4038
4b47b4ce0f12 IDE: refactor ERPC URI editor, add serial and USB URI types
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3908
diff changeset
     6
from connectors.ERPC_URI import schemes_desc, per_scheme_model
4b47b4ce0f12 IDE: refactor ERPC URI editor, add serial and USB URI types
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3908
diff changeset
     7
from connectors.SchemeEditor import SchemeEditor
4b47b4ce0f12 IDE: refactor ERPC URI editor, add serial and USB URI types
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3908
diff changeset
     8
4b47b4ce0f12 IDE: refactor ERPC URI editor, add serial and USB URI types
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3908
diff changeset
     9
## Scheme list for the dialog's combobox
4b47b4ce0f12 IDE: refactor ERPC URI editor, add serial and USB URI types
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3908
diff changeset
    10
4b47b4ce0f12 IDE: refactor ERPC URI editor, add serial and USB URI types
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3908
diff changeset
    11
Schemes = list(zip(*schemes_desc))[0]
3884
34da877021d5 Replace PYRO with ERPC. Work In Progress.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    12
34da877021d5 Replace PYRO with ERPC. Work In Progress.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    13
4038
4b47b4ce0f12 IDE: refactor ERPC URI editor, add serial and USB URI types
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3908
diff changeset
    14
## Specialized SchemeEditor panel for ERPC 
3884
34da877021d5 Replace PYRO with ERPC. Work In Progress.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    15
34da877021d5 Replace PYRO with ERPC. Work In Progress.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    16
class ERPC_dialog(SchemeEditor):
34da877021d5 Replace PYRO with ERPC. Work In Progress.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    17
    def __init__(self, scheme, *args, **kwargs):
4038
4b47b4ce0f12 IDE: refactor ERPC URI editor, add serial and USB URI types
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3908
diff changeset
    18
        self.model, self.EnableIDSelector, self.parser, self.builder = per_scheme_model[scheme]
3884
34da877021d5 Replace PYRO with ERPC. Work In Progress.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    19
34da877021d5 Replace PYRO with ERPC. Work In Progress.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    20
        SchemeEditor.__init__(self, scheme, *args, **kwargs)
34da877021d5 Replace PYRO with ERPC. Work In Progress.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    21
34da877021d5 Replace PYRO with ERPC. Work In Progress.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    22
    def SetLoc(self, loc):
4038
4b47b4ce0f12 IDE: refactor ERPC URI editor, add serial and USB URI types
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3908
diff changeset
    23
        self.SetFields(self.parser(loc))
3884
34da877021d5 Replace PYRO with ERPC. Work In Progress.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    24
34da877021d5 Replace PYRO with ERPC. Work In Progress.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    25
    def GetLoc(self):
4038
4b47b4ce0f12 IDE: refactor ERPC URI editor, add serial and USB URI types
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3908
diff changeset
    26
        return self.builder(self.GetFields())