public static short ReadBit() { // Send the byte and get back what was sent var result = TMEX.TMTouchBit(_session.SessionHandle, 0xFF); // Return the result return(result); }
public static void Access() { // Attempt to access the device var result = TMEX.TMAccess(_session.SessionHandle, _session.StateBuffer); // Check to see if we could access the device if (result != 1) { // Throw an access exception throw new OneWireException(OneWireException.ExceptionFunction.Access, _lastId, result); } }
public static short SendBit(short output) { // Send the byte and get back what was sent var result = TMEX.TMTouchBit(_session.SessionHandle, output); // Check that the value was sent correctly if (result != output) { // Throw an exception throw new OneWireException(OneWireException.ExceptionFunction.SendBit, _lastId); } // Return the result return(result); }
public static short SendBlock(byte[] data, short byteCount, bool reset) { // Send the block and return the result var result = reset ? TMEX.TMBlockStream(_session.SessionHandle, data, byteCount) : TMEX.TMBlockIO(_session.SessionHandle, data, byteCount); // Check to see if the bytes sent matches the value returned if (result != byteCount) { // Throw an access exception throw new OneWireException(OneWireException.ExceptionFunction.SendBlock, _lastId, result); } // Return the result return(result); }
public static short SetLevel(TMEX.LevelOperation nOperation, TMEX.LevelMode nLevelMode, TMEX.LevelPrime nPrimed) { // Set the level var result = TMEX.TMOneWireLevel(_session.SessionHandle, TMEX.LevelOperation.Write, TMEX.LevelMode.Normal, TMEX.LevelPrime.Immediate); // Check the result if (result < 0) { // Throw an exception throw new OneWireException(OneWireException.ExceptionFunction.SetLevel, result); } // Return the result return(result); }
public static void Select(Identifier id) { // Set the ID of the device we want to talk to var result = TMEX.TMRom(_session.SessionHandle, _session.StateBuffer, id.RawId); // Check the result if (result != 1) { // Throw a ROM exception throw new OneWireException(OneWireException.ExceptionFunction.Select, id, result); } // Copy the ID as the last selected ID _lastId = id; // Access the device Access(); }
private void AddWeatherDevice(Device device) { // TODO - Handle device mapping for multiple devices that use the same family code switch (device.Family) { case 0x12: TMEX.FileEntry fileEntry = new TMEX.FileEntry(); // Entry to describe a file byte[] fileData = new byte[8]; // File data Identifier deviceID; // Identifier for the other device // Select this device Adapter.Select(device.Id); // Setup to try to open the pressure sensor file fileEntry.Name = System.Text.Encoding.ASCII.GetBytes("8570"); fileEntry.Extension = 0; // Try to open the file short fileHandle = TMEX.TMOpenFile(OneWireSession.SessionHandle, OneWireSession.StateBuffer, ref fileEntry); // If a file was found then try to read it if (fileHandle >= 0) { // Read the file to get the ID of the other device TMEX.TMReadFile(OneWireSession.SessionHandle, OneWireSession.StateBuffer, fileHandle, fileData, (short)fileData.Length); // Close the file TMEX.TMCloseFile(OneWireSession.SessionHandle, OneWireSession.StateBuffer, fileHandle); // Create an ID so we can get the string name deviceID = new Identifier(fileData); // Find the other device Device otherDevice = (Device)OneWireSession.Network.Devices[deviceID.Name]; // Create a new pressure device and it to the the list Devices.Add(new PressureDevice(this, device, otherDevice)); } break; case 0x10: // Create a new temperature device and add it to the list Devices.Add(new TemperatureDevice(this, device)); break; case 0x1D: if (device.Id.Name == "4000000004A4081D") { // Create a new rain device and add it to the list Devices.Add(new RainDevice(this, device)); } else { // Create a new wind speed device and add it to the list Devices.Add(new WindSpeedDevice(this, device)); } break; case 0x20: // Create a new wind direction device and add it to the list Devices.Add(new WindDirectionDevice(this, device)); break; case 0x26: // Create a new humidity device and add it to the list Devices.Add(new HumidityDevice(this, device)); break; } }
public static short Reset() { // Reset all devices return(TMEX.TMTouchReset(_session.SessionHandle)); }