VERSION 5.00 Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX" Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX" Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX" Begin VB.Form OptionIP Caption = "Form1" ClientHeight = 6255 ClientLeft = 120 ClientTop = 450 ClientWidth = 14025 LinkTopic = "Form1" ScaleHeight = 6255 ScaleWidth = 14025 StartUpPosition = 3 'Windows Default Begin MSComctlLib.ProgressBar bar Height = 255 Index = 0 Left = 240 TabIndex = 48 Top = 720 Width = 3855 _ExtentX = 6800 _ExtentY = 450 _Version = 393216 Appearance = 0 Max = 1000 End Begin VB.TextBox txt_print Height = 405 Left = 5640 MultiLine = -1 'True TabIndex = 47 Text = "Form1.frx":0000 Top = 240 Width = 5895 End Begin VB.Timer Timer4 Enabled = 0 'False Interval = 10 Left = 4440 Top = 360 End Begin VB.ComboBox LstIP Height = 315 Index = 4 ItemData = "Form1.frx":0006 Left = 9480 List = "Form1.frx":0013 TabIndex = 44 Top = 840 Width = 855 End Begin VB.ComboBox LstIP Height = 315 Index = 3 ItemData = "Form1.frx":0023 Left = 8520 List = "Form1.frx":0030 TabIndex = 43 Top = 840 Width = 855 End Begin VB.ComboBox LstIP Height = 315 Index = 2 ItemData = "Form1.frx":0040 Left = 7560 List = "Form1.frx":004D TabIndex = 42 Top = 840 Width = 855 End Begin VB.ComboBox LstIP Height = 315 Index = 1 ItemData = "Form1.frx":005D Left = 6600 List = "Form1.frx":006A TabIndex = 41 Top = 840 Width = 855 End Begin VB.ComboBox LstIP Height = 315 Index = 0 ItemData = "Form1.frx":007A Left = 5640 List = "Form1.frx":0087 TabIndex = 40 Top = 840 Width = 855 End Begin VB.CommandButton cmdRead Caption = "ReadData" Height = 495 Left = 10560 TabIndex = 39 Top = 1440 Visible = 0 'False Width = 975 End Begin VB.TextBox LegReg Height = 285 Index = 4 Left = 9480 TabIndex = 38 Text = "Text2" Top = 1800 Width = 855 End Begin VB.TextBox strReg Height = 285 Index = 4 Left = 9480 TabIndex = 37 Text = "Text1" Top = 1320 Width = 855 End Begin VB.Timer Timer3 Enabled = 0 'False Interval = 1000 Left = 4080 Top = 360 End Begin VB.TextBox strReg Height = 285 Index = 3 Left = 8520 TabIndex = 35 Text = "Text1" Top = 1320 Width = 855 End Begin VB.TextBox LegReg Height = 285 Index = 3 Left = 8520 TabIndex = 34 Text = "Text2" Top = 1800 Width = 855 End Begin VB.TextBox strReg Height = 285 Index = 2 Left = 7560 TabIndex = 33 Text = "Text1" Top = 1320 Width = 855 End Begin VB.TextBox LegReg Height = 285 Index = 2 Left = 7560 TabIndex = 32 Text = "Text2" Top = 1800 Width = 855 End Begin VB.TextBox strReg Height = 285 Index = 1 Left = 6600 TabIndex = 31 Text = "Text1" Top = 1320 Width = 855 End Begin VB.TextBox LegReg Height = 285 Index = 1 Left = 6600 TabIndex = 30 Text = "Text2" Top = 1800 Width = 855 End Begin VB.TextBox LegReg Height = 285 Index = 0 Left = 5640 TabIndex = 27 Text = "Text2" Top = 1800 Width = 855 End Begin VB.TextBox strReg Height = 285 Index = 0 Left = 5640 TabIndex = 26 Text = "Text1" Top = 1320 Width = 855 End Begin MSFlexGridLib.MSFlexGrid tabel Height = 3615 Left = 4200 TabIndex = 25 Top = 2400 Width = 9615 _ExtentX = 16960 _ExtentY = 6376 _Version = 393216 End Begin VB.Timer Timer2 Enabled = 0 'False Interval = 1000 Left = 4800 Top = 360 End Begin VB.Timer tloading Enabled = 0 'False Interval = 5 Left = 5160 Top = 360 End Begin VB.Frame frmDevice Caption = "Device A" Enabled = 0 'False Height = 1575 Index = 2 Left = 240 TabIndex = 17 Top = 4320 Width = 3855 Begin VB.TextBox txtIP Height = 375 Index = 2 Left = 120 TabIndex = 21 Text = "780e0629aa27.sn.mynetname.net" Top = 600 Width = 2535 End Begin VB.TextBox txtPort Height = 375 Index = 2 Left = 2760 TabIndex = 20 Text = "502" Top = 600 Width = 975 End Begin VB.CommandButton cmdConnect Caption = "Connect" Height = 375 Index = 2 Left = 1800 TabIndex = 19 Top = 1080 Width = 975 End Begin VB.CommandButton cmdDisconnect Caption = "DisConect" Height = 375 Index = 2 Left = 2760 TabIndex = 18 Top = 1080 Width = 975 End Begin VB.Label Label1 Caption = "IP Addres :" Height = 255 Index = 2 Left = 120 TabIndex = 24 Top = 360 Width = 975 End Begin VB.Label Label2 Caption = "Port :" Height = 255 Index = 2 Left = 2760 TabIndex = 23 Top = 360 Width = 735 End Begin VB.Label lblStatus BackColor = &H008080FF& Caption = "Label3" Height = 375 Index = 2 Left = 120 TabIndex = 22 Top = 1080 Width = 1695 End End Begin VB.Frame frmDevice Caption = "Device A" Enabled = 0 'False Height = 1575 Index = 1 Left = 240 TabIndex = 9 Top = 2640 Width = 3855 Begin VB.TextBox txtIP Height = 375 Index = 1 Left = 120 TabIndex = 13 Text = "80e0629aa27.sn.mynetname.net" Top = 600 Width = 2535 End Begin VB.TextBox txtPort Height = 375 Index = 1 Left = 2760 TabIndex = 12 Text = "502" Top = 600 Width = 975 End Begin VB.CommandButton cmdConnect Caption = "Connect" Height = 375 Index = 1 Left = 1800 TabIndex = 11 Top = 1080 Width = 975 End Begin VB.CommandButton cmdDisconnect Caption = "DisConect" Height = 375 Index = 1 Left = 2760 TabIndex = 10 Top = 1080 Width = 975 End Begin VB.Label Label1 Caption = "IP Addres :" Height = 255 Index = 1 Left = 120 TabIndex = 16 Top = 360 Width = 975 End Begin VB.Label Label2 Caption = "Port :" Height = 255 Index = 1 Left = 2760 TabIndex = 15 Top = 360 Width = 735 End Begin VB.Label lblStatus BackColor = &H008080FF& Caption = "Label3" Height = 375 Index = 1 Left = 120 TabIndex = 14 Top = 1080 Width = 1695 End End Begin VB.CommandButton cmdConnectDev Caption = "Connect" Height = 495 Left = 10560 TabIndex = 7 Top = 840 Visible = 0 'False Width = 975 End Begin VB.Frame frmDevice Caption = "Device A" Enabled = 0 'False Height = 1575 Index = 0 Left = 240 TabIndex = 0 Top = 1080 Width = 3855 Begin VB.CommandButton cmdDisconnect Caption = "DisConect" Height = 375 Index = 0 Left = 2760 TabIndex = 8 Top = 1080 Width = 975 End Begin VB.CommandButton cmdConnect Caption = "Connect" Height = 375 Index = 0 Left = 1800 TabIndex = 6 Top = 1080 Width = 975 End Begin VB.TextBox txtPort Height = 375 Index = 0 Left = 2760 TabIndex = 3 Text = "502" Top = 600 Width = 975 End Begin VB.TextBox txtIP Height = 375 Index = 0 Left = 120 TabIndex = 1 Text = "780e0629aa27.sn.mynetname.net" Top = 600 Width = 2535 End Begin VB.Label lblStatus BackColor = &H008080FF& Caption = "Label3" Height = 375 Index = 0 Left = 120 TabIndex = 5 Top = 1080 Width = 1695 End Begin VB.Label Label2 Caption = "Port :" Height = 255 Index = 0 Left = 2760 TabIndex = 4 Top = 360 Width = 735 End Begin VB.Label Label1 Caption = "IP Addres :" Height = 255 Index = 0 Left = 120 TabIndex = 2 Top = 360 Width = 975 End End Begin MSWinsockLib.Winsock Winsock1 Index = 1 Left = 5880 Top = 360 _ExtentX = 741 _ExtentY = 741 _Version = 393216 End Begin MSWinsockLib.Winsock Winsock1 Index = 2 Left = 6240 Top = 360 _ExtentX = 741 _ExtentY = 741 _Version = 393216 End Begin MSWinsockLib.Winsock Winsock1 Index = 0 Left = 5520 Top = 360 _ExtentX = 741 _ExtentY = 741 _Version = 393216 End Begin VB.Label lb_file Caption = "Label6" Height = 375 Left = 4080 TabIndex = 46 Top = 240 Width = 1455 End Begin VB.Label Label4 Caption = "Label4" Height = 255 Left = 240 TabIndex = 45 Top = 240 Width = 2655 End Begin VB.Label Label5 Caption = "DEVICE" Height = 255 Left = 4320 TabIndex = 36 Top = 960 Width = 975 End Begin VB.Label Label3 Caption = "LegRegister" Height = 255 Index = 1 Left = 4320 TabIndex = 29 Top = 1920 Width = 1215 End Begin VB.Label Label3 Caption = "Star Register" Height = 255 Index = 0 Left = 4320 TabIndex = 28 Top = 1440 Width = 1215 End End Attribute VB_Name = "OptionIP" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Dim counter As Integer Dim t As Integer Dim x As Integer Dim SSconect0 As String Dim SSconect1 As String Dim SSconect2 As String Dim MbusQuery(11) As Byte Dim MbusByteArray(255) As Byte Dim MbusResponse As String Dim ModbusTimeOut As Integer Dim MbusRead As Boolean Dim MbusWrite As Boolean Dim ModbusWait As Boolean Dim c As Integer Dim ipx As Byte Private Sub cmdConnect_Click(index As Integer) On Error Resume Next Me.MousePointer = vbHourglass Winsock1(index).RemoteHost = txtIP(index).Text Winsock1(index).RemotePort = txtPort(index).Text Winsock1(index).Connect Dim StartTime StartTime = Timer Do While ((Timer < StartTime + 2) And (Winsock1(index).State <> 7)) DoEvents Loop If (Winsock1(index).State = 7) Then lblStatus(index).Caption = "Connected OK" lblStatus(index).BackColor = vbGreen Else lblStatus(index).Caption = "Tidak bisa Connect " lblStatus(index).BackColor = vbYellow End If cmdConnect(index).Enabled = False Me.MousePointer = vbDefault End Sub Private Sub cmdDisconnect_Click(index As Integer) Me.MousePointer = vbHourglass If (Winsock1(index).State <> sckClosed) Then Winsock1(index).Close End If Dim StartTime StartTime = Timer Do While ((Timer < StartTime + 2) And (Winsock1(index).State <> sckClosed)) DoEvents Loop If (Winsock1(index).State = sckClosed) Then lblStatus(index).Caption = "Disconnected" lblStatus(index).BackColor = vbRed cmdConnect(index).Enabled = True ' cmdDisconnect(Index).Enabled = False Else lblStatus(index).Caption = "Error disconnect!" lblStatus(index).BackColor = vbYellow End If Me.MousePointer = vbDefault End Sub Private Sub cmdRead_Click() On Error Resume Next Dim StartLow As Byte Dim StartHigh As Byte Dim LengthLow As Byte Dim LengthHigh As Byte Dim cc As Integer ipx = LstIP(counter).ListIndex If (Winsock1(ipx).State = 7) Then StartLow = Val(strReg(counter).Text - 1) Mod 256 StartHigh = Val(strReg(counter).Text - 1) \ 256 LengthLow = Val(LegReg(counter).Text) Mod 256 LengthHigh = Val(LegReg(counter).Text) \ 256 MbusQuery(0) = 0 MbusQuery(1) = 0 MbusQuery(2) = 0 MbusQuery(3) = 0 MbusQuery(4) = 0 MbusQuery(5) = 6 MbusQuery(6) = 1 MbusQuery(7) = 3 MbusQuery(8) = StartHigh MbusQuery(9) = StartLow MbusQuery(10) = LengthHigh MbusQuery(11) = LengthLow MbusRead = True MbusWrite = False Winsock1(ipx).SendData MbusQuery ' ModbusWait = True ' ModbusTimeOut = 0 ' TimerTO.Enabled = True ' Timer1.Enabled = False If lblStatus(ipx).Caption = "Transmit" Then lblStatus(ipx).Caption = "Transmit.............." Else lblStatus(ipx).Caption = "Transmit" End If Else lblStatus(ipx).Caption = ("Not connected") If Not Winsock1(ipx).State = 7 And cmdConnect(ipx).Enabled = False Then tloading.Enabled = True End If For xx = 1 To LegReg(counter) tabel.TextMatrix(xx, ((counter + 1) * 2)) = "???" Next xx If counter < 4 Then Timer4.Enabled = True Else strReg(4).BackColor = &H80000005 End If End If End Sub Sub print_click() On Error Resume Next lb_file.Caption = "\data.txt" namefile = App.Path & lb_file.Caption Open namefile For Output As 1 txt_print.Text = "" txt_print.Text = "#" & tabel.TextMatrix(1, 2) & "#" & tabel.TextMatrix(1, 4) & "#" & tabel.TextMatrix(1, 6) & "#" & tabel.TextMatrix(5, 8) & "#" & tabel.TextMatrix(1, 10) 'For i = 1 To 10 'txt_print.Text = txt_print.Text & "," & tabel.TextMatrix(1, i) 'Next i Print #1, txt_print.Text Close #1 End Sub Private Sub Form_Load() counter = 4 tabel.Rows = 30 tabel.Cols = 30 tabel.ColWidth(0) = 400 tabel.RowHeightMin = 300 SSconect0 = GetSettingINI("set", "Scon0", True) SSconect1 = GetSettingINI("set", "Scon1", True) SSconect2 = GetSettingINI("set", "Scon2", True) '----------------------------------------------- txtPort(0) = GetSettingINI("set", "port0", "502") txtPort(1) = GetSettingINI("set", "port1", "502") txtPort(2) = GetSettingINI("set", "port2", "502") '----------------------------------------------- '----------------------------------------------- txtIP(0) = GetSettingINI("set", "txtIP0", "192.168.1.1") txtIP(1) = GetSettingINI("set", "txtIP1", "192.168.1.1") txtIP(2) = GetSettingINI("set", "txtIP2", "192.168.1.1") '----------------------------------------------------------- strReg(0) = GetSettingINI("set", "strreg0", "000") strReg(1) = GetSettingINI("set", "strreg1", "000") strReg(2) = GetSettingINI("set", "strreg2", "000") strReg(3) = GetSettingINI("set", "strreg3", "000") strReg(4) = GetSettingINI("set", "strreg4", "000") '---------------------------------------------------------- LegReg(0) = GetSettingINI("set", "legreg0", "000") LegReg(1) = GetSettingINI("set", "legreg1", "000") LegReg(2) = GetSettingINI("set", "legreg2", "000") LegReg(3) = GetSettingINI("set", "legreg3", "000") LegReg(4) = GetSettingINI("set", "legreg4", "000") '------------------------------------------------------------ LstIP(0).ListIndex = GetSettingINI("set", "LstIP0", "000") LstIP(1).ListIndex = GetSettingINI("set", "LstIP1", "000") LstIP(2).ListIndex = GetSettingINI("set", "LstIP2", "000") LstIP(3).ListIndex = GetSettingINI("set", "LstIP3", "000") LstIP(4).ListIndex = GetSettingINI("set", "LstIP4", "000") For i = 1 To 19 tabel.ColWidth(i) = 800 Next i For i = 0 To 4 For xx = 0 To LegReg(i) - 1 tabel.TextMatrix(xx + 1, (i + 1) * 2 - 1) = (strReg(i)) + xx & ">>" Next xx Next i tloading.Enabled = True bar(0).Visible = True '-------------------------------------------------- End Sub Private Sub cmdConnectDev_Click() Timer4.Enabled = False bar(0).Visible = True If counter >= 4 Then counter = 0 Else counter = counter + 1 End If Select Case counter Case 0 strReg(0).BackColor = &HFF00& strReg(1).BackColor = &H80000005 strReg(2).BackColor = &H80000005 strReg(3).BackColor = &H80000005 strReg(4).BackColor = &H80000005 Case 1 ' Or "22" strReg(0).BackColor = &H80000005 strReg(1).BackColor = &HFF00& strReg(2).BackColor = &H80000005 strReg(3).BackColor = &H80000005 strReg(4).BackColor = &H80000005 Case 2 strReg(0).BackColor = &H80000005 strReg(1).BackColor = &H80000005 strReg(2).BackColor = &HFF00& strReg(3).BackColor = &H80000005 strReg(4).BackColor = &H80000005 Case 3 strReg(0).BackColor = &H80000005 strReg(1).BackColor = &H80000005 strReg(2).BackColor = &H80000005 strReg(3).BackColor = &HFF00& strReg(4).BackColor = &H80000005 Case 4 strReg(0).BackColor = &H80000005 strReg(1).BackColor = &H80000005 strReg(2).BackColor = &H80000005 strReg(3).BackColor = &H80000005 strReg(4).BackColor = &HFF00& End Select Call cmdRead_Click End Sub Private Sub Form_Unload(Cancel As Integer) Call save End Sub Sub save() SaveSettingINI "set", "Scon0", cmdConnect(0).Enabled SaveSettingINI "set", "Scon1", cmdConnect(1).Enabled SaveSettingINI "set", "Scon2", cmdConnect(2).Enabled '-------------------------------------------------------------------- SaveSettingINI "set", "port0", txtPort(0).Text SaveSettingINI "set", "port1", txtPort(1).Text SaveSettingINI "set", "port2", txtPort(2).Text '--------------------------------------------------------------------- SaveSettingINI "set", "txtIP0", txtIP(0).Text SaveSettingINI "set", "txtIP1", txtIP(1).Text SaveSettingINI "set", "txtIP2", txtIP(2).Text '------------------------------------------------------------------------- SaveSettingINI "set", "strreg0", strReg(0).Text SaveSettingINI "set", "strreg1", strReg(1).Text SaveSettingINI "set", "strreg2", strReg(2).Text SaveSettingINI "set", "strreg3", strReg(3).Text SaveSettingINI "set", "strreg4", strReg(4).Text '------------------------------------------------------------------------- SaveSettingINI "set", "legreg0", LegReg(0).Text SaveSettingINI "set", "legreg1", LegReg(1).Text SaveSettingINI "set", "legreg2", LegReg(2).Text SaveSettingINI "set", "legreg3", LegReg(3).Text SaveSettingINI "set", "legreg4", LegReg(4).Text '------------------------------------------------------------------------------- SaveSettingINI "set", "LstIP0", LstIP(0).ListIndex SaveSettingINI "set", "LstIP1", LstIP(1).ListIndex SaveSettingINI "set", "LstIP2", LstIP(2).ListIndex SaveSettingINI "set", "LstIP3", LstIP(3).ListIndex SaveSettingINI "set", "LstIP4", LstIP(4).ListIndex End Sub Private Sub Timer1_Timer() End Sub Private Sub Timer2_Timer() If x < 10 Then x = x + 1 Else x = 0 Timer2.Enabled = False tloading.Enabled = True End If Label4.Visible = True Label4 = "Gagal koneksi..." & x End Sub Private Sub Timer3_Timer() Call cmdConnectDev_Click Call print_click End Sub Private Sub Timer4_Timer() Call cmdConnectDev_Click End Sub Private Sub tloading_Timer() Label4.Visible = False bar(0).Visible = True If t < 1000 Then t = t + 1 End If bar(0).Value = t Select Case t 'cek status koneksi------------------------------------------------------------ Case 50 If Not Winsock1(0).State = 7 Then Call cmdDisconnect_Click(0) End If Case 100 If Not Winsock1(1).State = 7 Then Call cmdDisconnect_Click(1) End If Case 150 If Not Winsock1(2).State = 7 Then Call cmdDisconnect_Click(2) End If '---------------------------------------------------------------------------- 'coba konek------------------------------------------------------------------ Case 300 If Winsock1(0).State = 0 And SSconect0 = False Then Call cmdConnect_Click(0) End If Case 500 If Winsock1(1).State = 0 And SSconect1 = False Then Call cmdConnect_Click(1) End If Case 700 If Winsock1(2).State = 0 And SSconect2 = False Then Call cmdConnect_Click(2) End If '------------------------------------------------------------------------------ Case 950 frmDevice(0).Enabled = True frmDevice(1).Enabled = True frmDevice(2).Enabled = True Timer3.Enabled = True Case 990 tloading.Enabled = False bar(0).Value = 0 bar(0).Visible = False t = 0 '------------------------------------------------------------------------------------- 'cek yg gagal koneksi----------------------------------------------------------------- If (Not Winsock1(0).State = 7 And SSconect0 = False) Or (Not Winsock1(1).State = 7 And SSconect1 = False) Or (Not Winsock1(2).State = 7 And SSconect2 = False) Then Timer2.Enabled = True End If '------------------------------------------------------------------------------------- End Select End Sub Private Sub Winsock1_DataArrival(index As Integer, ByVal bytesTotal As Long) On Error Resume Next Dim bData As Byte Dim j As Byte Dim data1 As String If bytesTotal >= 255 Then bytesTotal = 250 End If For i = 1 To bytesTotal Winsock1(ipx).GetData bData MbusByteArray(i) = bData Next j = 1 If MbusRead And Winsock1(ipx).State = 7 Then Label6 = MbusByteArray(9) + 9 ' For i = 10 To MbusByteArray(9) + 9 Step 2 For i = 10 To (LegReg(counter) * 2) + 9 Step 2 data1 = MbusByteArray(i) * 128 tabel.TextMatrix(j, ((counter + 1) * 2)) = (data1 * 2) + MbusByteArray(i + 1) If j < LegReg(counter) Then j = j + 1 End If Next i lblStatus(ipx).Caption = "Received" lblStatus(ipx).BackColor = vbGreen 'ModbusWait = False 'ModbusTimeOut = 0 'TimerTO.Enabled = False Else lblStatus(ipx).Caption = "Data Loss" lblStatus(ipx).BackColor = vbYellow End If If counter < 4 Then Timer4.Enabled = True Else strReg(4).BackColor = &H80000005 End If End Sub