Alejandro Acuña
2024-07-30 65a64a81d30f00f1fffd5da6866850e1308e1135
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
'***************************************************************************
'* Form frmSosPhone                                                        *
'*                                                                         *
'* This forms acts a interface for each E301 module (a sos phone).         *
'* It implements the full funcionality of the module, but with a very      *
'* plain graphic design, jut to make it as easy to anderstand as possible. *
'*                                                                         *
'* EQUITEL C.V. February 2007                                         ALMDI*
'***************************************************************************
 
Public Class frmSosPhone
 
#Region "Declarations"
    Public WithEvents mSosPhone As ClassSosPhone
    'Delegates to implement safety cross-thread calls within the events
    Delegate Sub AudioTestLedChangeCallback(ByVal Color As String)
    Delegate Sub WindowShowCallBack()
    Delegate Sub AlarmRefeshCallBack()
    Delegate Sub SliderVolumeRefreshCallBack()
    Delegate Sub ShowDataInCallBack(ByVal Value As Byte)
    Delegate Sub IncomingCallResponseCallBack(ByVal kind As String, ByVal MasterSlave As Byte)
    Delegate Sub ShowAlarmsCallBack()
    Delegate Sub ButtonEnableRefreshCallBack()
#End Region
 
#Region "Constructor"
    Public Sub New(ByVal Ip As String, ByVal N As Integer, ByVal Description As String)
        InitializeComponent()
        mSosPhone = New ClassSosPhone(Ip, N, Description)
        Me.Text = "Sos Phone " + mSosPhone.Number + "->" + mSosPhone.IP + " [" + mSosPhone.Description + "]"
        LedTestFon.Image = ImageListLeds.Images.Item("Off")
        lblIncomingCall.Visible = False
        ButtonEnableRefresh()
    End Sub
#End Region
 
#Region "Events"
    Public Event Log As TxtEventHandler
    Public Event ConnectionSuccessful As EventHandler
    Public Event ConnectionFailed As EventHandler
 
    Protected Overridable Sub OnLog(ByVal Txt As String)
        Dim e As New TxtEventArgs
        e.TxtLog = Txt
        RaiseEvent Log(Me, e)
    End Sub
 
    Protected Overridable Sub OnConnectionSuccessful()
        RaiseEvent ConnectionSuccessful(Me, New EventArgs())
    End Sub
 
    Protected Overridable Sub OnConnectionFailed()
        RaiseEvent ConnectionFailed(Me, New EventArgs())
    End Sub
#End Region
 
#Region "Form Controls behaviour"
    Private Sub BtnWaitingMessage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnWaitingMessage.Click
        mSosPhone.AudioMessageOn(ClassSosPhone.AudioMessageType.ReceivedCall, MasterOrSlave())
    End Sub
 
    Private Sub BtnOutOfServiceMessage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOutOfServiceMessage.Click
        mSosPhone.AudioMessageOn(ClassSosPhone.AudioMessageType.OutOfService, MasterOrSlave())
    End Sub
 
    Private Sub BtnMessageOff_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnMessageOff.Click
        mSosPhone.AudioMessageOff(MasterOrSlave())
    End Sub
 
    Private Sub BtnCallToneON_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCallToneON.Click
        mSosPhone.ToneOn(MasterOrSlave(), ClassSosPhone.ToneType.Ringing)
    End Sub
 
    Private Sub BtnOccupiedToneON_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOccupiedToneON.Click
        mSosPhone.ToneOn(MasterOrSlave(), ClassSosPhone.ToneType.Occupied)
    End Sub
 
    Private Sub BtnToneOFF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnToneOFF.Click
        mSosPhone.ToneOff(MasterOrSlave())
    End Sub
 
    Private Sub BtnAudioOn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAudioOn.Click
        mSosPhone.AudioOn(P_MAS)
        lblIncomingCall.Visible = False
        TimerFlashLabel.Enabled = False
        'When audio starts, the microphone volume is always the maximum
        SliderVolMic.Value = 7
        LblVolMic.Text = "7"
    End Sub
 
    Private Sub BtnAudioOff_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAudioOff.Click
        mSosPhone.AudioOff(MasterOrSlave())
    End Sub
 
    Private Sub BtnMaitenanceTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnMaitenanceTest.Click
        mSosPhone.MaitenanceTest()
    End Sub
 
    Private Sub BtnAudioTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAudioTest.Click
        LedAudioTestChange("Off")
        mSosPhone.AudioTest(MasterOrSlave())
    End Sub
 
    Private Sub BtnReadIO_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnReadIO.Click
        mSosPhone.ReadAuxiliaryPort()
    End Sub
 
    Private Sub BtnWriteIO_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnWriteIO.Click
        Dim Value As Byte = 0
        If Bt_Out_0.Text = "1" Then Value = Value Or &H1
        If Bt_Out_1.Text = "1" Then Value = Value Or &H2
        If Bt_Out_2.Text = "1" Then Value = Value Or &H4
        If Bt_Out_3.Text = "1" Then Value = Value Or &H8
        If Bt_Out_4.Text = "1" Then Value = Value Or &H10
        If Bt_Out_5.Text = "1" Then Value = Value Or &H20
        If Bt_Out_6.Text = "1" Then Value = Value Or &H40
        If Bt_Out_7.Text = "1" Then Value = Value Or &H80
        mSosPhone.WriteAuxiliaryPort(Value)
    End Sub
 
    Private Sub SliderVolOut_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles SliderVolOut.MouseUp
        If e.Button = Windows.Forms.MouseButtons.Left Then
            mSosPhone.ChangeOutputVolume(MasterOrSlave(), SliderVolOut.Value)
        End If
    End Sub
 
    Private Sub Btn_ECO_ON_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_ECO_ON.Click
        mSosPhone.EchoCancellerOn()
    End Sub
 
    Private Sub Btn_ECO_OFF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_ECO_OFF.Click
        mSosPhone.EchoCancellerOff()
    End Sub
 
    Private Sub SliderVolMic_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles SliderVolMic.MouseUp
        If e.Button = Windows.Forms.MouseButtons.Left Then
            mSosPhone.ChangeMicVolume(MasterOrSlave(), SliderVolMic.Value)
        End If
    End Sub
 
    Private Sub SliderVolMic_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SliderVolMic.Scroll
        LblVolMic.Text = Format(SliderVolMic.Value, "0")
    End Sub
 
    Private Sub SliderVolOut_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SliderVolOut.Scroll
        LblVolOut.Text = SliderVolOut.Value.ToString
    End Sub
 
    Private Sub Bt_Out_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt_Out_0.Click, Bt_Out_1.Click, Bt_Out_2.Click, Bt_Out_3.Click, Bt_Out_4.Click, Bt_Out_5.Click, Bt_Out_6.Click, Bt_Out_7.Click
        If sender.text = "0" Then sender.text = "1" Else sender.text = "0"
    End Sub
 
    Private Sub frmSosPhone_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Me.Hide()
        e.Cancel = True
    End Sub
 
    Private Sub ChkMaster_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChkMaster.Click
        If Not ChkMaster.Checked Then
            ChkMaster.Checked = True
            ChkSlave.Checked = Not ChkMaster.Checked
            SliderVolumeRefresh()
        End If
    End Sub
 
    Private Sub ChkSlave_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChkSlave.Click
        If Not ChkSlave.Checked Then
            ChkSlave.Checked = True
            ChkMaster.Checked = Not ChkSlave.Checked
            SliderVolumeRefresh()
        End If
    End Sub
 
    Private Sub TimerFlashLabel_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerFlashLabel.Tick
        lblIncomingCall.Visible = Not lblIncomingCall.Visible
    End Sub
#End Region
 
#Region "Sos Phone Event Trap"
 
    Private Sub mSosPhone_Log(ByVal sender As Object, ByVal e As TxtEventArgs) Handles mSosPhone.Log
        Dim S As String
        S = "P" + mSosPhone.Number + "-> " + e.TxtLog
        OnLog(S)
    End Sub
 
    Private Sub mSosPhone_IncomingUserCall(ByVal sender As Object, ByVal e As ByteEventArgs) Handles mSosPhone.IncomingUserCall
        'Dim D As New IncomingCallResponseCallBack(AddressOf IncomingCallResponse)
        'Me.Invoke(D, "User", e.Data)
    End Sub
 
    Private Sub mSosPhone_IncomingServiceCall(ByVal sender As Object, ByVal e As ByteEventArgs) Handles mSosPhone.IncomingServiceCall
        'Dim D As New IncomingCallResponseCallBack(AddressOf IncomingCallResponse)
        'Me.Invoke(D, "Service", e.Data)
    End Sub
 
 
    Private Sub mSosPhone_AudioTestResult(ByVal sender As Object, ByVal e As ByteEventArgs) Handles mSosPhone.AudioTestCompleted
        Dim Color As String
        Dim d As New AudioTestLedChangeCallback(AddressOf LedAudioTestChange)
        If e.Data = TST_OK Then Color = "Verde" Else Color = "Rojo"
        Invoke(d, Color)
    End Sub
 
    Private Sub mSosPhone_LecturaIO(ByVal sender As Object, ByVal e As ByteEventArgs) Handles mSosPhone.AuxilaryPortRead
        Dim A As New ShowDataInCallBack(AddressOf ShowDataIn)
        Me.Invoke(A, e.Data)
    End Sub
 
    Private Sub mSosPhone_MaintenanceTestResponse(ByVal sender As Object, ByVal e As EventArgs) Handles mSosPhone.MaitenanceTestCompleted
        'Dim A As New AlarmRefeshCallBack(AddressOf AlarmRefresh)
        'Dim S As New SliderVolumeRefreshCallBack(AddressOf SliderVolumeRefresh)
        'Me.Invoke(A)
        'Me.Invoke(S)
    End Sub
 
    Private Sub mSosPhone_Alarm(ByVal sender As Object, ByVal e As EventArgs) Handles mSosPhone.AlarmsReceived
        'Dim A As New ShowAlarmsCallBack(AddressOf ShowAlarms)
        'Me.Invoke(A)
    End Sub
 
    Private Sub mSosPhone_ConnectionSuccesfull(ByVal sender As Object, ByVal e As EventArgs) Handles mSosPhone.ConnectionSuccesful
        Dim D As New ButtonEnableRefreshCallBack(AddressOf ButtonEnableRefresh)
        Me.Invoke(D)
        OnConnectionSuccessful()
    End Sub
 
    Private Sub mSosPhone_OnConnectionFailed(ByVal sender As Object, ByVal e As EventArgs) Handles mSosPhone.ConnectionFailed
        Dim D As New ButtonEnableRefreshCallBack(AddressOf ButtonEnableRefresh)
        Me.Invoke(D)
        OnConnectionFailed()
    End Sub
#End Region
 
#Region "Auxilary functions"
    Private Sub AlarmRefresh()
        If mSosPhone.UpdatedAlarms Then
            ChkBx_DM.Checked = mSosPhone.MasterDoorAlarm
            ChkBx_DS.Checked = mSosPhone.SlaveDoorAlarm
            ChkBx_AM.Checked = mSosPhone.MasterAudioOn
            ChkBx_AS.Checked = mSosPhone.SlaveAudioOn
            ChkBx_TM.Checked = mSosPhone.MasterToneOn
            ChkBx_TS.Checked = mSosPhone.SlaveToneOn
            ChkBx_LB.Checked = mSosPhone.LowBattery
            ChkBx_PF.Checked = mSosPhone.PowerFail
        Else
            ChkBx_DM.Checked = False
            ChkBx_DS.Checked = False
            ChkBx_AM.Checked = False
            ChkBx_AS.Checked = False
            ChkBx_TM.Checked = False
            ChkBx_TS.Checked = False
            ChkBx_LB.Checked = False
            ChkBx_PF.Checked = False
            ChkBx_DM.CheckState = CheckState.Indeterminate
            ChkBx_DS.CheckState = CheckState.Indeterminate
            ChkBx_AM.CheckState = CheckState.Indeterminate
            ChkBx_AS.CheckState = CheckState.Indeterminate
            ChkBx_TM.CheckState = CheckState.Indeterminate
            ChkBx_TS.CheckState = CheckState.Indeterminate
            ChkBx_LB.CheckState = CheckState.Indeterminate
            ChkBx_PF.CheckState = CheckState.Indeterminate
        End If
    End Sub
 
    Private Sub ShowDataIn(ByVal Value As Byte)
        RB_Input_0.Checked = ((Value And &H1) <> 0)
        RB_Input_1.Checked = ((Value And &H2) <> 0)
        RB_Input_2.Checked = ((Value And &H4) <> 0)
        RB_Input_3.Checked = ((Value And &H8) <> 0)
        RB_Input_4.Checked = ((Value And &H10) <> 0)
        RB_Input_5.Checked = ((Value And &H20) <> 0)
        RB_Input_6.Checked = ((Value And &H40) <> 0)
        RB_Input_7.Checked = ((Value And &H80) <> 0)
    End Sub
 
    Private Sub IncomingCallResponse(ByVal Kind As String, ByVal MasterSlave As Byte)
        Me.Show()
        TabOrdenes.SelectedTab = TabOrdenesFonia
        ChkMaster.Checked = (MasterSlave = P_MAS)
        ChkSlave.Checked = (MasterSlave = P_ESC)
        lblIncomingCall.Text = Kind + " incoming Call !"
        lblIncomingCall.Visible = True
        TimerFlashLabel.Enabled = True
    End Sub
 
    Private Sub ShowAlarms()
        AlarmRefresh()
        TabOrdenes.SelectedTab = TabEstado
        Me.Show()
    End Sub
 
    Private Sub ButtonEnableRefresh()
        Me.Btn_ECO_OFF.Enabled = mSosPhone.Connected
        Me.Btn_ECO_ON.Enabled = mSosPhone.Connected
        Me.BtnAudioOff.Enabled = mSosPhone.Connected
        Me.BtnAudioOn.Enabled = mSosPhone.Connected
        Me.SliderVolMic.Enabled = mSosPhone.Connected
        Me.SliderVolOut.Enabled = mSosPhone.Connected
        Me.BtnOccupiedToneON.Enabled = mSosPhone.Connected
        Me.BtnToneOFF.Enabled = mSosPhone.Connected
        Me.BtnCallToneON.Enabled = mSosPhone.Connected
        Me.BtnMessageOff.Enabled = mSosPhone.Connected
        Me.BtnOutOfServiceMessage.Enabled = mSosPhone.Connected
        Me.BtnWaitingMessage.Enabled = mSosPhone.Connected
        Me.BtnAudioTest.Enabled = mSosPhone.Connected
        Me.BtnMaitenanceTest.Enabled = mSosPhone.Connected
        Me.GB_Outputs.Enabled = mSosPhone.Connected
        Me.GB_Inputs.Enabled = mSosPhone.Connected
        Me.BtnWriteIO.Enabled = mSosPhone.Connected
        Me.BtnReadIO.Enabled = mSosPhone.Connected
        Me.Label1.Enabled = mSosPhone.Connected
        Me.Label3.Enabled = mSosPhone.Connected
        Me.Label4.Enabled = mSosPhone.Connected
        Me.Label5.Enabled = mSosPhone.Connected
        Me.Label6.Enabled = mSosPhone.Connected
        Me.Label7.Enabled = mSosPhone.Connected
        Me.LblVolOut.Enabled = mSosPhone.Connected
        Me.LblVolMic.Enabled = mSosPhone.Connected
        Me.ChkMaster.Enabled = mSosPhone.Connected
        Me.ChkSlave.Enabled = mSosPhone.Connected
    End Sub
 
    Private Sub SliderVolumeRefresh()
        Dim M As Byte
        M = MasterOrSlave()
        If M = P_MAS Then
            If mSosPhone.MasterVolume >= 1 And mSosPhone.MasterVolume <= 7 Then
                SliderVolOut.Value = mSosPhone.MasterVolume
                LblVolOut.Text = mSosPhone.MasterVolume.ToString
            Else
                SliderVolOut.Value = 1
                LblVolOut.Text = "¿" + mSosPhone.MasterVolume.ToString + "?"
            End If
        Else
            If mSosPhone.MasterVolume >= 1 And mSosPhone.SlaveVolume <= 7 Then
                SliderVolOut.Value = mSosPhone.SlaveVolume
                LblVolOut.Text = mSosPhone.SlaveVolume.ToString
            Else
                SliderVolOut.Value = 1
                LblVolOut.Text = "¿" + mSosPhone.SlaveVolume.ToString + "?"
            End If
        End If
    End Sub
 
    Private Sub LedAudioTestChange(ByVal color As String)
        LedTestFon.Image = ImageListLeds.Images.Item(color)
    End Sub
 
    Private Function MasterOrSlave() As Byte
        If ChkMaster.Checked Then
            Return P_MAS
        Else
            Return P_ESC
        End If
    End Function
 
#End Region
End Class