connectors/LPC/LPCObject.py
author Edouard Tisserant
Sat, 19 May 2012 19:00:55 +0200
changeset 733 915be999f3f0
parent 717 1c23952dbde1
permissions -rwxr-xr-x
targets and connectors are nor extensible
448
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
     1
#!/usr/bin/env python
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
     3
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
     4
#This file is part of Beremiz, a Integrated Development Environment for
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
     5
#programming IEC 61131-3 automates supporting plcopen standard and CanFestival. 
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
     6
#
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
     8
#
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
     9
#See COPYING file for copyrights details.
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    10
#
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    15
#
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    19
#General Public License for more details.
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    20
#
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    24
453
923d036dfa90 LPC connector enhancements
edouard
parents: 448
diff changeset
    25
from LPCProto import *
448
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    26
569
37af7286dd65 LPC program transfer more verbose, test code added in __main__ of LPCBootProto
Edouqrd Tisserant <edouard.tisserant@gmail.com>
parents: 563
diff changeset
    27
37af7286dd65 LPC program transfer more verbose, test code added in __main__ of LPCBootProto
Edouqrd Tisserant <edouard.tisserant@gmail.com>
parents: 563
diff changeset
    28
448
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    29
class LPCObject():
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 578
diff changeset
    30
    def __init__(self, confnodesroot, comportstr):
508
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    31
        self.PLCStatus = "Disconnected"
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 578
diff changeset
    32
        self.confnodesroot = confnodesroot
1c23952dbde1 refactoring
Edouard Tisserant
parents: 578
diff changeset
    33
        self.PLCprint = confnodesroot.logger.writeyield
453
923d036dfa90 LPC connector enhancements
edouard
parents: 448
diff changeset
    34
        self._Idxs = []
556
1ad4e7f1e89e LPC Composer don't send comma at the end of serial port name.
Lolitech
parents: 545
diff changeset
    35
        comport = int(comportstr[3:]) - 1
545
627e5c636a4f Refactored LPC connector for new bootloader and application modes
Lolitech
parents: 525
diff changeset
    36
        try:
627e5c636a4f Refactored LPC connector for new bootloader and application modes
Lolitech
parents: 525
diff changeset
    37
            self.connect(comportstr)
627e5c636a4f Refactored LPC connector for new bootloader and application modes
Lolitech
parents: 525
diff changeset
    38
        except Exception,e:
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 578
diff changeset
    39
            self.confnodesroot.logger.write_error(str(e)+"\n")
545
627e5c636a4f Refactored LPC connector for new bootloader and application modes
Lolitech
parents: 525
diff changeset
    40
            self.SerialConnection = None
627e5c636a4f Refactored LPC connector for new bootloader and application modes
Lolitech
parents: 525
diff changeset
    41
            self.PLCStatus = "Disconnected"
508
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    42
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    43
    def HandleSerialTransaction(self, transaction):
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    44
        if self.SerialConnection is not None:
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    45
            try:
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    46
                self.PLCStatus, res = self.SerialConnection.HandleTransaction(transaction)
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    47
                return res
578
6f5795bdee49 Making debugger more stable with LPC
edouard
parents: 576
diff changeset
    48
            except LPCProtoError,e:
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 578
diff changeset
    49
                self.confnodesroot.logger.write(_("PLC disconnected\n"))
578
6f5795bdee49 Making debugger more stable with LPC
edouard
parents: 576
diff changeset
    50
                if self.SerialConnection is not None:
6f5795bdee49 Making debugger more stable with LPC
edouard
parents: 576
diff changeset
    51
                    self.SerialConnection.close()
6f5795bdee49 Making debugger more stable with LPC
edouard
parents: 576
diff changeset
    52
                    self.SerialConnection = None
6f5795bdee49 Making debugger more stable with LPC
edouard
parents: 576
diff changeset
    53
                self.PLCStatus = "Disconnected"
6f5795bdee49 Making debugger more stable with LPC
edouard
parents: 576
diff changeset
    54
                return None
569
37af7286dd65 LPC program transfer more verbose, test code added in __main__ of LPCBootProto
Edouqrd Tisserant <edouard.tisserant@gmail.com>
parents: 563
diff changeset
    55
            except Exception,e:
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 578
diff changeset
    56
                self.confnodesroot.logger.write_warning(str(e)+"\n")
545
627e5c636a4f Refactored LPC connector for new bootloader and application modes
Lolitech
parents: 525
diff changeset
    57
        
448
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    58
    def StartPLC(self, debug=False):
545
627e5c636a4f Refactored LPC connector for new bootloader and application modes
Lolitech
parents: 525
diff changeset
    59
        raise LPCProtoError("Not implemented")
448
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    60
            
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    61
    def StopPLC(self):
545
627e5c636a4f Refactored LPC connector for new bootloader and application modes
Lolitech
parents: 525
diff changeset
    62
        raise LPCProtoError("Not implemented")
448
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    63
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    64
    def GetPLCstatus(self):
545
627e5c636a4f Refactored LPC connector for new bootloader and application modes
Lolitech
parents: 525
diff changeset
    65
        raise LPCProtoError("Not implemented")
448
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    66
    
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    67
    def NewPLC(self, md5sum, data, extrafiles):
545
627e5c636a4f Refactored LPC connector for new bootloader and application modes
Lolitech
parents: 525
diff changeset
    68
        raise LPCProtoError("Not implemented")
448
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    69
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    70
    def MatchMD5(self, MD5):
545
627e5c636a4f Refactored LPC connector for new bootloader and application modes
Lolitech
parents: 525
diff changeset
    71
        raise LPCProtoError("Not implemented")
502
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
    72
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
    73
    def SetTraceVariablesList(self, idxs):
545
627e5c636a4f Refactored LPC connector for new bootloader and application modes
Lolitech
parents: 525
diff changeset
    74
        raise LPCProtoError("Not implemented")
502
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
    75
448
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    76
    def GetTraceVariables(self):
545
627e5c636a4f Refactored LPC connector for new bootloader and application modes
Lolitech
parents: 525
diff changeset
    77
        raise LPCProtoError("Not implemented")
448
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    78