connectors/LPC/LPCObject.py
author Edouard TISSERANT <edouard.tisserant@gmail.com>
Wed, 23 Dec 2009 22:23:02 +0100
changeset 532 a822b0b64252
parent 525 e43bc748d1fe
child 545 627e5c636a4f
permissions -rwxr-xr-x
Fixed startin debugger with non empty debug variable list
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
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    25
import ctypes, os, commands, types, sys
453
923d036dfa90 LPC connector enhancements
edouard
parents: 448
diff changeset
    26
from LPCProto import *
448
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    27
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    28
class LPCObject():
508
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    29
    def __init__(self,pluginsroot, location):
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    30
        self.PLCStatus = "Disconnected"
448
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    31
        self.pluginsroot = pluginsroot
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    32
        self.PLCprint = pluginsroot.logger.write
453
923d036dfa90 LPC connector enhancements
edouard
parents: 448
diff changeset
    33
        self._Idxs = []
508
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    34
        self.UpdateLocation(location)
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    35
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    36
    def UpdateLocation(self, location):
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    37
        # Is that a comport ?
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    38
        if len(location) == 5 and\
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    39
           location.startswith("COM") and \
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    40
           location[3].isdigit() and \
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    41
           location[4]==":" :
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    42
            self.StorageConnection = None
453
923d036dfa90 LPC connector enhancements
edouard
parents: 448
diff changeset
    43
            try:
508
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    44
                comport = int(location[3]) - 1
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    45
                self.SerialConnection = LPCProto(comport,#number
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    46
                                                 115200, #speed
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    47
                                                 2)      #timeout
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    48
                # This will update status
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    49
                self.HandleSerialTransaction(IDLETransaction())
453
923d036dfa90 LPC connector enhancements
edouard
parents: 448
diff changeset
    50
            except Exception,e:
923d036dfa90 LPC connector enhancements
edouard
parents: 448
diff changeset
    51
                self.pluginsroot.logger.write_error(str(e)+"\n")
923d036dfa90 LPC connector enhancements
edouard
parents: 448
diff changeset
    52
                self.SerialConnection = None
508
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    53
                self.PLCStatus = "Disconnected"
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    54
        # or a drive unit ?
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    55
        elif len(location)==2 and \
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    56
             location[0].isalpha() and \
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    57
             location[1] == ':' :
453
923d036dfa90 LPC connector enhancements
edouard
parents: 448
diff changeset
    58
            self.SerialConnection = None
520
ca5a2047e0ed Fixed typos in LPC connector
edouard
parents: 508
diff changeset
    59
            if os.path.exists(location):
508
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    60
                self.StorageConnection = location
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    61
                self.PLCStatus = "Stopped"
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    62
            else:
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    63
                self.pluginsroot.logger.write_error("Drive "+
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    64
                                                    location+
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    65
                                                    " do not exist !\n")
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    66
                self.StorageConnection = None
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    67
                self.PLCStatus = "Disconnected"
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    68
        
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    69
    def HandleSerialTransaction(self, transaction):
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    70
        if self.SerialConnection is not None:
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    71
            try:
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    72
                self.PLCStatus, res = self.SerialConnection.HandleTransaction(transaction)
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    73
                return res
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    74
            except LPCError,e:
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    75
                self.pluginsroot.logger.write_error(str(e)+"\n")
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    76
                self.SerialConnection = None
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    77
                self.PLCStatus = "Disconnected"
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    78
                return None
453
923d036dfa90 LPC connector enhancements
edouard
parents: 448
diff changeset
    79
448
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    80
    def StartPLC(self, debug=False):
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    81
        PLCprint("StartPLC")
453
923d036dfa90 LPC connector enhancements
edouard
parents: 448
diff changeset
    82
        self.HandleSerialTransaction(STARTTransaction())
448
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    83
            
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    84
    def StopPLC(self):
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    85
        PLCprint("StopPLC")
453
923d036dfa90 LPC connector enhancements
edouard
parents: 448
diff changeset
    86
        self.HandleSerialTransaction(STOPTransaction())
448
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    87
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    88
    def ForceReload(self):
453
923d036dfa90 LPC connector enhancements
edouard
parents: 448
diff changeset
    89
        pass
448
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    90
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    91
    def GetPLCstatus(self):
508
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    92
        self.HandleSerialTransaction(IDLETransaction())
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
    93
        return self.PLCStatus
448
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    94
    
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
    95
    def NewPLC(self, md5sum, data, extrafiles):
521
02cb9e5fb6f6 LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents: 520
diff changeset
    96
        if os.path.exists(self.StorageConnection):
02cb9e5fb6f6 LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents: 520
diff changeset
    97
            firmwarepath = os.path.join(
02cb9e5fb6f6 LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents: 520
diff changeset
    98
                    self.StorageConnection, 
02cb9e5fb6f6 LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents: 520
diff changeset
    99
                    "firmware.bin")
02cb9e5fb6f6 LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents: 520
diff changeset
   100
            try:
02cb9e5fb6f6 LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents: 520
diff changeset
   101
                if os.path.exists(firmwarepath ):
02cb9e5fb6f6 LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents: 520
diff changeset
   102
                    os.unlink(firmwarepath)
02cb9e5fb6f6 LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents: 520
diff changeset
   103
                f = open(firmwarepath, "wb")
02cb9e5fb6f6 LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents: 520
diff changeset
   104
                f.write(data)
02cb9e5fb6f6 LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents: 520
diff changeset
   105
                f.close()
02cb9e5fb6f6 LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents: 520
diff changeset
   106
                return True
02cb9e5fb6f6 LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents: 520
diff changeset
   107
            except LPCError,e:
02cb9e5fb6f6 LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents: 520
diff changeset
   108
                self.StorageConnection = None
02cb9e5fb6f6 LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents: 520
diff changeset
   109
                self.PLCStatus = "Disconnected"
02cb9e5fb6f6 LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents: 520
diff changeset
   110
                self.pluginsroot.logger.write_error(
02cb9e5fb6f6 LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents: 520
diff changeset
   111
                                    "LPC transfer error : "+
02cb9e5fb6f6 LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents: 520
diff changeset
   112
                                    str(e)+"\n")
448
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
   113
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
   114
    def MatchMD5(self, MD5):
521
02cb9e5fb6f6 LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents: 520
diff changeset
   115
        data = self.HandleSerialTransaction(GET_PLCIDTransaction())
525
e43bc748d1fe LPCobject writes PLC info string to stdout, for LPC composer to update
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents: 521
diff changeset
   116
        print "PLCINFO",data[32:]
521
02cb9e5fb6f6 LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents: 520
diff changeset
   117
        return data[:32] == MD5
02cb9e5fb6f6 LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents: 520
diff changeset
   118
448
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
   119
    class IEC_STRING(ctypes.Structure):
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
   120
        """
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
   121
        Must be changed according to changes in iec_types.h
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
   122
        """
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
   123
        _fields_ = [("len", ctypes.c_uint8),
502
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   124
                    ("body", ctypes.c_char * 126)] 
448
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
   125
    
502
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   126
    TypeTranslator = {"BOOL" :       (ctypes.c_uint8,  lambda x:x.value!=0,     lambda t,x:t(x)),
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   127
                      "STEP" :       (ctypes.c_uint8,  lambda x:x.value,        lambda t,x:t(x)),
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   128
                      "TRANSITION" : (ctypes.c_uint8,  lambda x:x.value,        lambda t,x:t(x)),
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   129
                      "ACTION" :     (ctypes.c_uint8,  lambda x:x.value,        lambda t,x:t(x)),
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   130
                      "SINT" :       (ctypes.c_int8,   lambda x:x.value,        lambda t,x:t(x)),
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   131
                      "USINT" :      (ctypes.c_uint8,  lambda x:x.value,        lambda t,x:t(x)),
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   132
                      "BYTE" :       (ctypes.c_uint8,  lambda x:x.value,        lambda t,x:t(x)),
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   133
                      "STRING" :     (IEC_STRING,      lambda x:x.body[:x.len], lambda t,x:t(len(x),x)),
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   134
                      "INT" :        (ctypes.c_int16,  lambda x:x.value,        lambda t,x:t(x)),
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   135
                      "UINT" :       (ctypes.c_uint16, lambda x:x.value,        lambda t,x:t(x)),
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   136
                      "WORD" :       (ctypes.c_uint16, lambda x:x.value,        lambda t,x:t(x)),
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   137
                      "WSTRING" :    (None,            None,                    None),#TODO
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   138
                      "DINT" :       (ctypes.c_int32,  lambda x:x.value,        lambda t,x:t(x)),
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   139
                      "UDINT" :      (ctypes.c_uint32, lambda x:x.value,        lambda t,x:t(x)),
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   140
                      "DWORD" :      (ctypes.c_uint32, lambda x:x.value,        lambda t,x:t(x)),
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   141
                      "LINT" :       (ctypes.c_int64,  lambda x:x.value,        lambda t,x:t(x)),
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   142
                      "ULINT" :      (ctypes.c_uint64, lambda x:x.value,        lambda t,x:t(x)),
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   143
                      "LWORD" :      (ctypes.c_uint64, lambda x:x.value,        lambda t,x:t(x)),
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   144
                      "REAL" :       (ctypes.c_float,  lambda x:x.value,        lambda t,x:t(x)),
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   145
                      "LREAL" :      (ctypes.c_double, lambda x:x.value,        lambda t,x:t(x)),
448
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
   146
                      } 
502
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   147
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   148
    def SetTraceVariablesList(self, idxs):
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   149
        """
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   150
        Call ctype imported function to append 
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   151
        these indexes to registred variables in PLC debugger
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   152
        """
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   153
        if idxs:
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   154
            buff = ""
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   155
            # keep a copy of requested idx
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   156
            self._Idxs = idxs[:]
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   157
            for idx,iectype,force in idxs:
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   158
                idxstr = ctypes.string_at(
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   159
                          ctypes.pointer(
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   160
                           ctypes.c_uint32(length)),4)
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   161
                if force !=None:
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   162
                    c_type,unpack_func, pack_func = self.TypeTranslator.get(iectype, (None,None,None))
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   163
                    forcedsizestr = chr(ctypes.sizeof(c_type))
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   164
                    forcestr = ctypes.string_at(
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   165
                                ctypes.pointer(
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   166
                                 pack_func(c_type,force)),
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   167
                                 forced_type_size)
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   168
                    buff += idxstr + forced_type_size_str + forcestr
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   169
                else:
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   170
                    buff += idxstr + chr(0)
508
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
   171
            data = self.HandleSerialTransaction(
502
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   172
                   SET_TRACE_VARIABLETransaction(buff))
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   173
        else:
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   174
            self._Idxs =  []
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   175
448
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
   176
    def GetTraceVariables(self):
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
   177
        """
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
   178
        Return a list of variables, corresponding to the list of required idx
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
   179
        """
508
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
   180
        offset = 0
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
   181
        strbuf = self.HandleSerialTransaction(
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
   182
                                     GET_TRACE_VARIABLETransaction())
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
   183
        size = len(strbuf) - 4
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
   184
        if size > 0 and self.PLCStatus == "Started":
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
   185
            tick = ctypes.cast(
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
   186
                    ctypes.c_char_p(strbuf[:4]),
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
   187
                    ctypes.POINTER(ctypes.c_int)).contents
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
   188
            buffer = ctypes.cast(
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
   189
                      ctypes.c_char_p(strbuf[4:]),
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
   190
                      ctypes.c_void_p)
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
   191
            for idx, iectype, forced in self._Idxs:
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
   192
                cursor = ctypes.c_void_p(buffer.value + offset)
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
   193
                c_type,unpack_func, pack_func = self.TypeTranslator.get(iectype, (None,None,None))
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
   194
                if c_type is not None and offset < size:
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
   195
                    res.append(unpack_func(ctypes.cast(cursor,
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
   196
                                                       ctypes.POINTER(c_type)).contents))
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
   197
                    offset += ctypes.sizeof(c_type)
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
   198
                else:
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
   199
                    if c_type is None:
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
   200
                        PLCprint("Debug error - " + iectype + " not supported !")
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
   201
                    if offset >= size:
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
   202
                        PLCprint("Debug error - buffer too small !")
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
   203
                    break
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
   204
            if offset and offset == size:
502
5343ae43f6d0 LPC connector - one step further
edouard
parents: 453
diff changeset
   205
                return self.PLCStatus, tick.value, res
508
73ecb803d8af Revamped LPC connector and toolchain
edouard
parents: 502
diff changeset
   206
            PLCprint("Debug error - wrong buffer unpack !")
453
923d036dfa90 LPC connector enhancements
edouard
parents: 448
diff changeset
   207
        return self.PLCStatus, None, None
448
8ef035de86de Some rough copy'n'paste to pave path for an LPC connector
ed
parents:
diff changeset
   208