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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
| 'Default Property Values:
Const m_def_prefix = "1001"
Const m_def_uitgang = "00000000000000000000000000000000"
Const m_def_ingang = "11111111111111111111111111111111"
'Const m_def_waarde = 0
'Property Variables:
Dim m_prefix As Variant
Dim m_uitgang As Variant
Dim m_ingang As Variant
'Dim m_waarde As Variant
'Event Declarations:
'Event IODataAvailable(ReadData As Byte) 'MappingInfo=IOOcx1,IOOcx1,-1,IODataAvailable
'Event Show() 'MappingInfo=UserControl,UserControl,-1,Terminate
'Dim X, Y As Byte
Dim scl, adres
Function read_i2c(adr)
Static leesdata As String, lees(8)
: start_i2c: write_i2c (adr)
For Y = 1 To 8: For X = 0 To 7
IOOcx1.WriteIO (2 + scl(X) Xor 3): If X = 5 Then lees(Y) = (IOOcx1.ReadIO() And 64) / 64
Next X: Next Y
IOOcx1.WriteIO (1): leesdata = ""
For X = 1 To 8: leesdata = leesdata + Mid(Str(lees(X)), 2, 1): Next X: read_i2c = leesdata
End Function
Sub start_i2c()
Static sda
For X = 0 To 7
If X > 5 Then sda = 0 Else sda = 1
IOOcx1.WriteIO (sda * 2 + scl(X) Xor 3)
Next X
End Sub
Sub write_i2c(adr)
For Y = 1 To 9
For X = 0 To 7: IOOcx1.WriteIO (Mid(adr, Y, 1) * 2 + scl(X) Xor 3): Next X
Next Y
'IOOcx1.WriteIO (1)
End Sub
Private Sub Timer1_Timer()
Static uit(3), i(3) As String
'************** uit = uitgang i = ingang *************
For a = 0 To 3
uit(a) = Mid(m_uitgang, (a * 8) + 1, 8)
: start_i2c: write_i2c (m_prefix + adres(a) + "0" + "1"): write_i2c (uit(a) + "1")
Next a
For a = 4 To 7: i(a - 4) = "": i(a - 4) = read_i2c(m_prefix + adres(a) + "1" + "1"): Next a
m_ingang = i(3) & i(2) & i(1) & i(0)
End Sub
Private Sub UserControl_Initialize()
scl = Array(0, 0, 0, 0, 1, 1, 1, 1): adres = Array("000", "001", "010", "011", "100", "101", "110", "111")
End Sub
'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
'MappingInfo=Timer1,Timer1,-1,Enabled
Public Property Get Enabled() As Boolean
Enabled = Timer1.Enabled
End Property
Public Property Let Enabled(ByVal New_Enabled As Boolean)
Timer1.Enabled() = New_Enabled
PropertyChanged "Enabled"
End Property
'
'Public Property Get waarde() As Variant
' waarde = m_waarde
'End Property
'
'Public Property Let waarde(ByVal New_waarde As Variant)
' m_waarde = New_waarde
' PropertyChanged "waarde"
'End Property
'Initialize Properties for User Control
Private Sub UserControl_InitProperties()
' m_waarde = m_def_waarde
m_ingang = m_def_ingang
m_uitgang = m_def_uitgang
m_prefix = m_def_prefix
End Sub
'Load property values from storage
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
Timer1.Enabled = PropBag.ReadProperty("Enabled", True)
' m_waarde = PropBag.ReadProperty("waarde", m_def_waarde)
m_ingang = PropBag.ReadProperty("ingang", m_def_ingang)
m_uitgang = PropBag.ReadProperty("uitgang", m_def_uitgang)
IOOcx1.Interval = PropBag.ReadProperty("Interval", 1)
m_prefix = PropBag.ReadProperty("prefix", m_def_prefix)
End Sub
Private Sub UserControl_Terminate()
Timer1.Enabled = False
For a = 0 To 3
: start_i2c: write_i2c (m_prefix + adres(a) + "0" + "1"): write_i2c ("000000001")
Next a
End Sub
'Write property values to storage
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Call PropBag.WriteProperty("Enabled", Timer1.Enabled, True)
' Call PropBag.WriteProperty("waarde", m_waarde, m_def_waarde)
Call PropBag.WriteProperty("ingang", m_ingang, m_def_ingang)
Call PropBag.WriteProperty("uitgang", m_uitgang, m_def_uitgang)
Call PropBag.WriteProperty("Interval", IOOcx1.Interval, 1)
Call PropBag.WriteProperty("prefix", m_prefix, m_def_prefix)
End Sub
'
''WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
''MappingInfo=UserControl,UserControl,-1,Refresh
'Public Sub Refresh()
' UserControl.Refresh
'End Sub
'
'Private Sub UserControl_Terminate()
' RaiseEvent Show
'End Sub
'
Public Sub Refresh()
End Sub
Public Property Get ingang() As Variant
ingang = m_ingang
End Property
Public Property Let ingang(ByVal New_ingang As Variant)
m_ingang = New_ingang
PropertyChanged "ingang"
End Property
Public Property Get uitgang() As Variant
uitgang = m_uitgang
End Property
Public Property Let uitgang(ByVal New_uitgang As Variant)
m_uitgang = New_uitgang
PropertyChanged "uitgang"
End Property
'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
'MappingInfo=IOOcx1,IOOcx1,-1,Interval
Public Property Get Interval() As Long
Interval = IOOcx1.Interval
End Property
Public Property Let Interval(ByVal New_Interval As Long)
IOOcx1.Interval() = New_Interval
PropertyChanged "Interval"
End Property
'
'Private Sub IOOcx1_IODataAvailable(ReadData As Byte)
' RaiseEvent IODataAvailable(ReadData)
'End Sub
'
Public Property Get prefix() As Variant
prefix = m_prefix
End Property
Public Property Let prefix(ByVal New_prefix As Variant)
m_prefix = New_prefix
PropertyChanged "prefix"
End Property |