LAMPIRAN
Design Form Utama
Source Code Form Utama
Dim nid As NOTIFYICONDATA ' Variabel Tray Icon Dim PjnHP As String
Dim PDU As String Dim rPDU As String Dim vPDU As String Dim i As Integer Dim j As Integer
Private Static Sub CommMicon_OnComm() Dim Buffer As Variant
Dim Asap As String Dim Suhu As String
Select Case CommMicon.CommEvent Case comEvReceive
If Mid(Buffer, 1, 1) = "O" Then
Private Sub Form_Load() Call Module1.Buka Timer1.Interval = 1000 tmrMicon.Enabled = False tmrMicon.Interval = 100
Me.Icon = LoadPicture(App.Path & "\FMS.ico") CommMicon.RThreshold = 1
CommMicon.SThreshold = 1
imgApi.Picture = LoadPicture(App.Path & "\GmbrNoApi.jpg") imgAsap.Picture = LoadPicture(App.Path & "\no asap.jpg") imgRoom.Picture = LoadPicture(App.Path & "\Ok.jpg") lblWarn.Caption = "A M A N"
End Sub
Private Sub mnAbout_Click() Load About
Private Sub mnClose_Click() minimize_to_tray
End Sub
Private Sub mnExit_Click() End
End Sub
Private Sub mnHP_Click() Load PortHP
PortHP.Show End Sub
Private Sub mnSensor_Click() Load PortSensor
PortSensor.Show End Sub
Private Sub mnTambah_Click() Load frmPenerima
frmPenerima.Show End Sub
Private Sub Timer1_Timer() 'status
StatusBar1.Panels(3).Text = Time
StatusBar1.Panels(3).ToolTipText = Date End Sub
' Prosedur Mengirim SMS Private Sub Kirim_SMS() On Error GoTo EH Dim waktu As Date waktu = Now()
If rs.State <> adStateClosed Then rs.Close
rs.Open "SELECT * FROM TblPenerima", db, adOpenStatic, adLockOptimistic For j = 1 To rs.RecordCount
PjnHP = "0" & Hex(Len(rs.Fields(1).Value)) If (Len(rs.Fields(1).Value) Mod 2 = 0) Then PDU = rs.Fields(1).Value
End If
.Output = "AT+CMGS =" & Val(49) + Len(rPDU) / 2 & Chr(13) & Chr(10) Load frmProgress
frmProgress.Show
frmProgress.pbKirim.Max = 100 frmProgress.pbKirim.Min = 10 Do
DoEvents
.Output = "001100" & PjnHP & "81" & rPDU & "0000A7" & _
"2ED7B0DC9D761F43A110885A9693CBF4F27A9E062DCBE2F03A2C0FBB41E4 34485A6F87D1A0A09B1C7601" & Chr(26) & Chr$(13)
Buffer$ = Buffer$ & .Input
frmProgress.pbKirim.Value = Second(waktu)
Loop Until InStr(Buffer$, "CMGS=0") Or Now > DateAdd("s", 20, waktu) If InStr(Buffer$, "OK") Then
MsgBox "Pesan Telah Terkirim" Else
MsgBox "Pesan Gagal Terkirim" End If
MsgBox Err.Description, vbExclamation, "Kesalahan" End Sub
' Prosedur Meminimize Tray Sub minimize_to_tray() Me.Hide
nid.cbSize = Len(nid) nid.hwnd = Me.hwnd nid.uId = vbNull
nid.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE nid.uCallBackMessage = WM_MOUSEMOVE
nid.szTip = "Fire Monitoring System" & vbNullChar Shell_NotifyIcon NIM_ADD, nid
End Sub
' Kondisi saat minimize tray icon
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim msg As Long Dim sFilter As String
msg = x / Screen.TwipsPerPixelX Select Case msg
Case WM_LBUTTONDOWN Me.Show ' menampilkan form
Shell_NotifyIcon NIM_DELETE, nid ' del tray icon Case WM_LBUTTONUP
Case WM_LBUTTONDBLCLK Case WM_RBUTTONDOWN Case WM_RBUTTONUP Me.Show
Shell_NotifyIcon NIM_DELETE, nid Case WM_RBUTTONDBLCLK End Select
End Sub
' Form ketika unload
Private Sub Form_Unload(Cancel As Integer)
Shell_NotifyIcon NIM_DELETE, nid ' del tray icon
If commHP.PortOpen = True Then commHP.PortOpen = False
If CommMicon.PortOpen = True Then CommMicon.PortOpen = False End Sub
Private Sub tmrMicon_Timer() 'sensor
If StatusBar1.Panels(2).Text = "Microcontroller : Connect" Then Empty_Buffer = CommMicon.Input
CommMicon.Output = "a" End If
Design Form Setting Mikrokontroller
Source Code Form Setting Mikrokontroller
Public Sub Micon_Connect() On Error GoTo EH
If cmdOK.Caption = "Connect" Then With MainForm.CommMicon
If .PortOpen = True Then .PortOpen = False .CommPort = Right(cboPort.Text, 1)
.Settings = "9600,N,8,1" If Not .PortOpen Then .PortOpen = True End If
.Output = "a" Dim waktu As Date waktu = Now() Do
DoEvents
Buffer$ = Buffer$ & .Input
Loop Until InStr(Buffer$, "OK") Or Now > DateAdd("s", 5, waktu) If InStr(Buffer$, "OK") Then
MsgBox "Terhubung Dengan Micon"
MainForm.StatusBar1.Panels(2).Text = "Microcontroller : Connect" MainForm.tmrMicon.Enabled = True
Unload Me Else
MsgBox "Port Tidak Terhubung" & vbCrLf & "Dengan MicroController", vbInformation, "Kesalahan Setting"
If .PortOpen = True Then .PortOpen = False End If
End With
cmdOK.Caption = "Disconnect" cboPort.Enabled = False
ElseIf cmdOK.Caption = "Disconnect" Then
If MainForm.CommMicon.PortOpen = True Then MainForm.CommMicon.PortOpen = False
cmdOK.Caption = "Connect"
'cboPort.Text = GetSetting(App.Title, "FMS", "Port", "COM1") cboPort.Enabled = True
MsgBox Err.Description, vbExclamation, "Kesalahan" End Sub
Private Sub cmdCancel_Click() Unload Me
End Sub
Private Sub cmdOK_Click() Call Micon_Connect End Sub
Design Form Setting HP
Source Code Setting HP
Public Sub HP_Connect() On Error GoTo EH
If cmdOK.Caption = "Connect" Then With MainForm.commHP
If .PortOpen = True Then .PortOpen = False .CommPort = Right(cboPort.Text, 1)
.Settings = "9600,N,8,1" If Not .PortOpen Then .PortOpen = True End If
.Output = "AT" & Chr(13) & Chr(10) Dim waktu As Date
waktu = Now() Do
DoEvents
Buffer$ = Buffer$ & .Input
Loop Until InStr(Buffer$, "OK") Or Now > DateAdd("s", 10, waktu) If InStr(Buffer$, "OK") Then
MsgBox "Terhubung Dengan HP"
MainForm.StatusBar1.Panels(1).Text = "HP : Online" Unload Me
MsgBox "Port Tidak Terhubung" & vbCrLf & "Dengan Handphone", vbInformation, "Kesalahan Setting"
MainForm.StatusBar1.Panels(1).Text = "HP : Offline" If .PortOpen = True Then .PortOpen = False
End If End With
cmdOK.Caption = "Disconnect" cboPort.Enabled = False
ElseIf cmdOK.Caption = "Disconnect" Then
If MainForm.commHP.PortOpen = True Then MainForm.commHP.PortOpen = False
MsgBox Err.Description, vbExclamation, "Kesalahan" End Sub
Private Sub cmdCancel_Click() Unload Me
End Sub
Private Sub cmdOK_Click() Call HP_Connect
End Sub
txtDataBits.Locked = True txtParity.Text = "None" txtParity.Locked = True txtStopBits.Text = "1" txtStopBits.Locked = True End Sub
Design Form Penerima SMS
Source Code Form Setting Mikrokontroller
Dim Tambah As Byte
Private Sub KTbl(ByVal Kunci As Boolean) cmdTambah.Enabled = Not Kunci
cmdEdit.Enabled = Not Kunci cmdHapus.Enabled = Not Kunci cmdSimpan.Enabled = Kunci cmdBatal.Enabled = Kunci mfMA.Enabled = Not Kunci End Sub
Private Sub KText(ByVal Kunci As Boolean) txtMA.Locked = Kunci
Private Sub Bersih() txtMA.Text = "" txtTelp.Text = "" txtMA.SetFocus End Sub
Private Sub Tampil() Dim i As Byte
Private Sub cmdBatal_Click() KTbl (False)
KText (True)
Tambah = 0 End Sub
Private Sub cmdEdit_Click() If txtTelp.Text <> "" Then
MsgBox "Pilih dulu data dari tabel!", vbExclamation, "Edit" End If
End Sub
Private Sub cmdHapus_Click() Dim Tanya As String
If txtTelp.Text <> "" Then
Tanya = MsgBox("Yakin ingin hapus " & txtMA.Text & " ?", vbYesNo + vbExclamation, "Hapus Data")
If Tanya = vbYes Then
MsgBox "Pilih dulu data dari tabel!", vbExclamation, "Hapus" End If
End Sub
Private Sub cmdSimpan_Click() On Error GoTo EH
If txtTelp.Text <> "" Then If Tambah = 1 Then
txtMA.Text & "','" & _
If rs.State <> adStateClosed Then rs.Close
rs.Open "SELECT * FROM TblPenerima", db, adOpenStatic, adLockOptimistic Call Tampil
Else
MsgBox "No HP harus diisi!", vbInformation, "Simpan Data" End If
Exit Sub EH:
MsgBox "No HP sudah terdaftar", vbExclamation, "Simpan Data" txtTelp.SetFocus
End Sub
Private Sub cmdTambah_Click() 'rs.AddNew
Private Sub cmdTutup_Click() Unload Me
End Sub
Private Sub Form_Activate() txtMA.SetFocus
Private Sub Form_Load()
If rs.State <> adStateClosed Then rs.Close
rs.Open "SELECT * FROM TblPenerima", db, adOpenStatic, adLockOptimistic Call Tampil
Call KTbl(False) Call KText(True) End Sub
Private Sub mfMA_Click() Dim Brs As Integer
With mfMA Brs = .Row
txtMA.Text = .TextMatrix(Brs, 0) txtTelp.Text = .TextMatrix(Brs, 1) End With
End Sub
Source Code Module1.bas
'Sound
Declare Function sndplaysound Lib "winmm.dll" Alias _ "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal _ uFlags As Long) As Long
'database
Public db As New ADODB.Connection Public rs As New ADODB.Recordset Public SQL As String
' Create an Icon in System Tray Needs Public Type NOTIFYICONDATA cbSize As Long
hwnd As Long uId As Long uFlags As Long
uCallBackMessage As Long hIcon As Long
Public Const NIM_ADD = &H0 Public Const NIM_MODIFY = &H1 Public Const NIM_DELETE = &H2
Public Const WM_MOUSEMOVE = &H200 Public Const NIF_MESSAGE = &H1
Public Const NIF_ICON = &H2 Public Const NIF_TIP = &H4
Public Const WM_LBUTTONDBLCLK = &H203 'Double-click Public Const WM_LBUTTONDOWN = &H201 'Button down Public Const WM_LBUTTONUP = &H202 'Button up
Public Const WM_RBUTTONDBLCLK = &H206 'Double-click Public Const WM_RBUTTONDOWN = &H204 'Button down Public Const WM_RBUTTONUP = &H205 'Button up
Public Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Public Sub Buka()
db.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" & App.Path & "\dbPenerima.mdb;" & _
"Persist Security Info=False" db.Open