0
我是一名新手,正在编写自动啤酒厂中的代码,并将其重写为从模拟温度感测转换为单线。OneWire DS18B20从指定的传感器获取vb.net中的温度
但是,我正在努力获得任何喜悦,有人可以运行他们的大脑在这段代码对我和建议请吗?目标是让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
问候
史蒂夫