Reading DS2406 And DS2423 using TMEX and VB6

Forum about 1-Wire devices.
Mhwlng
Member
Member
Posts: 172
Joined: Sun Aug 26, 2007 4:16 pm
Location: Netherlands

Reading DS2406 And DS2423 using TMEX and VB6

Post by Mhwlng »

I got your code working,

1) you need to perform TMSetup once (see BeginTMEXSession in tmex.cpp)
2) you do need to read the two CRC bytes before the output is switched (see switch.cpp)
3) remember to add +5V

Code: Select all

Function SetFlipFlop(S As Integer, RoMID As String, Fam As Integer) As Boolean

Dim Num As Integer
Dim ROM(8) As Integer
Dim flag As Integer
Dim romstr As String
Dim I As Integer
Dim CRCByte As Byte
Dim CRC16 As Integer
'// 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

  '// check to see if setup needs to be done
  If (Not SetupDone) Then
      flag = TMSetup(SHandle)
      SetupDone = True
  End If



 '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
                                       
                   
'  If (TMStrongAccess(SHandle, state_buffer(0)) = 1) Then
  
'    If (TMAccess(SHandle, state_buffer(0)) = 1) Then
    
                        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, 31)
                        CRCByte = &H1F
                        CRC16 = TMCRC(1, CRCByte, CRC16, 1)
                        
                        flag = TMTouchByte(SHandle, &HFF)
                        CRCByte = flag
                        CRC16 = TMCRC(1, CRCByte, CRC16, 1)
                        
                        flag = TMTouchByte(SHandle, &HFF)
                        CRCByte = flag
                        CRC16 = TMCRC(1, CRCByte, CRC16, 1)
                        
    
 '   End If
 '   End If
                    End If
        
                End If
     
            Wend
  End If
End Function
maeron
Starting Member
Starting Member
Posts: 12
Joined: Tue Feb 19, 2008 12:50 pm

Reading DS2406 And DS2423 using TMEX and VB6

Post by maeron »

Alright thanx alot,

But I don't understand why we need to read two additional bytes, but if we need to do that we gotta do that *smile*

I will try when I get the +5V powered in *smile*

And thanx again for all

/Maeron
Post Reply

Return to “1-Wire Forum”