summaryrefslogtreecommitdiffstats
path: root/awlsim.py
blob: 370eca308865e9ae9cc16beabec78395014efbfb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# -*- coding: utf-8 -*-
#
# AWL simulator
# Copyright 2012-2013 Michael Buesch <m@bues.ch>
#
# Licensed under the terms of the GNU General Public License version 2.
#

from awlcpu import *
from util import *


VERSION_MAJOR = 0
VERSION_MINOR = 7


class AwlSim(object):
	def __init__(self):
		self.cpu = S7CPU(self)

	def load(self, parseTree):
		self.cpu.load(parseTree)
		self.cpu.startup()

	def getCPU(self):
		return self.cpu

	def runCycle(self):
		ex = None
		try:
			self.cpu.runCycle()
		except AwlSimError as e:
			ex = e
		if ex:
			raise AwlSimError("ERROR at AWL line %d: %s\n\n%s" %\
				(self.cpu.getCurrentInsn().getLineNr(),
				 str(ex), str(self.cpu)))

	def __repr__(self):
		return str(self.cpu)
bues.ch cgit interface