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