'*************************************************************************** '* 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