Can you help me in converting a code written in VB5 into VB6? Also can you provide me any source book which compares VB5 and VB6? The source code to be converted into VB6 will be as follows:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1 .1#0"; "MSCOMM32.O CX"
Begin VB.Form frm_thermometer
ClientHeight = 3600
ClientLeft = 60
ClientTop = 345
ClientWidth = 6045
Icon = "frm_thermomete r.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 3600
ScaleWidth = 6045
StartUpPosition = 2 'CenterScreen
Begin VB.Frame Frame4
Height = 1335
Left = 120
TabIndex = 11
Top = 0
Width = 5775
Begin VB.CheckBox check_start_min imized
Caption = "start minimized"
Height = 375
Left = 4200
TabIndex = 26
ToolTipText = "Start as an icon in taskbar"
Top = 480
Width = 1335
End
Begin VB.CheckBox check_log_to_fi le
Caption = "log data to file"
Height = 375
Left = 4200
TabIndex = 17
ToolTipText = "log temperatures on text file ""pc_thermomete r.txt"""
Top = 840
Width = 1335
End
Begin VB.CheckBox check_farenheit
Caption = "use Farenheit"
Height = 375
Left = 4200
TabIndex = 12
ToolTipText = "Show as Fahrenheit or Celsius (centigrade)"
Top = 120
Width = 1335
End
Begin VB.Label Label4
Alignment = 2 'Center
BackStyle = 0 'Transparent
Caption = "outside"
Height = 375
Left = 2280
TabIndex = 16
Top = 120
Width = 1215
End
Begin VB.Label Label1
Alignment = 2 'Center
BackStyle = 0 'Transparent
Caption = "indoor"
Height = 375
Left = 120
TabIndex = 15
Top = 120
Width = 1215
End
Begin VB.Label label_temperatu re_outside
Alignment = 2 'Center
Caption = "--.-"
BeginProperty Font
Name = "MS Sans Serif"
Size = 18
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 735
Left = 2280
TabIndex = 14
Top = 480
Width = 1215
End
Begin VB.Label label_temperatu re_indoor
Alignment = 2 'Center
Caption = "--.-"
BeginProperty Font
Name = "MS Sans Serif"
Size = 18
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 735
Left = 120
TabIndex = 13
Top = 480
Width = 1215
End
End
Begin VB.Frame Frame3
Caption = "Sample time"
Height = 2055
Left = 4200
TabIndex = 6
Top = 1440
Width = 1695
Begin VB.OptionButton option_1_min
Caption = "1 min."
Height = 375
Left = 240
TabIndex = 10
Top = 1440
Width = 855
End
Begin VB.OptionButton option_30_sec
Caption = "30 sec."
Height = 375
Left = 240
TabIndex = 9
Top = 1080
Width = 855
End
Begin VB.OptionButton option_5_sec
Caption = "5 sec."
Height = 375
Left = 240
TabIndex = 8
Top = 720
Width = 855
End
Begin VB.OptionButton option_1_sec
Caption = "1 sec."
Height = 375
Left = 240
TabIndex = 7
Top = 360
Value = -1 'True
Width = 855
End
End
Begin VB.Frame Frame2
Caption = "N. of sensor ICs"
Height = 2055
Left = 2280
TabIndex = 1
Top = 1440
Width = 1935
Begin VB.OptionButton option_double
BeginProperty Font
Name = "MS Sans Serif"
Size = 13.5
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 240
TabIndex = 3
Top = 1080
Width = 375
End
Begin VB.OptionButton option_single
BeginProperty Font
Name = "MS Sans Serif"
Size = 13.5
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 240
TabIndex = 2
Top = 360
Value = -1 'True
Width = 375
End
Begin VB.Label Label3
Caption = "double IC (indoor + outside)"
Height = 735
Left = 600
TabIndex = 5
Top = 1200
Width = 1215
End
Begin VB.Label Label2
Caption = "single IC (indoor temperature)"
Height = 735
Left = 720
TabIndex = 4
Top = 360
Width = 1095
End
End
Begin VB.Frame Frame1
Caption = "Com port:"
Height = 2055
Left = 120
TabIndex = 0
Top = 1440
Width = 2175
Begin VB.OptionButton option_com8
Caption = "Com8"
Height = 375
Left = 1200
TabIndex = 25
Top = 1440
Width = 855
End
Begin VB.OptionButton option_com7
Caption = "Com7"
Height = 375
Left = 1200
TabIndex = 24
Top = 1080
Width = 855
End
Begin VB.OptionButton option_com6
Caption = "Com6"
Height = 375
Left = 1200
TabIndex = 23
Top = 720
Width = 855
End
Begin VB.OptionButton option_com5
Caption = "Com5"
Height = 375
Left = 1200
TabIndex = 22
Top = 360
Width = 855
End
Begin VB.OptionButton option_com4
Caption = "Com4"
Height = 375
Left = 120
TabIndex = 21
Top = 1440
Width = 855
End
Begin VB.OptionButton option_com3
Caption = "Com3"
Height = 375
Left = 120
TabIndex = 20
Top = 1080
Width = 855
End
Begin VB.OptionButton option_com2
Caption = "Com2"
Height = 375
Left = 120
TabIndex = 19
Top = 720
Width = 855
End
Begin VB.OptionButton option_com1
Caption = "Com1"
Height = 375
Left = 120
TabIndex = 18
Top = 360
Width = 855
End
End
Begin VB.Timer Timer1
Interval = 1000
Left = 1200
Top = 4200
End
Begin MSCommLib.MSCom m MSComm1
Left = 2760
Top = 4320
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
CommPort = 3
DTREnable = -1 'True
RTSEnable = -1 'True
End
End
Attribute VB_Name = "frm_thermomete r"
Attribute VB_GlobalNameSp ace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredI d = True
Attribute VB_Exposed = False
Option Explicit
Private Sub Form_Load()
ReadIni
update_com_port
update_sample_r ate
If check_start_min imized.Value Then
Me.WindowState = vbMinimized
End If
End Sub
Private Sub Form_Unload(Can cel As Integer)
close_iic_bus
SaveIni
End Sub
Private Sub option_1_min_Cl ick()
update_sample_r ate
End Sub
Private Sub option_1_min_Ke yPress(KeyAscii As Integer)
update_sample_r ate
End Sub
Private Sub option_1_sec_Cl ick()
update_sample_r ate
End Sub
Private Sub option_1_sec_Ke yPress(KeyAscii As Integer)
update_sample_r ate
End Sub
Private Sub option_30_sec_C lick()
update_sample_r ate
End Sub
Private Sub option_30_sec_K eyPress(KeyAsci i As Integer)
update_sample_r ate
End Sub
Private Sub option_5_sec_Cl ick()
update_sample_r ate
End Sub
Private Sub option_5_sec_Ke yPress(KeyAscii As Integer)
update_sample_r ate
End Sub
Private Sub option_com1_Cli ck()
update_com_port
End Sub
Private Sub option_com1_Key Press(KeyAscii As Integer)
update_com_port
End Sub
Private Sub option_com2_Cli ck()
update_com_port
End Sub
Private Sub option_com2_Key Press(KeyAscii As Integer)
update_com_port
End Sub
Private Sub option_com3_Cli ck()
update_com_port
End Sub
Private Sub option_com3_Key Press(KeyAscii As Integer)
update_com_port
End Sub
Private Sub option_com4_Cli ck()
update_com_port
End Sub
Private Sub option_com4_Key Press(KeyAscii As Integer)
update_com_port
End Sub
Private Sub option_com5_Cli ck()
update_com_port
End Sub
Private Sub option_com5_Key Press(KeyAscii As Integer)
update_com_port
End Sub
Private Sub option_com6_Cli ck()
update_com_port
End Sub
Private Sub option_com6_Key Press(KeyAscii As Integer)
update_com_port
End Sub
Private Sub option_com7_Cli ck()
update_com_port
End Sub
Private Sub option_com7_Key Press(KeyAscii As Integer)
update_com_port
End Sub
Private Sub option_com8_Cli ck()
update_com_port
End Sub
Private Sub option_com8_Key Press(KeyAscii As Integer)
update_com_port
End Sub
Private Sub Timer1_Timer()
Dim t As Double
Dim unit As String
If check_farenheit Then
unit = "°F"
Else
unit = "°C"
End If
t = temperature(&H4 8)
If t = ERROR_TEMPERATU RE_NOT_READ Then
MsgBox "Unable to read internal temperature", vbOKOnly, "Error"
Timer1.Enabled = False
label_temperatu re_indoor.Capti on = "--.-" + unit
Else
If check_farenheit Then
t = farenheit(t)
End If
label_temperatu re_indoor.Capti on = Format(t, "#0.0" + unit)
End If
If option_double Then
t = temperature(&H4 9)
If t = ERROR_TEMPERATU RE_NOT_READ Then
MsgBox "Unable to read external temperature", vbOKOnly, "Error"
Timer1.Enabled = False
label_temperatu re_outside.Capt ion = "--.-" + unit
Else
If check_farenheit Then
t = farenheit(t)
End If
label_temperatu re_outside.Capt ion = Format(t, "#0.0" + unit)
End If
Else
label_temperatu re_outside.Capt ion = "--.-" + unit
End If
If option_double Then
frm_thermometer .Caption = label_temperatu re_indoor.Capti on + " ( out " + label_temperatu re_outside.Capt ion + " )"
Else
frm_thermometer .Caption = label_temperatu re_indoor.Capti on
End If
log_to_file
End Sub
Private Function temperature(ByV al address As Integer) As Double
Dim temperature_int As Long
Dim temperature_fra c As Long
'For I2C bus communication, addresses are shifted one place to left,
'as the least significant bit is used for the R/W flag.
'In binary, shifting to left is equivalent to multiplying by two
address = address * 2
On Error GoTo errors
open_iic_bus MSComm1.object
'an extra stop doesn't hurt...and ensures we start from a clean bus condition
IIC_stop
'read sequence, as per DS1621 datasheet
IIC_start 'Bus Master initiates a START condition.
IIC_tx_byte address 'Bus Master sends DS1621 address; R/ W= 0 (DS1621 generates acknowledge bit).
IIC_tx_byte &HAC 'Bus Master sends Access Config command protocol.DS1621 generates acknowledge bit.
IIC_tx_byte &H1 'Bus Master sets up DS1621 for output polarity active low, one-shot conversion.
'DS1621 generates acknowledge bit.
IIC_start 'Bus Master generates a repeated START condition.
IIC_tx_byte address 'Bus Master sends DS1621 address; R/ W= 0.DS1621 generates acknowledge bit.
IIC_tx_byte &HEE 'Bus Master sends Start Convert T command protocol.DS1621 generates acknowledge bit.
IIC_stop 'Bus Master initiates STOP condition.
IIC_start 'Bus Master initiates a START condition.
IIC_tx_byte address 'Bus Master sends DS1621 address; R/ W= 0 (DS1621 generates acknowledge bit).
IIC_tx_byte &HAA 'Bus Master sends Read Temperature command protocol.DS1621 generates acknowledge bit.
IIC_start 'Bus Master generates a repeated START condition.
IIC_tx_byte address + 1 'Bus Master sends DS1621 address; R/ W= 1 = READING (DS1621 generates acknowledge bit).
temperature_int = IIC_rx_byte(1) 'Bus Master receives first byte of data and generates acknowledge.
temperature_fra c = IIC_rx_byte(0) 'Bus Master receives second byte of data from DS162 and does not generate acknowledge to signal end of reception.
IIC_stop 'Bus Master initiates STOP condition.
'some bynary math to convert to a data format Visual Basic can understand
temperature = (temperature_in t * 256 + temperature_fra c) / 128 * 5 / 10
If temperature_int >= 128 Then
temperature = temperature - 256
End If
Exit Function
errors:
temperature = ERROR_TEMPERATU RE_NOT_READ
End Function
Private Function update_sample_r ate()
If option_1_sec Then
Timer1.Interval = 1000
ElseIf option_5_sec Then
Timer1.Interval = 5000
ElseIf option_30_sec Then
Timer1.Interval = 30000
ElseIf option_1_min Then
Timer1.Interval = 60000
Else
Timer1.Interval = 1000
End If
End Function
Private Function update_com_port ()
If MSComm1.PortOpe n Then
MSComm1.PortOpe n = False
End If
If option_com1 Then
MSComm1.CommPor t = 1
Timer1.Enabled = True
ElseIf option_com2 Then
MSComm1.CommPor t = 2
Timer1.Enabled = True
ElseIf option_com3 Then
MSComm1.CommPor t = 3
Timer1.Enabled = True
ElseIf option_com4 Then
MSComm1.CommPor t = 4
Timer1.Enabled = True
ElseIf option_com5 Then
MSComm1.CommPor t = 5
Timer1.Enabled = True
ElseIf option_com6 Then
MSComm1.CommPor t = 6
Timer1.Enabled = True
ElseIf option_com7 Then
MSComm1.CommPor t = 7
Timer1.Enabled = True
ElseIf option_com8 Then
MSComm1.CommPor t = 8
Timer1.Enabled = True
Else
MSComm1.CommPor t = 1
Timer1.Enabled = False
End If
End Function
Private Function farenheit(ByVal t As Double)
farenheit = 32 + 9 / 5 * t
End Function
Private Function log_to_file()
If check_log_to_fi le Then
Open "pc_thermometer .txt" For Append As #1
Print #1, Date$, Time$, label_temperatu re_outside.Capt ion, label_temperatu re_indoor.Capti on
Close #1
End If
End Function
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1 .1#0"; "MSCOMM32.O CX"
Begin VB.Form frm_thermometer
ClientHeight = 3600
ClientLeft = 60
ClientTop = 345
ClientWidth = 6045
Icon = "frm_thermomete r.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 3600
ScaleWidth = 6045
StartUpPosition = 2 'CenterScreen
Begin VB.Frame Frame4
Height = 1335
Left = 120
TabIndex = 11
Top = 0
Width = 5775
Begin VB.CheckBox check_start_min imized
Caption = "start minimized"
Height = 375
Left = 4200
TabIndex = 26
ToolTipText = "Start as an icon in taskbar"
Top = 480
Width = 1335
End
Begin VB.CheckBox check_log_to_fi le
Caption = "log data to file"
Height = 375
Left = 4200
TabIndex = 17
ToolTipText = "log temperatures on text file ""pc_thermomete r.txt"""
Top = 840
Width = 1335
End
Begin VB.CheckBox check_farenheit
Caption = "use Farenheit"
Height = 375
Left = 4200
TabIndex = 12
ToolTipText = "Show as Fahrenheit or Celsius (centigrade)"
Top = 120
Width = 1335
End
Begin VB.Label Label4
Alignment = 2 'Center
BackStyle = 0 'Transparent
Caption = "outside"
Height = 375
Left = 2280
TabIndex = 16
Top = 120
Width = 1215
End
Begin VB.Label Label1
Alignment = 2 'Center
BackStyle = 0 'Transparent
Caption = "indoor"
Height = 375
Left = 120
TabIndex = 15
Top = 120
Width = 1215
End
Begin VB.Label label_temperatu re_outside
Alignment = 2 'Center
Caption = "--.-"
BeginProperty Font
Name = "MS Sans Serif"
Size = 18
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 735
Left = 2280
TabIndex = 14
Top = 480
Width = 1215
End
Begin VB.Label label_temperatu re_indoor
Alignment = 2 'Center
Caption = "--.-"
BeginProperty Font
Name = "MS Sans Serif"
Size = 18
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 735
Left = 120
TabIndex = 13
Top = 480
Width = 1215
End
End
Begin VB.Frame Frame3
Caption = "Sample time"
Height = 2055
Left = 4200
TabIndex = 6
Top = 1440
Width = 1695
Begin VB.OptionButton option_1_min
Caption = "1 min."
Height = 375
Left = 240
TabIndex = 10
Top = 1440
Width = 855
End
Begin VB.OptionButton option_30_sec
Caption = "30 sec."
Height = 375
Left = 240
TabIndex = 9
Top = 1080
Width = 855
End
Begin VB.OptionButton option_5_sec
Caption = "5 sec."
Height = 375
Left = 240
TabIndex = 8
Top = 720
Width = 855
End
Begin VB.OptionButton option_1_sec
Caption = "1 sec."
Height = 375
Left = 240
TabIndex = 7
Top = 360
Value = -1 'True
Width = 855
End
End
Begin VB.Frame Frame2
Caption = "N. of sensor ICs"
Height = 2055
Left = 2280
TabIndex = 1
Top = 1440
Width = 1935
Begin VB.OptionButton option_double
BeginProperty Font
Name = "MS Sans Serif"
Size = 13.5
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 240
TabIndex = 3
Top = 1080
Width = 375
End
Begin VB.OptionButton option_single
BeginProperty Font
Name = "MS Sans Serif"
Size = 13.5
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 240
TabIndex = 2
Top = 360
Value = -1 'True
Width = 375
End
Begin VB.Label Label3
Caption = "double IC (indoor + outside)"
Height = 735
Left = 600
TabIndex = 5
Top = 1200
Width = 1215
End
Begin VB.Label Label2
Caption = "single IC (indoor temperature)"
Height = 735
Left = 720
TabIndex = 4
Top = 360
Width = 1095
End
End
Begin VB.Frame Frame1
Caption = "Com port:"
Height = 2055
Left = 120
TabIndex = 0
Top = 1440
Width = 2175
Begin VB.OptionButton option_com8
Caption = "Com8"
Height = 375
Left = 1200
TabIndex = 25
Top = 1440
Width = 855
End
Begin VB.OptionButton option_com7
Caption = "Com7"
Height = 375
Left = 1200
TabIndex = 24
Top = 1080
Width = 855
End
Begin VB.OptionButton option_com6
Caption = "Com6"
Height = 375
Left = 1200
TabIndex = 23
Top = 720
Width = 855
End
Begin VB.OptionButton option_com5
Caption = "Com5"
Height = 375
Left = 1200
TabIndex = 22
Top = 360
Width = 855
End
Begin VB.OptionButton option_com4
Caption = "Com4"
Height = 375
Left = 120
TabIndex = 21
Top = 1440
Width = 855
End
Begin VB.OptionButton option_com3
Caption = "Com3"
Height = 375
Left = 120
TabIndex = 20
Top = 1080
Width = 855
End
Begin VB.OptionButton option_com2
Caption = "Com2"
Height = 375
Left = 120
TabIndex = 19
Top = 720
Width = 855
End
Begin VB.OptionButton option_com1
Caption = "Com1"
Height = 375
Left = 120
TabIndex = 18
Top = 360
Width = 855
End
End
Begin VB.Timer Timer1
Interval = 1000
Left = 1200
Top = 4200
End
Begin MSCommLib.MSCom m MSComm1
Left = 2760
Top = 4320
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
CommPort = 3
DTREnable = -1 'True
RTSEnable = -1 'True
End
End
Attribute VB_Name = "frm_thermomete r"
Attribute VB_GlobalNameSp ace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredI d = True
Attribute VB_Exposed = False
Option Explicit
Private Sub Form_Load()
ReadIni
update_com_port
update_sample_r ate
If check_start_min imized.Value Then
Me.WindowState = vbMinimized
End If
End Sub
Private Sub Form_Unload(Can cel As Integer)
close_iic_bus
SaveIni
End Sub
Private Sub option_1_min_Cl ick()
update_sample_r ate
End Sub
Private Sub option_1_min_Ke yPress(KeyAscii As Integer)
update_sample_r ate
End Sub
Private Sub option_1_sec_Cl ick()
update_sample_r ate
End Sub
Private Sub option_1_sec_Ke yPress(KeyAscii As Integer)
update_sample_r ate
End Sub
Private Sub option_30_sec_C lick()
update_sample_r ate
End Sub
Private Sub option_30_sec_K eyPress(KeyAsci i As Integer)
update_sample_r ate
End Sub
Private Sub option_5_sec_Cl ick()
update_sample_r ate
End Sub
Private Sub option_5_sec_Ke yPress(KeyAscii As Integer)
update_sample_r ate
End Sub
Private Sub option_com1_Cli ck()
update_com_port
End Sub
Private Sub option_com1_Key Press(KeyAscii As Integer)
update_com_port
End Sub
Private Sub option_com2_Cli ck()
update_com_port
End Sub
Private Sub option_com2_Key Press(KeyAscii As Integer)
update_com_port
End Sub
Private Sub option_com3_Cli ck()
update_com_port
End Sub
Private Sub option_com3_Key Press(KeyAscii As Integer)
update_com_port
End Sub
Private Sub option_com4_Cli ck()
update_com_port
End Sub
Private Sub option_com4_Key Press(KeyAscii As Integer)
update_com_port
End Sub
Private Sub option_com5_Cli ck()
update_com_port
End Sub
Private Sub option_com5_Key Press(KeyAscii As Integer)
update_com_port
End Sub
Private Sub option_com6_Cli ck()
update_com_port
End Sub
Private Sub option_com6_Key Press(KeyAscii As Integer)
update_com_port
End Sub
Private Sub option_com7_Cli ck()
update_com_port
End Sub
Private Sub option_com7_Key Press(KeyAscii As Integer)
update_com_port
End Sub
Private Sub option_com8_Cli ck()
update_com_port
End Sub
Private Sub option_com8_Key Press(KeyAscii As Integer)
update_com_port
End Sub
Private Sub Timer1_Timer()
Dim t As Double
Dim unit As String
If check_farenheit Then
unit = "°F"
Else
unit = "°C"
End If
t = temperature(&H4 8)
If t = ERROR_TEMPERATU RE_NOT_READ Then
MsgBox "Unable to read internal temperature", vbOKOnly, "Error"
Timer1.Enabled = False
label_temperatu re_indoor.Capti on = "--.-" + unit
Else
If check_farenheit Then
t = farenheit(t)
End If
label_temperatu re_indoor.Capti on = Format(t, "#0.0" + unit)
End If
If option_double Then
t = temperature(&H4 9)
If t = ERROR_TEMPERATU RE_NOT_READ Then
MsgBox "Unable to read external temperature", vbOKOnly, "Error"
Timer1.Enabled = False
label_temperatu re_outside.Capt ion = "--.-" + unit
Else
If check_farenheit Then
t = farenheit(t)
End If
label_temperatu re_outside.Capt ion = Format(t, "#0.0" + unit)
End If
Else
label_temperatu re_outside.Capt ion = "--.-" + unit
End If
If option_double Then
frm_thermometer .Caption = label_temperatu re_indoor.Capti on + " ( out " + label_temperatu re_outside.Capt ion + " )"
Else
frm_thermometer .Caption = label_temperatu re_indoor.Capti on
End If
log_to_file
End Sub
Private Function temperature(ByV al address As Integer) As Double
Dim temperature_int As Long
Dim temperature_fra c As Long
'For I2C bus communication, addresses are shifted one place to left,
'as the least significant bit is used for the R/W flag.
'In binary, shifting to left is equivalent to multiplying by two
address = address * 2
On Error GoTo errors
open_iic_bus MSComm1.object
'an extra stop doesn't hurt...and ensures we start from a clean bus condition
IIC_stop
'read sequence, as per DS1621 datasheet
IIC_start 'Bus Master initiates a START condition.
IIC_tx_byte address 'Bus Master sends DS1621 address; R/ W= 0 (DS1621 generates acknowledge bit).
IIC_tx_byte &HAC 'Bus Master sends Access Config command protocol.DS1621 generates acknowledge bit.
IIC_tx_byte &H1 'Bus Master sets up DS1621 for output polarity active low, one-shot conversion.
'DS1621 generates acknowledge bit.
IIC_start 'Bus Master generates a repeated START condition.
IIC_tx_byte address 'Bus Master sends DS1621 address; R/ W= 0.DS1621 generates acknowledge bit.
IIC_tx_byte &HEE 'Bus Master sends Start Convert T command protocol.DS1621 generates acknowledge bit.
IIC_stop 'Bus Master initiates STOP condition.
IIC_start 'Bus Master initiates a START condition.
IIC_tx_byte address 'Bus Master sends DS1621 address; R/ W= 0 (DS1621 generates acknowledge bit).
IIC_tx_byte &HAA 'Bus Master sends Read Temperature command protocol.DS1621 generates acknowledge bit.
IIC_start 'Bus Master generates a repeated START condition.
IIC_tx_byte address + 1 'Bus Master sends DS1621 address; R/ W= 1 = READING (DS1621 generates acknowledge bit).
temperature_int = IIC_rx_byte(1) 'Bus Master receives first byte of data and generates acknowledge.
temperature_fra c = IIC_rx_byte(0) 'Bus Master receives second byte of data from DS162 and does not generate acknowledge to signal end of reception.
IIC_stop 'Bus Master initiates STOP condition.
'some bynary math to convert to a data format Visual Basic can understand
temperature = (temperature_in t * 256 + temperature_fra c) / 128 * 5 / 10
If temperature_int >= 128 Then
temperature = temperature - 256
End If
Exit Function
errors:
temperature = ERROR_TEMPERATU RE_NOT_READ
End Function
Private Function update_sample_r ate()
If option_1_sec Then
Timer1.Interval = 1000
ElseIf option_5_sec Then
Timer1.Interval = 5000
ElseIf option_30_sec Then
Timer1.Interval = 30000
ElseIf option_1_min Then
Timer1.Interval = 60000
Else
Timer1.Interval = 1000
End If
End Function
Private Function update_com_port ()
If MSComm1.PortOpe n Then
MSComm1.PortOpe n = False
End If
If option_com1 Then
MSComm1.CommPor t = 1
Timer1.Enabled = True
ElseIf option_com2 Then
MSComm1.CommPor t = 2
Timer1.Enabled = True
ElseIf option_com3 Then
MSComm1.CommPor t = 3
Timer1.Enabled = True
ElseIf option_com4 Then
MSComm1.CommPor t = 4
Timer1.Enabled = True
ElseIf option_com5 Then
MSComm1.CommPor t = 5
Timer1.Enabled = True
ElseIf option_com6 Then
MSComm1.CommPor t = 6
Timer1.Enabled = True
ElseIf option_com7 Then
MSComm1.CommPor t = 7
Timer1.Enabled = True
ElseIf option_com8 Then
MSComm1.CommPor t = 8
Timer1.Enabled = True
Else
MSComm1.CommPor t = 1
Timer1.Enabled = False
End If
End Function
Private Function farenheit(ByVal t As Double)
farenheit = 32 + 9 / 5 * t
End Function
Private Function log_to_file()
If check_log_to_fi le Then
Open "pc_thermometer .txt" For Append As #1
Print #1, Date$, Time$, label_temperatu re_outside.Capt ion, label_temperatu re_indoor.Capti on
Close #1
End If
End Function
Comment