Reading DS2406 And DS2423 using TMEX and VB6

Forum about 1-Wire devices.

Reading DS2406 And DS2423 using TMEX and VB6

Postby maeron » Tue Feb 19, 2008 12:59 pm

Hi all,

Im writing a litte class lab for students to program 1 Wire devices from Visual Basic 6. We use TMEX API.

I have some problems with the DS2406. What should I send for setting the switch value? flag = TMAccess(SHandle., ??)

The same code I use for DS2405 does not work on DS2406.

I havn't started on the DS2423 counter yet but I can't find anything (examples or so) on how to acces this device from Visual basic 6.

Any other examples for use with 1 wire devices and Visual Basic 6 and TMEX is very, very, very welcome :)

Best Regards
Maeron
maeron
Starting Member
Starting Member
 
Posts: 12
Joined: February 2008
Location:

Reading DS2406 And DS2423 using TMEX and VB6

Postby Digit » Tue Feb 19, 2008 1:14 pm

Did you try the Software Search Engine?
http://www.maxim-ic.com/products/ibutton/example/
DS2406 + ALL + TMEX + VB gives a result...

For DS2423 i can provide Delphi source, so you can translate that.
But first try the above search on that one to.
User avatar
Digit
Global Moderator
Global Moderator
 
Posts: 3099
Joined: March 2006
Location: Netherlands

Reading DS2406 And DS2423 using TMEX and VB6

Postby maeron » Tue Feb 19, 2008 1:23 pm

Yes I've seen that but that code does not set the switch it just check for it and try to acces its filesystem that generates a error.
maeron
Starting Member
Starting Member
 
Posts: 12
Joined: February 2008
Location:

Reading DS2406 And DS2423 using TMEX and VB6

Postby Digit » Tue Feb 19, 2008 1:28 pm

In that case:
Forum member mhwlng wrote a 1-wire plugin for Girder:
http://www.promixis.com/forums/showthread.php?t=12458
He knows[:)]
User avatar
Digit
Global Moderator
Global Moderator
 
Posts: 3099
Joined: March 2006
Location: Netherlands

Reading DS2406 And DS2423 using TMEX and VB6

Postby maeron » Tue Feb 19, 2008 1:38 pm

Thanx

I will contact him

/M
maeron
Starting Member
Starting Member
 
Posts: 12
Joined: February 2008
Location:

Reading DS2406 And DS2423 using TMEX and VB6

Postby Mhwlng » Tue Feb 19, 2008 2:07 pm

c++ source code is included in above mentioned plugin...

see switch.cpp

I used code from here as an example :

http://sheepdogsoftware.co.uk

Marcel
Mhwlng
Member
Member
 
Posts: 159
Joined: August 2007
Location: Eindhoven, Netherlands

Reading DS2406 And DS2423 using TMEX and VB6

Postby maeron » Tue Feb 19, 2008 2:41 pm

That was fast *smile*

Thanx alot I will check that page ...

And thax again
/Maeron
maeron
Starting Member
Starting Member
 
Posts: 12
Joined: February 2008
Location:

Reading DS2406 And DS2423 using TMEX and VB6

Postby maeron » Tue Feb 19, 2008 4:00 pm

mhwlng,

I found what I was looking for in you C++ code, thanx for sharing.

I will try this tonight and see if I can get it to work :)

/Maeron
maeron
Starting Member
Starting Member
 
Posts: 12
Joined: February 2008
Location:

Reading DS2406 And DS2423 using TMEX and VB6

Postby maeron » Tue Feb 19, 2008 7:05 pm

Hmm I tried to send the following command "flag = TMTouchByte(SHandle, &H1F)" HEX 1F = 31 thay SHOULD set channel a AND B to ON but it does not work

the complete code I tried:

Code: Select all
                        '// Write STATUS command
                        flag = TMTouchByte(SHandle, &H55)
                        CRCByte = &H55
                        CRC16 = TMCRC(1, CRCByte, CRC16, 1)
                   
                        flag = TMTouchByte(SHandle, &H7)
                        CRCByte = &H7
                        CRC16 = TMCRC(1, CRCByte, CRC16, 1)
                   
                        flag = TMTouchByte(SHandle, &H0)
                        CRCByte = &H0
                        CRC16 = TMCRC(1, CRCByte, CRC16, 1)
                       
                        ' 31    00011111  A on  B on  = 001F HEX
                        ' 127   01111111  A off B off = 007F HEX
                        ' 63    00111111  A off B on  = 003F HEX
                        ' 95    01011111  A on  B off = 005F HEX
                   
                        '// Skicka koder om Av Och P
                        flag = TMTouchByte(SHandle, &H1F)
                        CRCByte = &H1F
                        CRC16 = TMCRC(1, CRCByte, CRC16, 1)


What am I doing wrong?

/Maeron
maeron
Starting Member
Starting Member
 
Posts: 12
Joined: February 2008
Location:

Reading DS2406 And DS2423 using TMEX and VB6

Postby Mhwlng » Tue Feb 19, 2008 7:36 pm

<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">What am I doing wrong?
/Maeron
<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">

Sorry, but at the moment, I don't have time to study the 1-wire specifications again and it's too long ago for me to remember exactly how the 1-wire protocol works, from memory...

is it wired correctly ?

your vb example only shows a subset of the complete tmex code (see onewire.cpp, tmex.cpp)

if you perform a device list( see list.cpp) do you see it ?

I know the C++ code works, because I tested it myself with all supported devices. (I used a 6-PIN TSOC 2406 with a led and resistor going from pin 3 to +5V on a breadboard)
I don't remember, if I needed to set output A to 0 or 1 to make the led light up...
Mhwlng
Member
Member
 
Posts: 159
Joined: August 2007
Location: Eindhoven, Netherlands

Reading DS2406 And DS2423 using TMEX and VB6

Postby Digit » Tue Feb 19, 2008 9:53 pm

And i've never done anything with a DS2406...[:I]
So only thing i could do is help you search for possible mistakes in translating to VB. Send me PM if you think that is helpful.
User avatar
Digit
Global Moderator
Global Moderator
 
Posts: 3099
Joined: March 2006
Location: Netherlands

Reading DS2406 And DS2423 using TMEX and VB6

Postby maeron » Tue Feb 19, 2008 11:07 pm

The device is found by the program and it shows up correctly.

Here is the complete function:

Code: Select all

Function SetFlipFlop(S As Integer, RoMID As String, Fam As Integer) As Boolean
'// Start session
    SHandle = -1
    Num = 0
    While (SHandle <= 0)
        SHandle = TMExtendedStartSession(PortNum, PortType, vbNullString)
        Num = Num + 1
        If Num > 50 Then Exit Function  ' This is just to break the function if we cant communicate with the 1 wire bus
    Wend

    'Soo now we have  handle on the 1 Wire bus


'Now we are going to lookup the DS2406 we wanna change
' We are looking for the RomID
If TMFamilySearchSetup(SHandle, state_buffer(0), &H12) = 1 Then
            While TMNext(SHandle, state_buffer(0)) = 1
                '// Read the ROM number
                ROM(0) = 0
                flag = TMRom(SHandle, state_buffer(0), ROM(0))
                '// Check for the correct type
                If ((Fam And &H7F) = (ROM(0) And &H7F)) Then
                '// Create a string out of the ROM number
                    romstr = ""
                    For i = 7 To 0 Step -1
                        If (ROM(i) <= &HF) Then romstr = romstr + "0"
                        romstr = romstr + Hex$(ROM(i))
                    Next i
               
                    If romstr = RoMID Then

'// Write STATUS command
                        flag = TMTouchByte(SHandle, &H55)
                        CRCByte = &H55
                        CRC16 = TMCRC(1, CRCByte, CRC16, 1)
                   
                        flag = TMTouchByte(SHandle, &H7)
                        CRCByte = &H7
                        CRC16 = TMCRC(1, CRCByte, CRC16, 1)
                   
                        flag = TMTouchByte(SHandle, &H0)
                        CRCByte = &H0
                        CRC16 = TMCRC(1, CRCByte, CRC16, 1)
                       
                        ' 31    00011111  A on  B on  = 001F HEX
                        ' 127   01111111  A off B off = 007F HEX
                        ' 63    00111111  A off B on  = 003F HEX
                        ' 95    01011111  A on  B off = 005F HEX
                   
                        '// Send the HARDCODED 00011111 to the Switch
                        flag = TMTouchByte(SHandle, &H1F)
                        CRCByte = &H1F
                        CRC16 = TMCRC(1, CRCByte, CRC16, 1)
   
                    End If
       
                End If
     
            Wend

maeron
Starting Member
Starting Member
 
Posts: 12
Joined: February 2008
Location:

Reading DS2406 And DS2423 using TMEX and VB6

Postby Mhwlng » Tue Feb 19, 2008 11:46 pm

I just tested the plugin in girder with a 6-PIN TSOC 2406 with a led and resistor going from pin 3 to +5V on a breadboard)

and I can confirm :

127 -> led off
31 -> led on

note that you need to apply 5V!
it doesn't work on parasitic power...

(on parasitic power, it still shows up in the device list, though)

Marcel
Mhwlng
Member
Member
 
Posts: 159
Joined: August 2007
Location: Eindhoven, Netherlands

Reading DS2406 And DS2423 using TMEX and VB6

Postby maeron » Wed Feb 20, 2008 7:55 am

Doesn't it work if powered with the DS94940R (The USB)?
What I understood IT could power the 1 wire network.

/Maeron
maeron
Starting Member
Starting Member
 
Posts: 12
Joined: February 2008
Location:

Reading DS2406 And DS2423 using TMEX and VB6

Postby Mhwlng » Wed Feb 20, 2008 10:24 am

only simple devices like DS18S20 temperature sensor work on parasitic power.

other devices can be detected on parasitic power, but the rest of the functionality requires 5V to work reliably...
Mhwlng
Member
Member
 
Posts: 159
Joined: August 2007
Location: Eindhoven, Netherlands

Next

Return to 1-Wire Forum

Who is online

Users browsing this forum: No registered users and 0 guests