#Copyright (C) 2011: Edouard TISSERANT and Laurent BESSARD
#See COPYING file for copyrights details.
#This library is free software; you can redistribute it and/or
#modify it under the terms of the GNU General Public
#License as published by the Free Software Foundation; either
#version 2.1 of the License, or (at your option) any later version.
#This library is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#General Public License for more details.
#You should have received a copy of the GNU General Public
#License along with this library; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from datetime import timedelta as td
class IEC_STRING(Structure):
Must be changed according to changes in iec_types.h
_fields_ = [("len", c_uint8),
class IEC_TIME(Structure):
Must be changed according to changes in iec_types.h
_fields_ = [("s", c_long), #tv_sec
def _t(t, u=lambda x:x.value, p=lambda t,x:t(x)): return (t, u, p)
def _ttime(): return (IEC_TIME,
lambda x:td(0, x.s, x.ns/1000),
lambda t,x:t(x.days * 24 * 3600 + x.seconds, x.microseconds*1000))
SameEndianessTypeTranslator = {
"BOOL" : _t(c_uint8, lambda x:x.value!=0),
"TRANSITION" : _t(c_uint8),
SwapedEndianessTypeTranslator = {
TypeTranslator=SameEndianessTypeTranslator
# Construct debugger natively supported types
DebugTypesSize = dict([(key,sizeof(t)) for key,(t,p,u) in SameEndianessTypeTranslator.iteritems() if t is not None])
def UnpackDebugBuffer(buff, size, indexes):
for idx, iectype, forced in indexes:
cursor = c_void_p(buff.value + offset)
c_type,unpack_func, pack_func = \
TypeTranslator.get(iectype,
if c_type is not None and offset < size:
POINTER(c_type)).contents))
offset += sizeof(c_type) if iectype != "STRING" else len(res[-1])+1
# PLCprint("Debug error - " + iectype +
# PLCprint("Debug error - buffer too small ! %d != %d"%(offset, size))
if offset and offset == size:
LogLevels = ["CRITICAL","WARNING","INFO","DEBUG"]
LogLevelsCount = len(LogLevels)
LogLevelsDict = dict(zip(LogLevels,range(LogLevelsCount)))
LogLevelsDefault = LogLevelsDict["DEBUG"]