'------------------------------------------ Start ' Prog VB (A.d.p. Gusmini Claudio 5^Ben 2004/2005) '------------------------------------------ Dichiarazione variabili Dim Sg As Integer ' Latch 1, bit 3 (allarme) Dim LedVerde As Integer ' Latch 1, bit 2 Dim LedGiallo As Integer ' Latch 1, bit 1 Dim LedRosso As Integer ' Latch 1, bit 0 Dim Sensore1 As Integer ' Latch 2, bit 3 Dim Sensore2 As Integer ' Latch 2, bit 2 Dim Sensore3 As Integer ' Latch 2, bit 1 Dim Sensore4 As Integer ' Latch 2, bit 0 Dim Esecuzione As Long ' Comando esecuzione programmi Dim RetVal As Double ' Comando spegnimento Webcam Dim cont As Integer ' Contatore per il latch da attivare Dim WebAttivata As Integer ' Segnala se la webcam è attiva Dim WebRegistra As Integer ' Segnala se la webcam è in registrazione Dim AttWeb As Integer ' Ritardo per antifurto e webcam Dim RegWeb As Integer ' Ritardo per registrazione webcam Dim intrus As Integer ' Ritardo per l'allarme intrusione '------------------------------------------ Avvio programma Private Sub Form_Load() ' Inizializzazione porta LPT (visibile in WXP) Esecuzione = ShellExecute(hWnd, "Open", "LPT.exe", vbNullString, vbNullString, SW_NORMAL) End Sub Private Sub Timer1_Timer() ' Timer 10ms Ora.Text = Now ' Data e ora cont = cont + 1 ' Contatore per attivazione latch If cont = 1 Then Out &H37A, 225 ' Setta il primo latch Stato379.Text = Inp(&H379) ' Carica stato Sg, LedVerde, LedGiallo e LedRosso dalla porta 379 If Stato379.Text = 143 Then ' Decodificazione Sg = 0 LedVerde = 0 LedGiallo = 0 LedRosso = 0 End If If Stato379.Text = 159 Then Sg = 0 LedVerde = 0 LedGiallo = 0 LedRosso = 1 End If If Stato379.Text = 175 Then Sg = 0 LedVerde = 0 LedGiallo = 1 LedRosso = 0 End If If Stato379.Text = 191 Then Sg = 0 LedVerde = 0 LedGiallo = 1 LedRosso = 1 End If If Stato379.Text = 15 Then Sg = 0 LedVerde = 1 LedGiallo = 0 LedRosso = 0 End If If Stato379.Text = 31 Then Sg = 0 LedVerde = 1 LedGiallo = 0 LedRosso = 1 End If If Stato379.Text = 47 Then Sg = 0 LedVerde = 1 LedGiallo = 1 LedRosso = 0 End If If Stato379.Text = 63 Then Sg = 0 LedVerde = 1 LedGiallo = 1 LedRosso = 1 End If If Stato379.Text = 207 Then Sg = 1 LedVerde = 0 LedGiallo = 0 LedRosso = 0 End If If Stato379.Text = 223 Then Sg = 1 LedVerde = 0 LedGiallo = 0 LedRosso = 1 End If If Stato379.Text = 239 Then Sg = 1 LedVerde = 0 LedGiallo = 1 LedRosso = 0 End If If Stato379.Text = 255 Then Sg = 1 LedVerde = 0 LedGiallo = 1 LedRosso = 1 End If If Stato379.Text = 79 Then Sg = 1 LedVerde = 1 LedGiallo = 0 LedRosso = 0 End If If Stato379.Text = 95 Then Sg = 1 LedVerde = 1 LedGiallo = 0 LedRosso = 1 End If If Stato379.Text = 111 Then Sg = 1 LedVerde = 1 LedGiallo = 1 LedRosso = 0 End If If Stato379.Text = 127 Then Sg = 1 LedVerde = 1 LedGiallo = 1 LedRosso = 1 End If If LedVerde = 1 Then ' Accende/spegne led verde LEDV.FillColor = &HFF00& Else LEDV.FillColor = &H4000& End If If LedGiallo = 1 Then ' Accende/spegne led giallo (attiva/disattiva l'antifurto e la webcam) LEDG.FillColor = &HFFFF& If StatoAF.Text <> "ALLARME INTRUSIONE!" Then ' Accedi alla gestione antifurto solo se non ci sono stati allarmi AttWeb = AttWeb + 1 ' Attendi 2.5 sec prima di attivare la webcam If AttWeb > 75 Then AttWeb = 100 ' Limitatore (per evitare l'overflow) If StatoAF.Text <> "Antifurto attivato" Then StatoAF.Text = "Antifurto attivato" If Webcam.Text <> "In registrazione" Then Shell "C:\windows\amcap.exe", vbNormalFocus Webcam.Text = "Avviata" WebAttivata = 1 End If End If End If End If Else LEDG.FillColor = &H4040& If StatoAF.Text <> "ALLARME INTRUSIONE!" Then AttWeb = 0 ' Resetta ritardo per antifurto e webcam If StatoAF.Text <> "Antifurto disattivato" Then StatoAF.Text = "Antifurto disattivato" If WebAttivata = 1 Then If WebRegistra = 1 Then SendKeys "%{TAB}", True ' Sequenza di tasti per lo spegnimento webcam SendKeys "%{TAB}", True SendKeys "%", True SendKeys "{right}", True SendKeys "{right}", True SendKeys "{right}", True SendKeys "{down}", True SendKeys "{down}", True SendKeys "{ENTER}", True RetVal = Shell("taskkill /F /IM Amcap.exe", vbNormalFocus) WebAttivata = 0 WebRegistra = 0 Else RetVal = Shell("taskkill /F /IM Amcap.exe", vbNormalFocus) WebAttivata = 0 End If End If Webcam.Text = "Standby" End If End If End If If LedRosso = 1 Then ' Accende/spegne il led rosso LEDR.FillColor = &HFF& Else LEDR.FillColor = &H40& End If If Sg = 1 Or StatoAF = "ALLARME INTRUSIONE!" Then ' Intrusione! If StatoAF.Text <> "ALLARME INTRUSIONE!" Then intrus = intrus + 1 ' Ciclo di ritardo (per acquisire qual'è il sensore manomesso) If intrus > 1 Then intrus = 2 ' Limitatore RegWeb = RegWeb + 1 If RegWeb = 1 Then WebRegistra = 1 SendKeys "%{TAB}", True ' Sequenza di tasti per la registrazione SendKeys "%{TAB}", True SendKeys "%", True SendKeys "{right}", True SendKeys "{right}", True SendKeys "{right}", True SendKeys "{down}", True SendKeys "{ENTER}", True End If If RegWeb = 20 Then ' Ritardo prima dell'ultimo ENTER SendKeys "{ENTER}", True Webcam.Text = "In registrazione" ' Webcam in registrazione OraSgamo.Visible = True ' Segnalazione data/ora e dettagli OraSgamo.Text = Ora.Text StatoAF.Text = "ALLARME INTRUSIONE!" StatoAF.ForeColor = &HFF& Label27.Visible = False StatoAll.Visible = False Label1.Visible = True If Sensore1 = 0 Then Sensore.Text = "Sensore/i n°1" End If If Sensore2 = 0 Then Sensore.Text = "Sensore/i n°2" End If If Sensore3 = 0 Then Sensore.Text = "Sensore/i n°3" End If If Sensore4 = 0 Then Sensore.Text = "Sensore/i n°4" End If Dettaglitxt = FreeFile ' Creazione file di report (dettagli.txt) Open "Dettagli.txt" For Append As #Dettaglitxt Print #Dettaglitxt, "Antifurto a combinazione - Dettagli riguardo l'allarme intrusione" Print #Dettaglitxt, "" Print #Dettaglitxt, "Data e ora dell'intrusione: " + OraSgamo.Text Print #Dettaglitxt, "Sensore manomesso: " + Sensore.Text Print #Dettaglitxt, "Stato della webcam: " + Webcam.Text Print #Dettaglitxt, "" Print #Dettaglitxt, "------------------------------------------------------------------" Print #Dettaglitxt, "" Close #Dettaglitxt Report.Visible = True intrus = 0 ' Resetta ritardo per l'allarme intrusione RegWeb = 0 ' Resetta ritardo per la registrazione webcam End If End If Else If LedVerde = 0 And LedRosso = 0 And Sg = 0 Then ' Se l'allarme è spento, controlla se è stata ripristinata qualche condizione If LedGiallo = 1 Then StatoAF.ForeColor = &H80000008 StatoAF = "Antifurto attivato" Else StatoAF.ForeColor = &H80000008 ' Si disattiva tutto StatoAF = "Antifurto disattivato" If WebAttivata = 1 Then If WebRegistra = 1 Then SendKeys "%{TAB}", True ' Sequenza di tasti per lo spegnimento webcam SendKeys "%{TAB}", True SendKeys "%", True SendKeys "{right}", True SendKeys "{right}", True SendKeys "{right}", True SendKeys "{down}", True SendKeys "{down}", True SendKeys "{ENTER}", True RetVal = Shell("taskkill /F /IM Amcap.exe", vbNormalFocus) WebAttivata = 0 WebRegistra = 0 Else RetVal = Shell("taskkill /F /IM Amcap.exe", vbNormalFocus) WebAttivata = 0 End If End If Webcam.Text = "Standby" End If End If End If End If Else Out &H37A, 230 ' Setta il secondo latch Stato379.Text = Inp(&H379) ' Carica stato dei sensori If Stato379.Text = 143 Then ' Decodificazione Sensore4 = 0 Sensore3 = 0 Sensore2 = 0 Sensore1 = 0 End If If Stato379.Text = 159 Then Sensore4 = 0 Sensore3 = 0 Sensore2 = 0 Sensore1 = 1 End If If Stato379.Text = 175 Then Sensore4 = 0 Sensore3 = 0 Sensore2 = 1 Sensore1 = 0 End If If Stato379.Text = 191 Then Sensore4 = 0 Sensore3 = 0 Sensore2 = 1 Sensore1 = 1 End If If Stato379.Text = 15 Then Sensore4 = 0 Sensore3 = 1 Sensore2 = 0 Sensore1 = 0 End If If Stato379.Text = 31 Then Sensore4 = 0 Sensore3 = 1 Sensore2 = 0 Sensore1 = 1 End If If Stato379.Text = 47 Then Sensore4 = 0 Sensore3 = 1 Sensore2 = 1 Sensore1 = 0 End If If Stato379.Text = 63 Then Sensore4 = 0 Sensore3 = 1 Sensore2 = 1 Sensore1 = 1 End If If Stato379.Text = 207 Then Sensore4 = 1 Sensore3 = 0 Sensore2 = 0 Sensore1 = 0 End If If Stato379.Text = 223 Then Sensore4 = 1 Sensore3 = 0 Sensore2 = 0 Sensore1 = 1 End If If Stato379.Text = 239 Then Sensore4 = 1 Sensore3 = 0 Sensore2 = 1 Sensore1 = 0 End If If Stato379.Text = 255 Then Sensore4 = 1 Sensore3 = 0 Sensore2 = 1 Sensore1 = 1 End If If Stato379.Text = 79 Then Sensore4 = 1 Sensore3 = 1 Sensore2 = 0 Sensore1 = 0 End If If Stato379.Text = 95 Then Sensore4 = 1 Sensore3 = 1 Sensore2 = 0 Sensore1 = 1 End If If Stato379.Text = 111 Then Sensore4 = 1 Sensore3 = 1 Sensore2 = 1 Sensore1 = 0 End If If Stato379.Text = 127 Then Sensore4 = 1 Sensore3 = 1 Sensore2 = 1 Sensore1 = 1 End If If Sensore4 = 1 Then ' Accendi led sensori S4.FillColor = &HFFFF& Else S4.FillColor = &H4040& End If If Sensore3 = 1 Then S3.FillColor = &HFFFF& Else S3.FillColor = &H4040& End If If Sensore2 = 1 Then S2.FillColor = &HFFFF& Else S2.FillColor = &H4040& End If If Sensore1 = 1 Then S1.FillColor = &HFFFF& Else S1.FillColor = &H4040& End If cont = 0 ' Resetta contatore per il latch da attivare End If End Sub '------------------------------------------ Visualizza file di report Private Sub Report_Click() Esecuzione = ShellExecute(hWnd, "Open", "Dettagli.txt", vbNullString, vbNullString, SW_NORMAL) End Sub '------------------------------------------ Tasto mail Private Sub Info_Click() Esecuzione = ShellExecute(hWnd, "Open", "mailto:djgusmy85@hwtweakers.net?subject=Antifurto&Body=", vbNullString, vbNullString, SW_NORMAL) End Sub '------------------------------------------ Esci Private Sub Exit_Click() If WebAttivata = 1 Then If WebRegistra = 1 Then SendKeys "%{TAB}", True ' Sequenza di tasti per lo spegnimento webcam SendKeys "%", True SendKeys "{right}", True SendKeys "{right}", True SendKeys "{right}", True SendKeys "{down}", True SendKeys "{down}", True SendKeys "{ENTER}", True RetVal = Shell("taskkill /F /IM Amcap.exe", vbNormalFocus) Else RetVal = Shell("taskkill /F /IM Amcap.exe", vbNormalFocus) End If End If End ' Close! End Sub