Akkor ez a kérdés megoldva.
Marad nekem a fő problémám, a VB6-ban írt kód és az arduinós összehozása I2C kommunikációra.
Az I2C buszon Ds1624 hőmérők vannak, erre van a VB6 ban írt program:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "mscomm32.ocx"
Begin VB.Form frm_thermometer
ClientHeight = 7710
ClientLeft = 60
ClientTop = 345
ClientWidth = 8055
Icon = "frm_thermometer.frx":0000
LinkTopic = "Form1"
ScaleHeight = 7710
ScaleWidth = 8055
StartUpPosition = 2 'Képernyő közepére
Begin VB.Frame Frame4
Height = 1335
Left = 120
TabIndex = 11
Top = 0
Width = 6135
Begin VB.CheckBox check_start_minimized
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_file
Caption = "log data to file"
Height = 375
Left = 4200
TabIndex = 17
ToolTipText = "log temperatures on text file ""pc_thermometer.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 külsődéli
Alignment = 2 'Középre
BackStyle = 0 'Átlátszó
Caption = "külső déli"
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 238
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 2280
TabIndex = 16
Top = 120
Width = 1215
End
Begin VB.Label padlószint
Alignment = 2 'Középre
BackStyle = 0 'Átlátszó
Caption = "padlószint"
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 238
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 720
TabIndex = 15
Top = 120
Width = 1215
End
Begin VB.Label label_temperature_külsődéli
Alignment = 2 'Középre
Caption = "--.---"
BeginProperty Font
Name = "MS Sans Serif"
Size = 17.25
Charset = 238
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 735
Left = 2040
TabIndex = 14
Top = 480
Width = 1815
End
Begin VB.Label label_temperature_padlószint
Alignment = 2 'Középre
Caption = "--.---"
BeginProperty Font
Name = "MS Sans Serif"
Size = 17.25
Charset = 238
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 735
Left = 120
TabIndex = 13
Top = 480
Width = 1815
End
End
Begin VB.Frame Frame3
Caption = "Sample time"
Height = 2055
Left = 4560
TabIndex = 6
Top = 4440
Width = 1575
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_6_sec
Caption = "6 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 = 2400
TabIndex = 1
Top = 4440
Width = 2055
Begin VB.OptionButton option_double
BeginProperty Font
Name = "MS Sans Serif"
Size = 13.5
Charset = 238
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 = 238
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 = 615
Left = 720
TabIndex = 5
Top = 1200
Width = 1215
End
Begin VB.Label Label2
Caption = "single IC (indoor temperature)"
Height = 735
Left = 840
TabIndex = 4
Top = 360
Width = 1095
End
End
Begin VB.Frame Frame1
Caption = "Com port:"
Height = 2055
Left = 120
TabIndex = 0
Top = 4440
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 = 240
Top = 6840
End
Begin MSCommLib.MSComm MSComm1
Left = 2400
Top = 6720
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
RTSEnable = -1 'True
End
Begin VB.Label ad_ertek
Height = 735
Left = 6360
TabIndex = 41
Top = 3120
Width = 1575
End
Begin VB.Label ADC
Caption = "ADC"
Height = 495
Left = 6240
TabIndex = 40
Top = 1560
Width = 1575
End
Begin VB.Label label_temperature_ADC
Caption = "--,---"
BeginProperty Font
Name = "MS Sans Serif"
Size = 13.5
Charset = 238
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 615
Left = 6360
TabIndex = 39
Top = 2280
Width = 1455
End
Begin VB.Label Label_temperature_opoph424el
Alignment = 2 'Középre
Caption = "--.-"
BeginProperty Font
Name = "MS Sans Serif"
Size = 17.25
Charset = 238
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 4320
TabIndex = 38
Top = 3840
Width = 1695
End
Begin VB.Label OPOPH424EL
Caption = "OPOP H424 EL"
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 238
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 4320
TabIndex = 37
Top = 3000
Width = 1695
End
Begin VB.Label Label_temperature_opoph424be
Alignment = 2 'Középre
Caption = "--.-"
BeginProperty Font
Name = "MS Sans Serif"
Size = 17.25
Charset = 238
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 4320
TabIndex = 36
Top = 2280
Width = 1695
End
Begin VB.Label OPOPH424BE
Alignment = 2 'Középre
Caption = "OPOP H424 BE"
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 238
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 4320
TabIndex = 35
Top = 1560
Width = 1695
End
Begin VB.Label Label_temperature_boiler
Alignment = 2 'Középre
Caption = "--.-"
BeginProperty Font
Name = "MS Sans Serif"
Size = 17.25
Charset = 238
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 2280
TabIndex = 34
Top = 3840
Width = 1815
End
Begin VB.Label Boiler
Alignment = 2 'Középre
Caption = "Boiler"
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 238
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 2880
TabIndex = 33
Top = 3120
Width = 1215
End
Begin VB.Label Label_temperature_fancoilel
Alignment = 2 'Középre
Caption = "--.-"
BeginProperty Font
Name = "MS Sans Serif"
Size = 17.25
Charset = 238
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 120
TabIndex = 32
Top = 3600
Width = 1815
End
Begin VB.Label Label_temperature_fancoilbe
Alignment = 2 'Középre
Caption = "--.-"
BeginProperty Font
Name = "MS Sans Serif"
Size = 17.25
Charset = 238
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 120
TabIndex = 31
Top = 2160
Width = 1815
End
Begin VB.Label fancoilel
Alignment = 2 'Középre
Caption = "Fan-Coil El"
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 238
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 120
TabIndex = 30
Top = 2880
Width = 1455
End
Begin VB.Label fancoilbe
Alignment = 2 'Középre
Caption = "Fan-Coil Be"
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 238
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 120
TabIndex = 29
Top = 1440
Width = 1455
End
Begin VB.Label label_temperature_radiator
Alignment = 2 'Középre
Caption = "--.-"
BeginProperty Font
Name = "MS Sans Serif"
Size = 17.25
Charset = 238
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 2280
TabIndex = 28
Top = 2280
Width = 1815
End
Begin VB.Label radiator
Alignment = 2 'Középre
Caption = "radiator"
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 238
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 2880
TabIndex = 27
Top = 1560
Width = 1215
End
End
Attribute VB_Name = "frm_thermometer"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim address_adc As Double
Dim parancs As Double
Dim feny_ertek As Long
Dim szamlalo
Private Sub ad_szoveg_Click()
End Sub
Private Sub ADC_label_Click()
End Sub
Private Sub Form_Load()
ReadIni
update_com_port
update_sample_rate
If check_start_minimized.Value Then
Me.WindowState = vbMinimized
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
close_iic_bus
SaveIni
End Sub
Private Sub option_1_min_Click()
update_sample_rate
End Sub
Private Sub option_1_min_KeyPress(KeyAscii As Integer)
update_sample_rate
End Sub
Private Sub option_1_sec_Click()
update_sample_rate
End Sub
Private Sub option_1_sec_KeyPress(KeyAscii As Integer)
update_sample_rate
End Sub
Private Sub option_30_sec_Click()
update_sample_rate
End Sub
Private Sub option_30_sec_KeyPress(KeyAscii As Integer)
update_sample_rate
End Sub
Private Sub option_6_sec_Click()
update_sample_rate
End Sub
Private Sub option_6_sec_KeyPress(KeyAscii As Integer)
update_sample_rate
End Sub
Private Sub option_com1_Click()
update_com_port
End Sub
Private Sub option_com1_KeyPress(KeyAscii As Integer)
update_com_port
End Sub
Private Sub option_com2_Click()
update_com_port
End Sub
Private Sub option_com2_KeyPress(KeyAscii As Integer)
update_com_port
End Sub
Private Sub option_com3_Click()
update_com_port
End Sub
Private Sub option_com3_KeyPress(KeyAscii As Integer)
update_com_port
End Sub
Private Sub option_com4_Click()
update_com_port
End Sub
Private Sub option_com4_KeyPress(KeyAscii As Integer)
update_com_port
End Sub
Private Sub option_com5_Click()
update_com_port
End Sub
Private Sub option_com5_KeyPress(KeyAscii As Integer)
update_com_port
End Sub
Private Sub option_com6_Click()
update_com_port
End Sub
Private Sub option_com6_KeyPress(KeyAscii As Integer)
update_com_port
End Sub
Private Sub option_com7_Click()
update_com_port
End Sub
Private Sub option_com7_KeyPress(KeyAscii As Integer)
update_com_port
End Sub
Private Sub option_com8_Click()
update_com_port
End Sub
Private Sub option_com8_KeyPress(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(&H48)
If t = ERROR_TEMPERATURE_NOT_READ Then
MsgBox "Unable to read padlószint temperature", vbOKOnly, "Error"
Timer1.Enabled = False
label_temperature_padlószint.Caption = "--.---" + unit
Else
If check_farenheit Then
t = farenheit(t)
End If
label_temperature_padlószint.Caption = Format(t, "#00.000")
End If
If option_double Then
t = temperature(&H49)
If t = ERROR_TEMPERATURE_NOT_READ Then
MsgBox "Unable to read külsődéli temperature", vbOKOnly, "Error"
Timer1.Enabled = False
label_temperature_külsődéli.Caption = "--.---" + unit
Else
If check_farenheit Then
t = farenheit(t)
End If
label_temperature_külsődéli.Caption = Format(t, "#00.000")
End If
Else
label_temperature_külsődéli.Caption = "--.---" + unit
End If
If option_double Then
t = temperature(&H4A)
If t = ERROR_TEMPERATURE_NOT_READ Then
MsgBox "Unable to read radiator temperature", vbOKOnly, "Error"
Timer1.Enabled = False
label_temperature_radiator.Caption = "--.---" + unit
Else
If check_farenheit Then
t = farenheit(t)
End If
label_temperature_radiator.Caption = Format(t, "#00.000")
End If
Else
label_temperature_radiator.Caption = "--.---" + unit
End If
If option_double Then
t = temperature(&H4B)
If t = ERROR_TEMPERATURE_NOT_READ Then
MsgBox "Unable to read fancoilbe temperature", vbOKOnly, "Error"
Timer1.Enabled = False
Label_temperature_fancoilbe.Caption = "--.---" + unit
Else
If check_farenheit Then
t = farenheit(t)
End If
Label_temperature_fancoilbe.Caption = Format(t, "#00.000")
End If
Else
Label_temperature_fancoilbe.Caption = "--.---" + unit
End If
If option_double Then
t = temperature(&H4C)
If t = ERROR_TEMPERATURE_NOT_READ Then
MsgBox "Unable to read fancoilel temperature", vbOKOnly, "Error"
Timer1.Enabled = False
Label_temperature_fancoilel.Caption = "--.---" + unit
Else
If check_farenheit Then
t = farenheit(t)
End If
Label_temperature_fancoilel.Caption = Format(t, "#00.000")
End If
Else
Label_temperature_fancoilel.Caption = "--.---" + unit
End If
If option_double Then
t = temperature(&H4D)
If t = ERROR_TEMPERATURE_NOT_READ Then
MsgBox "Unable to read opoph424be temperature", vbOKOnly, "Error"
Timer1.Enabled = False
Label_temperature_opoph424be.Caption = "--.---" + unit
Else
If check_farenheit Then
t = farenheit(t)
End If
Label_temperature_opoph424be.Caption = Format(t, "#00.000")
End If
Else
Label_temperature_opoph424be.Caption = "--.---" + unit
End If
If option_double Then
t = temperature(&H4E)
If t = ERROR_TEMPERATURE_NOT_READ Then
MsgBox "Unable to read opoph424el temperature", vbOKOnly, "Error"
Timer1.Enabled = False
Label_temperature_opoph424el.Caption = "--.---" + unit
Else
If check_farenheit Then
t = farenheit(t)
End If
Label_temperature_opoph424el.Caption = Format(t, "#00.000")
End If
Else
Label_temperature_opoph424el.Caption = "--.---" + unit
End If
If option_double Then
t = temperature(&H4F)
If t = ERROR_TEMPERATURE_NOT_READ Then
MsgBox "Unable to read boiler temperature", vbOKOnly, "Error"
Timer1.Enabled = False
Label_temperature_boiler.Caption = "--.---" + unit
Else
If check_farenheit Then
t = farenheit(t)
End If
Label_temperature_boiler.Caption = Format(t, "#00.000")
End If
Else
Label_temperature_boiler.Caption = "--.---" + unit
End If
If option_double Then
t = temperature(&H32)
If t = ERROR_TEMPERATURE_NOT_READ Then
MsgBox "Unable to read ADC temperature", vbOKOnly, "Error"
Timer1.Enabled = False
label_temperature_ADC.Caption = "--.---" + unit
Else
If check_farenheit Then
t = farenheit(t)
End If
label_temperature_ADC.Caption = Format(t, "#00.000")
End If
Else
label_temperature_ADC.Caption = "--.---" + unit
End If
If option_double Then
frm_thermometer.Caption = label_temperature_padlószint.Caption + " ( out " + label_temperature_külsődéli.Caption + " )"
Else
frm_thermometer.Caption = label_temperature_padlószint.Caption
End If
End Sub
Private Function temperature(address As Integer) As Double
Dim temperature_int As Long
Dim temperature_frac As Long
'address = address(&H48)
address = address * 2
On Error GoTo errors
open_iic_bus MSComm1.object
'/*resettiamo bene il chip*/
IIC_stop
'/**/
IIC_start
IIC_tx_byte &H90 + address
IIC_tx_byte &HAC
IIC_tx_byte &H2
IIC_start
IIC_tx_byte &H90 + address
IIC_tx_byte &HEE
IIC_stop
IIC_start
IIC_tx_byte &H90 + address
IIC_tx_byte &HAA
IIC_start
IIC_tx_byte &H91 + address
temperature_int = IIC_rx_byte(1)
temperature_frac = IIC_rx_byte(0)
temperature = (temperature_int * 256 + temperature_frac) / 128 * 5 / 10
If temperature_int >= 128 Then
temperature = temperature - 256
End If
IIC_stop
Exit Function
errors:
temperature = ERROR_TEMPERATURE_NOT_READ
End Function
Private Function update_sample_rate()
If option_1_sec Then
Timer1.Interval = 1000
ElseIf option_6_sec Then
Timer1.Interval = 6000
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.PortOpen Then
MSComm1.PortOpen = False
End If
If option_com1 Then
MSComm1.CommPort = 1
Timer1.Enabled = True
ElseIf option_com2 Then
MSComm1.CommPort = 2
Timer1.Enabled = True
ElseIf option_com3 Then
MSComm1.CommPort = 3
Timer1.Enabled = True
ElseIf option_com4 Then
MSComm1.CommPort = 4
Timer1.Enabled = True
ElseIf option_com5 Then
MSComm1.CommPort = 5
Timer1.Enabled = True
ElseIf option_com6 Then
MSComm1.CommPort = 6
Timer1.Enabled = True
ElseIf option_com7 Then
MSComm1.CommPort = 7
Timer1.Enabled = True
ElseIf option_com8 Then
MSComm1.CommPort = 8
Timer1.Enabled = True
Else
MSComm1.CommPort = 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_file Then
Open "pc_thermometer.csv" For Append As #1
Print #1, Date$, Time$, label_temperature_padlószint.Caption, label_temperature_külsődéli.Caption, Label_temperature_fancoilbe.Caption, Label_temperature_fancoilel.Caption, Label_temperature_boiler.Caption, Label_temperature_opoph424el.Caption, Label_temperature_opoph424be.Caption, label_temperature_radiator.Caption, feny_ertek
Close #1
End If
End Function
A kérdés, hogyan kell az arduino slave móddal kapcsolatot teremteni a VB6 kódból?