我是编程新手,正在重写我的自动啤酒厂的代码,以从模拟温度传感转移到单线。
然而,我正在努力获得任何快乐,有人可以为我运行这段代码并提供建议吗?目的是让 HLT_currenttemp 读取 hltaddress 处 DS18B20 传感器的当前温度。
Dim owd As com.dalsemi.onewire.container.OneWireContainer
Dim state As Object
Dim tc As com.dalsemi.onewire.container.TemperatureContainer
' Try
' get exclusive use of 1-Wire network
adapter.beginExclusive(True)
' clear any previous search restrictions
adapter.setSearchAllDevices()
adapter.targetAllFamilies()
adapter.setSpeed(com.dalsemi.onewire.adapter.DSPortAdapter.SPEED_REGULAR)
owd = CreateObject("OWAPI.OneWireContainer28")
' retrieve OneWireContainer
owd.setupContainer(adapter, hltaddress)
' cast the OneWireContainer to TemperatureContainer
tc = DirectCast(owd, com.dalsemi.onewire.container.TemperatureContainer)
' read the device
state = tc.readDevice
' extract the temperature from previous read
tc.doTemperatureConvert(state)
' retrieve Temp
HLT_Currentemp = (Math.Round(tc.getTemperature(state), 2))
Debug.WriteLine(tc.getTemperature(state))
' end exclusive use of 1-Wire net adapter
adapter.endExclusive()
'Catch ex As Exception
Debug.WriteLine(hltaddress)
' End Try
问候
史蒂夫