DS2423 Counter Reading

Platypus

New Member
Hi,

I have got various 1-Wire devices running quite happily on my MicroLan and can read/write to them from my VB6 program, BUT...

I just can't seem to work out how to read the counters on the DS2423 and it's driving me mad!

To give you an idea of what I've got this is a typical example of how I read a DS18S20
[codebox] ' Create a container for the water thermometer
If bIsItemInListBox(sWaterTherm, frmSettings.DeviceList) Then
Set owContainer = owAdapter.getDeviceContainer(sWaterTherm)
Set owContainer = owContainer.getMostSpecificComponent

' Set read status
Set sState = owContainer.readDevice

' read the temp
owContainer.doTemperatureConvert (sState)
Set sState = owContainer.readDevice
DataSet.Temperature(3) = Format(owContainer.getTemperature(sState), "#0.0")
End If
[/codebox]

This works fine so I tried something similar for the DS2324
[codebox]' Create a container for the water level counter
If bIsItemInListBox(sWaterLevelCounter, frmSettings.DeviceList) Then
Set owContainer = owAdapter.getDeviceContainer(sWaterLevelCounter)
'Set owContainer = owContainer.getMostSpecificComponent

' Set read status
' Set sState = owContainer.readDevice

' read the counters
' DataSet.WaterLevel = OneWireContainer1D(owContainer, sWaterLevelCounter)
DataSet.WaterLevel = CalcWaterLevel(owContainer.readCounter(14), DataSet.MeasurementInterval)
End If
[/codebox]

You can see some of the (commented out) ways I have tried but I always get the same sort of error;
method not supported by this device or something like that

The error is always thrown by the owContainer.readCounter(14) call.
The DS2423 is found and identified correctly but I just can't read from it!

Can anyone point me in the right direction?
Have you got the counter to work in VB6?
If so would you be willing to post a code snippet showing how I should be doing it?


Thanks
 
but I always get the same sort of error;
method not supported by this device or something like that
or "something like that"??? How about "run time error 438, object doesn't support this property or method"? Its not that hard to type an error message accurately, especially if you're asking for help. We can't see your screen. gronk!

If that's the error message, its a VB error telling you that it doesn't know about something. I'm guessing its readcounter(). You didn't show enough code (gronk! again) so I don't know if this is going to be of use. I'm guessing again that you have "dim owcontainer as onewirecontainer". readcounter() is a method of onewirecontainer1d, not onewirecontainer.

Try something like this. It compiles and works up to a point, but I don't have a spare counter to test it or debug it with. In fact I use TMEX, not OWAPI, so this may be a pile of poop.

[codebox]
Sub Main()

Const swaterlevelcounter = "f0000000286c3581" ' put your ds2423 ID here

Dim owaccess As OneWireAccessProvider
Dim owadapter As Object ' DSPortAdapter
'dim owcontainer as object
Dim owcontainer As OneWireContainer1D

Set owaccess = New owapi.OneWireAccessProvider

Set owadapter = owaccess.getDefaultAdapter()

Set owcontainer = owadapter.getDeviceContainer(swaterlevelcounter)

Debug.Print owcontainer.readCounter(14)

End Sub
[/codebox]

Water temp and water level? Sounds interesting. What are you monitoring and what's driving the counter?
 
Thanks sda

You are right I was using onewirecontainer, I'll try it out with onewirecontainer1D as you suggested.

or "something like that"??? How about "run time error 438, object doesn't support this property or method"? Its not that hard to type an error message accurately, especially if you're asking for help. We can't see your screen. gronk!
Sorry about that, but I posted the plea for help from work so didn't have the error code in front of me!

Water temp and water level? Sounds interesting. What are you monitoring and what's driving the counter?
The water level measurement is based on this [post="0"]article[/post] and I'm planning to use it for monitoring a koi pond. It will (hopefully) measure the water level and I'll then use a DS2405 to open a top-up valve as necessary. The thermometer will be used to monitor the Koi water temp and used to detirmine feeding rates.
 
Ok,

I have the following to get the network and adapter set up;
[codebox]Global owAccess As OneWireAccessProvider
Global owAdapter As Object
Set owAccess = New owapi.OneWireAccessProvider
Set owAdapter = owAccess.getDefaultAdapter()[/codebox]
Then if I do this;
[codebox]Dim owCounter As OneWireContainer1D
Set owCounter = owAdapter.getDeviceContainer(B400000009F6171D)
Debug.Print owCounter.readCounter(14)[/codebox]
Then the Set owCounter = line throws a Type mismatch error

If I do this;
[codebox]Dim owCounter As OneWireContainer1D
Debug.Print owCounter.readCounter(14)[/codebox]
Then the Debug.Print line throws a Object variable or With block variable not set
error, as you would expect

But If I do this;
[codebox]Dim owCounter As New OneWireContainer1D
Debug.Print owCounter.readCounter(14)[/codebox]
Then the Debug.Print line throws a java.lang.NullPointerException
error, so I'm atleast now getting Java errors instead of VB ones.

And it seams that the API is saying it has not been given a pointer to the specific device (cos I took it out earlier!)

So I put the Set owCounter = line back in...
[codebox]Dim owCounter As New OneWireContainer1D
Set owCounter = owAdapter.getDeviceContainer(B400000009F6171D)
Debug.Print owCounter.readCounter(14)[/codebox]
But the Set owCounter = line just throws the Type mismatch error again

So I think I need to use another method of assigning the unique device ID to owCounter, but I can't figure out how!
I have gone through the documentation in the SDKbut the ONLY methods associated with OneWireContainer1D are;
readCounter(int counterPage) which is supposed to read the counter
freeObject() which "Sets this object's reference to null"
isObjectInitialized() which "Returns true if this COM Stub class refers to an object which is not null"

I have added the line debug.print owCounter.isObjectInitialized before the Set owCounter = and this returns True but still throws the Type mismatch error

And If I take out the Set owCounter = then the line debug.print owCounter.isObjectInitialized returns True but still throws the java.lang.NullPointerException error


I'm rapidly running out of ideas
Any suggestions welcome

Thanks
 
Further to my previous post I have also tried;
[codebox]Debug.Print owCounter.isObjectInitialized
owCounter.setupContainer owAdapter, "B400000009F6171D"
Debug.Print owCounter.isObjectInitialized
Debug.Print owCounter.readCounter(14)[/codebox]
This returns True to the first Debug.Print, True to the second Debug.Print and throws the error com.dalsemi.onewire.adapter.OneWireIOException: OneWireContainer1D-device not present to the third Debug.Print even though the devices IS present AND shows up in the device list routine.

Feels like I'm getting closer, but not much.
 
I took down my electric meter counter for a few minutes so I could debug and test it.
This works for me. Copied from VB and pasted directly here.
Its pretty much the same as your last post.
Double check your Dims and that "B400000009F6171D" is really your DS2423 ID.


Sub Main()

Const counterid = "D600000009F44D1D" ' put your ds2423 ID here

Dim owaccess As OneWireAccessProvider
Dim owadapter As Object ' DSPortAdapter
Dim owc1d As OneWireContainer1D

Set owaccess = New owapi.OneWireAccessProvider
Set owadapter = owaccess.getDefaultAdapter()

Set owc1d = New OneWireContainer1D
owc1d.setupContainer owadapter, counterid

MsgBox owc1d.readCounter(14)

End Sub


FWIW, this stuff is really screwed up in VB. No wonder you're frustrated. VB has strict type checking that's hard to get around and that's why VB is throwing errors for stuff like
dim owc as onewirecontainer
set owc = owa.getdevicecontainer(id)
when logically it shouldn't.
Add that to the fact that its really an interface to Java and you've got a real rat-fxxx-fest.


When I asked about what you were doing, you said "The water level measurement is based on this article", but the "article" link doesn't seem to go anywhere.
 
sda,

I used your code verbatim and still couldn't get it to work at first.
Then I remembered I'd turned off the 5v supply to Vbat while I made a coffee, DOH!

It turns out that the DS2423 responds normally without Vbat connected, to all commands except readCounter where it throws the error com.dalsemi.onewire.adapter.OneWireIOException: OneWireContainer1D-device not present even though it can still see the device.

Like you said "a real rat-fxxx-fest"

So thanks again sda, without your help and proof that the code works I would probably have thrown the damn thing out the window.

Don't know why the link didn't work, but this is the address it should have pointed to http://www.edn.com/article/CA63743.html

Here's the article in word format too
View attachment OneWire_Water_Level.doc
 
You're welcome. It was a learning experiece for me too. I learned that OWCOM isn't that great and I'll stick with the TMEX bit twiddling.

The water level gauge is definitely an interesting usage of the counter.
 
Back
Top