1-Wire API for .NET Version 4.00
|
Inherited by ADContainer, ClockContainer, HumidityContainer, PotentiometerContainer, SwitchContainer, and TemperatureContainer.
Public Member Functions | |
byte[] | readDevice () throws OneWireIOException, OneWireException |
Retrieves the 1-Wire device sensor state. | |
void | writeDevice (byte[] state) throws OneWireIOException, OneWireException |
Writes the 1-Wire device sensor state that have been changed by 'set' methods. |
1-Wire sensor interface class for basic sensor operations.
Typically the operations of 1-Wire Sensors are memory mapped so writing to a particular location causes the state to change. To accommodate this type of architecture and reduce the number of 1- Wire operations that need to take place, a 'read-modify-write' technique is used. Each Sensor interface is derived from this super-interface that contain just two methods: readDevice, writeDevice. The read returns a byte array and the write takes a byte array. The byte array is the state of the device. The interfaces that extend this interface have 'get' and 'set' methods that manipulate the byte array. So a OneWireSensor operation is:
Read the sensed level of a SwitchContainer instance 'sw':
byte[] state = sw.readDevice();
if (sw.hasLevelSensing())
{
for (int ch = 0; ch < sw.getNumberChannels(state); ch++)
{
System.out.print("Level for channel " + ch + " is : ");
if (sw.getLevel(ch, state))
System.out.println("HIGH");
else
System.out.println("HIGH");
}
}
else
System.out.println("This SwitchContainer can not sense level");
Set the clock of a ClockContainer instance 'cl':
byte[] state = cl.readDevice();
cl.setClock((new Date().getTime()), state);
cl.setClockRunEnable(true, state);
cl.writeDevice(state);
byte [] readDevice | ( | ) | throws OneWireIOException, OneWireException |
Retrieves the 1-Wire device sensor state.
This state is returned as a byte array. Pass this byte array to the 'get' and 'set' methods. If the device state needs to be changed then call the 'writeDevice' to finalize the changes.
OneWireIOException | on a 1-Wire communication error such as reading an incorrect CRC from a 1-Wire device. This could be caused by a physical interruption in the 1-Wire Network due to shorts or a newly arriving 1-Wire device issuing a 'presence pulse'. |
OneWireException | on a communication or setup error with the 1-Wire adapter |
Implemented in OneWireContainer04, OneWireContainer05, OneWireContainer10, OneWireContainer12, OneWireContainer1C, OneWireContainer1F, OneWireContainer20, OneWireContainer21, OneWireContainer24, OneWireContainer28, OneWireContainer29, OneWireContainer2C, OneWireContainer30, OneWireContainer3A, OneWireContainer41, and OneWireContainer42.
void writeDevice | ( | byte[] | state | ) | throws OneWireIOException, OneWireException |
Writes the 1-Wire device sensor state that have been changed by 'set' methods.
Only the state registers that changed are updated. This is done by referencing a field information appended to the state data.
state | 1-Wire device sensor state |
OneWireIOException | on a 1-Wire communication error such as reading an incorrect CRC from a 1-Wire device. This could be caused by a physical interruption in the 1-Wire Network due to shorts or a newly arriving 1-Wire device issuing a 'presence pulse'. |
OneWireException | on a communication or setup error with the 1-Wire adapter |
Implemented in OneWireContainer04, OneWireContainer05, OneWireContainer10, OneWireContainer12, OneWireContainer1C, OneWireContainer1F, OneWireContainer20, OneWireContainer21, OneWireContainer24, OneWireContainer28, OneWireContainer29, OneWireContainer2C, OneWireContainer30, OneWireContainer3A, OneWireContainer41, and OneWireContainer42.