Today is 13/12/2013 3.54am. I am still working for my project because On 20/12/2013 i have a presentation of my final year project . The presentation need us to do a poster for my project. I dont have idea how to do a poster, luckly my previous senior give me sample how to do final year project poster. He told me to use Microsoft publisher to make a poster. This is a sample of the poster..tq brother.
*Hopefully I can finish the poster before this coming sunday .From this time I have 6 days to study about my fyp project and I am planning 3 days before presentation day I want to meet Mr, Saharuddin. I hope he is satisfied with my work and give me 'A' grade for my fyp 2. I will upload my poster within this week.tq:)
SOLAR MONITORING SYSTEM USING VISUAL BASIC
Name: Mohd Hadri Hafiz Bin Sutaji ID : 51210211174 Advisor : Sir Saharuddin Bin Othman
Thursday, 12 December 2013
Testing the project
After done with the visual basic program . I do a testing of my project operation wether its fulfill the objective or not. Actually I already make a video for my operation of this project but the video cannot upload here because of the file is about 800MB. So I decide to print screen every moment in my video to picture.
This is all the component that i needed to run a solar monitoring system :
1) Battery 12V
2) 2 x Photovoltaic module
3) Computer
4) USB converter wire
5) Main circuit between for my input voltage and computer
Firstly I do a connection for solar panel 1, solar panel 2 and the battery to my circuit. Other to get reading for battery, its also use to supply power for microcontroller.
After done the connection for my circuit i connect usb cable to my computer:
For this experiment i put my PV1 and PV2 at my house rooftoop
After all thing ready i open the graph monitoring system inside vb6 folder
To start the monitoring i click the 'play' symbol
To run the system i click 'capture' . From here we can see a graph indicator for Battery, PV1 and PV2 and data log
I fulfill the project objective to get a voltage output for battery, PV1 and PV2 and all the result save to microsft Excell and lastly construct the graph.:)
This is all the component that i needed to run a solar monitoring system :
1) Battery 12V
2) 2 x Photovoltaic module
3) Computer
4) USB converter wire
5) Main circuit between for my input voltage and computer
Firstly I do a connection for solar panel 1, solar panel 2 and the battery to my circuit. Other to get reading for battery, its also use to supply power for microcontroller.
After done the connection for my circuit i connect usb cable to my computer:
For this experiment i put my PV1 and PV2 at my house rooftoop
This is my monitoring system look alike
To run the system i click 'capture' . From here we can see a graph indicator for Battery, PV1 and PV2 and data log
All the data/ result that we get, its store/save into microsoft excell.
From the microsft excell we can do a graph result.
I fulfill the project objective to get a voltage output for battery, PV1 and PV2 and all the result save to microsft Excell and lastly construct the graph.:)
Construct the programming for visual basic
After finish soldering the circuit i do a programming for visual basic. This is the view of my interface visual basic vb6 .
This is the coding for my visual basic 6 :
Global xmax As Single
Global ymax As Single
Global zmax As Single
Global xmin As Single
Global ymin As Single
Global zmin As Single
Global xval As Single
Global yval As Single
Global zval As Single
Global xavg As Single
Global yavg As Single
Global zavg As Single
Global LogPeriod As Long
Global readcount As Integer
Global pi As Single
Global angle As Single
Global angle2 As Single
Global linlen As Single
Dim X1, X2, X12, X22, X13, X23 As Single
Dim Y1, Y2, Y12, Y22, Y13, Y23 As Single
Dim vall, vall2, vall3 As Single
Public Sub LineActive(ByVal ValLine As Single)
Dim xx1, xx2, xx1a, xx2a As Single
Dim yy1, yy2, yy1a, yy2a As Single
With Form1
xx1 = X1
yy1 = Y1
xx2 = X2
xx1a = X1a
yy1a = Y1a
xx2a = X2a
Y2 = ValLine * 3000 ''untuk size graph battery berapa besar ratio untuk normal/kecil 1000
Y2a = ValLine * 10
yy2 = Y2
yy2a = Y2a
.Picture1.Line (xx1, 1300 - yy1)-(xx2, 1300 - yy2), vbGreen '1300 untuk graph battery start daripada value 0
If X2 >= .Picture1.Width Then X2 = -10: .Picture1.Cls: Call MakeGrid
X1 = X2
Y1 = Y2
X2 = X2 + 10
End With
End Sub
Public Sub LineActive2(ByVal ValLine2 As Single)
Dim xx12, xx22 As Single
Dim yy12, yy22 As Single
With Form1
xx12 = X12
yy12 = Y12
xx22 = X22
Y22 = ValLine2 * 3000 ''untuk size graph pv1 berapa besar ratio untuk normal/kecil 1000
yy22 = Y22
.Picture2.Line (xx12, 1300 - yy12)-(xx22, 1300 - yy22), vbRed '1300 untuk graph pv1 start daripada value 0
If X22 >= .Picture2.Width Then X22 = -10: .Picture2.Cls: Call MakeGrid2
X12 = X22
Y12 = Y22
X22 = X22 + 10
End With
End Sub
Public Sub LineActive3(ByVal ValLine3 As Single)
Dim xx13, xx23 As Single
Dim yy13, yy23 As Single
With Form1
xx13 = X13
yy13 = Y13
xx23 = X23
Y23 = ValLine3 * 3000 ''untuk size graph pv2 berapa besar ratio untuk normal/kecil 1000
yy23 = Y23
.Picture3.Line (xx13, 1300 - yy13)-(xx23, 1300 - yy23), vbWhite '1300 untuk graph pv2 start daripada value 0
If X23 >= .Picture3.Width Then X23 = -10: .Picture3.Cls: Call MakeGrid3
X13 = X23
Y13 = Y23
X23 = X23 + 10
End With
End Sub
Public Sub main()
X1 = 0
Y1 = 0
X2 = 0
Y2 = 0
X12 = 0
Y12 = 0
X22 = 0
Y22 = 0
X13 = 0
Y13 = 0
X23 = 0
Y23 = 0
End Sub
Public Sub MakeGrid()
Dim StepVal As Integer
Dim CountVal As Integer
With Form1
.Picture1.DrawStyle = vbDot
.Picture1.DrawWidth = 1
For CountVal = 1 To 3 Step 1
StepVal = StepVal + 2400
.Picture1.Line (StepVal, 3100)-(StepVal, 0), &HC0C0C0
Next
.Picture1.Line (0, 2500)-((.Picture1.Width), 2500), &HC0C0C0
.Picture1.DrawStyle = vbSolid
.Picture1.Line (0, 2500)-((.Picture1.Width), 2500), &HC0C0C0
.Picture1.Line (0, 2500)-((.Picture1.Width), 2500), &HC0C0C0
End With
End Sub
Public Sub MakeGrid2()
Dim StepVal2 As Integer
Dim CountVal2 As Integer
With Form1
.Picture2.DrawStyle = vbDot
.Picture2.DrawWidth = 1
For CountVal2 = 1 To 3 Step 1
StepVal2 = StepVal2 + 2400
.Picture2.Line (StepVal2, 3100)-(StepVal2, 0), &HC0C0C0
Next
.Picture2.Line (0, 2500)-((.Picture2.Width), 2500), &HC0C0C0
.Picture2.DrawStyle = vbSolid
.Picture2.Line (0, 2500)-((.Picture2.Width), 2500), &HC0C0C0
.Picture2.Line (0, 2500)-((.Picture2.Width), 2500), &HC0C0C0
End With
End Sub
Public Sub MakeGrid3()
Dim StepVal3 As Integer
Dim CountVal3 As Integer
With Form1
.Picture3.DrawStyle = vbDot
.Picture3.DrawWidth = 1
For CountVal3 = 1 To 3 Step 1
StepVal3 = StepVal3 + 2400
.Picture3.Line (StepVal3, 3100)-(StepVal3, 0), &HC0C0C0
Next
.Picture3.Line (0, 2500)-((.Picture3.Width), 2500), &HC0C0C0
.Picture3.DrawStyle = vbSolid
.Picture3.Line (0, 2500)-((.Picture3.Width), 2500), &HC0C0C0
.Picture3.Line (0, 2500)-((.Picture3.Width), 2500), &HC0C0C0
End With
End Sub
Coding For Battery voltage:
Dim gLogFile$
Dim bLog As Boolean
Private Sub CmdLogFile_Click()
Dim Ptr%, OldPtr%
'Set Filters
CMFile1.CancelError = True
On Error GoTo ComFileEnd
CMFile1.DialogTitle = "Open Logging File"
CMFile1.Filter = "All Files (*.CSV)|*.CSV|"
CMFile1.FileName = "*.CSV"
'Specify Default Filter
CMFile1.FilterIndex = 2
'Display the Open Dialog box
CMFile1.Action = 1
'Call the open file procedure
'If Err Then Exit Sub
gLogFile$ = CMFile1.FileName
ComFileEnd:
Ptr% = 1
Do
Ptr% = InStr(Ptr%, gLogFile$, "\", 1)
If Ptr% > 0 Then
OldPtr% = Ptr%
End If
Ptr% = Ptr% + 1
Loop Until Ptr% < OldPtr% Or Ptr% = 1
'If OldPtr% > 1 Then
' gLogDir$ = Mid(gLogFile$, 1, OldPtr%)
'Else
' gLogDir$ = ""
'End If
'LblFileName.Caption = gLogFile$
End Sub
Private Sub SaveList(lst As ListBox, file As String)
On Error GoTo ERROR
Dim i As Integer
Dim a As String
Open file For Output As #1
For i = 0 To lst.ListCount - 1
a = lst.List(i)
Print #1, a
Next
Close 1
Exit Sub
ERROR:
MsgBox "There has been a error!", vbOKOnly, "Error"
End Sub
Private Sub CmdStartLog_Click()
Dim ChkFile
' If Not IsNumeric(TxtPeriod.Text) Then
' MsgBox "ERROR Log Period must be >=1 sec"
' Exit Sub
' End If
If gLogFile$ = "" Then
MsgBox "ERROR Log File hasn't been selected"
Exit Sub
End If
' If ChkLogEnable(0).Value = vbUnchecked And ChkLogEnable(1).Value = vbUnchecked And ChkLogEnable(2).Value = vbUnchecked And ChkLogEnable(3).Value = vbUnchecked Then
' MsgBox "ERROR No Temperatures enabled for Logging"
' Exit Sub
' End If
ChkFile = Dir(gLogFile$)
If ChkFile <> "" Then
iResponse = MsgBox("Log File already exists. Do you wish to overwrite?", vbYesNo)
If iResponse = vbYes Then
Open gLogFile$ For Output As #2
Call AddLogHeading
Close #2
bLog = True
TotSecs = 0
gLogSecs = 0
Exit Sub
Else
iResponse = MsgBox("Log File already exists. Do you wish to append data to it?", vbYesNo)
If iResponse = vbYes Then
bLog = True
TotSecs = 0
gLogSecs = 0
End If
End If
Else
bLog = True
TotSecs = 0
gLogSecs = 0
Open gLogFile$ For Output As #2
Call AddLogHeading
Close #2
Exit Sub
End If
End Sub
Private Sub CmdStopLog_Click()
bLog = False
End Sub
Private Sub Command1_Click()
xmax = 0
ymax = 0
zmax = 0
xmin = 0
ymin = 0
zmin = 0
txtMax(0) = Str(xmax)
txtMin(0) = Str(xmin)
txtMax(1) = Str(ymax)
txtMin(1) = Str(ymin)
txtMax(2) = Str(zmax)
txtMin(2) = Str(zmin)
Line1(0).Y1 = Shape1(0).Top + Shape1(0).Height
Line1(0).Y2 = Line1(0).Y1
Line2(0).Y1 = Shape2(0).Top
Line2(0).Y2 = Line2(0).Y1
Line1(1).Y1 = Shape1(1).Top + Shape1(1).Height
Line1(1).Y2 = Line1(1).Y1
Line2(1).Y1 = Shape2(1).Top
Line2(1).Y2 = Line2(1).Y1
Line1(2).Y1 = Shape1(2).Top + Shape1(2).Height
Line1(2).Y2 = Line1(2).Y1
Line2(2).Y1 = Shape2(2).Top
Line2(2).Y2 = Line2(2).Y1
End Sub
Private Sub Command2_Click()
Form2.Show
End Sub
Private Sub Command4_Click()
Call Logging
End Sub
Private Sub Command5_Click()
Timer2.Interval = 0
Timer3.Interval = 0
Timer4.Interval = 0
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
Timer6.Enabled = False
Command6.Visible = True
Command5.Visible = False
End Sub
Private Sub Form_Deactivate()
Unload Me
End Sub
Private Sub Form_Load()
'Declare myfilename and myfilename2 as strings and specify Log files
Dim myfilename As String
Dim myfilename2 As String
myfilename = "Table1Order.log"
myfilename2 = "Table2Order.log"
'Make sure the log files are there, if not, create them.
If Dir(myfilename, vbNormal Or vbReadOnly Or vbHidden Or _
vbSystem Or vbArchive) = "" Then
Open App.Path & "\Table1Order.log" For Output As #1
Close #1
End If
linlen = lnRoll(0).X2 - lnRoll(0).X1
pi = 3.14159265358979
openCom (Val(Form2.txtPort.Text))
Command1_Click
'Shape2(0).Top = Shape1(0).Top + Shape1(0).Height
End Sub
Private Sub MSComm1_OnComm()
Dim i As Integer
Dim j As Integer
Dim iTmp1 As Integer, iTmp2 As Integer, iTmp3 As Integer
Dim S1, S2 As String
Select Case MSComm1.CommEvent
Case comEvReceive
S1 = MSComm1.Input
For i = 1 To Len(S1) Step 1
S2 = Mid$(S1, i, 1)
j = Asc(S2)
If (j = 7) Then ' BELL = ERROR!
Debug.Print " ";
RX.Text = RX.Text
iFlagACK = 2
Call SPLITTER
ElseIf (j = 13) Then ' CR = OK
Debug.Print " "
RX.Text = RX.Text + S2
iFlagACK = 1
Call SPLITTER
'Timer4.Enabled = True
Else
Debug.Print " ";
RX.Text = RX.Text + S2
Call SPLITTER
'Timer4.Enabled = True
End If
Next i
End Select
End Sub
Private Sub SPLITTER()
Dim strInputString As String
Dim strFilterText As String
Dim astrSplitItems() As String
Dim astrFilteredItems() As String
Dim strFilteredString As String
Dim intX As Integer
Dim t As String
strInputString = RX.Text
astrSplitItems = Split(strInputString, ",")
For intX = 0 To UBound(astrSplitItems)
RXData(intX).Text = astrSplitItems(intX)
Next
End Sub
Private Sub TEST_Click()
End Sub
Private Sub S1x_Change()
End Sub
Private Sub Save_Click()
Open App.Path & "\Log.csv" For Append As #1
Print #1, " " & lblDate & " ; " & lblTime & " ; " & S1x & " ; " & S2x & " ; " & S3x & " ; "
Close #1
Call UPDATE2
End Sub
Private Sub Text2_Change()
lnRoll(0).Y1 = lnRoll(0).Y2 + (linlen * Sin(angle))
lnRoll(0).X1 = lnRoll(0).X2 - (linlen * Cos(angle))
lnRoll(1).Y2 = lnRoll(1).Y1 - (linlen * Sin(angle))
lnRoll(1).X2 = lnRoll(1).X1 + (linlen * Cos(angle))
End Sub
Private Sub Text3_Change()
lnPitch(0).Y1 = lnPitch(0).Y2 + (linlen * Sin(angle2))
lnPitch(0).X1 = lnPitch(0).X2 + (linlen * Cos(angle2))
lnPitch(1).Y2 = lnPitch(1).Y1 - (linlen * Sin(angle2))
lnPitch(1).X2 = lnPitch(1).X1 - (linlen * Cos(angle2))
End Sub
Private Sub Text4_Change()
Timer2.Interval = Text4
End Sub
Private Sub Timer1_Timer()
'set time and date
lblDate.Caption = Format(Now, "dd/mm/yyyy")
lblTime.Caption = Format(Now, "hh:mm:ss")
End Sub
Private Sub txtFilt_Change()
If Val(txtFilt.Text) < 1 Then txtFilt.Text = "1"
End Sub
Private Sub Timer5_Timer()
If Not (RXData(3).Text = "") Then
Call Logging
RX.Text = ""
End If
End Sub
Private Sub Timer6_Timer()
Call Save_Click
End Sub
Private Sub txtScale_Change()
If Val(txtScale.Text) <= 0 Then txtScale.Text = "1"
For i = 0 To 2
Label10(i).Caption = txtScale.Text
Label11(i).Caption = "-" & txtScale.Text
Next i
End Sub
Private Function Arcsin(X As Single)
Dim tmp As Single
tmp = -X * X + 1
If tmp < 0 Then tmp = -tmp
tmp = Sqr(tmp)
If tmp <> 0 Then
tmp = Atn(X / tmp)
Else
tmp = pi / 2
If X < 0 Then tmp = -tmp
End If
Arcsin = tmp
End Function
Sub openCom(port As Integer)
On Error GoTo comError
If MSComm1.PortOpen <> False Then
MSComm1.PortOpen = False
End If
MSComm1.CommPort = port
MSComm1.PortOpen = True
Exit Sub
comError:
MsgBox "Unable to open Com Port " & port
End Sub
Sub AddLogHeading()
'Add the heading to the log file
Dim sStr$, Delim$
Dim i%
sStr$ = ""
Delim$ = ""
sStr$ = "LOG PERIOD,"
sStr$ = sStr$ & "DATE"
Delim$ = ","
sStr$ = sStr$ & Delim$ & "TIME"
Delim$ = ","
' For i% = 0 To 3
' If ChkLogEnable(i%).Value = vbChecked Then
' sStr$ = sStr$ & Delim$ & TxtDescript(i%).Text
' Delim$ = ","
' End If
' Next i%
sStr$ = sStr$ & Delim$ & "X,Y,Z"
Print #2, sStr$
End Sub
Private Sub Command6_Click()
Call MakeGrid
Call MakeGrid2
Call MakeGrid3
'If Command6.Caption = "STOP" Then
'Timer2.Interval = 0
'Timer3.Interval = 0
'Timer4.Interval = 0
Command6.Caption = "CAPTURE"
'Else
Timer2.Enabled = True
Timer3.Enabled = True
Timer4.Enabled = True
Timer2.Interval = 100
Timer3.Interval = 1
Timer4.Interval = 1
vall = Val(S1.Text)
vall = Val(S2.Text)
vall = Val(S3.Text)
'Command6.Caption = "STOP"
Command5.Visible = True
Command6.Visible = False
Timer6.Enabled = True
'End If
End Sub
Private Sub Form_Activate()
Timer2.Interval = 0
Timer3.Interval = 0
Timer4.Interval = 0
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
Timer6.Enabled = False
Call MakeGrid
Call MakeGrid2
Call MakeGrid3
End Sub
Private Sub Timer2_Timer()
vall = Val(S1.Text)
Call LineActive(vall)
vall = Val(S2.Text)
Call LineActive2(vall)
vall = Val(S3.Text)
Call LineActive3(vall)
End Sub
'Private Sub Timer3_Timer()
'vall = Val(S1.Text)
'Call LineActive(vall)
'vall = Val(S2.Text)
'Call LineActive2(vall)
'vall = Val(S3.Text)
'Call LineActive3(vall)
'End Sub
'Private Sub Timer4_Timer()
'vall = Val(S1.Text)
'Call LineActive(vall)
'vall = Val(S2.Text)
'Call LineActive2(vall)
'vall = Val(S3.Text)
'Call LineActive3(vall)
'End Sub
Private Sub Logging()
'Coding dibawah untuk data yang datang drpd RX232
If RXData(0).Text = "X" Then
'S1x untuk battery voltage
S1x.Text = S1.Text
S1.Text = RXData(1) / 100
S1x.Text = S1.Text * 100
'S2x untuk pv1 voltage
S2x.Text = S2.Text
S2.Text = RXData(2) / 100
S2x.Text = S2.Text * 100
'S3x untuk pv2 voltage
S3x.Text = S3.Text
S3.Text = RXData(3) / 100
S3x.Text = S3.Text * 100
'S4x untuk temperature
S4x.Text = S4.Text
S4.Text = RXData(4) / 100
S4x.Text = S4.Text * 100
End If
End Sub
Private Sub UPDATE()
End Sub
Private Sub UPDATE2()
lstLateRecord.Clear
Open App.Path & "\Log.csv" For Input As #1
Do Until EOF(1)
Line Input #1, tmpVar
lstLateRecord.AddItem (tmpVar)
Loop
Close #1
End Sub
Coding For PV1 :
Dim gLogFile$
Dim bLog As Boolean
Private Sub CmdLogFile_Click()
Dim Ptr%, OldPtr%
'Set Filters
CMFile1.CancelError = True
On Error GoTo ComFileEnd
CMFile1.DialogTitle = "Open Logging File"
CMFile1.Filter = "All Files (*.CSV)|*.CSV|"
CMFile1.FileName = "*.CSV"
'Specify Default Filter
CMFile1.FilterIndex = 2
'Display the Open Dialog box
CMFile1.Action = 1
'Call the open file procedure
'If Err Then Exit Sub
gLogFile$ = CMFile1.FileName
ComFileEnd:
Ptr% = 1
Do
Ptr% = InStr(Ptr%, gLogFile$, "\", 1)
If Ptr% > 0 Then
OldPtr% = Ptr%
End If
Ptr% = Ptr% + 1
Loop Until Ptr% < OldPtr% Or Ptr% = 1
'If OldPtr% > 1 Then
' gLogDir$ = Mid(gLogFile$, 1, OldPtr%)
'Else
' gLogDir$ = ""
'End If
'LblFileName.Caption = gLogFile$
End Sub
Private Sub SaveList(lst As ListBox, file As String)
On Error GoTo ERROR
Dim i As Integer
Dim a As String
Open file For Output As #1
For i = 0 To lst.ListCount - 1
a = lst.List(i)
Print #1, a
Next
Close 1
Exit Sub
ERROR:
MsgBox "There has been a error!", vbOKOnly, "Error"
End Sub
Private Sub CmdStartLog_Click()
Dim ChkFile
' If Not IsNumeric(TxtPeriod.Text) Then
' MsgBox "ERROR Log Period must be >=1 sec"
' Exit Sub
' End If
If gLogFile$ = "" Then
MsgBox "ERROR Log File hasn't been selected"
Exit Sub
End If
' If ChkLogEnable(0).Value = vbUnchecked And ChkLogEnable(1).Value = vbUnchecked And ChkLogEnable(2).Value = vbUnchecked And ChkLogEnable(3).Value = vbUnchecked Then
' MsgBox "ERROR No Temperatures enabled for Logging"
' Exit Sub
' End If
ChkFile = Dir(gLogFile$)
If ChkFile <> "" Then
iResponse = MsgBox("Log File already exists. Do you wish to overwrite?", vbYesNo)
If iResponse = vbYes Then
Open gLogFile$ For Output As #2
Call AddLogHeading
Close #2
bLog = True
TotSecs = 0
gLogSecs = 0
Exit Sub
Else
iResponse = MsgBox("Log File already exists. Do you wish to append data to it?", vbYesNo)
If iResponse = vbYes Then
bLog = True
TotSecs = 0
gLogSecs = 0
End If
End If
Else
bLog = True
TotSecs = 0
gLogSecs = 0
Open gLogFile$ For Output As #2
Call AddLogHeading
Close #2
Exit Sub
End If
End Sub
Private Sub CmdStopLog_Click()
bLog = False
End Sub
Private Sub Command1_Click()
xmax = 0
ymax = 0
zmax = 0
xmin = 0
ymin = 0
zmin = 0
txtMax(0) = Str(xmax)
txtMin(0) = Str(xmin)
txtMax(1) = Str(ymax)
txtMin(1) = Str(ymin)
txtMax(2) = Str(zmax)
txtMin(2) = Str(zmin)
Line1(0).Y1 = Shape1(0).Top + Shape1(0).Height
Line1(0).Y2 = Line1(0).Y1
Line2(0).Y1 = Shape2(0).Top
Line2(0).Y2 = Line2(0).Y1
Line1(1).Y1 = Shape1(1).Top + Shape1(1).Height
Line1(1).Y2 = Line1(1).Y1
Line2(1).Y1 = Shape2(1).Top
Line2(1).Y2 = Line2(1).Y1
Line1(2).Y1 = Shape1(2).Top + Shape1(2).Height
Line1(2).Y2 = Line1(2).Y1
Line2(2).Y1 = Shape2(2).Top
Line2(2).Y2 = Line2(2).Y1
End Sub
Private Sub Command2_Click()
Form2.Show
End Sub
Private Sub Command4_Click()
Call Logging
End Sub
Private Sub Command5_Click()
Timer2.Interval = 0
Timer3.Interval = 0
Timer4.Interval = 0
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
Timer6.Enabled = False
Command6.Visible = True
Command5.Visible = False
End Sub
Private Sub Form_Deactivate()
Unload Me
End Sub
Private Sub Form_Load()
'Declare myfilename and myfilename2 as strings and specify Log files
Dim myfilename As String
Dim myfilename2 As String
myfilename = "Table1Order.log"
myfilename2 = "Table2Order.log"
'Make sure the log files are there, if not, create them.
If Dir(myfilename, vbNormal Or vbReadOnly Or vbHidden Or _
vbSystem Or vbArchive) = "" Then
Open App.Path & "\Table1Order.log" For Output As #1
Close #1
End If
linlen = lnRoll(0).X2 - lnRoll(0).X1
pi = 3.14159265358979
openCom (Val(Form2.txtPort.Text))
Command1_Click
'Shape2(0).Top = Shape1(0).Top + Shape1(0).Height
End Sub
Private Sub MSComm1_OnComm()
Dim i As Integer
Dim j As Integer
Dim iTmp1 As Integer, iTmp2 As Integer, iTmp3 As Integer
Dim S1, S2 As String
Select Case MSComm1.CommEvent
Case comEvReceive
S1 = MSComm1.Input
For i = 1 To Len(S1) Step 1
S2 = Mid$(S1, i, 1)
j = Asc(S2)
If (j = 7) Then ' BELL = ERROR!
Debug.Print " ";
RX.Text = RX.Text
iFlagACK = 2
Call SPLITTER
ElseIf (j = 13) Then ' CR = OK
Debug.Print " "
RX.Text = RX.Text + S2
iFlagACK = 1
Call SPLITTER
'Timer4.Enabled = True
Else
Debug.Print " ";
RX.Text = RX.Text + S2
Call SPLITTER
'Timer4.Enabled = True
End If
Next i
End Select
End Sub
Private Sub SPLITTER()
Dim strInputString As String
Dim strFilterText As String
Dim astrSplitItems() As String
Dim astrFilteredItems() As String
Dim strFilteredString As String
Dim intX As Integer
Dim t As String
strInputString = RX.Text
astrSplitItems = Split(strInputString, ",")
For intX = 0 To UBound(astrSplitItems)
RXData(intX).Text = astrSplitItems(intX)
Next
End Sub
Private Sub TEST_Click()
End Sub
Private Sub S1x_Change()
End Sub
Private Sub S2x_Change()
End Sub
Private Sub Save_Click()
Open App.Path & "\Log.csv" For Append As #1
Print #1, " " & lblDate & " ; " & lblTime & " ; " & S1x & " ; " & S2x & " ; " & S3x & " ; "
Close #1
Call UPDATE2
End Sub
Private Sub Text2_Change()
lnRoll(0).Y1 = lnRoll(0).Y2 + (linlen * Sin(angle))
lnRoll(0).X1 = lnRoll(0).X2 - (linlen * Cos(angle))
lnRoll(1).Y2 = lnRoll(1).Y1 - (linlen * Sin(angle))
lnRoll(1).X2 = lnRoll(1).X1 + (linlen * Cos(angle))
End Sub
Private Sub Text3_Change()
lnPitch(0).Y1 = lnPitch(0).Y2 + (linlen * Sin(angle2))
lnPitch(0).X1 = lnPitch(0).X2 + (linlen * Cos(angle2))
lnPitch(1).Y2 = lnPitch(1).Y1 - (linlen * Sin(angle2))
lnPitch(1).X2 = lnPitch(1).X1 - (linlen * Cos(angle2))
End Sub
Private Sub Text4_Change()
Timer2.Interval = Text4
End Sub
Private Sub Timer1_Timer()
'set time and date
lblDate.Caption = Format(Now, "dd/mm/yyyy")
lblTime.Caption = Format(Now, "hh:mm:ss")
End Sub
Private Sub txtFilt_Change()
If Val(txtFilt.Text) < 1 Then txtFilt.Text = "1"
End Sub
Private Sub Timer5_Timer()
If Not (RXData(3).Text = "") Then
Call Logging
RX.Text = ""
End If
End Sub
Private Sub Timer6_Timer()
Call Save_Click
End Sub
Private Sub txtScale_Change()
If Val(txtScale.Text) <= 0 Then txtScale.Text = "1"
For i = 0 To 2
Label10(i).Caption = txtScale.Text
Label11(i).Caption = "-" & txtScale.Text
Next i
End Sub
Private Function Arcsin(X As Single)
Dim tmp As Single
tmp = -X * X + 1
If tmp < 0 Then tmp = -tmp
tmp = Sqr(tmp)
If tmp <> 0 Then
tmp = Atn(X / tmp)
Else
tmp = pi / 2
If X < 0 Then tmp = -tmp
End If
Arcsin = tmp
End Function
Sub openCom(port As Integer)
On Error GoTo comError
If MSComm1.PortOpen <> False Then
MSComm1.PortOpen = False
End If
MSComm1.CommPort = port
MSComm1.PortOpen = True
Exit Sub
comError:
MsgBox "Unable to open Com Port " & port
End Sub
Sub AddLogHeading()
'Add the heading to the log file
Dim sStr$, Delim$
Dim i%
sStr$ = ""
Delim$ = ""
sStr$ = "LOG PERIOD,"
sStr$ = sStr$ & "DATE"
Delim$ = ","
sStr$ = sStr$ & Delim$ & "TIME"
Delim$ = ","
' For i% = 0 To 3
' If ChkLogEnable(i%).Value = vbChecked Then
' sStr$ = sStr$ & Delim$ & TxtDescript(i%).Text
' Delim$ = ","
' End If
' Next i%
sStr$ = sStr$ & Delim$ & "X,Y,Z"
Print #2, sStr$
End Sub
Private Sub Command6_Click()
Call MakeGrid
Call MakeGrid2
Call MakeGrid3
'If Command6.Caption = "STOP" Then
'Timer2.Interval = 0
'Timer3.Interval = 0
'Timer4.Interval = 0
Command6.Caption = "CAPTURE"
'Else
Timer2.Enabled = True
Timer3.Enabled = True
Timer4.Enabled = True
Timer2.Interval = 100
Timer3.Interval = 1
Timer4.Interval = 1
vall = Val(S1.Text)
vall = Val(S2.Text)
vall = Val(S3.Text)
'Command6.Caption = "STOP"
Command5.Visible = True
Command6.Visible = False
Timer6.Enabled = True
'End If
End Sub
Private Sub Form_Activate()
Timer2.Interval = 0
Timer3.Interval = 0
Timer4.Interval = 0
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
Timer6.Enabled = False
Call MakeGrid
Call MakeGrid2
Call MakeGrid3
End Sub
Private Sub Timer2_Timer()
vall = Val(S1.Text)
Call LineActive(vall)
vall = Val(S2.Text)
Call LineActive2(vall)
vall = Val(S3.Text)
Call LineActive3(vall)
End Sub
'Private Sub Timer3_Timer()
'vall = Val(S1.Text)
'Call LineActive(vall)
'vall = Val(S2.Text)
'Call LineActive2(vall)
'vall = Val(S3.Text)
'Call LineActive3(vall)
'End Sub
'Private Sub Timer4_Timer()
'vall = Val(S1.Text)
'Call LineActive(vall)
'vall = Val(S2.Text)
'Call LineActive2(vall)
'vall = Val(S3.Text)
'Call LineActive3(vall)
'End Sub
Private Sub Logging()
'Coding dibawah untuk data yang datang drpd RX232
If RXData(0).Text = "X" Then
'S1x untuk battery voltage
S1x.Text = S1.Text
S1.Text = RXData(1) / 100
S1x.Text = S1.Text * 100
'S2x untuk pv1 voltage
S2x.Text = S2.Text
S2.Text = RXData(2) / 100
S2x.Text = S2.Text * 100
'S3x untuk pv2 voltage
S3x.Text = S3.Text
S3.Text = RXData(3) / 100
S3x.Text = S3.Text * 100
'S4x untuk temperature
S4x.Text = S4.Text
S4.Text = RXData(4) / 100
S4x.Text = S4.Text * 100
End If
End Sub
Private Sub UPDATE()
End Sub
Private Sub UPDATE2()
lstLateRecord.Clear
Open App.Path & "\Log.csv" For Input As #1
Do Until EOF(1)
Line Input #1, tmpVar
lstLateRecord.AddItem (tmpVar)
Loop
Close #1
End Sub
Coding For PV2 :
Dim gLogFile$
Dim bLog As Boolean
Private Sub CmdLogFile_Click()
Dim Ptr%, OldPtr%
'Set Filters
CMFile1.CancelError = True
On Error GoTo ComFileEnd
CMFile1.DialogTitle = "Open Logging File"
CMFile1.Filter = "All Files (*.CSV)|*.CSV|"
CMFile1.FileName = "*.CSV"
'Specify Default Filter
CMFile1.FilterIndex = 2
'Display the Open Dialog box
CMFile1.Action = 1
'Call the open file procedure
'If Err Then Exit Sub
gLogFile$ = CMFile1.FileName
ComFileEnd:
Ptr% = 1
Do
Ptr% = InStr(Ptr%, gLogFile$, "\", 1)
If Ptr% > 0 Then
OldPtr% = Ptr%
End If
Ptr% = Ptr% + 1
Loop Until Ptr% < OldPtr% Or Ptr% = 1
'If OldPtr% > 1 Then
' gLogDir$ = Mid(gLogFile$, 1, OldPtr%)
'Else
' gLogDir$ = ""
'End If
'LblFileName.Caption = gLogFile$
End Sub
Private Sub SaveList(lst As ListBox, file As String)
On Error GoTo ERROR
Dim i As Integer
Dim a As String
Open file For Output As #1
For i = 0 To lst.ListCount - 1
a = lst.List(i)
Print #1, a
Next
Close 1
Exit Sub
ERROR:
MsgBox "There has been a error!", vbOKOnly, "Error"
End Sub
Private Sub CmdStartLog_Click()
Dim ChkFile
' If Not IsNumeric(TxtPeriod.Text) Then
' MsgBox "ERROR Log Period must be >=1 sec"
' Exit Sub
' End If
If gLogFile$ = "" Then
MsgBox "ERROR Log File hasn't been selected"
Exit Sub
End If
' If ChkLogEnable(0).Value = vbUnchecked And ChkLogEnable(1).Value = vbUnchecked And ChkLogEnable(2).Value = vbUnchecked And ChkLogEnable(3).Value = vbUnchecked Then
' MsgBox "ERROR No Temperatures enabled for Logging"
' Exit Sub
' End If
ChkFile = Dir(gLogFile$)
If ChkFile <> "" Then
iResponse = MsgBox("Log File already exists. Do you wish to overwrite?", vbYesNo)
If iResponse = vbYes Then
Open gLogFile$ For Output As #2
Call AddLogHeading
Close #2
bLog = True
TotSecs = 0
gLogSecs = 0
Exit Sub
Else
iResponse = MsgBox("Log File already exists. Do you wish to append data to it?", vbYesNo)
If iResponse = vbYes Then
bLog = True
TotSecs = 0
gLogSecs = 0
End If
End If
Else
bLog = True
TotSecs = 0
gLogSecs = 0
Open gLogFile$ For Output As #2
Call AddLogHeading
Close #2
Exit Sub
End If
End Sub
Private Sub CmdStopLog_Click()
bLog = False
End Sub
Private Sub Command1_Click()
xmax = 0
ymax = 0
zmax = 0
xmin = 0
ymin = 0
zmin = 0
txtMax(0) = Str(xmax)
txtMin(0) = Str(xmin)
txtMax(1) = Str(ymax)
txtMin(1) = Str(ymin)
txtMax(2) = Str(zmax)
txtMin(2) = Str(zmin)
Line1(0).Y1 = Shape1(0).Top + Shape1(0).Height
Line1(0).Y2 = Line1(0).Y1
Line2(0).Y1 = Shape2(0).Top
Line2(0).Y2 = Line2(0).Y1
Line1(1).Y1 = Shape1(1).Top + Shape1(1).Height
Line1(1).Y2 = Line1(1).Y1
Line2(1).Y1 = Shape2(1).Top
Line2(1).Y2 = Line2(1).Y1
Line1(2).Y1 = Shape1(2).Top + Shape1(2).Height
Line1(2).Y2 = Line1(2).Y1
Line2(2).Y1 = Shape2(2).Top
Line2(2).Y2 = Line2(2).Y1
End Sub
Private Sub Command2_Click()
Form2.Show
End Sub
Private Sub Command4_Click()
Call Logging
End Sub
Private Sub Command5_Click()
Timer2.Interval = 0
Timer3.Interval = 0
Timer4.Interval = 0
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
Timer6.Enabled = False
Command6.Visible = True
Command5.Visible = False
End Sub
Private Sub Form_Deactivate()
Unload Me
End Sub
Private Sub Form_Load()
'Declare myfilename and myfilename2 as strings and specify Log files
Dim myfilename As String
Dim myfilename2 As String
myfilename = "Table1Order.log"
myfilename2 = "Table2Order.log"
'Make sure the log files are there, if not, create them.
If Dir(myfilename, vbNormal Or vbReadOnly Or vbHidden Or _
vbSystem Or vbArchive) = "" Then
Open App.Path & "\Table1Order.log" For Output As #1
Close #1
End If
linlen = lnRoll(0).X2 - lnRoll(0).X1
pi = 3.14159265358979
openCom (Val(Form2.txtPort.Text))
Command1_Click
'Shape2(0).Top = Shape1(0).Top + Shape1(0).Height
End Sub
Private Sub MSComm1_OnComm()
Dim i As Integer
Dim j As Integer
Dim iTmp1 As Integer, iTmp2 As Integer, iTmp3 As Integer
Dim S1, S2 As String
Select Case MSComm1.CommEvent
Case comEvReceive
S1 = MSComm1.Input
For i = 1 To Len(S1) Step 1
S2 = Mid$(S1, i, 1)
j = Asc(S2)
If (j = 7) Then ' BELL = ERROR!
Debug.Print " ";
RX.Text = RX.Text
iFlagACK = 2
Call SPLITTER
ElseIf (j = 13) Then ' CR = OK
Debug.Print " "
RX.Text = RX.Text + S2
iFlagACK = 1
Call SPLITTER
'Timer4.Enabled = True
Else
Debug.Print " ";
RX.Text = RX.Text + S2
Call SPLITTER
'Timer4.Enabled = True
End If
Next i
End Select
End Sub
Private Sub SPLITTER()
Dim strInputString As String
Dim strFilterText As String
Dim astrSplitItems() As String
Dim astrFilteredItems() As String
Dim strFilteredString As String
Dim intX As Integer
Dim t As String
strInputString = RX.Text
astrSplitItems = Split(strInputString, ",")
For intX = 0 To UBound(astrSplitItems)
RXData(intX).Text = astrSplitItems(intX)
Next
End Sub
Private Sub TEST_Click()
End Sub
Private Sub S1x_Change()
End Sub
Private Sub S2x_Change()
End Sub
Private Sub S3x_Change()
End Sub
Private Sub Save_Click()
Open App.Path & "\Log.csv" For Append As #1
Print #1, " " & lblDate & " ; " & lblTime & " ; " & S1x & " ; " & S2x & " ; " & S3x & " ; "
Close #1
Call UPDATE2
End Sub
Private Sub Text2_Change()
lnRoll(0).Y1 = lnRoll(0).Y2 + (linlen * Sin(angle))
lnRoll(0).X1 = lnRoll(0).X2 - (linlen * Cos(angle))
lnRoll(1).Y2 = lnRoll(1).Y1 - (linlen * Sin(angle))
lnRoll(1).X2 = lnRoll(1).X1 + (linlen * Cos(angle))
End Sub
Private Sub Text3_Change()
lnPitch(0).Y1 = lnPitch(0).Y2 + (linlen * Sin(angle2))
lnPitch(0).X1 = lnPitch(0).X2 + (linlen * Cos(angle2))
lnPitch(1).Y2 = lnPitch(1).Y1 - (linlen * Sin(angle2))
lnPitch(1).X2 = lnPitch(1).X1 - (linlen * Cos(angle2))
End Sub
Private Sub Text4_Change()
Timer2.Interval = Text4
End Sub
Private Sub Timer1_Timer()
'set time and date
lblDate.Caption = Format(Now, "dd/mm/yyyy")
lblTime.Caption = Format(Now, "hh:mm:ss")
End Sub
Private Sub txtFilt_Change()
If Val(txtFilt.Text) < 1 Then txtFilt.Text = "1"
End Sub
Private Sub Timer5_Timer()
If Not (RXData(3).Text = "") Then
Call Logging
RX.Text = ""
End If
End Sub
Private Sub Timer6_Timer()
Call Save_Click
End Sub
Private Sub txtScale_Change()
If Val(txtScale.Text) <= 0 Then txtScale.Text = "1"
For i = 0 To 2
Label10(i).Caption = txtScale.Text
Label11(i).Caption = "-" & txtScale.Text
Next i
End Sub
Private Function Arcsin(X As Single)
Dim tmp As Single
tmp = -X * X + 1
If tmp < 0 Then tmp = -tmp
tmp = Sqr(tmp)
If tmp <> 0 Then
tmp = Atn(X / tmp)
Else
tmp = pi / 2
If X < 0 Then tmp = -tmp
End If
Arcsin = tmp
End Function
Sub openCom(port As Integer)
On Error GoTo comError
If MSComm1.PortOpen <> False Then
MSComm1.PortOpen = False
End If
MSComm1.CommPort = port
MSComm1.PortOpen = True
Exit Sub
comError:
MsgBox "Unable to open Com Port " & port
End Sub
Sub AddLogHeading()
'Add the heading to the log file
Dim sStr$, Delim$
Dim i%
sStr$ = ""
Delim$ = ""
sStr$ = "LOG PERIOD,"
sStr$ = sStr$ & "DATE"
Delim$ = ","
sStr$ = sStr$ & Delim$ & "TIME"
Delim$ = ","
' For i% = 0 To 3
' If ChkLogEnable(i%).Value = vbChecked Then
' sStr$ = sStr$ & Delim$ & TxtDescript(i%).Text
' Delim$ = ","
' End If
' Next i%
sStr$ = sStr$ & Delim$ & "X,Y,Z"
Print #2, sStr$
End Sub
Private Sub Command6_Click()
Call MakeGrid
Call MakeGrid2
Call MakeGrid3
'If Command6.Caption = "STOP" Then
'Timer2.Interval = 0
'Timer3.Interval = 0
'Timer4.Interval = 0
Command6.Caption = "CAPTURE"
'Else
Timer2.Enabled = True
Timer3.Enabled = True
Timer4.Enabled = True
Timer2.Interval = 100
Timer3.Interval = 1
Timer4.Interval = 1
vall = Val(S1.Text)
vall = Val(S2.Text)
vall = Val(S3.Text)
'Command6.Caption = "STOP"
Command5.Visible = True
Command6.Visible = False
Timer6.Enabled = True
'End If
End Sub
Private Sub Form_Activate()
Timer2.Interval = 0
Timer3.Interval = 0
Timer4.Interval = 0
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
Timer6.Enabled = False
Call MakeGrid
Call MakeGrid2
Call MakeGrid3
End Sub
Private Sub Timer2_Timer()
vall = Val(S1.Text)
Call LineActive(vall)
vall = Val(S2.Text)
Call LineActive2(vall)
vall = Val(S3.Text)
Call LineActive3(vall)
End Sub
'Private Sub Timer3_Timer()
'vall = Val(S1.Text)
'Call LineActive(vall)
'vall = Val(S2.Text)
'Call LineActive2(vall)
'vall = Val(S3.Text)
'Call LineActive3(vall)
'End Sub
'Private Sub Timer4_Timer()
'vall = Val(S1.Text)
'Call LineActive(vall)
'vall = Val(S2.Text)
'Call LineActive2(vall)
'vall = Val(S3.Text)
'Call LineActive3(vall)
'End Sub
Private Sub Logging()
'Coding dibawah untuk data yang datang drpd RX232
If RXData(0).Text = "X" Then
'S1x untuk battery voltage
S1x.Text = S1.Text
S1.Text = RXData(1) / 100
S1x.Text = S1.Text * 100
'S2x untuk pv1 voltage
S2x.Text = S2.Text
S2.Text = RXData(2) / 100
S2x.Text = S2.Text * 100
'S3x untuk pv2 voltage
S3x.Text = S3.Text
S3.Text = RXData(3) / 100
S3x.Text = S3.Text * 100
'S4x untuk temperature
S4x.Text = S4.Text
S4.Text = RXData(4) / 100
S4x.Text = S4.Text * 100
End If
End Sub
Private Sub UPDATE()
End Sub
Private Sub UPDATE2()
lstLateRecord.Clear
Open App.Path & "\Log.csv" For Input As #1
Do Until EOF(1)
Line Input #1, tmpVar
lstLateRecord.AddItem (tmpVar)
Loop
Close #1
End Sub
Coding For Battery Graph :
Private Sub Picture1_Click()
End Sub
Private Sub S1x_Change()
End Sub
Private Sub S2x_Change()
End Sub
Private Sub S3x_Change()
End Sub
Private Sub Save_Click()
Open App.Path & "\Log.csv" For Append As #1
Print #1, " " & lblDate & " ; " & lblTime & " ; " & S1x & " ; " & S2x & " ; " & S3x & " ; "
Close #1
Call UPDATE2
End Sub
Private Sub Text2_Change()
lnRoll(0).Y1 = lnRoll(0).Y2 + (linlen * Sin(angle))
lnRoll(0).X1 = lnRoll(0).X2 - (linlen * Cos(angle))
lnRoll(1).Y2 = lnRoll(1).Y1 - (linlen * Sin(angle))
lnRoll(1).X2 = lnRoll(1).X1 + (linlen * Cos(angle))
End Sub
Private Sub Text3_Change()
lnPitch(0).Y1 = lnPitch(0).Y2 + (linlen * Sin(angle2))
lnPitch(0).X1 = lnPitch(0).X2 + (linlen * Cos(angle2))
lnPitch(1).Y2 = lnPitch(1).Y1 - (linlen * Sin(angle2))
lnPitch(1).X2 = lnPitch(1).X1 - (linlen * Cos(angle2))
End Sub
Private Sub Text4_Change()
Timer2.Interval = Text4
End Sub
Private Sub Timer1_Timer()
'set time and date
lblDate.Caption = Format(Now, "dd/mm/yyyy")
lblTime.Caption = Format(Now, "hh:mm:ss")
End Sub
Private Sub txtFilt_Change()
If Val(txtFilt.Text) < 1 Then txtFilt.Text = "1"
End Sub
Private Sub Timer5_Timer()
If Not (RXData(3).Text = "") Then
Call Logging
RX.Text = ""
End If
End Sub
Private Sub Timer6_Timer()
Call Save_Click
End Sub
Private Sub txtScale_Change()
If Val(txtScale.Text) <= 0 Then txtScale.Text = "1"
For i = 0 To 2
Label10(i).Caption = txtScale.Text
Label11(i).Caption = "-" & txtScale.Text
Next i
End Sub
Private Function Arcsin(X As Single)
Dim tmp As Single
tmp = -X * X + 1
If tmp < 0 Then tmp = -tmp
tmp = Sqr(tmp)
If tmp <> 0 Then
tmp = Atn(X / tmp)
Else
tmp = pi / 2
If X < 0 Then tmp = -tmp
End If
Arcsin = tmp
End Function
Sub openCom(port As Integer)
On Error GoTo comError
If MSComm1.PortOpen <> False Then
MSComm1.PortOpen = False
End If
MSComm1.CommPort = port
MSComm1.PortOpen = True
Exit Sub
comError:
MsgBox "Unable to open Com Port " & port
End Sub
Sub AddLogHeading()
'Add the heading to the log file
Dim sStr$, Delim$
Dim i%
sStr$ = ""
Delim$ = ""
sStr$ = "LOG PERIOD,"
sStr$ = sStr$ & "DATE"
Delim$ = ","
sStr$ = sStr$ & Delim$ & "TIME"
Delim$ = ","
' For i% = 0 To 3
' If ChkLogEnable(i%).Value = vbChecked Then
' sStr$ = sStr$ & Delim$ & TxtDescript(i%).Text
' Delim$ = ","
' End If
' Next i%
sStr$ = sStr$ & Delim$ & "X,Y,Z"
Print #2, sStr$
End Sub
Private Sub Command6_Click()
Call MakeGrid
Call MakeGrid2
Call MakeGrid3
'If Command6.Caption = "STOP" Then
'Timer2.Interval = 0
'Timer3.Interval = 0
'Timer4.Interval = 0
Command6.Caption = "CAPTURE"
'Else
Timer2.Enabled = True
Timer3.Enabled = True
Timer4.Enabled = True
Timer2.Interval = 100
Timer3.Interval = 1
Timer4.Interval = 1
vall = Val(S1.Text)
vall = Val(S2.Text)
vall = Val(S3.Text)
'Command6.Caption = "STOP"
Command5.Visible = True
Command6.Visible = False
Timer6.Enabled = True
'End If
End Sub
Private Sub Form_Activate()
Timer2.Interval = 0
Timer3.Interval = 0
Timer4.Interval = 0
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
Timer6.Enabled = False
Call MakeGrid
Call MakeGrid2
Call MakeGrid3
End Sub
Private Sub Timer2_Timer()
vall = Val(S1.Text)
Call LineActive(vall)
vall = Val(S2.Text)
Call LineActive2(vall)
vall = Val(S3.Text)
Call LineActive3(vall)
End Sub
'Private Sub Timer3_Timer()
'vall = Val(S1.Text)
'Call LineActive(vall)
'vall = Val(S2.Text)
'Call LineActive2(vall)
'vall = Val(S3.Text)
'Call LineActive3(vall)
'End Sub
'Private Sub Timer4_Timer()
'vall = Val(S1.Text)
'Call LineActive(vall)
'vall = Val(S2.Text)
'Call LineActive2(vall)
'vall = Val(S3.Text)
'Call LineActive3(vall)
'End Sub
Private Sub Logging()
'Coding dibawah untuk data yang datang drpd RX232
If RXData(0).Text = "X" Then
'S1x untuk battery voltage
S1x.Text = S1.Text
S1.Text = RXData(1) / 100
S1x.Text = S1.Text * 100
'S2x untuk pv1 voltage
S2x.Text = S2.Text
S2.Text = RXData(2) / 100
S2x.Text = S2.Text * 100
'S3x untuk pv2 voltage
S3x.Text = S3.Text
S3.Text = RXData(3) / 100
S3x.Text = S3.Text * 100
'S4x untuk temperature
S4x.Text = S4.Text
S4.Text = RXData(4) / 100
S4x.Text = S4.Text * 100
End If
End Sub
Private Sub UPDATE()
End Sub
Private Sub UPDATE2()
lstLateRecord.Clear
Open App.Path & "\Log.csv" For Input As #1
Do Until EOF(1)
Line Input #1, tmpVar
lstLateRecord.AddItem (tmpVar)
Loop
Close #1
End Sub
Coding For PV1 Graph :
Dim gLogFile$
Dim bLog As Boolean
Private Sub CmdLogFile_Click()
Dim Ptr%, OldPtr%
'Set Filters
CMFile1.CancelError = True
On Error GoTo ComFileEnd
CMFile1.DialogTitle = "Open Logging File"
CMFile1.Filter = "All Files (*.CSV)|*.CSV|"
CMFile1.FileName = "*.CSV"
'Specify Default Filter
CMFile1.FilterIndex = 2
'Display the Open Dialog box
CMFile1.Action = 1
'Call the open file procedure
'If Err Then Exit Sub
gLogFile$ = CMFile1.FileName
ComFileEnd:
Ptr% = 1
Do
Ptr% = InStr(Ptr%, gLogFile$, "\", 1)
If Ptr% > 0 Then
OldPtr% = Ptr%
End If
Ptr% = Ptr% + 1
Loop Until Ptr% < OldPtr% Or Ptr% = 1
'If OldPtr% > 1 Then
' gLogDir$ = Mid(gLogFile$, 1, OldPtr%)
'Else
' gLogDir$ = ""
'End If
'LblFileName.Caption = gLogFile$
End Sub
Private Sub SaveList(lst As ListBox, file As String)
On Error GoTo ERROR
Dim i As Integer
Dim a As String
Open file For Output As #1
For i = 0 To lst.ListCount - 1
a = lst.List(i)
Print #1, a
Next
Close 1
Exit Sub
ERROR:
MsgBox "There has been a error!", vbOKOnly, "Error"
End Sub
Private Sub CmdStartLog_Click()
Dim ChkFile
' If Not IsNumeric(TxtPeriod.Text) Then
' MsgBox "ERROR Log Period must be >=1 sec"
' Exit Sub
' End If
If gLogFile$ = "" Then
MsgBox "ERROR Log File hasn't been selected"
Exit Sub
End If
' If ChkLogEnable(0).Value = vbUnchecked And ChkLogEnable(1).Value = vbUnchecked And ChkLogEnable(2).Value = vbUnchecked And ChkLogEnable(3).Value = vbUnchecked Then
' MsgBox "ERROR No Temperatures enabled for Logging"
' Exit Sub
' End If
ChkFile = Dir(gLogFile$)
If ChkFile <> "" Then
iResponse = MsgBox("Log File already exists. Do you wish to overwrite?", vbYesNo)
If iResponse = vbYes Then
Open gLogFile$ For Output As #2
Call AddLogHeading
Close #2
bLog = True
TotSecs = 0
gLogSecs = 0
Exit Sub
Else
iResponse = MsgBox("Log File already exists. Do you wish to append data to it?", vbYesNo)
If iResponse = vbYes Then
bLog = True
TotSecs = 0
gLogSecs = 0
End If
End If
Else
bLog = True
TotSecs = 0
gLogSecs = 0
Open gLogFile$ For Output As #2
Call AddLogHeading
Close #2
Exit Sub
End If
End Sub
Private Sub CmdStopLog_Click()
bLog = False
End Sub
Private Sub Command1_Click()
xmax = 0
ymax = 0
zmax = 0
xmin = 0
ymin = 0
zmin = 0
txtMax(0) = Str(xmax)
txtMin(0) = Str(xmin)
txtMax(1) = Str(ymax)
txtMin(1) = Str(ymin)
txtMax(2) = Str(zmax)
txtMin(2) = Str(zmin)
Line1(0).Y1 = Shape1(0).Top + Shape1(0).Height
Line1(0).Y2 = Line1(0).Y1
Line2(0).Y1 = Shape2(0).Top
Line2(0).Y2 = Line2(0).Y1
Line1(1).Y1 = Shape1(1).Top + Shape1(1).Height
Line1(1).Y2 = Line1(1).Y1
Line2(1).Y1 = Shape2(1).Top
Line2(1).Y2 = Line2(1).Y1
Line1(2).Y1 = Shape1(2).Top + Shape1(2).Height
Line1(2).Y2 = Line1(2).Y1
Line2(2).Y1 = Shape2(2).Top
Line2(2).Y2 = Line2(2).Y1
End Sub
Private Sub Command2_Click()
Form2.Show
End Sub
Private Sub Command4_Click()
Call Logging
End Sub
Private Sub Command5_Click()
Timer2.Interval = 0
Timer3.Interval = 0
Timer4.Interval = 0
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
Timer6.Enabled = False
Command6.Visible = True
Command5.Visible = False
End Sub
Private Sub Form_Deactivate()
Unload Me
End Sub
Private Sub Form_Load()
'Declare myfilename and myfilename2 as strings and specify Log files
Dim myfilename As String
Dim myfilename2 As String
myfilename = "Table1Order.log"
myfilename2 = "Table2Order.log"
'Make sure the log files are there, if not, create them.
If Dir(myfilename, vbNormal Or vbReadOnly Or vbHidden Or _
vbSystem Or vbArchive) = "" Then
Open App.Path & "\Table1Order.log" For Output As #1
Close #1
End If
linlen = lnRoll(0).X2 - lnRoll(0).X1
pi = 3.14159265358979
openCom (Val(Form2.txtPort.Text))
Command1_Click
'Shape2(0).Top = Shape1(0).Top + Shape1(0).Height
End Sub
Private Sub MSComm1_OnComm()
Dim i As Integer
Dim j As Integer
Dim iTmp1 As Integer, iTmp2 As Integer, iTmp3 As Integer
Dim S1, S2 As String
Select Case MSComm1.CommEvent
Case comEvReceive
S1 = MSComm1.Input
For i = 1 To Len(S1) Step 1
S2 = Mid$(S1, i, 1)
j = Asc(S2)
If (j = 7) Then ' BELL = ERROR!
Debug.Print " ";
RX.Text = RX.Text
iFlagACK = 2
Call SPLITTER
ElseIf (j = 13) Then ' CR = OK
Debug.Print " "
RX.Text = RX.Text + S2
iFlagACK = 1
Call SPLITTER
'Timer4.Enabled = True
Else
Debug.Print " ";
RX.Text = RX.Text + S2
Call SPLITTER
'Timer4.Enabled = True
End If
Next i
End Select
End Sub
Private Sub SPLITTER()
Dim strInputString As String
Dim strFilterText As String
Dim astrSplitItems() As String
Dim astrFilteredItems() As String
Dim strFilteredString As String
Dim intX As Integer
Dim t As String
strInputString = RX.Text
astrSplitItems = Split(strInputString, ",")
For intX = 0 To UBound(astrSplitItems)
RXData(intX).Text = astrSplitItems(intX)
Next
End Sub
Private Sub TEST_Click()
End Sub
Private Sub Picture1_Click()
End Sub
Private Sub Picture2_Click()
End Sub
Private Sub S1x_Change()
End Sub
Private Sub S2x_Change()
End Sub
Private Sub S3x_Change()
End Sub
Private Sub Save_Click()
Open App.Path & "\Log.csv" For Append As #1
Print #1, " " & lblDate & " ; " & lblTime & " ; " & S1x & " ; " & S2x & " ; " & S3x & " ; "
Close #1
Call UPDATE2
End Sub
Private Sub Text2_Change()
lnRoll(0).Y1 = lnRoll(0).Y2 + (linlen * Sin(angle))
lnRoll(0).X1 = lnRoll(0).X2 - (linlen * Cos(angle))
lnRoll(1).Y2 = lnRoll(1).Y1 - (linlen * Sin(angle))
lnRoll(1).X2 = lnRoll(1).X1 + (linlen * Cos(angle))
End Sub
Private Sub Text3_Change()
lnPitch(0).Y1 = lnPitch(0).Y2 + (linlen * Sin(angle2))
lnPitch(0).X1 = lnPitch(0).X2 + (linlen * Cos(angle2))
lnPitch(1).Y2 = lnPitch(1).Y1 - (linlen * Sin(angle2))
lnPitch(1).X2 = lnPitch(1).X1 - (linlen * Cos(angle2))
End Sub
Private Sub Text4_Change()
Timer2.Interval = Text4
End Sub
Private Sub Timer1_Timer()
'set time and date
lblDate.Caption = Format(Now, "dd/mm/yyyy")
lblTime.Caption = Format(Now, "hh:mm:ss")
End Sub
Private Sub txtFilt_Change()
If Val(txtFilt.Text) < 1 Then txtFilt.Text = "1"
End Sub
Private Sub Timer5_Timer()
If Not (RXData(3).Text = "") Then
Call Logging
RX.Text = ""
End If
End Sub
Private Sub Timer6_Timer()
Call Save_Click
End Sub
Private Sub txtScale_Change()
If Val(txtScale.Text) <= 0 Then txtScale.Text = "1"
For i = 0 To 2
Label10(i).Caption = txtScale.Text
Label11(i).Caption = "-" & txtScale.Text
Next i
End Sub
Private Function Arcsin(X As Single)
Dim tmp As Single
tmp = -X * X + 1
If tmp < 0 Then tmp = -tmp
tmp = Sqr(tmp)
If tmp <> 0 Then
tmp = Atn(X / tmp)
Else
tmp = pi / 2
If X < 0 Then tmp = -tmp
End If
Arcsin = tmp
End Function
Sub openCom(port As Integer)
On Error GoTo comError
If MSComm1.PortOpen <> False Then
MSComm1.PortOpen = False
End If
MSComm1.CommPort = port
MSComm1.PortOpen = True
Exit Sub
comError:
MsgBox "Unable to open Com Port " & port
End Sub
Sub AddLogHeading()
'Add the heading to the log file
Dim sStr$, Delim$
Dim i%
sStr$ = ""
Delim$ = ""
sStr$ = "LOG PERIOD,"
sStr$ = sStr$ & "DATE"
Delim$ = ","
sStr$ = sStr$ & Delim$ & "TIME"
Delim$ = ","
' For i% = 0 To 3
' If ChkLogEnable(i%).Value = vbChecked Then
' sStr$ = sStr$ & Delim$ & TxtDescript(i%).Text
' Delim$ = ","
' End If
' Next i%
sStr$ = sStr$ & Delim$ & "X,Y,Z"
Print #2, sStr$
End Sub
Private Sub Command6_Click()
Call MakeGrid
Call MakeGrid2
Call MakeGrid3
'If Command6.Caption = "STOP" Then
'Timer2.Interval = 0
'Timer3.Interval = 0
'Timer4.Interval = 0
Command6.Caption = "CAPTURE"
'Else
Timer2.Enabled = True
Timer3.Enabled = True
Timer4.Enabled = True
Timer2.Interval = 100
Timer3.Interval = 1
Timer4.Interval = 1
vall = Val(S1.Text)
vall = Val(S2.Text)
vall = Val(S3.Text)
'Command6.Caption = "STOP"
Command5.Visible = True
Command6.Visible = False
Timer6.Enabled = True
'End If
End Sub
Private Sub Form_Activate()
Timer2.Interval = 0
Timer3.Interval = 0
Timer4.Interval = 0
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
Timer6.Enabled = False
Call MakeGrid
Call MakeGrid2
Call MakeGrid3
End Sub
Private Sub Timer2_Timer()
vall = Val(S1.Text)
Call LineActive(vall)
vall = Val(S2.Text)
Call LineActive2(vall)
vall = Val(S3.Text)
Call LineActive3(vall)
End Sub
'Private Sub Timer3_Timer()
'vall = Val(S1.Text)
'Call LineActive(vall)
'vall = Val(S2.Text)
'Call LineActive2(vall)
'vall = Val(S3.Text)
'Call LineActive3(vall)
'End Sub
'Private Sub Timer4_Timer()
'vall = Val(S1.Text)
'Call LineActive(vall)
'vall = Val(S2.Text)
'Call LineActive2(vall)
'vall = Val(S3.Text)
'Call LineActive3(vall)
'End Sub
Private Sub Logging()
'Coding dibawah untuk data yang datang drpd RX232
If RXData(0).Text = "X" Then
'S1x untuk battery voltage
S1x.Text = S1.Text
S1.Text = RXData(1) / 100
S1x.Text = S1.Text * 100
'S2x untuk pv1 voltage
S2x.Text = S2.Text
S2.Text = RXData(2) / 100
S2x.Text = S2.Text * 100
'S3x untuk pv2 voltage
S3x.Text = S3.Text
S3.Text = RXData(3) / 100
S3x.Text = S3.Text * 100
'S4x untuk temperature
S4x.Text = S4.Text
S4.Text = RXData(4) / 100
S4x.Text = S4.Text * 100
End If
End Sub
Private Sub UPDATE()
End Sub
Private Sub UPDATE2()
lstLateRecord.Clear
Open App.Path & "\Log.csv" For Input As #1
Do Until EOF(1)
Line Input #1, tmpVar
lstLateRecord.AddItem (tmpVar)
Loop
Close #1
End Sub
Coding For PV2
Dim gLogFile$
Dim bLog As Boolean
Private Sub CmdLogFile_Click()
Dim Ptr%, OldPtr%
'Set Filters
CMFile1.CancelError = True
On Error GoTo ComFileEnd
CMFile1.DialogTitle = "Open Logging File"
CMFile1.Filter = "All Files (*.CSV)|*.CSV|"
CMFile1.FileName = "*.CSV"
'Specify Default Filter
CMFile1.FilterIndex = 2
'Display the Open Dialog box
CMFile1.Action = 1
'Call the open file procedure
'If Err Then Exit Sub
gLogFile$ = CMFile1.FileName
ComFileEnd:
Ptr% = 1
Do
Ptr% = InStr(Ptr%, gLogFile$, "\", 1)
If Ptr% > 0 Then
OldPtr% = Ptr%
End If
Ptr% = Ptr% + 1
Loop Until Ptr% < OldPtr% Or Ptr% = 1
'If OldPtr% > 1 Then
' gLogDir$ = Mid(gLogFile$, 1, OldPtr%)
'Else
' gLogDir$ = ""
'End If
'LblFileName.Caption = gLogFile$
End Sub
Private Sub SaveList(lst As ListBox, file As String)
On Error GoTo ERROR
Dim i As Integer
Dim a As String
Open file For Output As #1
For i = 0 To lst.ListCount - 1
a = lst.List(i)
Print #1, a
Next
Close 1
Exit Sub
ERROR:
MsgBox "There has been a error!", vbOKOnly, "Error"
End Sub
Private Sub CmdStartLog_Click()
Dim ChkFile
' If Not IsNumeric(TxtPeriod.Text) Then
' MsgBox "ERROR Log Period must be >=1 sec"
' Exit Sub
' End If
If gLogFile$ = "" Then
MsgBox "ERROR Log File hasn't been selected"
Exit Sub
End If
' If ChkLogEnable(0).Value = vbUnchecked And ChkLogEnable(1).Value = vbUnchecked And ChkLogEnable(2).Value = vbUnchecked And ChkLogEnable(3).Value = vbUnchecked Then
' MsgBox "ERROR No Temperatures enabled for Logging"
' Exit Sub
' End If
ChkFile = Dir(gLogFile$)
If ChkFile <> "" Then
iResponse = MsgBox("Log File already exists. Do you wish to overwrite?", vbYesNo)
If iResponse = vbYes Then
Open gLogFile$ For Output As #2
Call AddLogHeading
Close #2
bLog = True
TotSecs = 0
gLogSecs = 0
Exit Sub
Else
iResponse = MsgBox("Log File already exists. Do you wish to append data to it?", vbYesNo)
If iResponse = vbYes Then
bLog = True
TotSecs = 0
gLogSecs = 0
End If
End If
Else
bLog = True
TotSecs = 0
gLogSecs = 0
Open gLogFile$ For Output As #2
Call AddLogHeading
Close #2
Exit Sub
End If
End Sub
Private Sub CmdStopLog_Click()
bLog = False
End Sub
Private Sub Command1_Click()
xmax = 0
ymax = 0
zmax = 0
xmin = 0
ymin = 0
zmin = 0
txtMax(0) = Str(xmax)
txtMin(0) = Str(xmin)
txtMax(1) = Str(ymax)
txtMin(1) = Str(ymin)
txtMax(2) = Str(zmax)
txtMin(2) = Str(zmin)
Line1(0).Y1 = Shape1(0).Top + Shape1(0).Height
Line1(0).Y2 = Line1(0).Y1
Line2(0).Y1 = Shape2(0).Top
Line2(0).Y2 = Line2(0).Y1
Line1(1).Y1 = Shape1(1).Top + Shape1(1).Height
Line1(1).Y2 = Line1(1).Y1
Line2(1).Y1 = Shape2(1).Top
Line2(1).Y2 = Line2(1).Y1
Line1(2).Y1 = Shape1(2).Top + Shape1(2).Height
Line1(2).Y2 = Line1(2).Y1
Line2(2).Y1 = Shape2(2).Top
Line2(2).Y2 = Line2(2).Y1
End Sub
Private Sub Command2_Click()
Form2.Show
End Sub
Private Sub Command4_Click()
Call Logging
End Sub
Private Sub Command5_Click()
Timer2.Interval = 0
Timer3.Interval = 0
Timer4.Interval = 0
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
Timer6.Enabled = False
Command6.Visible = True
Command5.Visible = False
End Sub
Private Sub Form_Deactivate()
Unload Me
End Sub
Private Sub Form_Load()
'Declare myfilename and myfilename2 as strings and specify Log files
Dim myfilename As String
Dim myfilename2 As String
myfilename = "Table1Order.log"
myfilename2 = "Table2Order.log"
'Make sure the log files are there, if not, create them.
If Dir(myfilename, vbNormal Or vbReadOnly Or vbHidden Or _
vbSystem Or vbArchive) = "" Then
Open App.Path & "\Table1Order.log" For Output As #1
Close #1
End If
linlen = lnRoll(0).X2 - lnRoll(0).X1
pi = 3.14159265358979
openCom (Val(Form2.txtPort.Text))
Command1_Click
'Shape2(0).Top = Shape1(0).Top + Shape1(0).Height
End Sub
Private Sub MSComm1_OnComm()
Dim i As Integer
Dim j As Integer
Dim iTmp1 As Integer, iTmp2 As Integer, iTmp3 As Integer
Dim S1, S2 As String
Select Case MSComm1.CommEvent
Case comEvReceive
S1 = MSComm1.Input
For i = 1 To Len(S1) Step 1
S2 = Mid$(S1, i, 1)
j = Asc(S2)
If (j = 7) Then ' BELL = ERROR!
Debug.Print " ";
RX.Text = RX.Text
iFlagACK = 2
Call SPLITTER
ElseIf (j = 13) Then ' CR = OK
Debug.Print " "
RX.Text = RX.Text + S2
iFlagACK = 1
Call SPLITTER
'Timer4.Enabled = True
Else
Debug.Print " ";
RX.Text = RX.Text + S2
Call SPLITTER
'Timer4.Enabled = True
End If
Next i
End Select
End Sub
Private Sub SPLITTER()
Dim strInputString As String
Dim strFilterText As String
Dim astrSplitItems() As String
Dim astrFilteredItems() As String
Dim strFilteredString As String
Dim intX As Integer
Dim t As String
strInputString = RX.Text
astrSplitItems = Split(strInputString, ",")
For intX = 0 To UBound(astrSplitItems)
RXData(intX).Text = astrSplitItems(intX)
Next
End Sub
Private Sub TEST_Click()
End Sub
Private Sub Picture1_Click()
End Sub
Private Sub Picture2_Click()
End Sub
Private Sub Picture3_Click()
End Sub
Private Sub S1x_Change()
End Sub
Private Sub S2x_Change()
End Sub
Private Sub S3x_Change()
End Sub
Private Sub Save_Click()
Open App.Path & "\Log.csv" For Append As #1
Print #1, " " & lblDate & " ; " & lblTime & " ; " & S1x & " ; " & S2x & " ; " & S3x & " ; "
Close #1
Call UPDATE2
End Sub
Private Sub Text2_Change()
lnRoll(0).Y1 = lnRoll(0).Y2 + (linlen * Sin(angle))
lnRoll(0).X1 = lnRoll(0).X2 - (linlen * Cos(angle))
lnRoll(1).Y2 = lnRoll(1).Y1 - (linlen * Sin(angle))
lnRoll(1).X2 = lnRoll(1).X1 + (linlen * Cos(angle))
End Sub
Private Sub Text3_Change()
lnPitch(0).Y1 = lnPitch(0).Y2 + (linlen * Sin(angle2))
lnPitch(0).X1 = lnPitch(0).X2 + (linlen * Cos(angle2))
lnPitch(1).Y2 = lnPitch(1).Y1 - (linlen * Sin(angle2))
lnPitch(1).X2 = lnPitch(1).X1 - (linlen * Cos(angle2))
End Sub
Private Sub Text4_Change()
Timer2.Interval = Text4
End Sub
Private Sub Timer1_Timer()
'set time and date
lblDate.Caption = Format(Now, "dd/mm/yyyy")
lblTime.Caption = Format(Now, "hh:mm:ss")
End Sub
Private Sub txtFilt_Change()
If Val(txtFilt.Text) < 1 Then txtFilt.Text = "1"
End Sub
Private Sub Timer5_Timer()
If Not (RXData(3).Text = "") Then
Call Logging
RX.Text = ""
End If
End Sub
Private Sub Timer6_Timer()
Call Save_Click
End Sub
Private Sub txtScale_Change()
If Val(txtScale.Text) <= 0 Then txtScale.Text = "1"
For i = 0 To 2
Label10(i).Caption = txtScale.Text
Label11(i).Caption = "-" & txtScale.Text
Next i
End Sub
Private Function Arcsin(X As Single)
Dim tmp As Single
tmp = -X * X + 1
If tmp < 0 Then tmp = -tmp
tmp = Sqr(tmp)
If tmp <> 0 Then
tmp = Atn(X / tmp)
Else
tmp = pi / 2
If X < 0 Then tmp = -tmp
End If
Arcsin = tmp
End Function
Sub openCom(port As Integer)
On Error GoTo comError
If MSComm1.PortOpen <> False Then
MSComm1.PortOpen = False
End If
MSComm1.CommPort = port
MSComm1.PortOpen = True
Exit Sub
comError:
MsgBox "Unable to open Com Port " & port
End Sub
Sub AddLogHeading()
'Add the heading to the log file
Dim sStr$, Delim$
Dim i%
sStr$ = ""
Delim$ = ""
sStr$ = "LOG PERIOD,"
sStr$ = sStr$ & "DATE"
Delim$ = ","
sStr$ = sStr$ & Delim$ & "TIME"
Delim$ = ","
' For i% = 0 To 3
' If ChkLogEnable(i%).Value = vbChecked Then
' sStr$ = sStr$ & Delim$ & TxtDescript(i%).Text
' Delim$ = ","
' End If
' Next i%
sStr$ = sStr$ & Delim$ & "X,Y,Z"
Print #2, sStr$
End Sub
Private Sub Command6_Click()
Call MakeGrid
Call MakeGrid2
Call MakeGrid3
'If Command6.Caption = "STOP" Then
'Timer2.Interval = 0
'Timer3.Interval = 0
'Timer4.Interval = 0
Command6.Caption = "CAPTURE"
'Else
Timer2.Enabled = True
Timer3.Enabled = True
Timer4.Enabled = True
Timer2.Interval = 100
Timer3.Interval = 1
Timer4.Interval = 1
vall = Val(S1.Text)
vall = Val(S2.Text)
vall = Val(S3.Text)
'Command6.Caption = "STOP"
Command5.Visible = True
Command6.Visible = False
Timer6.Enabled = True
'End If
End Sub
Private Sub Form_Activate()
Timer2.Interval = 0
Timer3.Interval = 0
Timer4.Interval = 0
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
Timer6.Enabled = False
Call MakeGrid
Call MakeGrid2
Call MakeGrid3
End Sub
Private Sub Timer2_Timer()
vall = Val(S1.Text)
Call LineActive(vall)
vall = Val(S2.Text)
Call LineActive2(vall)
vall = Val(S3.Text)
Call LineActive3(vall)
End Sub
'Private Sub Timer3_Timer()
'vall = Val(S1.Text)
'Call LineActive(vall)
'vall = Val(S2.Text)
'Call LineActive2(vall)
'vall = Val(S3.Text)
'Call LineActive3(vall)
'End Sub
'Private Sub Timer4_Timer()
'vall = Val(S1.Text)
'Call LineActive(vall)
'vall = Val(S2.Text)
'Call LineActive2(vall)
'vall = Val(S3.Text)
'Call LineActive3(vall)
'End Sub
Private Sub Logging()
'Coding dibawah untuk data yang datang drpd RX232
If RXData(0).Text = "X" Then
'S1x untuk battery voltage
S1x.Text = S1.Text
S1.Text = RXData(1) / 100
S1x.Text = S1.Text * 100
'S2x untuk pv1 voltage
S2x.Text = S2.Text
S2.Text = RXData(2) / 100
S2x.Text = S2.Text * 100
'S3x untuk pv2 voltage
S3x.Text = S3.Text
S3.Text = RXData(3) / 100
S3x.Text = S3.Text * 100
'S4x untuk temperature
S4x.Text = S4.Text
S4.Text = RXData(4) / 100
S4x.Text = S4.Text * 100
End If
End Sub
Private Sub UPDATE()
End Sub
Private Sub UPDATE2()
lstLateRecord.Clear
Open App.Path & "\Log.csv" For Input As #1
Do Until EOF(1)
Line Input #1, tmpVar
lstLateRecord.AddItem (tmpVar)
Loop
Close #1
End Sub
This is the coding for my visual basic 6 :
Global xmax As Single
Global ymax As Single
Global zmax As Single
Global xmin As Single
Global ymin As Single
Global zmin As Single
Global xval As Single
Global yval As Single
Global zval As Single
Global xavg As Single
Global yavg As Single
Global zavg As Single
Global LogPeriod As Long
Global readcount As Integer
Global pi As Single
Global angle As Single
Global angle2 As Single
Global linlen As Single
Dim X1, X2, X12, X22, X13, X23 As Single
Dim Y1, Y2, Y12, Y22, Y13, Y23 As Single
Dim vall, vall2, vall3 As Single
Public Sub LineActive(ByVal ValLine As Single)
Dim xx1, xx2, xx1a, xx2a As Single
Dim yy1, yy2, yy1a, yy2a As Single
With Form1
xx1 = X1
yy1 = Y1
xx2 = X2
xx1a = X1a
yy1a = Y1a
xx2a = X2a
Y2 = ValLine * 3000 ''untuk size graph battery berapa besar ratio untuk normal/kecil 1000
Y2a = ValLine * 10
yy2 = Y2
yy2a = Y2a
.Picture1.Line (xx1, 1300 - yy1)-(xx2, 1300 - yy2), vbGreen '1300 untuk graph battery start daripada value 0
If X2 >= .Picture1.Width Then X2 = -10: .Picture1.Cls: Call MakeGrid
X1 = X2
Y1 = Y2
X2 = X2 + 10
End With
End Sub
Public Sub LineActive2(ByVal ValLine2 As Single)
Dim xx12, xx22 As Single
Dim yy12, yy22 As Single
With Form1
xx12 = X12
yy12 = Y12
xx22 = X22
Y22 = ValLine2 * 3000 ''untuk size graph pv1 berapa besar ratio untuk normal/kecil 1000
yy22 = Y22
.Picture2.Line (xx12, 1300 - yy12)-(xx22, 1300 - yy22), vbRed '1300 untuk graph pv1 start daripada value 0
If X22 >= .Picture2.Width Then X22 = -10: .Picture2.Cls: Call MakeGrid2
X12 = X22
Y12 = Y22
X22 = X22 + 10
End With
End Sub
Public Sub LineActive3(ByVal ValLine3 As Single)
Dim xx13, xx23 As Single
Dim yy13, yy23 As Single
With Form1
xx13 = X13
yy13 = Y13
xx23 = X23
Y23 = ValLine3 * 3000 ''untuk size graph pv2 berapa besar ratio untuk normal/kecil 1000
yy23 = Y23
.Picture3.Line (xx13, 1300 - yy13)-(xx23, 1300 - yy23), vbWhite '1300 untuk graph pv2 start daripada value 0
If X23 >= .Picture3.Width Then X23 = -10: .Picture3.Cls: Call MakeGrid3
X13 = X23
Y13 = Y23
X23 = X23 + 10
End With
End Sub
Public Sub main()
X1 = 0
Y1 = 0
X2 = 0
Y2 = 0
X12 = 0
Y12 = 0
X22 = 0
Y22 = 0
X13 = 0
Y13 = 0
X23 = 0
Y23 = 0
End Sub
Public Sub MakeGrid()
Dim StepVal As Integer
Dim CountVal As Integer
With Form1
.Picture1.DrawStyle = vbDot
.Picture1.DrawWidth = 1
For CountVal = 1 To 3 Step 1
StepVal = StepVal + 2400
.Picture1.Line (StepVal, 3100)-(StepVal, 0), &HC0C0C0
Next
.Picture1.Line (0, 2500)-((.Picture1.Width), 2500), &HC0C0C0
.Picture1.DrawStyle = vbSolid
.Picture1.Line (0, 2500)-((.Picture1.Width), 2500), &HC0C0C0
.Picture1.Line (0, 2500)-((.Picture1.Width), 2500), &HC0C0C0
End With
End Sub
Public Sub MakeGrid2()
Dim StepVal2 As Integer
Dim CountVal2 As Integer
With Form1
.Picture2.DrawStyle = vbDot
.Picture2.DrawWidth = 1
For CountVal2 = 1 To 3 Step 1
StepVal2 = StepVal2 + 2400
.Picture2.Line (StepVal2, 3100)-(StepVal2, 0), &HC0C0C0
Next
.Picture2.Line (0, 2500)-((.Picture2.Width), 2500), &HC0C0C0
.Picture2.DrawStyle = vbSolid
.Picture2.Line (0, 2500)-((.Picture2.Width), 2500), &HC0C0C0
.Picture2.Line (0, 2500)-((.Picture2.Width), 2500), &HC0C0C0
End With
End Sub
Public Sub MakeGrid3()
Dim StepVal3 As Integer
Dim CountVal3 As Integer
With Form1
.Picture3.DrawStyle = vbDot
.Picture3.DrawWidth = 1
For CountVal3 = 1 To 3 Step 1
StepVal3 = StepVal3 + 2400
.Picture3.Line (StepVal3, 3100)-(StepVal3, 0), &HC0C0C0
Next
.Picture3.Line (0, 2500)-((.Picture3.Width), 2500), &HC0C0C0
.Picture3.DrawStyle = vbSolid
.Picture3.Line (0, 2500)-((.Picture3.Width), 2500), &HC0C0C0
.Picture3.Line (0, 2500)-((.Picture3.Width), 2500), &HC0C0C0
End With
End Sub
Coding For Battery voltage:
Dim gLogFile$
Dim bLog As Boolean
Private Sub CmdLogFile_Click()
Dim Ptr%, OldPtr%
'Set Filters
CMFile1.CancelError = True
On Error GoTo ComFileEnd
CMFile1.DialogTitle = "Open Logging File"
CMFile1.Filter = "All Files (*.CSV)|*.CSV|"
CMFile1.FileName = "*.CSV"
'Specify Default Filter
CMFile1.FilterIndex = 2
'Display the Open Dialog box
CMFile1.Action = 1
'Call the open file procedure
'If Err Then Exit Sub
gLogFile$ = CMFile1.FileName
ComFileEnd:
Ptr% = 1
Do
Ptr% = InStr(Ptr%, gLogFile$, "\", 1)
If Ptr% > 0 Then
OldPtr% = Ptr%
End If
Ptr% = Ptr% + 1
Loop Until Ptr% < OldPtr% Or Ptr% = 1
'If OldPtr% > 1 Then
' gLogDir$ = Mid(gLogFile$, 1, OldPtr%)
'Else
' gLogDir$ = ""
'End If
'LblFileName.Caption = gLogFile$
End Sub
Private Sub SaveList(lst As ListBox, file As String)
On Error GoTo ERROR
Dim i As Integer
Dim a As String
Open file For Output As #1
For i = 0 To lst.ListCount - 1
a = lst.List(i)
Print #1, a
Next
Close 1
Exit Sub
ERROR:
MsgBox "There has been a error!", vbOKOnly, "Error"
End Sub
Private Sub CmdStartLog_Click()
Dim ChkFile
' If Not IsNumeric(TxtPeriod.Text) Then
' MsgBox "ERROR Log Period must be >=1 sec"
' Exit Sub
' End If
If gLogFile$ = "" Then
MsgBox "ERROR Log File hasn't been selected"
Exit Sub
End If
' If ChkLogEnable(0).Value = vbUnchecked And ChkLogEnable(1).Value = vbUnchecked And ChkLogEnable(2).Value = vbUnchecked And ChkLogEnable(3).Value = vbUnchecked Then
' MsgBox "ERROR No Temperatures enabled for Logging"
' Exit Sub
' End If
ChkFile = Dir(gLogFile$)
If ChkFile <> "" Then
iResponse = MsgBox("Log File already exists. Do you wish to overwrite?", vbYesNo)
If iResponse = vbYes Then
Open gLogFile$ For Output As #2
Call AddLogHeading
Close #2
bLog = True
TotSecs = 0
gLogSecs = 0
Exit Sub
Else
iResponse = MsgBox("Log File already exists. Do you wish to append data to it?", vbYesNo)
If iResponse = vbYes Then
bLog = True
TotSecs = 0
gLogSecs = 0
End If
End If
Else
bLog = True
TotSecs = 0
gLogSecs = 0
Open gLogFile$ For Output As #2
Call AddLogHeading
Close #2
Exit Sub
End If
End Sub
Private Sub CmdStopLog_Click()
bLog = False
End Sub
Private Sub Command1_Click()
xmax = 0
ymax = 0
zmax = 0
xmin = 0
ymin = 0
zmin = 0
txtMax(0) = Str(xmax)
txtMin(0) = Str(xmin)
txtMax(1) = Str(ymax)
txtMin(1) = Str(ymin)
txtMax(2) = Str(zmax)
txtMin(2) = Str(zmin)
Line1(0).Y1 = Shape1(0).Top + Shape1(0).Height
Line1(0).Y2 = Line1(0).Y1
Line2(0).Y1 = Shape2(0).Top
Line2(0).Y2 = Line2(0).Y1
Line1(1).Y1 = Shape1(1).Top + Shape1(1).Height
Line1(1).Y2 = Line1(1).Y1
Line2(1).Y1 = Shape2(1).Top
Line2(1).Y2 = Line2(1).Y1
Line1(2).Y1 = Shape1(2).Top + Shape1(2).Height
Line1(2).Y2 = Line1(2).Y1
Line2(2).Y1 = Shape2(2).Top
Line2(2).Y2 = Line2(2).Y1
End Sub
Private Sub Command2_Click()
Form2.Show
End Sub
Private Sub Command4_Click()
Call Logging
End Sub
Private Sub Command5_Click()
Timer2.Interval = 0
Timer3.Interval = 0
Timer4.Interval = 0
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
Timer6.Enabled = False
Command6.Visible = True
Command5.Visible = False
End Sub
Private Sub Form_Deactivate()
Unload Me
End Sub
Private Sub Form_Load()
'Declare myfilename and myfilename2 as strings and specify Log files
Dim myfilename As String
Dim myfilename2 As String
myfilename = "Table1Order.log"
myfilename2 = "Table2Order.log"
'Make sure the log files are there, if not, create them.
If Dir(myfilename, vbNormal Or vbReadOnly Or vbHidden Or _
vbSystem Or vbArchive) = "" Then
Open App.Path & "\Table1Order.log" For Output As #1
Close #1
End If
linlen = lnRoll(0).X2 - lnRoll(0).X1
pi = 3.14159265358979
openCom (Val(Form2.txtPort.Text))
Command1_Click
'Shape2(0).Top = Shape1(0).Top + Shape1(0).Height
End Sub
Private Sub MSComm1_OnComm()
Dim i As Integer
Dim j As Integer
Dim iTmp1 As Integer, iTmp2 As Integer, iTmp3 As Integer
Dim S1, S2 As String
Select Case MSComm1.CommEvent
Case comEvReceive
S1 = MSComm1.Input
For i = 1 To Len(S1) Step 1
S2 = Mid$(S1, i, 1)
j = Asc(S2)
If (j = 7) Then ' BELL = ERROR!
Debug.Print " ";
RX.Text = RX.Text
iFlagACK = 2
Call SPLITTER
ElseIf (j = 13) Then ' CR = OK
Debug.Print " "
RX.Text = RX.Text + S2
iFlagACK = 1
Call SPLITTER
'Timer4.Enabled = True
Else
Debug.Print " ";
RX.Text = RX.Text + S2
Call SPLITTER
'Timer4.Enabled = True
End If
Next i
End Select
End Sub
Private Sub SPLITTER()
Dim strInputString As String
Dim strFilterText As String
Dim astrSplitItems() As String
Dim astrFilteredItems() As String
Dim strFilteredString As String
Dim intX As Integer
Dim t As String
strInputString = RX.Text
astrSplitItems = Split(strInputString, ",")
For intX = 0 To UBound(astrSplitItems)
RXData(intX).Text = astrSplitItems(intX)
Next
End Sub
Private Sub TEST_Click()
End Sub
Private Sub S1x_Change()
End Sub
Private Sub Save_Click()
Open App.Path & "\Log.csv" For Append As #1
Print #1, " " & lblDate & " ; " & lblTime & " ; " & S1x & " ; " & S2x & " ; " & S3x & " ; "
Close #1
Call UPDATE2
End Sub
Private Sub Text2_Change()
lnRoll(0).Y1 = lnRoll(0).Y2 + (linlen * Sin(angle))
lnRoll(0).X1 = lnRoll(0).X2 - (linlen * Cos(angle))
lnRoll(1).Y2 = lnRoll(1).Y1 - (linlen * Sin(angle))
lnRoll(1).X2 = lnRoll(1).X1 + (linlen * Cos(angle))
End Sub
Private Sub Text3_Change()
lnPitch(0).Y1 = lnPitch(0).Y2 + (linlen * Sin(angle2))
lnPitch(0).X1 = lnPitch(0).X2 + (linlen * Cos(angle2))
lnPitch(1).Y2 = lnPitch(1).Y1 - (linlen * Sin(angle2))
lnPitch(1).X2 = lnPitch(1).X1 - (linlen * Cos(angle2))
End Sub
Private Sub Text4_Change()
Timer2.Interval = Text4
End Sub
Private Sub Timer1_Timer()
'set time and date
lblDate.Caption = Format(Now, "dd/mm/yyyy")
lblTime.Caption = Format(Now, "hh:mm:ss")
End Sub
Private Sub txtFilt_Change()
If Val(txtFilt.Text) < 1 Then txtFilt.Text = "1"
End Sub
Private Sub Timer5_Timer()
If Not (RXData(3).Text = "") Then
Call Logging
RX.Text = ""
End If
End Sub
Private Sub Timer6_Timer()
Call Save_Click
End Sub
Private Sub txtScale_Change()
If Val(txtScale.Text) <= 0 Then txtScale.Text = "1"
For i = 0 To 2
Label10(i).Caption = txtScale.Text
Label11(i).Caption = "-" & txtScale.Text
Next i
End Sub
Private Function Arcsin(X As Single)
Dim tmp As Single
tmp = -X * X + 1
If tmp < 0 Then tmp = -tmp
tmp = Sqr(tmp)
If tmp <> 0 Then
tmp = Atn(X / tmp)
Else
tmp = pi / 2
If X < 0 Then tmp = -tmp
End If
Arcsin = tmp
End Function
Sub openCom(port As Integer)
On Error GoTo comError
If MSComm1.PortOpen <> False Then
MSComm1.PortOpen = False
End If
MSComm1.CommPort = port
MSComm1.PortOpen = True
Exit Sub
comError:
MsgBox "Unable to open Com Port " & port
End Sub
Sub AddLogHeading()
'Add the heading to the log file
Dim sStr$, Delim$
Dim i%
sStr$ = ""
Delim$ = ""
sStr$ = "LOG PERIOD,"
sStr$ = sStr$ & "DATE"
Delim$ = ","
sStr$ = sStr$ & Delim$ & "TIME"
Delim$ = ","
' For i% = 0 To 3
' If ChkLogEnable(i%).Value = vbChecked Then
' sStr$ = sStr$ & Delim$ & TxtDescript(i%).Text
' Delim$ = ","
' End If
' Next i%
sStr$ = sStr$ & Delim$ & "X,Y,Z"
Print #2, sStr$
End Sub
Private Sub Command6_Click()
Call MakeGrid
Call MakeGrid2
Call MakeGrid3
'If Command6.Caption = "STOP" Then
'Timer2.Interval = 0
'Timer3.Interval = 0
'Timer4.Interval = 0
Command6.Caption = "CAPTURE"
'Else
Timer2.Enabled = True
Timer3.Enabled = True
Timer4.Enabled = True
Timer2.Interval = 100
Timer3.Interval = 1
Timer4.Interval = 1
vall = Val(S1.Text)
vall = Val(S2.Text)
vall = Val(S3.Text)
'Command6.Caption = "STOP"
Command5.Visible = True
Command6.Visible = False
Timer6.Enabled = True
'End If
End Sub
Private Sub Form_Activate()
Timer2.Interval = 0
Timer3.Interval = 0
Timer4.Interval = 0
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
Timer6.Enabled = False
Call MakeGrid
Call MakeGrid2
Call MakeGrid3
End Sub
Private Sub Timer2_Timer()
vall = Val(S1.Text)
Call LineActive(vall)
vall = Val(S2.Text)
Call LineActive2(vall)
vall = Val(S3.Text)
Call LineActive3(vall)
End Sub
'Private Sub Timer3_Timer()
'vall = Val(S1.Text)
'Call LineActive(vall)
'vall = Val(S2.Text)
'Call LineActive2(vall)
'vall = Val(S3.Text)
'Call LineActive3(vall)
'End Sub
'Private Sub Timer4_Timer()
'vall = Val(S1.Text)
'Call LineActive(vall)
'vall = Val(S2.Text)
'Call LineActive2(vall)
'vall = Val(S3.Text)
'Call LineActive3(vall)
'End Sub
Private Sub Logging()
'Coding dibawah untuk data yang datang drpd RX232
If RXData(0).Text = "X" Then
'S1x untuk battery voltage
S1x.Text = S1.Text
S1.Text = RXData(1) / 100
S1x.Text = S1.Text * 100
'S2x untuk pv1 voltage
S2x.Text = S2.Text
S2.Text = RXData(2) / 100
S2x.Text = S2.Text * 100
'S3x untuk pv2 voltage
S3x.Text = S3.Text
S3.Text = RXData(3) / 100
S3x.Text = S3.Text * 100
'S4x untuk temperature
S4x.Text = S4.Text
S4.Text = RXData(4) / 100
S4x.Text = S4.Text * 100
End If
End Sub
Private Sub UPDATE()
End Sub
Private Sub UPDATE2()
lstLateRecord.Clear
Open App.Path & "\Log.csv" For Input As #1
Do Until EOF(1)
Line Input #1, tmpVar
lstLateRecord.AddItem (tmpVar)
Loop
Close #1
End Sub
Coding For PV1 :
Dim gLogFile$
Dim bLog As Boolean
Private Sub CmdLogFile_Click()
Dim Ptr%, OldPtr%
'Set Filters
CMFile1.CancelError = True
On Error GoTo ComFileEnd
CMFile1.DialogTitle = "Open Logging File"
CMFile1.Filter = "All Files (*.CSV)|*.CSV|"
CMFile1.FileName = "*.CSV"
'Specify Default Filter
CMFile1.FilterIndex = 2
'Display the Open Dialog box
CMFile1.Action = 1
'Call the open file procedure
'If Err Then Exit Sub
gLogFile$ = CMFile1.FileName
ComFileEnd:
Ptr% = 1
Do
Ptr% = InStr(Ptr%, gLogFile$, "\", 1)
If Ptr% > 0 Then
OldPtr% = Ptr%
End If
Ptr% = Ptr% + 1
Loop Until Ptr% < OldPtr% Or Ptr% = 1
'If OldPtr% > 1 Then
' gLogDir$ = Mid(gLogFile$, 1, OldPtr%)
'Else
' gLogDir$ = ""
'End If
'LblFileName.Caption = gLogFile$
End Sub
Private Sub SaveList(lst As ListBox, file As String)
On Error GoTo ERROR
Dim i As Integer
Dim a As String
Open file For Output As #1
For i = 0 To lst.ListCount - 1
a = lst.List(i)
Print #1, a
Next
Close 1
Exit Sub
ERROR:
MsgBox "There has been a error!", vbOKOnly, "Error"
End Sub
Private Sub CmdStartLog_Click()
Dim ChkFile
' If Not IsNumeric(TxtPeriod.Text) Then
' MsgBox "ERROR Log Period must be >=1 sec"
' Exit Sub
' End If
If gLogFile$ = "" Then
MsgBox "ERROR Log File hasn't been selected"
Exit Sub
End If
' If ChkLogEnable(0).Value = vbUnchecked And ChkLogEnable(1).Value = vbUnchecked And ChkLogEnable(2).Value = vbUnchecked And ChkLogEnable(3).Value = vbUnchecked Then
' MsgBox "ERROR No Temperatures enabled for Logging"
' Exit Sub
' End If
ChkFile = Dir(gLogFile$)
If ChkFile <> "" Then
iResponse = MsgBox("Log File already exists. Do you wish to overwrite?", vbYesNo)
If iResponse = vbYes Then
Open gLogFile$ For Output As #2
Call AddLogHeading
Close #2
bLog = True
TotSecs = 0
gLogSecs = 0
Exit Sub
Else
iResponse = MsgBox("Log File already exists. Do you wish to append data to it?", vbYesNo)
If iResponse = vbYes Then
bLog = True
TotSecs = 0
gLogSecs = 0
End If
End If
Else
bLog = True
TotSecs = 0
gLogSecs = 0
Open gLogFile$ For Output As #2
Call AddLogHeading
Close #2
Exit Sub
End If
End Sub
Private Sub CmdStopLog_Click()
bLog = False
End Sub
Private Sub Command1_Click()
xmax = 0
ymax = 0
zmax = 0
xmin = 0
ymin = 0
zmin = 0
txtMax(0) = Str(xmax)
txtMin(0) = Str(xmin)
txtMax(1) = Str(ymax)
txtMin(1) = Str(ymin)
txtMax(2) = Str(zmax)
txtMin(2) = Str(zmin)
Line1(0).Y1 = Shape1(0).Top + Shape1(0).Height
Line1(0).Y2 = Line1(0).Y1
Line2(0).Y1 = Shape2(0).Top
Line2(0).Y2 = Line2(0).Y1
Line1(1).Y1 = Shape1(1).Top + Shape1(1).Height
Line1(1).Y2 = Line1(1).Y1
Line2(1).Y1 = Shape2(1).Top
Line2(1).Y2 = Line2(1).Y1
Line1(2).Y1 = Shape1(2).Top + Shape1(2).Height
Line1(2).Y2 = Line1(2).Y1
Line2(2).Y1 = Shape2(2).Top
Line2(2).Y2 = Line2(2).Y1
End Sub
Private Sub Command2_Click()
Form2.Show
End Sub
Private Sub Command4_Click()
Call Logging
End Sub
Private Sub Command5_Click()
Timer2.Interval = 0
Timer3.Interval = 0
Timer4.Interval = 0
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
Timer6.Enabled = False
Command6.Visible = True
Command5.Visible = False
End Sub
Private Sub Form_Deactivate()
Unload Me
End Sub
Private Sub Form_Load()
'Declare myfilename and myfilename2 as strings and specify Log files
Dim myfilename As String
Dim myfilename2 As String
myfilename = "Table1Order.log"
myfilename2 = "Table2Order.log"
'Make sure the log files are there, if not, create them.
If Dir(myfilename, vbNormal Or vbReadOnly Or vbHidden Or _
vbSystem Or vbArchive) = "" Then
Open App.Path & "\Table1Order.log" For Output As #1
Close #1
End If
linlen = lnRoll(0).X2 - lnRoll(0).X1
pi = 3.14159265358979
openCom (Val(Form2.txtPort.Text))
Command1_Click
'Shape2(0).Top = Shape1(0).Top + Shape1(0).Height
End Sub
Private Sub MSComm1_OnComm()
Dim i As Integer
Dim j As Integer
Dim iTmp1 As Integer, iTmp2 As Integer, iTmp3 As Integer
Dim S1, S2 As String
Select Case MSComm1.CommEvent
Case comEvReceive
S1 = MSComm1.Input
For i = 1 To Len(S1) Step 1
S2 = Mid$(S1, i, 1)
j = Asc(S2)
If (j = 7) Then ' BELL = ERROR!
Debug.Print " ";
RX.Text = RX.Text
iFlagACK = 2
Call SPLITTER
ElseIf (j = 13) Then ' CR = OK
Debug.Print " "
RX.Text = RX.Text + S2
iFlagACK = 1
Call SPLITTER
'Timer4.Enabled = True
Else
Debug.Print " ";
RX.Text = RX.Text + S2
Call SPLITTER
'Timer4.Enabled = True
End If
Next i
End Select
End Sub
Private Sub SPLITTER()
Dim strInputString As String
Dim strFilterText As String
Dim astrSplitItems() As String
Dim astrFilteredItems() As String
Dim strFilteredString As String
Dim intX As Integer
Dim t As String
strInputString = RX.Text
astrSplitItems = Split(strInputString, ",")
For intX = 0 To UBound(astrSplitItems)
RXData(intX).Text = astrSplitItems(intX)
Next
End Sub
Private Sub TEST_Click()
End Sub
Private Sub S1x_Change()
End Sub
Private Sub S2x_Change()
End Sub
Private Sub Save_Click()
Open App.Path & "\Log.csv" For Append As #1
Print #1, " " & lblDate & " ; " & lblTime & " ; " & S1x & " ; " & S2x & " ; " & S3x & " ; "
Close #1
Call UPDATE2
End Sub
Private Sub Text2_Change()
lnRoll(0).Y1 = lnRoll(0).Y2 + (linlen * Sin(angle))
lnRoll(0).X1 = lnRoll(0).X2 - (linlen * Cos(angle))
lnRoll(1).Y2 = lnRoll(1).Y1 - (linlen * Sin(angle))
lnRoll(1).X2 = lnRoll(1).X1 + (linlen * Cos(angle))
End Sub
Private Sub Text3_Change()
lnPitch(0).Y1 = lnPitch(0).Y2 + (linlen * Sin(angle2))
lnPitch(0).X1 = lnPitch(0).X2 + (linlen * Cos(angle2))
lnPitch(1).Y2 = lnPitch(1).Y1 - (linlen * Sin(angle2))
lnPitch(1).X2 = lnPitch(1).X1 - (linlen * Cos(angle2))
End Sub
Private Sub Text4_Change()
Timer2.Interval = Text4
End Sub
Private Sub Timer1_Timer()
'set time and date
lblDate.Caption = Format(Now, "dd/mm/yyyy")
lblTime.Caption = Format(Now, "hh:mm:ss")
End Sub
Private Sub txtFilt_Change()
If Val(txtFilt.Text) < 1 Then txtFilt.Text = "1"
End Sub
Private Sub Timer5_Timer()
If Not (RXData(3).Text = "") Then
Call Logging
RX.Text = ""
End If
End Sub
Private Sub Timer6_Timer()
Call Save_Click
End Sub
Private Sub txtScale_Change()
If Val(txtScale.Text) <= 0 Then txtScale.Text = "1"
For i = 0 To 2
Label10(i).Caption = txtScale.Text
Label11(i).Caption = "-" & txtScale.Text
Next i
End Sub
Private Function Arcsin(X As Single)
Dim tmp As Single
tmp = -X * X + 1
If tmp < 0 Then tmp = -tmp
tmp = Sqr(tmp)
If tmp <> 0 Then
tmp = Atn(X / tmp)
Else
tmp = pi / 2
If X < 0 Then tmp = -tmp
End If
Arcsin = tmp
End Function
Sub openCom(port As Integer)
On Error GoTo comError
If MSComm1.PortOpen <> False Then
MSComm1.PortOpen = False
End If
MSComm1.CommPort = port
MSComm1.PortOpen = True
Exit Sub
comError:
MsgBox "Unable to open Com Port " & port
End Sub
Sub AddLogHeading()
'Add the heading to the log file
Dim sStr$, Delim$
Dim i%
sStr$ = ""
Delim$ = ""
sStr$ = "LOG PERIOD,"
sStr$ = sStr$ & "DATE"
Delim$ = ","
sStr$ = sStr$ & Delim$ & "TIME"
Delim$ = ","
' For i% = 0 To 3
' If ChkLogEnable(i%).Value = vbChecked Then
' sStr$ = sStr$ & Delim$ & TxtDescript(i%).Text
' Delim$ = ","
' End If
' Next i%
sStr$ = sStr$ & Delim$ & "X,Y,Z"
Print #2, sStr$
End Sub
Private Sub Command6_Click()
Call MakeGrid
Call MakeGrid2
Call MakeGrid3
'If Command6.Caption = "STOP" Then
'Timer2.Interval = 0
'Timer3.Interval = 0
'Timer4.Interval = 0
Command6.Caption = "CAPTURE"
'Else
Timer2.Enabled = True
Timer3.Enabled = True
Timer4.Enabled = True
Timer2.Interval = 100
Timer3.Interval = 1
Timer4.Interval = 1
vall = Val(S1.Text)
vall = Val(S2.Text)
vall = Val(S3.Text)
'Command6.Caption = "STOP"
Command5.Visible = True
Command6.Visible = False
Timer6.Enabled = True
'End If
End Sub
Private Sub Form_Activate()
Timer2.Interval = 0
Timer3.Interval = 0
Timer4.Interval = 0
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
Timer6.Enabled = False
Call MakeGrid
Call MakeGrid2
Call MakeGrid3
End Sub
Private Sub Timer2_Timer()
vall = Val(S1.Text)
Call LineActive(vall)
vall = Val(S2.Text)
Call LineActive2(vall)
vall = Val(S3.Text)
Call LineActive3(vall)
End Sub
'Private Sub Timer3_Timer()
'vall = Val(S1.Text)
'Call LineActive(vall)
'vall = Val(S2.Text)
'Call LineActive2(vall)
'vall = Val(S3.Text)
'Call LineActive3(vall)
'End Sub
'Private Sub Timer4_Timer()
'vall = Val(S1.Text)
'Call LineActive(vall)
'vall = Val(S2.Text)
'Call LineActive2(vall)
'vall = Val(S3.Text)
'Call LineActive3(vall)
'End Sub
Private Sub Logging()
'Coding dibawah untuk data yang datang drpd RX232
If RXData(0).Text = "X" Then
'S1x untuk battery voltage
S1x.Text = S1.Text
S1.Text = RXData(1) / 100
S1x.Text = S1.Text * 100
'S2x untuk pv1 voltage
S2x.Text = S2.Text
S2.Text = RXData(2) / 100
S2x.Text = S2.Text * 100
'S3x untuk pv2 voltage
S3x.Text = S3.Text
S3.Text = RXData(3) / 100
S3x.Text = S3.Text * 100
'S4x untuk temperature
S4x.Text = S4.Text
S4.Text = RXData(4) / 100
S4x.Text = S4.Text * 100
End If
End Sub
Private Sub UPDATE()
End Sub
Private Sub UPDATE2()
lstLateRecord.Clear
Open App.Path & "\Log.csv" For Input As #1
Do Until EOF(1)
Line Input #1, tmpVar
lstLateRecord.AddItem (tmpVar)
Loop
Close #1
End Sub
Coding For PV2 :
Dim gLogFile$
Dim bLog As Boolean
Private Sub CmdLogFile_Click()
Dim Ptr%, OldPtr%
'Set Filters
CMFile1.CancelError = True
On Error GoTo ComFileEnd
CMFile1.DialogTitle = "Open Logging File"
CMFile1.Filter = "All Files (*.CSV)|*.CSV|"
CMFile1.FileName = "*.CSV"
'Specify Default Filter
CMFile1.FilterIndex = 2
'Display the Open Dialog box
CMFile1.Action = 1
'Call the open file procedure
'If Err Then Exit Sub
gLogFile$ = CMFile1.FileName
ComFileEnd:
Ptr% = 1
Do
Ptr% = InStr(Ptr%, gLogFile$, "\", 1)
If Ptr% > 0 Then
OldPtr% = Ptr%
End If
Ptr% = Ptr% + 1
Loop Until Ptr% < OldPtr% Or Ptr% = 1
'If OldPtr% > 1 Then
' gLogDir$ = Mid(gLogFile$, 1, OldPtr%)
'Else
' gLogDir$ = ""
'End If
'LblFileName.Caption = gLogFile$
End Sub
Private Sub SaveList(lst As ListBox, file As String)
On Error GoTo ERROR
Dim i As Integer
Dim a As String
Open file For Output As #1
For i = 0 To lst.ListCount - 1
a = lst.List(i)
Print #1, a
Next
Close 1
Exit Sub
ERROR:
MsgBox "There has been a error!", vbOKOnly, "Error"
End Sub
Private Sub CmdStartLog_Click()
Dim ChkFile
' If Not IsNumeric(TxtPeriod.Text) Then
' MsgBox "ERROR Log Period must be >=1 sec"
' Exit Sub
' End If
If gLogFile$ = "" Then
MsgBox "ERROR Log File hasn't been selected"
Exit Sub
End If
' If ChkLogEnable(0).Value = vbUnchecked And ChkLogEnable(1).Value = vbUnchecked And ChkLogEnable(2).Value = vbUnchecked And ChkLogEnable(3).Value = vbUnchecked Then
' MsgBox "ERROR No Temperatures enabled for Logging"
' Exit Sub
' End If
ChkFile = Dir(gLogFile$)
If ChkFile <> "" Then
iResponse = MsgBox("Log File already exists. Do you wish to overwrite?", vbYesNo)
If iResponse = vbYes Then
Open gLogFile$ For Output As #2
Call AddLogHeading
Close #2
bLog = True
TotSecs = 0
gLogSecs = 0
Exit Sub
Else
iResponse = MsgBox("Log File already exists. Do you wish to append data to it?", vbYesNo)
If iResponse = vbYes Then
bLog = True
TotSecs = 0
gLogSecs = 0
End If
End If
Else
bLog = True
TotSecs = 0
gLogSecs = 0
Open gLogFile$ For Output As #2
Call AddLogHeading
Close #2
Exit Sub
End If
End Sub
Private Sub CmdStopLog_Click()
bLog = False
End Sub
Private Sub Command1_Click()
xmax = 0
ymax = 0
zmax = 0
xmin = 0
ymin = 0
zmin = 0
txtMax(0) = Str(xmax)
txtMin(0) = Str(xmin)
txtMax(1) = Str(ymax)
txtMin(1) = Str(ymin)
txtMax(2) = Str(zmax)
txtMin(2) = Str(zmin)
Line1(0).Y1 = Shape1(0).Top + Shape1(0).Height
Line1(0).Y2 = Line1(0).Y1
Line2(0).Y1 = Shape2(0).Top
Line2(0).Y2 = Line2(0).Y1
Line1(1).Y1 = Shape1(1).Top + Shape1(1).Height
Line1(1).Y2 = Line1(1).Y1
Line2(1).Y1 = Shape2(1).Top
Line2(1).Y2 = Line2(1).Y1
Line1(2).Y1 = Shape1(2).Top + Shape1(2).Height
Line1(2).Y2 = Line1(2).Y1
Line2(2).Y1 = Shape2(2).Top
Line2(2).Y2 = Line2(2).Y1
End Sub
Private Sub Command2_Click()
Form2.Show
End Sub
Private Sub Command4_Click()
Call Logging
End Sub
Private Sub Command5_Click()
Timer2.Interval = 0
Timer3.Interval = 0
Timer4.Interval = 0
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
Timer6.Enabled = False
Command6.Visible = True
Command5.Visible = False
End Sub
Private Sub Form_Deactivate()
Unload Me
End Sub
Private Sub Form_Load()
'Declare myfilename and myfilename2 as strings and specify Log files
Dim myfilename As String
Dim myfilename2 As String
myfilename = "Table1Order.log"
myfilename2 = "Table2Order.log"
'Make sure the log files are there, if not, create them.
If Dir(myfilename, vbNormal Or vbReadOnly Or vbHidden Or _
vbSystem Or vbArchive) = "" Then
Open App.Path & "\Table1Order.log" For Output As #1
Close #1
End If
linlen = lnRoll(0).X2 - lnRoll(0).X1
pi = 3.14159265358979
openCom (Val(Form2.txtPort.Text))
Command1_Click
'Shape2(0).Top = Shape1(0).Top + Shape1(0).Height
End Sub
Private Sub MSComm1_OnComm()
Dim i As Integer
Dim j As Integer
Dim iTmp1 As Integer, iTmp2 As Integer, iTmp3 As Integer
Dim S1, S2 As String
Select Case MSComm1.CommEvent
Case comEvReceive
S1 = MSComm1.Input
For i = 1 To Len(S1) Step 1
S2 = Mid$(S1, i, 1)
j = Asc(S2)
If (j = 7) Then ' BELL = ERROR!
Debug.Print " ";
RX.Text = RX.Text
iFlagACK = 2
Call SPLITTER
ElseIf (j = 13) Then ' CR = OK
Debug.Print " "
RX.Text = RX.Text + S2
iFlagACK = 1
Call SPLITTER
'Timer4.Enabled = True
Else
Debug.Print " ";
RX.Text = RX.Text + S2
Call SPLITTER
'Timer4.Enabled = True
End If
Next i
End Select
End Sub
Private Sub SPLITTER()
Dim strInputString As String
Dim strFilterText As String
Dim astrSplitItems() As String
Dim astrFilteredItems() As String
Dim strFilteredString As String
Dim intX As Integer
Dim t As String
strInputString = RX.Text
astrSplitItems = Split(strInputString, ",")
For intX = 0 To UBound(astrSplitItems)
RXData(intX).Text = astrSplitItems(intX)
Next
End Sub
Private Sub TEST_Click()
End Sub
Private Sub S1x_Change()
End Sub
Private Sub S2x_Change()
End Sub
Private Sub S3x_Change()
End Sub
Private Sub Save_Click()
Open App.Path & "\Log.csv" For Append As #1
Print #1, " " & lblDate & " ; " & lblTime & " ; " & S1x & " ; " & S2x & " ; " & S3x & " ; "
Close #1
Call UPDATE2
End Sub
Private Sub Text2_Change()
lnRoll(0).Y1 = lnRoll(0).Y2 + (linlen * Sin(angle))
lnRoll(0).X1 = lnRoll(0).X2 - (linlen * Cos(angle))
lnRoll(1).Y2 = lnRoll(1).Y1 - (linlen * Sin(angle))
lnRoll(1).X2 = lnRoll(1).X1 + (linlen * Cos(angle))
End Sub
Private Sub Text3_Change()
lnPitch(0).Y1 = lnPitch(0).Y2 + (linlen * Sin(angle2))
lnPitch(0).X1 = lnPitch(0).X2 + (linlen * Cos(angle2))
lnPitch(1).Y2 = lnPitch(1).Y1 - (linlen * Sin(angle2))
lnPitch(1).X2 = lnPitch(1).X1 - (linlen * Cos(angle2))
End Sub
Private Sub Text4_Change()
Timer2.Interval = Text4
End Sub
Private Sub Timer1_Timer()
'set time and date
lblDate.Caption = Format(Now, "dd/mm/yyyy")
lblTime.Caption = Format(Now, "hh:mm:ss")
End Sub
Private Sub txtFilt_Change()
If Val(txtFilt.Text) < 1 Then txtFilt.Text = "1"
End Sub
Private Sub Timer5_Timer()
If Not (RXData(3).Text = "") Then
Call Logging
RX.Text = ""
End If
End Sub
Private Sub Timer6_Timer()
Call Save_Click
End Sub
Private Sub txtScale_Change()
If Val(txtScale.Text) <= 0 Then txtScale.Text = "1"
For i = 0 To 2
Label10(i).Caption = txtScale.Text
Label11(i).Caption = "-" & txtScale.Text
Next i
End Sub
Private Function Arcsin(X As Single)
Dim tmp As Single
tmp = -X * X + 1
If tmp < 0 Then tmp = -tmp
tmp = Sqr(tmp)
If tmp <> 0 Then
tmp = Atn(X / tmp)
Else
tmp = pi / 2
If X < 0 Then tmp = -tmp
End If
Arcsin = tmp
End Function
Sub openCom(port As Integer)
On Error GoTo comError
If MSComm1.PortOpen <> False Then
MSComm1.PortOpen = False
End If
MSComm1.CommPort = port
MSComm1.PortOpen = True
Exit Sub
comError:
MsgBox "Unable to open Com Port " & port
End Sub
Sub AddLogHeading()
'Add the heading to the log file
Dim sStr$, Delim$
Dim i%
sStr$ = ""
Delim$ = ""
sStr$ = "LOG PERIOD,"
sStr$ = sStr$ & "DATE"
Delim$ = ","
sStr$ = sStr$ & Delim$ & "TIME"
Delim$ = ","
' For i% = 0 To 3
' If ChkLogEnable(i%).Value = vbChecked Then
' sStr$ = sStr$ & Delim$ & TxtDescript(i%).Text
' Delim$ = ","
' End If
' Next i%
sStr$ = sStr$ & Delim$ & "X,Y,Z"
Print #2, sStr$
End Sub
Private Sub Command6_Click()
Call MakeGrid
Call MakeGrid2
Call MakeGrid3
'If Command6.Caption = "STOP" Then
'Timer2.Interval = 0
'Timer3.Interval = 0
'Timer4.Interval = 0
Command6.Caption = "CAPTURE"
'Else
Timer2.Enabled = True
Timer3.Enabled = True
Timer4.Enabled = True
Timer2.Interval = 100
Timer3.Interval = 1
Timer4.Interval = 1
vall = Val(S1.Text)
vall = Val(S2.Text)
vall = Val(S3.Text)
'Command6.Caption = "STOP"
Command5.Visible = True
Command6.Visible = False
Timer6.Enabled = True
'End If
End Sub
Private Sub Form_Activate()
Timer2.Interval = 0
Timer3.Interval = 0
Timer4.Interval = 0
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
Timer6.Enabled = False
Call MakeGrid
Call MakeGrid2
Call MakeGrid3
End Sub
Private Sub Timer2_Timer()
vall = Val(S1.Text)
Call LineActive(vall)
vall = Val(S2.Text)
Call LineActive2(vall)
vall = Val(S3.Text)
Call LineActive3(vall)
End Sub
'Private Sub Timer3_Timer()
'vall = Val(S1.Text)
'Call LineActive(vall)
'vall = Val(S2.Text)
'Call LineActive2(vall)
'vall = Val(S3.Text)
'Call LineActive3(vall)
'End Sub
'Private Sub Timer4_Timer()
'vall = Val(S1.Text)
'Call LineActive(vall)
'vall = Val(S2.Text)
'Call LineActive2(vall)
'vall = Val(S3.Text)
'Call LineActive3(vall)
'End Sub
Private Sub Logging()
'Coding dibawah untuk data yang datang drpd RX232
If RXData(0).Text = "X" Then
'S1x untuk battery voltage
S1x.Text = S1.Text
S1.Text = RXData(1) / 100
S1x.Text = S1.Text * 100
'S2x untuk pv1 voltage
S2x.Text = S2.Text
S2.Text = RXData(2) / 100
S2x.Text = S2.Text * 100
'S3x untuk pv2 voltage
S3x.Text = S3.Text
S3.Text = RXData(3) / 100
S3x.Text = S3.Text * 100
'S4x untuk temperature
S4x.Text = S4.Text
S4.Text = RXData(4) / 100
S4x.Text = S4.Text * 100
End If
End Sub
Private Sub UPDATE()
End Sub
Private Sub UPDATE2()
lstLateRecord.Clear
Open App.Path & "\Log.csv" For Input As #1
Do Until EOF(1)
Line Input #1, tmpVar
lstLateRecord.AddItem (tmpVar)
Loop
Close #1
End Sub
Coding For Battery Graph :
Private Sub Picture1_Click()
End Sub
Private Sub S1x_Change()
End Sub
Private Sub S2x_Change()
End Sub
Private Sub S3x_Change()
End Sub
Private Sub Save_Click()
Open App.Path & "\Log.csv" For Append As #1
Print #1, " " & lblDate & " ; " & lblTime & " ; " & S1x & " ; " & S2x & " ; " & S3x & " ; "
Close #1
Call UPDATE2
End Sub
Private Sub Text2_Change()
lnRoll(0).Y1 = lnRoll(0).Y2 + (linlen * Sin(angle))
lnRoll(0).X1 = lnRoll(0).X2 - (linlen * Cos(angle))
lnRoll(1).Y2 = lnRoll(1).Y1 - (linlen * Sin(angle))
lnRoll(1).X2 = lnRoll(1).X1 + (linlen * Cos(angle))
End Sub
Private Sub Text3_Change()
lnPitch(0).Y1 = lnPitch(0).Y2 + (linlen * Sin(angle2))
lnPitch(0).X1 = lnPitch(0).X2 + (linlen * Cos(angle2))
lnPitch(1).Y2 = lnPitch(1).Y1 - (linlen * Sin(angle2))
lnPitch(1).X2 = lnPitch(1).X1 - (linlen * Cos(angle2))
End Sub
Private Sub Text4_Change()
Timer2.Interval = Text4
End Sub
Private Sub Timer1_Timer()
'set time and date
lblDate.Caption = Format(Now, "dd/mm/yyyy")
lblTime.Caption = Format(Now, "hh:mm:ss")
End Sub
Private Sub txtFilt_Change()
If Val(txtFilt.Text) < 1 Then txtFilt.Text = "1"
End Sub
Private Sub Timer5_Timer()
If Not (RXData(3).Text = "") Then
Call Logging
RX.Text = ""
End If
End Sub
Private Sub Timer6_Timer()
Call Save_Click
End Sub
Private Sub txtScale_Change()
If Val(txtScale.Text) <= 0 Then txtScale.Text = "1"
For i = 0 To 2
Label10(i).Caption = txtScale.Text
Label11(i).Caption = "-" & txtScale.Text
Next i
End Sub
Private Function Arcsin(X As Single)
Dim tmp As Single
tmp = -X * X + 1
If tmp < 0 Then tmp = -tmp
tmp = Sqr(tmp)
If tmp <> 0 Then
tmp = Atn(X / tmp)
Else
tmp = pi / 2
If X < 0 Then tmp = -tmp
End If
Arcsin = tmp
End Function
Sub openCom(port As Integer)
On Error GoTo comError
If MSComm1.PortOpen <> False Then
MSComm1.PortOpen = False
End If
MSComm1.CommPort = port
MSComm1.PortOpen = True
Exit Sub
comError:
MsgBox "Unable to open Com Port " & port
End Sub
Sub AddLogHeading()
'Add the heading to the log file
Dim sStr$, Delim$
Dim i%
sStr$ = ""
Delim$ = ""
sStr$ = "LOG PERIOD,"
sStr$ = sStr$ & "DATE"
Delim$ = ","
sStr$ = sStr$ & Delim$ & "TIME"
Delim$ = ","
' For i% = 0 To 3
' If ChkLogEnable(i%).Value = vbChecked Then
' sStr$ = sStr$ & Delim$ & TxtDescript(i%).Text
' Delim$ = ","
' End If
' Next i%
sStr$ = sStr$ & Delim$ & "X,Y,Z"
Print #2, sStr$
End Sub
Private Sub Command6_Click()
Call MakeGrid
Call MakeGrid2
Call MakeGrid3
'If Command6.Caption = "STOP" Then
'Timer2.Interval = 0
'Timer3.Interval = 0
'Timer4.Interval = 0
Command6.Caption = "CAPTURE"
'Else
Timer2.Enabled = True
Timer3.Enabled = True
Timer4.Enabled = True
Timer2.Interval = 100
Timer3.Interval = 1
Timer4.Interval = 1
vall = Val(S1.Text)
vall = Val(S2.Text)
vall = Val(S3.Text)
'Command6.Caption = "STOP"
Command5.Visible = True
Command6.Visible = False
Timer6.Enabled = True
'End If
End Sub
Private Sub Form_Activate()
Timer2.Interval = 0
Timer3.Interval = 0
Timer4.Interval = 0
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
Timer6.Enabled = False
Call MakeGrid
Call MakeGrid2
Call MakeGrid3
End Sub
Private Sub Timer2_Timer()
vall = Val(S1.Text)
Call LineActive(vall)
vall = Val(S2.Text)
Call LineActive2(vall)
vall = Val(S3.Text)
Call LineActive3(vall)
End Sub
'Private Sub Timer3_Timer()
'vall = Val(S1.Text)
'Call LineActive(vall)
'vall = Val(S2.Text)
'Call LineActive2(vall)
'vall = Val(S3.Text)
'Call LineActive3(vall)
'End Sub
'Private Sub Timer4_Timer()
'vall = Val(S1.Text)
'Call LineActive(vall)
'vall = Val(S2.Text)
'Call LineActive2(vall)
'vall = Val(S3.Text)
'Call LineActive3(vall)
'End Sub
Private Sub Logging()
'Coding dibawah untuk data yang datang drpd RX232
If RXData(0).Text = "X" Then
'S1x untuk battery voltage
S1x.Text = S1.Text
S1.Text = RXData(1) / 100
S1x.Text = S1.Text * 100
'S2x untuk pv1 voltage
S2x.Text = S2.Text
S2.Text = RXData(2) / 100
S2x.Text = S2.Text * 100
'S3x untuk pv2 voltage
S3x.Text = S3.Text
S3.Text = RXData(3) / 100
S3x.Text = S3.Text * 100
'S4x untuk temperature
S4x.Text = S4.Text
S4.Text = RXData(4) / 100
S4x.Text = S4.Text * 100
End If
End Sub
Private Sub UPDATE()
End Sub
Private Sub UPDATE2()
lstLateRecord.Clear
Open App.Path & "\Log.csv" For Input As #1
Do Until EOF(1)
Line Input #1, tmpVar
lstLateRecord.AddItem (tmpVar)
Loop
Close #1
End Sub
Coding For PV1 Graph :
Dim gLogFile$
Dim bLog As Boolean
Private Sub CmdLogFile_Click()
Dim Ptr%, OldPtr%
'Set Filters
CMFile1.CancelError = True
On Error GoTo ComFileEnd
CMFile1.DialogTitle = "Open Logging File"
CMFile1.Filter = "All Files (*.CSV)|*.CSV|"
CMFile1.FileName = "*.CSV"
'Specify Default Filter
CMFile1.FilterIndex = 2
'Display the Open Dialog box
CMFile1.Action = 1
'Call the open file procedure
'If Err Then Exit Sub
gLogFile$ = CMFile1.FileName
ComFileEnd:
Ptr% = 1
Do
Ptr% = InStr(Ptr%, gLogFile$, "\", 1)
If Ptr% > 0 Then
OldPtr% = Ptr%
End If
Ptr% = Ptr% + 1
Loop Until Ptr% < OldPtr% Or Ptr% = 1
'If OldPtr% > 1 Then
' gLogDir$ = Mid(gLogFile$, 1, OldPtr%)
'Else
' gLogDir$ = ""
'End If
'LblFileName.Caption = gLogFile$
End Sub
Private Sub SaveList(lst As ListBox, file As String)
On Error GoTo ERROR
Dim i As Integer
Dim a As String
Open file For Output As #1
For i = 0 To lst.ListCount - 1
a = lst.List(i)
Print #1, a
Next
Close 1
Exit Sub
ERROR:
MsgBox "There has been a error!", vbOKOnly, "Error"
End Sub
Private Sub CmdStartLog_Click()
Dim ChkFile
' If Not IsNumeric(TxtPeriod.Text) Then
' MsgBox "ERROR Log Period must be >=1 sec"
' Exit Sub
' End If
If gLogFile$ = "" Then
MsgBox "ERROR Log File hasn't been selected"
Exit Sub
End If
' If ChkLogEnable(0).Value = vbUnchecked And ChkLogEnable(1).Value = vbUnchecked And ChkLogEnable(2).Value = vbUnchecked And ChkLogEnable(3).Value = vbUnchecked Then
' MsgBox "ERROR No Temperatures enabled for Logging"
' Exit Sub
' End If
ChkFile = Dir(gLogFile$)
If ChkFile <> "" Then
iResponse = MsgBox("Log File already exists. Do you wish to overwrite?", vbYesNo)
If iResponse = vbYes Then
Open gLogFile$ For Output As #2
Call AddLogHeading
Close #2
bLog = True
TotSecs = 0
gLogSecs = 0
Exit Sub
Else
iResponse = MsgBox("Log File already exists. Do you wish to append data to it?", vbYesNo)
If iResponse = vbYes Then
bLog = True
TotSecs = 0
gLogSecs = 0
End If
End If
Else
bLog = True
TotSecs = 0
gLogSecs = 0
Open gLogFile$ For Output As #2
Call AddLogHeading
Close #2
Exit Sub
End If
End Sub
Private Sub CmdStopLog_Click()
bLog = False
End Sub
Private Sub Command1_Click()
xmax = 0
ymax = 0
zmax = 0
xmin = 0
ymin = 0
zmin = 0
txtMax(0) = Str(xmax)
txtMin(0) = Str(xmin)
txtMax(1) = Str(ymax)
txtMin(1) = Str(ymin)
txtMax(2) = Str(zmax)
txtMin(2) = Str(zmin)
Line1(0).Y1 = Shape1(0).Top + Shape1(0).Height
Line1(0).Y2 = Line1(0).Y1
Line2(0).Y1 = Shape2(0).Top
Line2(0).Y2 = Line2(0).Y1
Line1(1).Y1 = Shape1(1).Top + Shape1(1).Height
Line1(1).Y2 = Line1(1).Y1
Line2(1).Y1 = Shape2(1).Top
Line2(1).Y2 = Line2(1).Y1
Line1(2).Y1 = Shape1(2).Top + Shape1(2).Height
Line1(2).Y2 = Line1(2).Y1
Line2(2).Y1 = Shape2(2).Top
Line2(2).Y2 = Line2(2).Y1
End Sub
Private Sub Command2_Click()
Form2.Show
End Sub
Private Sub Command4_Click()
Call Logging
End Sub
Private Sub Command5_Click()
Timer2.Interval = 0
Timer3.Interval = 0
Timer4.Interval = 0
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
Timer6.Enabled = False
Command6.Visible = True
Command5.Visible = False
End Sub
Private Sub Form_Deactivate()
Unload Me
End Sub
Private Sub Form_Load()
'Declare myfilename and myfilename2 as strings and specify Log files
Dim myfilename As String
Dim myfilename2 As String
myfilename = "Table1Order.log"
myfilename2 = "Table2Order.log"
'Make sure the log files are there, if not, create them.
If Dir(myfilename, vbNormal Or vbReadOnly Or vbHidden Or _
vbSystem Or vbArchive) = "" Then
Open App.Path & "\Table1Order.log" For Output As #1
Close #1
End If
linlen = lnRoll(0).X2 - lnRoll(0).X1
pi = 3.14159265358979
openCom (Val(Form2.txtPort.Text))
Command1_Click
'Shape2(0).Top = Shape1(0).Top + Shape1(0).Height
End Sub
Private Sub MSComm1_OnComm()
Dim i As Integer
Dim j As Integer
Dim iTmp1 As Integer, iTmp2 As Integer, iTmp3 As Integer
Dim S1, S2 As String
Select Case MSComm1.CommEvent
Case comEvReceive
S1 = MSComm1.Input
For i = 1 To Len(S1) Step 1
S2 = Mid$(S1, i, 1)
j = Asc(S2)
If (j = 7) Then ' BELL = ERROR!
Debug.Print " ";
RX.Text = RX.Text
iFlagACK = 2
Call SPLITTER
ElseIf (j = 13) Then ' CR = OK
Debug.Print " "
RX.Text = RX.Text + S2
iFlagACK = 1
Call SPLITTER
'Timer4.Enabled = True
Else
Debug.Print " ";
RX.Text = RX.Text + S2
Call SPLITTER
'Timer4.Enabled = True
End If
Next i
End Select
End Sub
Private Sub SPLITTER()
Dim strInputString As String
Dim strFilterText As String
Dim astrSplitItems() As String
Dim astrFilteredItems() As String
Dim strFilteredString As String
Dim intX As Integer
Dim t As String
strInputString = RX.Text
astrSplitItems = Split(strInputString, ",")
For intX = 0 To UBound(astrSplitItems)
RXData(intX).Text = astrSplitItems(intX)
Next
End Sub
Private Sub TEST_Click()
End Sub
Private Sub Picture1_Click()
End Sub
Private Sub Picture2_Click()
End Sub
Private Sub S1x_Change()
End Sub
Private Sub S2x_Change()
End Sub
Private Sub S3x_Change()
End Sub
Private Sub Save_Click()
Open App.Path & "\Log.csv" For Append As #1
Print #1, " " & lblDate & " ; " & lblTime & " ; " & S1x & " ; " & S2x & " ; " & S3x & " ; "
Close #1
Call UPDATE2
End Sub
Private Sub Text2_Change()
lnRoll(0).Y1 = lnRoll(0).Y2 + (linlen * Sin(angle))
lnRoll(0).X1 = lnRoll(0).X2 - (linlen * Cos(angle))
lnRoll(1).Y2 = lnRoll(1).Y1 - (linlen * Sin(angle))
lnRoll(1).X2 = lnRoll(1).X1 + (linlen * Cos(angle))
End Sub
Private Sub Text3_Change()
lnPitch(0).Y1 = lnPitch(0).Y2 + (linlen * Sin(angle2))
lnPitch(0).X1 = lnPitch(0).X2 + (linlen * Cos(angle2))
lnPitch(1).Y2 = lnPitch(1).Y1 - (linlen * Sin(angle2))
lnPitch(1).X2 = lnPitch(1).X1 - (linlen * Cos(angle2))
End Sub
Private Sub Text4_Change()
Timer2.Interval = Text4
End Sub
Private Sub Timer1_Timer()
'set time and date
lblDate.Caption = Format(Now, "dd/mm/yyyy")
lblTime.Caption = Format(Now, "hh:mm:ss")
End Sub
Private Sub txtFilt_Change()
If Val(txtFilt.Text) < 1 Then txtFilt.Text = "1"
End Sub
Private Sub Timer5_Timer()
If Not (RXData(3).Text = "") Then
Call Logging
RX.Text = ""
End If
End Sub
Private Sub Timer6_Timer()
Call Save_Click
End Sub
Private Sub txtScale_Change()
If Val(txtScale.Text) <= 0 Then txtScale.Text = "1"
For i = 0 To 2
Label10(i).Caption = txtScale.Text
Label11(i).Caption = "-" & txtScale.Text
Next i
End Sub
Private Function Arcsin(X As Single)
Dim tmp As Single
tmp = -X * X + 1
If tmp < 0 Then tmp = -tmp
tmp = Sqr(tmp)
If tmp <> 0 Then
tmp = Atn(X / tmp)
Else
tmp = pi / 2
If X < 0 Then tmp = -tmp
End If
Arcsin = tmp
End Function
Sub openCom(port As Integer)
On Error GoTo comError
If MSComm1.PortOpen <> False Then
MSComm1.PortOpen = False
End If
MSComm1.CommPort = port
MSComm1.PortOpen = True
Exit Sub
comError:
MsgBox "Unable to open Com Port " & port
End Sub
Sub AddLogHeading()
'Add the heading to the log file
Dim sStr$, Delim$
Dim i%
sStr$ = ""
Delim$ = ""
sStr$ = "LOG PERIOD,"
sStr$ = sStr$ & "DATE"
Delim$ = ","
sStr$ = sStr$ & Delim$ & "TIME"
Delim$ = ","
' For i% = 0 To 3
' If ChkLogEnable(i%).Value = vbChecked Then
' sStr$ = sStr$ & Delim$ & TxtDescript(i%).Text
' Delim$ = ","
' End If
' Next i%
sStr$ = sStr$ & Delim$ & "X,Y,Z"
Print #2, sStr$
End Sub
Private Sub Command6_Click()
Call MakeGrid
Call MakeGrid2
Call MakeGrid3
'If Command6.Caption = "STOP" Then
'Timer2.Interval = 0
'Timer3.Interval = 0
'Timer4.Interval = 0
Command6.Caption = "CAPTURE"
'Else
Timer2.Enabled = True
Timer3.Enabled = True
Timer4.Enabled = True
Timer2.Interval = 100
Timer3.Interval = 1
Timer4.Interval = 1
vall = Val(S1.Text)
vall = Val(S2.Text)
vall = Val(S3.Text)
'Command6.Caption = "STOP"
Command5.Visible = True
Command6.Visible = False
Timer6.Enabled = True
'End If
End Sub
Private Sub Form_Activate()
Timer2.Interval = 0
Timer3.Interval = 0
Timer4.Interval = 0
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
Timer6.Enabled = False
Call MakeGrid
Call MakeGrid2
Call MakeGrid3
End Sub
Private Sub Timer2_Timer()
vall = Val(S1.Text)
Call LineActive(vall)
vall = Val(S2.Text)
Call LineActive2(vall)
vall = Val(S3.Text)
Call LineActive3(vall)
End Sub
'Private Sub Timer3_Timer()
'vall = Val(S1.Text)
'Call LineActive(vall)
'vall = Val(S2.Text)
'Call LineActive2(vall)
'vall = Val(S3.Text)
'Call LineActive3(vall)
'End Sub
'Private Sub Timer4_Timer()
'vall = Val(S1.Text)
'Call LineActive(vall)
'vall = Val(S2.Text)
'Call LineActive2(vall)
'vall = Val(S3.Text)
'Call LineActive3(vall)
'End Sub
Private Sub Logging()
'Coding dibawah untuk data yang datang drpd RX232
If RXData(0).Text = "X" Then
'S1x untuk battery voltage
S1x.Text = S1.Text
S1.Text = RXData(1) / 100
S1x.Text = S1.Text * 100
'S2x untuk pv1 voltage
S2x.Text = S2.Text
S2.Text = RXData(2) / 100
S2x.Text = S2.Text * 100
'S3x untuk pv2 voltage
S3x.Text = S3.Text
S3.Text = RXData(3) / 100
S3x.Text = S3.Text * 100
'S4x untuk temperature
S4x.Text = S4.Text
S4.Text = RXData(4) / 100
S4x.Text = S4.Text * 100
End If
End Sub
Private Sub UPDATE()
End Sub
Private Sub UPDATE2()
lstLateRecord.Clear
Open App.Path & "\Log.csv" For Input As #1
Do Until EOF(1)
Line Input #1, tmpVar
lstLateRecord.AddItem (tmpVar)
Loop
Close #1
End Sub
Coding For PV2
Dim gLogFile$
Dim bLog As Boolean
Private Sub CmdLogFile_Click()
Dim Ptr%, OldPtr%
'Set Filters
CMFile1.CancelError = True
On Error GoTo ComFileEnd
CMFile1.DialogTitle = "Open Logging File"
CMFile1.Filter = "All Files (*.CSV)|*.CSV|"
CMFile1.FileName = "*.CSV"
'Specify Default Filter
CMFile1.FilterIndex = 2
'Display the Open Dialog box
CMFile1.Action = 1
'Call the open file procedure
'If Err Then Exit Sub
gLogFile$ = CMFile1.FileName
ComFileEnd:
Ptr% = 1
Do
Ptr% = InStr(Ptr%, gLogFile$, "\", 1)
If Ptr% > 0 Then
OldPtr% = Ptr%
End If
Ptr% = Ptr% + 1
Loop Until Ptr% < OldPtr% Or Ptr% = 1
'If OldPtr% > 1 Then
' gLogDir$ = Mid(gLogFile$, 1, OldPtr%)
'Else
' gLogDir$ = ""
'End If
'LblFileName.Caption = gLogFile$
End Sub
Private Sub SaveList(lst As ListBox, file As String)
On Error GoTo ERROR
Dim i As Integer
Dim a As String
Open file For Output As #1
For i = 0 To lst.ListCount - 1
a = lst.List(i)
Print #1, a
Next
Close 1
Exit Sub
ERROR:
MsgBox "There has been a error!", vbOKOnly, "Error"
End Sub
Private Sub CmdStartLog_Click()
Dim ChkFile
' If Not IsNumeric(TxtPeriod.Text) Then
' MsgBox "ERROR Log Period must be >=1 sec"
' Exit Sub
' End If
If gLogFile$ = "" Then
MsgBox "ERROR Log File hasn't been selected"
Exit Sub
End If
' If ChkLogEnable(0).Value = vbUnchecked And ChkLogEnable(1).Value = vbUnchecked And ChkLogEnable(2).Value = vbUnchecked And ChkLogEnable(3).Value = vbUnchecked Then
' MsgBox "ERROR No Temperatures enabled for Logging"
' Exit Sub
' End If
ChkFile = Dir(gLogFile$)
If ChkFile <> "" Then
iResponse = MsgBox("Log File already exists. Do you wish to overwrite?", vbYesNo)
If iResponse = vbYes Then
Open gLogFile$ For Output As #2
Call AddLogHeading
Close #2
bLog = True
TotSecs = 0
gLogSecs = 0
Exit Sub
Else
iResponse = MsgBox("Log File already exists. Do you wish to append data to it?", vbYesNo)
If iResponse = vbYes Then
bLog = True
TotSecs = 0
gLogSecs = 0
End If
End If
Else
bLog = True
TotSecs = 0
gLogSecs = 0
Open gLogFile$ For Output As #2
Call AddLogHeading
Close #2
Exit Sub
End If
End Sub
Private Sub CmdStopLog_Click()
bLog = False
End Sub
Private Sub Command1_Click()
xmax = 0
ymax = 0
zmax = 0
xmin = 0
ymin = 0
zmin = 0
txtMax(0) = Str(xmax)
txtMin(0) = Str(xmin)
txtMax(1) = Str(ymax)
txtMin(1) = Str(ymin)
txtMax(2) = Str(zmax)
txtMin(2) = Str(zmin)
Line1(0).Y1 = Shape1(0).Top + Shape1(0).Height
Line1(0).Y2 = Line1(0).Y1
Line2(0).Y1 = Shape2(0).Top
Line2(0).Y2 = Line2(0).Y1
Line1(1).Y1 = Shape1(1).Top + Shape1(1).Height
Line1(1).Y2 = Line1(1).Y1
Line2(1).Y1 = Shape2(1).Top
Line2(1).Y2 = Line2(1).Y1
Line1(2).Y1 = Shape1(2).Top + Shape1(2).Height
Line1(2).Y2 = Line1(2).Y1
Line2(2).Y1 = Shape2(2).Top
Line2(2).Y2 = Line2(2).Y1
End Sub
Private Sub Command2_Click()
Form2.Show
End Sub
Private Sub Command4_Click()
Call Logging
End Sub
Private Sub Command5_Click()
Timer2.Interval = 0
Timer3.Interval = 0
Timer4.Interval = 0
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
Timer6.Enabled = False
Command6.Visible = True
Command5.Visible = False
End Sub
Private Sub Form_Deactivate()
Unload Me
End Sub
Private Sub Form_Load()
'Declare myfilename and myfilename2 as strings and specify Log files
Dim myfilename As String
Dim myfilename2 As String
myfilename = "Table1Order.log"
myfilename2 = "Table2Order.log"
'Make sure the log files are there, if not, create them.
If Dir(myfilename, vbNormal Or vbReadOnly Or vbHidden Or _
vbSystem Or vbArchive) = "" Then
Open App.Path & "\Table1Order.log" For Output As #1
Close #1
End If
linlen = lnRoll(0).X2 - lnRoll(0).X1
pi = 3.14159265358979
openCom (Val(Form2.txtPort.Text))
Command1_Click
'Shape2(0).Top = Shape1(0).Top + Shape1(0).Height
End Sub
Private Sub MSComm1_OnComm()
Dim i As Integer
Dim j As Integer
Dim iTmp1 As Integer, iTmp2 As Integer, iTmp3 As Integer
Dim S1, S2 As String
Select Case MSComm1.CommEvent
Case comEvReceive
S1 = MSComm1.Input
For i = 1 To Len(S1) Step 1
S2 = Mid$(S1, i, 1)
j = Asc(S2)
If (j = 7) Then ' BELL = ERROR!
Debug.Print " ";
RX.Text = RX.Text
iFlagACK = 2
Call SPLITTER
ElseIf (j = 13) Then ' CR = OK
Debug.Print " "
RX.Text = RX.Text + S2
iFlagACK = 1
Call SPLITTER
'Timer4.Enabled = True
Else
Debug.Print " ";
RX.Text = RX.Text + S2
Call SPLITTER
'Timer4.Enabled = True
End If
Next i
End Select
End Sub
Private Sub SPLITTER()
Dim strInputString As String
Dim strFilterText As String
Dim astrSplitItems() As String
Dim astrFilteredItems() As String
Dim strFilteredString As String
Dim intX As Integer
Dim t As String
strInputString = RX.Text
astrSplitItems = Split(strInputString, ",")
For intX = 0 To UBound(astrSplitItems)
RXData(intX).Text = astrSplitItems(intX)
Next
End Sub
Private Sub TEST_Click()
End Sub
Private Sub Picture1_Click()
End Sub
Private Sub Picture2_Click()
End Sub
Private Sub Picture3_Click()
End Sub
Private Sub S1x_Change()
End Sub
Private Sub S2x_Change()
End Sub
Private Sub S3x_Change()
End Sub
Private Sub Save_Click()
Open App.Path & "\Log.csv" For Append As #1
Print #1, " " & lblDate & " ; " & lblTime & " ; " & S1x & " ; " & S2x & " ; " & S3x & " ; "
Close #1
Call UPDATE2
End Sub
Private Sub Text2_Change()
lnRoll(0).Y1 = lnRoll(0).Y2 + (linlen * Sin(angle))
lnRoll(0).X1 = lnRoll(0).X2 - (linlen * Cos(angle))
lnRoll(1).Y2 = lnRoll(1).Y1 - (linlen * Sin(angle))
lnRoll(1).X2 = lnRoll(1).X1 + (linlen * Cos(angle))
End Sub
Private Sub Text3_Change()
lnPitch(0).Y1 = lnPitch(0).Y2 + (linlen * Sin(angle2))
lnPitch(0).X1 = lnPitch(0).X2 + (linlen * Cos(angle2))
lnPitch(1).Y2 = lnPitch(1).Y1 - (linlen * Sin(angle2))
lnPitch(1).X2 = lnPitch(1).X1 - (linlen * Cos(angle2))
End Sub
Private Sub Text4_Change()
Timer2.Interval = Text4
End Sub
Private Sub Timer1_Timer()
'set time and date
lblDate.Caption = Format(Now, "dd/mm/yyyy")
lblTime.Caption = Format(Now, "hh:mm:ss")
End Sub
Private Sub txtFilt_Change()
If Val(txtFilt.Text) < 1 Then txtFilt.Text = "1"
End Sub
Private Sub Timer5_Timer()
If Not (RXData(3).Text = "") Then
Call Logging
RX.Text = ""
End If
End Sub
Private Sub Timer6_Timer()
Call Save_Click
End Sub
Private Sub txtScale_Change()
If Val(txtScale.Text) <= 0 Then txtScale.Text = "1"
For i = 0 To 2
Label10(i).Caption = txtScale.Text
Label11(i).Caption = "-" & txtScale.Text
Next i
End Sub
Private Function Arcsin(X As Single)
Dim tmp As Single
tmp = -X * X + 1
If tmp < 0 Then tmp = -tmp
tmp = Sqr(tmp)
If tmp <> 0 Then
tmp = Atn(X / tmp)
Else
tmp = pi / 2
If X < 0 Then tmp = -tmp
End If
Arcsin = tmp
End Function
Sub openCom(port As Integer)
On Error GoTo comError
If MSComm1.PortOpen <> False Then
MSComm1.PortOpen = False
End If
MSComm1.CommPort = port
MSComm1.PortOpen = True
Exit Sub
comError:
MsgBox "Unable to open Com Port " & port
End Sub
Sub AddLogHeading()
'Add the heading to the log file
Dim sStr$, Delim$
Dim i%
sStr$ = ""
Delim$ = ""
sStr$ = "LOG PERIOD,"
sStr$ = sStr$ & "DATE"
Delim$ = ","
sStr$ = sStr$ & Delim$ & "TIME"
Delim$ = ","
' For i% = 0 To 3
' If ChkLogEnable(i%).Value = vbChecked Then
' sStr$ = sStr$ & Delim$ & TxtDescript(i%).Text
' Delim$ = ","
' End If
' Next i%
sStr$ = sStr$ & Delim$ & "X,Y,Z"
Print #2, sStr$
End Sub
Private Sub Command6_Click()
Call MakeGrid
Call MakeGrid2
Call MakeGrid3
'If Command6.Caption = "STOP" Then
'Timer2.Interval = 0
'Timer3.Interval = 0
'Timer4.Interval = 0
Command6.Caption = "CAPTURE"
'Else
Timer2.Enabled = True
Timer3.Enabled = True
Timer4.Enabled = True
Timer2.Interval = 100
Timer3.Interval = 1
Timer4.Interval = 1
vall = Val(S1.Text)
vall = Val(S2.Text)
vall = Val(S3.Text)
'Command6.Caption = "STOP"
Command5.Visible = True
Command6.Visible = False
Timer6.Enabled = True
'End If
End Sub
Private Sub Form_Activate()
Timer2.Interval = 0
Timer3.Interval = 0
Timer4.Interval = 0
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
Timer6.Enabled = False
Call MakeGrid
Call MakeGrid2
Call MakeGrid3
End Sub
Private Sub Timer2_Timer()
vall = Val(S1.Text)
Call LineActive(vall)
vall = Val(S2.Text)
Call LineActive2(vall)
vall = Val(S3.Text)
Call LineActive3(vall)
End Sub
'Private Sub Timer3_Timer()
'vall = Val(S1.Text)
'Call LineActive(vall)
'vall = Val(S2.Text)
'Call LineActive2(vall)
'vall = Val(S3.Text)
'Call LineActive3(vall)
'End Sub
'Private Sub Timer4_Timer()
'vall = Val(S1.Text)
'Call LineActive(vall)
'vall = Val(S2.Text)
'Call LineActive2(vall)
'vall = Val(S3.Text)
'Call LineActive3(vall)
'End Sub
Private Sub Logging()
'Coding dibawah untuk data yang datang drpd RX232
If RXData(0).Text = "X" Then
'S1x untuk battery voltage
S1x.Text = S1.Text
S1.Text = RXData(1) / 100
S1x.Text = S1.Text * 100
'S2x untuk pv1 voltage
S2x.Text = S2.Text
S2.Text = RXData(2) / 100
S2x.Text = S2.Text * 100
'S3x untuk pv2 voltage
S3x.Text = S3.Text
S3.Text = RXData(3) / 100
S3x.Text = S3.Text * 100
'S4x untuk temperature
S4x.Text = S4.Text
S4.Text = RXData(4) / 100
S4x.Text = S4.Text * 100
End If
End Sub
Private Sub UPDATE()
End Sub
Private Sub UPDATE2()
lstLateRecord.Clear
Open App.Path & "\Log.csv" For Input As #1
Do Until EOF(1)
Line Input #1, tmpVar
lstLateRecord.AddItem (tmpVar)
Loop
Close #1
End Sub
Subscribe to:
Posts (Atom)