aboutsummaryrefslogtreecommitdiffstats
path: root/awlsim/library/iec/fc9_eq_dt.py
blob: a0bd6b39faa06d3bc94a594767160092d7d69bcd (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# -*- coding: utf-8 -*-
#
# AWL simulator - IEC library - FC 9 "EQ_DT"
#
# Copyright 2014 Michael Buesch <m@bues.ch>
#
# This program 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 of the License, or
# (at your option) any later version.
#
# This program 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 program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#

from __future__ import division, absolute_import, print_function, unicode_literals
from awlsim.common.compat import *

from awlsim.library.libentry import *


class Lib__IEC__FC9_EQ_DT(AwlLibFC):
	libraryName	= "IEC"
	staticIndex	= 9
	symbolName	= "EQ_DT"
	description	= "Compare two DATE_AND_TIME for equality"

	interfaceFields = {
		BlockInterfaceField.FTYPE_IN	: (
			BlockInterfaceField(name = "DT1",
					    dataType = AwlDataType.makeByName("DATE_AND_TIME")),
			BlockInterfaceField(name = "DT2",
					    dataType = AwlDataType.makeByName("DATE_AND_TIME")),
		),
		BlockInterfaceField.FTYPE_OUT	: (
			BlockInterfaceField(name = "RET_VAL",
					    dataType = AwlDataType.makeByName("BOOL")),
		),
		BlockInterfaceField.FTYPE_TEMP	: (
			BlockInterfaceField(name = "DBNR",
					    dataType = AwlDataType.makeByName("INT")),
		),
	}

	awlCodeCopyright = "Copyright (c) 2014 Michael Buesch <m@bues.ch>"
	awlCodeLicense = "BSD-2-clause"
	awlCodeIsStandard = True
	awlCodeVersion = "0.1"

	awlCode = """
	// Load a pointer to #DT1 into AR1 and open the DB
	LAR1	P##DT1
	L	W [AR1, P#0.0]
	T	#DBNR
	AUF	DB [#DBNR]
	L	D [AR1, P#2.0]
	LAR1

	// Load a pointer to #DT2 into AR2 and open the DB as DI
	LAR2	P##DT2
	L	W [AR2, P#0.0]
	T	#DBNR
	AUF	DI [#DBNR]
	L	D [AR2, P#2.0]
	// If #DT2 points to DB (area 84) change it to DI (area 85).
	// This also works, if #DT2 points to VL (area 87).
	// Other areas are not possible.
	OD	DW#16#85000000
	LAR2

	// Compare #DT1 with #DT2
	L	D [AR1, P#0.0]
	L	D [AR2, P#0.0]
	==D
	U(
	L	D [AR1, P#4.0]
	L	D [AR2, P#4.0]
	==D
	)
	=	#RET_VAL

	SET
	SAVE
	BE
"""

AwlLib.registerEntry(Lib__IEC__FC9_EQ_DT)
bues.ch cgit interface