0

私はプログラミングの初心者で、自動醸造所のコードを書き直して、アナログ温度センシングから onewire に移行しています。

私は喜びを得るのに苦労していますが、誰かがこのコードについて頭を悩ませてアドバイスしてもらえますか? 目的は、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

よろしく

スティーブ

4

1 に答える 1

0

ついにそれを理解しました!

' retrieve OneWireContainer
        owd = adapter.getDeviceContainer(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), 3))
于 2013-10-07T12:30:36.800 に答える