File and class renaming

This commit is contained in:
2015-01-16 18:06:47 -05:00
parent 47db415506
commit be11e8c8cb
17 changed files with 178 additions and 228 deletions

View File

@@ -1,17 +1,17 @@
namespace OneWireAPI namespace OneWireAPI
{ {
public class owAdapter public class Adapter
{ {
private static owSession _session; private static Session _session;
private static owIdentifier _lastId; private static Identifier _lastId;
public static void Initialize(owSession session) public static void Initialize(Session session)
{ {
// Store the session we are dealing with // Store the session we are dealing with
_session = session; _session = session;
} }
public static void Select(owIdentifier id) public static void Select(Identifier id)
{ {
// Set the ID of the device we want to talk to // Set the ID of the device we want to talk to
var result = TMEX.TMRom(_session.SessionHandle, _session.StateBuffer, id.RawId); var result = TMEX.TMRom(_session.SessionHandle, _session.StateBuffer, id.RawId);
@@ -20,7 +20,7 @@ namespace OneWireAPI
if (result != 1) if (result != 1)
{ {
// Throw a ROM exception // Throw a ROM exception
throw new owException(owException.ExceptionFunction.Select, id, result); throw new OneWireException(OneWireException.ExceptionFunction.Select, id, result);
} }
// Copy the ID as the last selected ID // Copy the ID as the last selected ID
@@ -39,7 +39,7 @@ namespace OneWireAPI
if (result != 1) if (result != 1)
{ {
// Throw an access exception // Throw an access exception
throw new owException(owException.ExceptionFunction.Access, _lastId, result); throw new OneWireException(OneWireException.ExceptionFunction.Access, _lastId, result);
} }
} }
@@ -52,7 +52,7 @@ namespace OneWireAPI
if (result != byteCount) if (result != byteCount)
{ {
// Throw an access exception // Throw an access exception
throw new owException(owException.ExceptionFunction.SendBlock, _lastId, result); throw new OneWireException(OneWireException.ExceptionFunction.SendBlock, _lastId, result);
} }
// Return the result // Return the result
@@ -68,7 +68,7 @@ namespace OneWireAPI
if (result != byteCount) if (result != byteCount)
{ {
// Throw an access exception // Throw an access exception
throw new owException(owException.ExceptionFunction.SendBlock, _lastId, result); throw new OneWireException(OneWireException.ExceptionFunction.SendBlock, _lastId, result);
} }
// Return the result // Return the result
@@ -93,7 +93,7 @@ namespace OneWireAPI
if (result != output) if (result != output)
{ {
// Throw an exception // Throw an exception
throw new owException(owException.ExceptionFunction.SendBit, _lastId); throw new OneWireException(OneWireException.ExceptionFunction.SendBit, _lastId);
} }
// Return the result // Return the result
@@ -124,7 +124,7 @@ namespace OneWireAPI
if (result != output) if (result != output)
{ {
// Throw an exception // Throw an exception
throw new owException(owException.ExceptionFunction.SendByte, _lastId); throw new OneWireException(OneWireException.ExceptionFunction.SendByte, _lastId);
} }
// Return the result // Return the result
@@ -140,7 +140,7 @@ namespace OneWireAPI
if (result < 0) if (result < 0)
{ {
// Throw an exception // Throw an exception
throw new owException(owException.ExceptionFunction.SetLevel, result); throw new OneWireException(OneWireException.ExceptionFunction.SetLevel, result);
} }
// Return the result // Return the result

View File

@@ -1,6 +1,6 @@
namespace OneWireAPI namespace OneWireAPI
{ {
internal class owCRC16 internal class Crc16
{ {
private static readonly short[] OddParity = { 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0 }; private static readonly short[] OddParity = { 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0 };

View File

@@ -1,10 +1,10 @@
namespace OneWireAPI namespace OneWireAPI
{ {
internal class owCRC8 internal class Crc8
{ {
private static byte[] _dataTable; // Lookup table of CRC8 values private static byte[] _dataTable; // Lookup table of CRC8 values
static owCRC8() static Crc8()
{ {
// Initialize the CRC lookup table // Initialize the CRC lookup table
InitializeCrcTable(); InitializeCrcTable();

View File

@@ -1,20 +1,20 @@
namespace OneWireAPI namespace OneWireAPI
{ {
public class owDevice public class Device
{ {
protected owSession Session; protected Session Session;
protected owIdentifier DeviceId; protected Identifier DeviceId;
public owDevice(owSession session, short[] rawId) public Device(Session session, short[] rawId)
{ {
// Store the session // Store the session
Session = session; Session = session;
// Create a new identifier and give it the ID supplied // Create a new identifier and give it the ID supplied
DeviceId = new owIdentifier(rawId); DeviceId = new Identifier(rawId);
} }
public owIdentifier Id public Identifier Id
{ {
get { return DeviceId; } get { return DeviceId; }
} }

View File

@@ -1,8 +1,8 @@
namespace OneWireAPI namespace OneWireAPI
{ {
public class owDeviceFamily10 : owDevice public class DeviceFamily10 : Device
{ {
public owDeviceFamily10(owSession session, short[] id) public DeviceFamily10(Session session, short[] id)
: base(session, id) : base(session, id)
{ {
// Just call the base constructor // Just call the base constructor
@@ -11,20 +11,20 @@ namespace OneWireAPI
public double GetTemperature() public double GetTemperature()
{ {
// Select and access the ID of the device we want to talk to // Select and access the ID of the device we want to talk to
owAdapter.Select(DeviceId); Adapter.Select(DeviceId);
// Setup for for power delivery after the next byte // Setup for for power delivery after the next byte
owAdapter.SetLevel(TMEX.LevelOperation.Write, TMEX.LevelMode.StrongPullup, TMEX.LevelPrime.AfterNextByte); Adapter.SetLevel(TMEX.LevelOperation.Write, TMEX.LevelMode.StrongPullup, TMEX.LevelPrime.AfterNextByte);
try try
{ {
// Send the byte and start strong pullup // Send the byte and start strong pullup
owAdapter.SendByte(0x44); Adapter.SendByte(0x44);
} }
catch catch
{ {
// Stop the strong pullup // Stop the strong pullup
owAdapter.SetLevel(TMEX.LevelOperation.Write, TMEX.LevelMode.Normal, TMEX.LevelPrime.Immediate); Adapter.SetLevel(TMEX.LevelOperation.Write, TMEX.LevelMode.Normal, TMEX.LevelPrime.Immediate);
// Re-throw the exception // Re-throw the exception
throw; throw;
@@ -34,10 +34,10 @@ namespace OneWireAPI
System.Threading.Thread.Sleep(1000); System.Threading.Thread.Sleep(1000);
// Stop the strong pullup // Stop the strong pullup
owAdapter.SetLevel(TMEX.LevelOperation.Write, TMEX.LevelMode.Normal, TMEX.LevelPrime.Immediate); Adapter.SetLevel(TMEX.LevelOperation.Write, TMEX.LevelMode.Normal, TMEX.LevelPrime.Immediate);
// Access the device we want to talk to // Access the device we want to talk to
owAdapter.Access(); Adapter.Access();
// Data buffer to send over the network // Data buffer to send over the network
var data = new byte[30]; var data = new byte[30];
@@ -53,16 +53,16 @@ namespace OneWireAPI
data[dataCount++] = 0xFF; data[dataCount++] = 0xFF;
// Send the data block and get data back // Send the data block and get data back
owAdapter.SendBlock(data, dataCount); Adapter.SendBlock(data, dataCount);
// Calculate the CRC of the first eight bytes of data // Calculate the CRC of the first eight bytes of data
var crc = owCRC8.Calculate(data, 1, 8); var crc = Crc8.Calculate(data, 1, 8);
// Check to see if our CRC matches the CRC supplied // Check to see if our CRC matches the CRC supplied
if (crc != data[9]) if (crc != data[9])
{ {
// Throw a CRC exception // Throw a CRC exception
throw new owException(owException.ExceptionFunction.Crc, DeviceId); throw new OneWireException(OneWireException.ExceptionFunction.Crc, DeviceId);
} }
// Get the LSB of the temperature data and divide it by two // Get the LSB of the temperature data and divide it by two

View File

@@ -1,12 +1,12 @@
namespace OneWireAPI namespace OneWireAPI
{ {
public class owDeviceFamily12 : owDevice public class DeviceFamily12 : Device
{ {
private const byte ChannelAccessCommand = 0xF5; private const byte ChannelAccessCommand = 0xF5;
private const byte WriteStatusCommand = 0x55; private const byte WriteStatusCommand = 0x55;
private const byte ReadStatusCommand = 0xAA; private const byte ReadStatusCommand = 0xAA;
public owDeviceFamily12(owSession session, short[] id) public DeviceFamily12(Session session, short[] id)
: base(session, id) : base(session, id)
{ {
// Just call the base constructor // Just call the base constructor
@@ -54,7 +54,7 @@ namespace OneWireAPI
public byte[] ReadDevice() public byte[] ReadDevice()
{ {
// Select and access the ID of the device we want to talk to // Select and access the ID of the device we want to talk to
owAdapter.Select(DeviceId); Adapter.Select(DeviceId);
// Data buffer to send over the network // Data buffer to send over the network
var data = new byte[30]; var data = new byte[30];
@@ -74,10 +74,10 @@ namespace OneWireAPI
data[dataCount++] = 0xFF; data[dataCount++] = 0xFF;
// Send the data // Send the data
owAdapter.SendBlock(data, dataCount); Adapter.SendBlock(data, dataCount);
// Calculate the CRC // Calculate the CRC
var crcResult = owCRC16.Calculate(data, 0, 4); var crcResult = Crc16.Calculate(data, 0, 4);
// Assemble the CRC provided by the device // Assemble the CRC provided by the device
var matchCrc = data[6] << 8; var matchCrc = data[6] << 8;
@@ -88,7 +88,7 @@ namespace OneWireAPI
if (crcResult != matchCrc) if (crcResult != matchCrc)
{ {
// Throw a CRC exception // Throw a CRC exception
throw new owException(owException.ExceptionFunction.Crc, DeviceId); throw new OneWireException(OneWireException.ExceptionFunction.Crc, DeviceId);
} }
var state = new byte[2]; var state = new byte[2];
@@ -111,13 +111,13 @@ namespace OneWireAPI
data[dataCount++] = 0xFF; data[dataCount++] = 0xFF;
// Select and access the ID of the device we want to talk to // Select and access the ID of the device we want to talk to
owAdapter.Select(DeviceId); Adapter.Select(DeviceId);
// Send the data // Send the data
owAdapter.SendBlock(data, dataCount); Adapter.SendBlock(data, dataCount);
// Calculate the CRC // Calculate the CRC
crcResult = owCRC16.Calculate(data, 0, 3); crcResult = Crc16.Calculate(data, 0, 3);
// Assemble the CRC provided by the device // Assemble the CRC provided by the device
matchCrc = data[5] << 8; matchCrc = data[5] << 8;
@@ -128,7 +128,7 @@ namespace OneWireAPI
if (crcResult != matchCrc) if (crcResult != matchCrc)
{ {
// Throw a CRC exception // Throw a CRC exception
throw new owException(owException.ExceptionFunction.Crc, DeviceId); throw new OneWireException(OneWireException.ExceptionFunction.Crc, DeviceId);
} }
// Store the state data // Store the state data
@@ -140,7 +140,7 @@ namespace OneWireAPI
public void WriteDevice(byte[] state) public void WriteDevice(byte[] state)
{ {
// Select and access the ID of the device we want to talk to // Select and access the ID of the device we want to talk to
owAdapter.Select(DeviceId); Adapter.Select(DeviceId);
// Data buffer to send over the network // Data buffer to send over the network
var data = new byte[30]; var data = new byte[30];
@@ -163,10 +163,10 @@ namespace OneWireAPI
data[dataCount++] = 0xFF; data[dataCount++] = 0xFF;
// Send the data // Send the data
owAdapter.SendBlock(data, dataCount); Adapter.SendBlock(data, dataCount);
// Calculate the CRC // Calculate the CRC
var crcResult = owCRC16.Calculate(data, 0, 3); var crcResult = Crc16.Calculate(data, 0, 3);
// Assemble the CRC provided by the device // Assemble the CRC provided by the device
var matchCrc = data[5] << 8; var matchCrc = data[5] << 8;
@@ -177,7 +177,7 @@ namespace OneWireAPI
if (crcResult != matchCrc) if (crcResult != matchCrc)
{ {
// Throw a CRC exception // Throw a CRC exception
throw new owException(owException.ExceptionFunction.Crc, DeviceId); throw new OneWireException(OneWireException.ExceptionFunction.Crc, DeviceId);
} }
} }
} }

View File

@@ -1,8 +1,8 @@
namespace OneWireAPI namespace OneWireAPI
{ {
public class owDeviceFamily1D : owDevice public class DeviceFamily1D : Device
{ {
public owDeviceFamily1D(owSession session, short[] id) public DeviceFamily1D(Session session, short[] id)
: base(session, id) : base(session, id)
{ {
// Just call the base constructor // Just call the base constructor
@@ -11,7 +11,7 @@ namespace OneWireAPI
public uint GetCounter(int counterPage) public uint GetCounter(int counterPage)
{ {
// Select and access the ID of the device we want to talk to // Select and access the ID of the device we want to talk to
owAdapter.Select(DeviceId); Adapter.Select(DeviceId);
// Data buffer to send over the network // Data buffer to send over the network
var data = new byte[30]; var data = new byte[30];
@@ -35,10 +35,10 @@ namespace OneWireAPI
for (var i = 0; i < 11; i++) data[dataCount++] = 0xFF; for (var i = 0; i < 11; i++) data[dataCount++] = 0xFF;
// Send the block of data to the device // Send the block of data to the device
owAdapter.SendBlock(data, dataCount); Adapter.SendBlock(data, dataCount);
// Calculate the CRC based on the data // Calculate the CRC based on the data
var crcResult = owCRC16.Calculate(data, 0, 11); var crcResult = Crc16.Calculate(data, 0, 11);
// Assemble the CRC provided by the device // Assemble the CRC provided by the device
var matchCrc = data[13] << 8; var matchCrc = data[13] << 8;
@@ -49,7 +49,7 @@ namespace OneWireAPI
if (crcResult != matchCrc) if (crcResult != matchCrc)
{ {
// Throw a CRC exception // Throw a CRC exception
throw new owException(owException.ExceptionFunction.Crc, DeviceId); throw new OneWireException(OneWireException.ExceptionFunction.Crc, DeviceId);
} }
uint counter = 0; uint counter = 0;

View File

@@ -1,6 +1,6 @@
namespace OneWireAPI namespace OneWireAPI
{ {
public class owDeviceFamily20 : owDevice public class DeviceFamily20 : Device
{ {
private readonly byte[] _control = new byte[16]; private readonly byte[] _control = new byte[16];
@@ -16,7 +16,7 @@ namespace OneWireAPI
SixteenBits = 0x00 SixteenBits = 0x00
} }
public owDeviceFamily20(owSession session, short[] id) public DeviceFamily20(Session session, short[] id)
: base(session, id) : base(session, id)
{ {
} }
@@ -53,7 +53,7 @@ namespace OneWireAPI
data[dataCount++] = (startAddress >> 8) & 0xFF; data[dataCount++] = (startAddress >> 8) & 0xFF;
// Select and access the ID of the device we want to talk to // Select and access the ID of the device we want to talk to
owAdapter.Select(DeviceId); Adapter.Select(DeviceId);
// Write to the data pages specified // Write to the data pages specified
for (var index = startAddress; index <= endAddress; index++) for (var index = startAddress; index <= endAddress; index++)
@@ -69,13 +69,13 @@ namespace OneWireAPI
data[dataCount++] = 0xFF; data[dataCount++] = 0xFF;
// Send the block // Send the block
owAdapter.SendBlock(data, dataCount); Adapter.SendBlock(data, dataCount);
// If the check byte doesn't match then throw an exception // If the check byte doesn't match then throw an exception
if (data[dataCount - 1] != _control[index - startAddress]) if (data[dataCount - 1] != _control[index - startAddress])
{ {
// Throw an exception // Throw an exception
throw new owException(owException.ExceptionFunction.SendBlock, DeviceId); throw new OneWireException(OneWireException.ExceptionFunction.SendBlock, DeviceId);
} }
int calculatedCrc; // CRC we calculated from sent data int calculatedCrc; // CRC we calculated from sent data
@@ -85,7 +85,7 @@ namespace OneWireAPI
if (index == startAddress) if (index == startAddress)
{ {
// Calculate the CRC16 of the data sent // Calculate the CRC16 of the data sent
calculatedCrc = owCRC16.Calculate(data, 0, 3); calculatedCrc = Crc16.Calculate(data, 0, 3);
// Reconstruct the CRC sent by the device // Reconstruct the CRC sent by the device
sentCrc = data[dataCount - 2] << 8; sentCrc = data[dataCount - 2] << 8;
@@ -95,7 +95,7 @@ namespace OneWireAPI
else else
{ {
// Calculate the CRC16 of the data sent // Calculate the CRC16 of the data sent
calculatedCrc = owCRC16.Calculate(_control[index - startAddress], index); calculatedCrc = Crc16.Calculate(_control[index - startAddress], index);
// Reconstruct the CRC sent by the device // Reconstruct the CRC sent by the device
sentCrc = data[dataCount - 2] << 8; sentCrc = data[dataCount - 2] << 8;
@@ -107,7 +107,7 @@ namespace OneWireAPI
if (calculatedCrc != sentCrc) if (calculatedCrc != sentCrc)
{ {
// Throw a CRC exception // Throw a CRC exception
throw new owException(owException.ExceptionFunction.Crc, DeviceId); throw new OneWireException(OneWireException.ExceptionFunction.Crc, DeviceId);
} }
// Reset the byte count // Reset the byte count
@@ -118,7 +118,7 @@ namespace OneWireAPI
public double[] GetVoltages() public double[] GetVoltages()
{ {
// Select and access the ID of the device we want to talk to // Select and access the ID of the device we want to talk to
owAdapter.Select(DeviceId); Adapter.Select(DeviceId);
// Data buffer to send over the network // Data buffer to send over the network
var data = new byte[30]; var data = new byte[30];
@@ -140,10 +140,10 @@ namespace OneWireAPI
data[dataCount++] = 0xFF; data[dataCount++] = 0xFF;
// Send the data block // Send the data block
owAdapter.SendBlock(data, dataCount); Adapter.SendBlock(data, dataCount);
// Calculate the CRC based on the transmit buffer // Calculate the CRC based on the transmit buffer
var calculatedCrc = owCRC16.Calculate(data, 0, 2); var calculatedCrc = Crc16.Calculate(data, 0, 2);
// Reconstruct the CRC sent by the device // Reconstruct the CRC sent by the device
var sentCrc = data[4] << 8; var sentCrc = data[4] << 8;
@@ -154,23 +154,23 @@ namespace OneWireAPI
if (calculatedCrc != sentCrc) if (calculatedCrc != sentCrc)
{ {
// Throw a CRC exception // Throw a CRC exception
throw new owException(owException.ExceptionFunction.Crc, DeviceId); throw new OneWireException(OneWireException.ExceptionFunction.Crc, DeviceId);
} }
// Setup for for power delivery after the next byte // Setup for for power delivery after the next byte
owAdapter.SetLevel(TMEX.LevelOperation.Write, TMEX.LevelMode.StrongPullup, TMEX.LevelPrime.AfterNextByte); Adapter.SetLevel(TMEX.LevelOperation.Write, TMEX.LevelMode.StrongPullup, TMEX.LevelPrime.AfterNextByte);
var nTransmitByte = (short) ((dataCount - 1) & 0x1F); var nTransmitByte = (short) ((dataCount - 1) & 0x1F);
try try
{ {
// Send the byte and start strong pullup // Send the byte and start strong pullup
owAdapter.SendByte(nTransmitByte); Adapter.SendByte(nTransmitByte);
} }
catch catch
{ {
// Stop the strong pullup // Stop the strong pullup
owAdapter.SetLevel(TMEX.LevelOperation.Write, TMEX.LevelMode.Normal, TMEX.LevelPrime.Immediate); Adapter.SetLevel(TMEX.LevelOperation.Write, TMEX.LevelMode.Normal, TMEX.LevelPrime.Immediate);
// Re-throw the exception // Re-throw the exception
throw; throw;
@@ -180,13 +180,13 @@ namespace OneWireAPI
System.Threading.Thread.Sleep(6); System.Threading.Thread.Sleep(6);
// Stop the strong pullup // Stop the strong pullup
owAdapter.SetLevel(TMEX.LevelOperation.Write, TMEX.LevelMode.Normal, TMEX.LevelPrime.Immediate); Adapter.SetLevel(TMEX.LevelOperation.Write, TMEX.LevelMode.Normal, TMEX.LevelPrime.Immediate);
// Read data to see if the conversion is over // Read data to see if the conversion is over
owAdapter.ReadByte(); Adapter.ReadByte();
// Select and access the ID of the device we want to talk to // Select and access the ID of the device we want to talk to
owAdapter.Select(DeviceId); Adapter.Select(DeviceId);
// Reinitialize the data count // Reinitialize the data count
dataCount = 0; dataCount = 0;
@@ -203,10 +203,10 @@ namespace OneWireAPI
data[dataCount++] = 0xFF; data[dataCount++] = 0xFF;
// Send the block to the device // Send the block to the device
owAdapter.SendBlock(data, dataCount); Adapter.SendBlock(data, dataCount);
// Calculate the CRC of the transmitted data // Calculate the CRC of the transmitted data
calculatedCrc = owCRC16.Calculate(data, 0, 10); calculatedCrc = Crc16.Calculate(data, 0, 10);
// Reconstruct the CRC sent by the device // Reconstruct the CRC sent by the device
sentCrc = data[dataCount - 1] << 8; sentCrc = data[dataCount - 1] << 8;
@@ -217,7 +217,7 @@ namespace OneWireAPI
if (calculatedCrc != sentCrc) if (calculatedCrc != sentCrc)
{ {
// Throw a CRC exception // Throw a CRC exception
throw new owException(owException.ExceptionFunction.Crc, DeviceId); throw new OneWireException(OneWireException.ExceptionFunction.Crc, DeviceId);
} }
// Voltage values to return // Voltage values to return

View File

@@ -1,8 +1,8 @@
namespace OneWireAPI namespace OneWireAPI
{ {
public class owDeviceFamily26 : owDevice public class DeviceFamily26 : Device
{ {
public owDeviceFamily26(owSession session, short[] id) public DeviceFamily26(Session session, short[] id)
: base(session, id) : base(session, id)
{ {
// Just call the base constructor // Just call the base constructor
@@ -19,7 +19,7 @@ namespace OneWireAPI
short busy; short busy;
// Select and access the ID of the device we want to talk to // Select and access the ID of the device we want to talk to
owAdapter.Select(DeviceId); Adapter.Select(DeviceId);
// Data buffer to send over the network // Data buffer to send over the network
var data = new byte[30]; var data = new byte[30];
@@ -34,13 +34,13 @@ namespace OneWireAPI
data[dataCount++] = 0x00; data[dataCount++] = 0x00;
// Send the data block // Send the data block
owAdapter.SendBlock(data, dataCount); Adapter.SendBlock(data, dataCount);
// Clear the data count // Clear the data count
dataCount = 0; dataCount = 0;
// Access the device we want to talk to // Access the device we want to talk to
owAdapter.Access(); Adapter.Access();
// Set the command to read the scratchpad // Set the command to read the scratchpad
data[dataCount++] = 0xBE; data[dataCount++] = 0xBE;
@@ -53,23 +53,23 @@ namespace OneWireAPI
data[dataCount++] = 0xFF; data[dataCount++] = 0xFF;
// Send the data block // Send the data block
owAdapter.SendBlock(data, dataCount); Adapter.SendBlock(data, dataCount);
// Calculate the CRC of the scratchpad data // Calculate the CRC of the scratchpad data
var crc = owCRC8.Calculate(data, 2, 9); var crc = Crc8.Calculate(data, 2, 9);
// If the CRC doesn't match then throw an exception // If the CRC doesn't match then throw an exception
if (crc != data[10]) if (crc != data[10])
{ {
// Throw a CRC exception // Throw a CRC exception
throw new owException(owException.ExceptionFunction.Crc, DeviceId); throw new OneWireException(OneWireException.ExceptionFunction.Crc, DeviceId);
} }
// TODO - Check if we really need to change the input selector // TODO - Check if we really need to change the input selector
if (true) if (true)
{ {
// Access the device we want to talk to // Access the device we want to talk to
owAdapter.Access(); Adapter.Access();
// Reset the data count // Reset the data count
dataCount = 0; dataCount = 0;
@@ -91,13 +91,13 @@ namespace OneWireAPI
data[dataCount++] = data[index + 4]; data[dataCount++] = data[index + 4];
// Send the data block // Send the data block
owAdapter.SendBlock(data, dataCount); Adapter.SendBlock(data, dataCount);
// Reset the data count // Reset the data count
dataCount = 0; dataCount = 0;
// Access the device we want to talk to // Access the device we want to talk to
owAdapter.Access(); Adapter.Access();
// Set the command to copy the scratchpad // Set the command to copy the scratchpad
data[dataCount++] = 0x48; data[dataCount++] = 0x48;
@@ -106,26 +106,26 @@ namespace OneWireAPI
data[dataCount++] = 0x00; data[dataCount++] = 0x00;
// Send the data block // Send the data block
owAdapter.SendBlock(data, dataCount); Adapter.SendBlock(data, dataCount);
// Loop until the data copy is complete // Loop until the data copy is complete
do do
{ {
busy = owAdapter.ReadByte(); busy = Adapter.ReadByte();
} }
while (busy == 0); while (busy == 0);
} }
// Access the device we want to talk to // Access the device we want to talk to
owAdapter.Access(); Adapter.Access();
// Send the voltage conversion command // Send the voltage conversion command
owAdapter.SendByte(0xB4); Adapter.SendByte(0xB4);
// Loop until conversion is complete // Loop until conversion is complete
do do
{ {
busy = owAdapter.ReadByte(); busy = Adapter.ReadByte();
} }
while (busy == 0); while (busy == 0);
@@ -139,16 +139,16 @@ namespace OneWireAPI
data[dataCount++] = 0x00; data[dataCount++] = 0x00;
// Access the device we want to talk to // Access the device we want to talk to
owAdapter.Access(); Adapter.Access();
// Send the data block // Send the data block
owAdapter.SendBlock(data, dataCount); Adapter.SendBlock(data, dataCount);
// Clear the data count // Clear the data count
dataCount = 0; dataCount = 0;
// Access the device we want to talk to // Access the device we want to talk to
owAdapter.Access(); Adapter.Access();
// Set the command to read the scratchpad // Set the command to read the scratchpad
data[dataCount++] = 0xBE; data[dataCount++] = 0xBE;
@@ -161,16 +161,16 @@ namespace OneWireAPI
data[dataCount++] = 0xFF; data[dataCount++] = 0xFF;
// Send the data block // Send the data block
owAdapter.SendBlock(data, dataCount); Adapter.SendBlock(data, dataCount);
// Calculate the CRC of the scratchpad data // Calculate the CRC of the scratchpad data
crc = owCRC8.Calculate(data, 2, 9); crc = Crc8.Calculate(data, 2, 9);
// If the CRC doesn't match then throw an exception // If the CRC doesn't match then throw an exception
if (crc != data[10]) if (crc != data[10])
{ {
// Throw a CRC exception // Throw a CRC exception
throw new owException(owException.ExceptionFunction.Crc, DeviceId); throw new OneWireException(OneWireException.ExceptionFunction.Crc, DeviceId);
} }
// Assemble the voltage data // Assemble the voltage data
@@ -193,16 +193,16 @@ namespace OneWireAPI
public double GetTemperature() public double GetTemperature()
{ {
// Select and access the ID of the device we want to talk to // Select and access the ID of the device we want to talk to
owAdapter.Select(DeviceId); Adapter.Select(DeviceId);
// Send the conversion command byte // Send the conversion command byte
owAdapter.SendByte(0x44); Adapter.SendByte(0x44);
// Sleep while the data is converted // Sleep while the data is converted
System.Threading.Thread.Sleep(10); System.Threading.Thread.Sleep(10);
// Access the device we want to talk to // Access the device we want to talk to
owAdapter.Access(); Adapter.Access();
// Data buffer to send over the network // Data buffer to send over the network
var data = new byte[30]; var data = new byte[30];
@@ -217,13 +217,13 @@ namespace OneWireAPI
data[dataCount++] = 0x00; data[dataCount++] = 0x00;
// Send the data block // Send the data block
owAdapter.SendBlock(data, dataCount); Adapter.SendBlock(data, dataCount);
// Clear the data count // Clear the data count
dataCount = 0; dataCount = 0;
// Access the device we want to talk to // Access the device we want to talk to
owAdapter.Access(); Adapter.Access();
// Set the command to read the scratchpad // Set the command to read the scratchpad
data[dataCount++] = 0xBE; data[dataCount++] = 0xBE;
@@ -236,16 +236,16 @@ namespace OneWireAPI
data[dataCount++] = 0xFF; data[dataCount++] = 0xFF;
// Send the data block // Send the data block
owAdapter.SendBlock(data, dataCount); Adapter.SendBlock(data, dataCount);
// Calculate the CRC of the scratchpad data // Calculate the CRC of the scratchpad data
var crc = owCRC8.Calculate(data, 2, 9); var crc = Crc8.Calculate(data, 2, 9);
// If the CRC doesn't match then throw an exception // If the CRC doesn't match then throw an exception
if (crc != data[10]) if (crc != data[10])
{ {
// Throw a CRC exception // Throw a CRC exception
throw new owException(owException.ExceptionFunction.Crc, DeviceId); throw new OneWireException(OneWireException.ExceptionFunction.Crc, DeviceId);
} }
// Get the two bytes of temperature data // Get the two bytes of temperature data

View File

@@ -1,11 +1,12 @@
namespace OneWireAPI namespace OneWireAPI
{ {
public class owDeviceFamilyFF : owDevice // ReSharper disable once InconsistentNaming
public class DeviceFamilyFF : Device
{ {
private int _width = 20; private int _width = 20;
private int _height = 4; private int _height = 4;
public owDeviceFamilyFF(owSession session, short[] id) public DeviceFamilyFF(Session session, short[] id)
: base(session, id) : base(session, id)
{ {
// Just call the base constructor // Just call the base constructor
@@ -20,28 +21,28 @@ namespace OneWireAPI
public void SetBackLight(bool state) public void SetBackLight(bool state)
{ {
// Select the device // Select the device
owAdapter.Select(DeviceId); Adapter.Select(DeviceId);
// Set the state of the backlight // Set the state of the backlight
owAdapter.SendByte((short) (state ? 0x8 : 0x7)); Adapter.SendByte((short) (state ? 0x8 : 0x7));
} }
public void SetText(string text) public void SetText(string text)
{ {
// Line number // Line number
var line = 1; var lineNumber = 1;
// Replace any CRLF pairs with just a newline // Replace any CRLF pairs with just a newline
text = text.Replace("\r\n", "\n"); text = text.Replace("\r\n", "\n");
// Split the input string at any newlines // Split the input string at any newlines
var sLines = text.Split("\n".ToCharArray(), _height); var lines = text.Split("\n".ToCharArray(), _height);
// Loop over each line // Loop over each line
foreach (var sLine in sLines) foreach (var line in lines)
{ {
// Set the text of this line // Set the text of this line
SetText(sLine, line++); SetText(line, lineNumber++);
} }
} }
@@ -86,7 +87,7 @@ namespace OneWireAPI
if (_width > 16) if (_width > 16)
{ {
// Select the device // Select the device
owAdapter.Select(DeviceId); Adapter.Select(DeviceId);
// Set the data block to just the first 16 characters // Set the data block to just the first 16 characters
sendData = text.Substring(0, 16); sendData = text.Substring(0, 16);
@@ -105,16 +106,16 @@ namespace OneWireAPI
data[dataCount++] = bChar; data[dataCount++] = bChar;
// Set the block // Set the block
owAdapter.SendBlock(data, dataCount); Adapter.SendBlock(data, dataCount);
// Select the device // Select the device
owAdapter.Select(DeviceId); Adapter.Select(DeviceId);
// Send the scratchpad data to the LCD // Send the scratchpad data to the LCD
owAdapter.SendByte(0x48); Adapter.SendByte(0x48);
// Reset the device // Reset the device
owAdapter.Reset(); Adapter.Reset();
// Increment the memory position // Increment the memory position
memoryPosition += 16; memoryPosition += 16;
@@ -129,7 +130,7 @@ namespace OneWireAPI
} }
// Select the device // Select the device
owAdapter.Select(DeviceId); Adapter.Select(DeviceId);
// Initialize the data array // Initialize the data array
data = new byte[18]; data = new byte[18];
@@ -148,25 +149,25 @@ namespace OneWireAPI
data[dataCount++] = bChar; data[dataCount++] = bChar;
// Set the block // Set the block
owAdapter.SendBlock(data, dataCount); Adapter.SendBlock(data, dataCount);
// Select the device // Select the device
owAdapter.Select(DeviceId); Adapter.Select(DeviceId);
// Send the scratchpad data to the LCD // Send the scratchpad data to the LCD
owAdapter.SendByte(0x48); Adapter.SendByte(0x48);
// Reset the device // Reset the device
owAdapter.Reset(); Adapter.Reset();
} }
public void Clear() public void Clear()
{ {
// Select the device // Select the device
owAdapter.Select(DeviceId); Adapter.Select(DeviceId);
// Clear the display // Clear the display
owAdapter.SendByte(0x49); Adapter.SendByte(0x49);
} }
} }
} }

View File

@@ -2,19 +2,19 @@ using System.Text;
namespace OneWireAPI namespace OneWireAPI
{ {
public class owIdentifier public class Identifier
{ {
private readonly short[] _rawId; // The raw ID array private readonly short[] _rawId; // The raw ID array
private readonly string _friendlyName; // Friendly display name private readonly string _friendlyName; // Friendly display name
private readonly int _familyCode; // Family code private readonly int _familyCode; // Family code
public owIdentifier() public Identifier()
{ {
// Create a blank ID // Create a blank ID
_rawId = new short[8]; _rawId = new short[8];
} }
public owIdentifier(byte[] deviceId) public Identifier(byte[] deviceId)
{ {
// Create a blank ID // Create a blank ID
_rawId = new short[8]; _rawId = new short[8];
@@ -30,7 +30,7 @@ namespace OneWireAPI
_familyCode = _rawId[0]; _familyCode = _rawId[0];
} }
public owIdentifier(short[] deviceId) public Identifier(short[] deviceId)
{ {
// Store the ID supplied // Store the ID supplied
_rawId = deviceId; _rawId = deviceId;

View File

@@ -2,19 +2,19 @@ using System.Collections.Generic;
namespace OneWireAPI namespace OneWireAPI
{ {
public class owNetwork public class Network
{ {
private owSession _session; // Current session private Session _session; // Current session
private Dictionary<string, owDevice> _deviceList; // List of current devices private Dictionary<string, Device> _deviceList; // List of current devices
public owNetwork(owSession session) public Network(Session session)
{ {
_session = session; _session = session;
_deviceList = new Dictionary<string, owDevice>(); _deviceList = new Dictionary<string, Device>();
} }
public delegate void DeviceEventDelegate(owDevice device); public delegate void DeviceEventDelegate(Device device);
public event DeviceEventDelegate DeviceAdded; public event DeviceEventDelegate DeviceAdded;
@@ -36,33 +36,33 @@ namespace OneWireAPI
if (nResult == 1) if (nResult == 1)
{ {
// Get the deviceID // Get the deviceID
var deviceId = new owIdentifier(id); var deviceId = new Identifier(id);
// Create a new device object // Create a new device object
owDevice device; Device device;
switch (deviceId.Family) switch (deviceId.Family)
{ {
case 0x10: case 0x10:
device = new owDeviceFamily10(_session, id); device = new DeviceFamily10(_session, id);
break; break;
case 0x1D: case 0x1D:
device = new owDeviceFamily1D(_session, id); device = new DeviceFamily1D(_session, id);
break; break;
case 0x20: case 0x20:
device = new owDeviceFamily20(_session, id); device = new DeviceFamily20(_session, id);
break; break;
case 0x26: case 0x26:
device = new owDeviceFamily26(_session, id); device = new DeviceFamily26(_session, id);
break; break;
case 0x12: case 0x12:
device = new owDeviceFamily12(_session, id); device = new DeviceFamily12(_session, id);
break; break;
case 0xFF: case 0xFF:
device = new owDeviceFamilyFF(_session, id); device = new DeviceFamilyFF(_session, id);
break; break;
default: default:
device = new owDevice(_session, id); device = new Device(_session, id);
break; break;
} }
@@ -83,7 +83,7 @@ namespace OneWireAPI
} }
} }
public Dictionary<string, owDevice> Devices public Dictionary<string, Device> Devices
{ {
get { return _deviceList; } get { return _deviceList; }
} }

View File

@@ -107,57 +107,51 @@
<Reference Include="System.Core"> <Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework> <RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference> </Reference>
<Reference Include="System.Data">
<Name>System.Data</Name>
</Reference>
<Reference Include="System.Xml">
<Name>System.XML</Name>
</Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs"> <Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="owAdapter.cs"> <Compile Include="Adapter.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="owCRC16.cs"> <Compile Include="Crc16.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="owCRC8.cs"> <Compile Include="Crc8.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="owDevice.cs"> <Compile Include="Device.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="owDeviceFamily10.cs"> <Compile Include="DeviceFamily10.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="owDeviceFamily12.cs"> <Compile Include="DeviceFamily12.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="owDeviceFamily1D.cs"> <Compile Include="DeviceFamily1D.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="owDeviceFamily20.cs"> <Compile Include="DeviceFamily20.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="owDeviceFamily26.cs"> <Compile Include="DeviceFamily26.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="owDeviceFamilyFF.cs"> <Compile Include="DeviceFamilyFF.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="owException.cs"> <Compile Include="OneWireException.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="owIdentifer.cs"> <Compile Include="Identifer.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="owNetwork.cs"> <Compile Include="Network.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="owSession.cs"> <Compile Include="Session.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="TMEX.cs"> <Compile Include="TMEX.cs">

View File

@@ -3,7 +3,7 @@ using System;
namespace OneWireAPI namespace OneWireAPI
{ {
[Serializable] [Serializable]
public class owException : Exception public class OneWireException : Exception
{ {
public enum ExceptionFunction public enum ExceptionFunction
{ {
@@ -20,9 +20,9 @@ namespace OneWireAPI
private readonly int _errorNumber; private readonly int _errorNumber;
private readonly ExceptionFunction _errorFunction; private readonly ExceptionFunction _errorFunction;
private readonly owIdentifier _deviceId; private readonly Identifier _deviceId;
public owException(ExceptionFunction function, int number) public OneWireException(ExceptionFunction function, int number)
{ {
// Store the exception function // Store the exception function
_errorFunction = function; _errorFunction = function;
@@ -31,7 +31,7 @@ namespace OneWireAPI
_errorNumber = number; _errorNumber = number;
} }
public owException(ExceptionFunction function, owIdentifier deviceId) public OneWireException(ExceptionFunction function, Identifier deviceId)
{ {
// Store the exception function // Store the exception function
_errorFunction = function; _errorFunction = function;
@@ -40,7 +40,7 @@ namespace OneWireAPI
_deviceId = deviceId; _deviceId = deviceId;
} }
public owException(ExceptionFunction function, owIdentifier deviceId, int number) public OneWireException(ExceptionFunction function, Identifier deviceId, int number)
{ {
// Store the exception function // Store the exception function
_errorFunction = function; _errorFunction = function;
@@ -52,7 +52,7 @@ namespace OneWireAPI
_errorNumber = number; _errorNumber = number;
} }
public owIdentifier DeviceId public Identifier DeviceId
{ {
get { return _deviceId; } get { return _deviceId; }
} }

View File

@@ -1,11 +1,5 @@
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices;
//
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
//
[assembly: AssemblyTitle("")] [assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")] [assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
@@ -15,44 +9,4 @@ using System.Runtime.CompilerServices;
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
// [assembly: AssemblyVersion("1.0.*")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.410.1323")]
//
// In order to sign your assembly you must specify a key to use. Refer to the
// Microsoft .NET Framework documentation for more information on assembly signing.
//
// Use the attributes below to control which key is used for signing.
//
// Notes:
// (*) If no key is specified, the assembly is not signed.
// (*) KeyName refers to a key that has been installed in the Crypto Service
// Provider (CSP) on your machine. KeyFile refers to a file which contains
// a key.
// (*) If the KeyFile and the KeyName values are both specified, the
// following processing occurs:
// (1) If the KeyName can be found in the CSP, that key is used.
// (2) If the KeyName does not exist and the KeyFile does exist, the key
// in the KeyFile is installed into the CSP and used.
// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
// When specifying the KeyFile, the location of the KeyFile should be
// relative to the project output directory which is
// %Project Directory%\obj\<configuration>. For example, if your KeyFile is
// located in the project directory, you would specify the AssemblyKeyFile
// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
// documentation for more information on this.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]

View File

@@ -3,16 +3,16 @@ using System;
namespace OneWireAPI namespace OneWireAPI
{ {
public class owSession public class Session
{ {
private int _sessionHandle; // Session handle private int _sessionHandle; // Session handle
private owNetwork _network; // Network object private Network _network; // Network object
private readonly short _portNumber; // Port number private readonly short _portNumber; // Port number
private readonly short _portType; // Port type private readonly short _portType; // Port type
private readonly byte[] _stateBuffer; // Global state buffer private readonly byte[] _stateBuffer; // Global state buffer
public owSession() public Session()
{ {
// Create the global state buffer // Create the global state buffer
_stateBuffer = new byte[(int) TMEX.StateBufferSize.NoEpromWriting]; _stateBuffer = new byte[(int) TMEX.StateBufferSize.NoEpromWriting];
@@ -23,7 +23,7 @@ namespace OneWireAPI
Tracer.WriteLine("TMReadDefaultPort - Return: {0}, Port Number: {1}, Port Type: {2}", result, _portNumber, _portType); Tracer.WriteLine("TMReadDefaultPort - Return: {0}, Port Number: {1}, Port Type: {2}", result, _portNumber, _portType);
} }
public owSession(short portNumber, short portType) public Session(short portNumber, short portType)
{ {
// Create the global state buffer // Create the global state buffer
_stateBuffer = new byte[(int) TMEX.StateBufferSize.NoEpromWriting]; _stateBuffer = new byte[(int) TMEX.StateBufferSize.NoEpromWriting];
@@ -48,7 +48,7 @@ namespace OneWireAPI
get { return _sessionHandle; } get { return _sessionHandle; }
} }
public owNetwork Network public Network Network
{ {
get { return _network; } get { return _network; }
} }
@@ -100,13 +100,13 @@ namespace OneWireAPI
} }
// Create the network object and pass ourself as the session // Create the network object and pass ourself as the session
_network = new owNetwork(this); _network = new Network(this);
// Initialize the network // Initialize the network
_network.Initialize(); _network.Initialize();
// Initialize the static adapter code with the session // Initialize the static adapter code with the session
owAdapter.Initialize(this); Adapter.Initialize(this);
return true; return true;
} }

View File

@@ -3,6 +3,7 @@ using System.Runtime.InteropServices;
namespace OneWireAPI namespace OneWireAPI
{ {
// ReSharper disable once InconsistentNaming
public class TMEX public class TMEX
{ {
// Size of the global state buffer // Size of the global state buffer