We highly encourage everyone to use our new Python package which is packed with features. This library is still supported, but is not recommended for new design.
The python script below demonstrates how to communicate with a DS2413, a dual-channel addressable switch IC. You can get one on an easy-to-use breakout board from our friends at Adafruit.
from binhoHostAdapter import binhoHostAdapterfrom time import sleep# change this to your COM portbinhoTesterCommPort ='COM22'print("Opening "+ binhoTesterCommPort +"...")print()for i inrange(3):# create the binhoHostAdapter object binhoTester = binhoHostAdapter.binhoHostAdapter(binhoTesterCommPort)print("Connecting to binho host adapter tester...")print() oneWireIndex =0 binhoTester.setLEDColor('CYAN') binhoTester.setOperationMode(0, '1WIRE')print(binhoTester.begin1WIRE(oneWireIndex, 0, True))print(binhoTester.reset1WIRE(oneWireIndex))print("Looking for a DS2413 on the bus")print(binhoTester.resetSearch1WIRE(oneWireIndex))print(binhoTester.search1WIRE(oneWireIndex))print(binhoTester.getAddress1WIRE(oneWireIndex))defwrite2413(state):print('state orig: '+str(state)) state |=0xfcprint('state now: '+str(state))print('state inv: '+str(~state +256))print('write2413 func begin')print(binhoTester.reset1WIRE(oneWireIndex))print(binhoTester.select1WIRE(oneWireIndex))print(binhoTester.writeByte1WIRE(oneWireIndex, 90))print(binhoTester.writeByte1WIRE(oneWireIndex, state))print(binhoTester.writeByte1WIRE(oneWireIndex, ~state +256))print(binhoTester.readByte1WIRE(oneWireIndex))print(binhoTester.readByte1WIRE(oneWireIndex))print(binhoTester.reset1WIRE(oneWireIndex))write2413(3)print('Sleeping for a hot sec ... ')sleep(1.0)print('doing it again...')write2413(0)print('Finished!') binhoTester.close()