From be11e8c8cb6be3c5b639112bbcb2d355e5bdf7e3 Mon Sep 17 00:00:00 2001 From: Chris Kaczor Date: Fri, 16 Jan 2015 18:06:47 -0500 Subject: [PATCH] File and class renaming --- owAdapter.cs => Adapter.cs | 24 +++++----- owCRC16.cs => Crc16.cs | 2 +- owCRC8.cs => Crc8.cs | 4 +- owDevice.cs => Device.cs | 12 ++--- owDeviceFamily10.cs => DeviceFamily10.cs | 22 ++++----- owDeviceFamily12.cs => DeviceFamily12.cs | 28 +++++------ owDeviceFamily1D.cs => DeviceFamily1D.cs | 12 ++--- owDeviceFamily20.cs => DeviceFamily20.cs | 42 ++++++++--------- owDeviceFamily26.cs => DeviceFamily26.cs | 60 ++++++++++++------------ owDeviceFamilyFF.cs => DeviceFamilyFF.cs | 41 ++++++++-------- owIdentifer.cs => Identifer.cs | 8 ++-- owNetwork.cs => Network.cs | 38 +++++++-------- OneWireAPI.csproj | 34 ++++++-------- owException.cs => OneWireException.cs | 12 ++--- Properties/AssemblyInfo.cs | 50 +------------------- owSession.cs => Session.cs | 16 +++---- TMEX.cs | 1 + 17 files changed, 178 insertions(+), 228 deletions(-) rename owAdapter.cs => Adapter.cs (81%) rename owCRC16.cs => Crc16.cs (98%) rename owCRC8.cs => Crc8.cs (96%) rename owDevice.cs => Device.cs (58%) rename owDeviceFamily10.cs => DeviceFamily10.cs (75%) rename owDeviceFamily12.cs => DeviceFamily12.cs (84%) rename owDeviceFamily1D.cs => DeviceFamily1D.cs (84%) rename owDeviceFamily20.cs => DeviceFamily20.cs (82%) rename owDeviceFamily26.cs => DeviceFamily26.cs (81%) rename owDeviceFamilyFF.cs => DeviceFamilyFF.cs (81%) rename owIdentifer.cs => Identifer.cs (92%) rename owNetwork.cs => Network.cs (69%) rename owException.cs => OneWireException.cs (87%) rename owSession.cs => Session.cs (92%) diff --git a/owAdapter.cs b/Adapter.cs similarity index 81% rename from owAdapter.cs rename to Adapter.cs index dc8f63d..003bc23 100644 --- a/owAdapter.cs +++ b/Adapter.cs @@ -1,17 +1,17 @@ namespace OneWireAPI { - public class owAdapter + public class Adapter { - private static owSession _session; - private static owIdentifier _lastId; + private static Session _session; + private static Identifier _lastId; - public static void Initialize(owSession session) + public static void Initialize(Session session) { // Store the session we are dealing with _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 var result = TMEX.TMRom(_session.SessionHandle, _session.StateBuffer, id.RawId); @@ -20,7 +20,7 @@ namespace OneWireAPI if (result != 1) { // 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 @@ -39,7 +39,7 @@ namespace OneWireAPI if (result != 1) { // 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) { // Throw an access exception - throw new owException(owException.ExceptionFunction.SendBlock, _lastId, result); + throw new OneWireException(OneWireException.ExceptionFunction.SendBlock, _lastId, result); } // Return the result @@ -68,7 +68,7 @@ namespace OneWireAPI if (result != byteCount) { // Throw an access exception - throw new owException(owException.ExceptionFunction.SendBlock, _lastId, result); + throw new OneWireException(OneWireException.ExceptionFunction.SendBlock, _lastId, result); } // Return the result @@ -93,7 +93,7 @@ namespace OneWireAPI if (result != output) { // Throw an exception - throw new owException(owException.ExceptionFunction.SendBit, _lastId); + throw new OneWireException(OneWireException.ExceptionFunction.SendBit, _lastId); } // Return the result @@ -124,7 +124,7 @@ namespace OneWireAPI if (result != output) { // Throw an exception - throw new owException(owException.ExceptionFunction.SendByte, _lastId); + throw new OneWireException(OneWireException.ExceptionFunction.SendByte, _lastId); } // Return the result @@ -140,7 +140,7 @@ namespace OneWireAPI if (result < 0) { // Throw an exception - throw new owException(owException.ExceptionFunction.SetLevel, result); + throw new OneWireException(OneWireException.ExceptionFunction.SetLevel, result); } // Return the result diff --git a/owCRC16.cs b/Crc16.cs similarity index 98% rename from owCRC16.cs rename to Crc16.cs index aa1fe49..9504a24 100644 --- a/owCRC16.cs +++ b/Crc16.cs @@ -1,6 +1,6 @@ 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 }; diff --git a/owCRC8.cs b/Crc8.cs similarity index 96% rename from owCRC8.cs rename to Crc8.cs index df75d8e..9ee19cf 100644 --- a/owCRC8.cs +++ b/Crc8.cs @@ -1,10 +1,10 @@ namespace OneWireAPI { - internal class owCRC8 + internal class Crc8 { private static byte[] _dataTable; // Lookup table of CRC8 values - static owCRC8() + static Crc8() { // Initialize the CRC lookup table InitializeCrcTable(); diff --git a/owDevice.cs b/Device.cs similarity index 58% rename from owDevice.cs rename to Device.cs index a05e2e9..5a53238 100644 --- a/owDevice.cs +++ b/Device.cs @@ -1,20 +1,20 @@ namespace OneWireAPI { - public class owDevice + public class Device { - protected owSession Session; - protected owIdentifier DeviceId; + protected Session Session; + protected Identifier DeviceId; - public owDevice(owSession session, short[] rawId) + public Device(Session session, short[] rawId) { // Store the session Session = session; // 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; } } diff --git a/owDeviceFamily10.cs b/DeviceFamily10.cs similarity index 75% rename from owDeviceFamily10.cs rename to DeviceFamily10.cs index f4b6c1c..9e1e049 100644 --- a/owDeviceFamily10.cs +++ b/DeviceFamily10.cs @@ -1,8 +1,8 @@ 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) { // Just call the base constructor @@ -11,20 +11,20 @@ namespace OneWireAPI public double GetTemperature() { // 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 - owAdapter.SetLevel(TMEX.LevelOperation.Write, TMEX.LevelMode.StrongPullup, TMEX.LevelPrime.AfterNextByte); + Adapter.SetLevel(TMEX.LevelOperation.Write, TMEX.LevelMode.StrongPullup, TMEX.LevelPrime.AfterNextByte); try { // Send the byte and start strong pullup - owAdapter.SendByte(0x44); + Adapter.SendByte(0x44); } catch { // 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 throw; @@ -34,10 +34,10 @@ namespace OneWireAPI System.Threading.Thread.Sleep(1000); // 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 - owAdapter.Access(); + Adapter.Access(); // Data buffer to send over the network var data = new byte[30]; @@ -53,16 +53,16 @@ namespace OneWireAPI data[dataCount++] = 0xFF; // 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 - var crc = owCRC8.Calculate(data, 1, 8); + var crc = Crc8.Calculate(data, 1, 8); // Check to see if our CRC matches the CRC supplied if (crc != data[9]) { // 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 diff --git a/owDeviceFamily12.cs b/DeviceFamily12.cs similarity index 84% rename from owDeviceFamily12.cs rename to DeviceFamily12.cs index 2bfd0fa..7083123 100644 --- a/owDeviceFamily12.cs +++ b/DeviceFamily12.cs @@ -1,12 +1,12 @@ namespace OneWireAPI { - public class owDeviceFamily12 : owDevice + public class DeviceFamily12 : Device { private const byte ChannelAccessCommand = 0xF5; private const byte WriteStatusCommand = 0x55; private const byte ReadStatusCommand = 0xAA; - public owDeviceFamily12(owSession session, short[] id) + public DeviceFamily12(Session session, short[] id) : base(session, id) { // Just call the base constructor @@ -54,7 +54,7 @@ namespace OneWireAPI public byte[] ReadDevice() { // 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 var data = new byte[30]; @@ -74,10 +74,10 @@ namespace OneWireAPI data[dataCount++] = 0xFF; // Send the data - owAdapter.SendBlock(data, dataCount); + Adapter.SendBlock(data, dataCount); // Calculate the CRC - var crcResult = owCRC16.Calculate(data, 0, 4); + var crcResult = Crc16.Calculate(data, 0, 4); // Assemble the CRC provided by the device var matchCrc = data[6] << 8; @@ -88,7 +88,7 @@ namespace OneWireAPI if (crcResult != matchCrc) { // Throw a CRC exception - throw new owException(owException.ExceptionFunction.Crc, DeviceId); + throw new OneWireException(OneWireException.ExceptionFunction.Crc, DeviceId); } var state = new byte[2]; @@ -111,13 +111,13 @@ namespace OneWireAPI data[dataCount++] = 0xFF; // Select and access the ID of the device we want to talk to - owAdapter.Select(DeviceId); + Adapter.Select(DeviceId); // Send the data - owAdapter.SendBlock(data, dataCount); + Adapter.SendBlock(data, dataCount); // Calculate the CRC - crcResult = owCRC16.Calculate(data, 0, 3); + crcResult = Crc16.Calculate(data, 0, 3); // Assemble the CRC provided by the device matchCrc = data[5] << 8; @@ -128,7 +128,7 @@ namespace OneWireAPI if (crcResult != matchCrc) { // Throw a CRC exception - throw new owException(owException.ExceptionFunction.Crc, DeviceId); + throw new OneWireException(OneWireException.ExceptionFunction.Crc, DeviceId); } // Store the state data @@ -140,7 +140,7 @@ namespace OneWireAPI public void WriteDevice(byte[] state) { // 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 var data = new byte[30]; @@ -163,10 +163,10 @@ namespace OneWireAPI data[dataCount++] = 0xFF; // Send the data - owAdapter.SendBlock(data, dataCount); + Adapter.SendBlock(data, dataCount); // Calculate the CRC - var crcResult = owCRC16.Calculate(data, 0, 3); + var crcResult = Crc16.Calculate(data, 0, 3); // Assemble the CRC provided by the device var matchCrc = data[5] << 8; @@ -177,7 +177,7 @@ namespace OneWireAPI if (crcResult != matchCrc) { // Throw a CRC exception - throw new owException(owException.ExceptionFunction.Crc, DeviceId); + throw new OneWireException(OneWireException.ExceptionFunction.Crc, DeviceId); } } } diff --git a/owDeviceFamily1D.cs b/DeviceFamily1D.cs similarity index 84% rename from owDeviceFamily1D.cs rename to DeviceFamily1D.cs index 5301abb..d384b8c 100644 --- a/owDeviceFamily1D.cs +++ b/DeviceFamily1D.cs @@ -1,8 +1,8 @@ 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) { // Just call the base constructor @@ -11,7 +11,7 @@ namespace OneWireAPI public uint GetCounter(int counterPage) { // 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 var data = new byte[30]; @@ -35,10 +35,10 @@ namespace OneWireAPI for (var i = 0; i < 11; i++) data[dataCount++] = 0xFF; // Send the block of data to the device - owAdapter.SendBlock(data, dataCount); + Adapter.SendBlock(data, dataCount); // 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 var matchCrc = data[13] << 8; @@ -49,7 +49,7 @@ namespace OneWireAPI if (crcResult != matchCrc) { // Throw a CRC exception - throw new owException(owException.ExceptionFunction.Crc, DeviceId); + throw new OneWireException(OneWireException.ExceptionFunction.Crc, DeviceId); } uint counter = 0; diff --git a/owDeviceFamily20.cs b/DeviceFamily20.cs similarity index 82% rename from owDeviceFamily20.cs rename to DeviceFamily20.cs index 687313b..2444b4e 100644 --- a/owDeviceFamily20.cs +++ b/DeviceFamily20.cs @@ -1,6 +1,6 @@ namespace OneWireAPI { - public class owDeviceFamily20 : owDevice + public class DeviceFamily20 : Device { private readonly byte[] _control = new byte[16]; @@ -16,7 +16,7 @@ namespace OneWireAPI SixteenBits = 0x00 } - public owDeviceFamily20(owSession session, short[] id) + public DeviceFamily20(Session session, short[] id) : base(session, id) { } @@ -53,7 +53,7 @@ namespace OneWireAPI data[dataCount++] = (startAddress >> 8) & 0xFF; // 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 for (var index = startAddress; index <= endAddress; index++) @@ -69,13 +69,13 @@ namespace OneWireAPI data[dataCount++] = 0xFF; // Send the block - owAdapter.SendBlock(data, dataCount); + Adapter.SendBlock(data, dataCount); // If the check byte doesn't match then throw an exception if (data[dataCount - 1] != _control[index - startAddress]) { // 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 @@ -85,7 +85,7 @@ namespace OneWireAPI if (index == startAddress) { // 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 sentCrc = data[dataCount - 2] << 8; @@ -95,7 +95,7 @@ namespace OneWireAPI else { // 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 sentCrc = data[dataCount - 2] << 8; @@ -107,7 +107,7 @@ namespace OneWireAPI if (calculatedCrc != sentCrc) { // Throw a CRC exception - throw new owException(owException.ExceptionFunction.Crc, DeviceId); + throw new OneWireException(OneWireException.ExceptionFunction.Crc, DeviceId); } // Reset the byte count @@ -118,7 +118,7 @@ namespace OneWireAPI public double[] GetVoltages() { // 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 var data = new byte[30]; @@ -140,10 +140,10 @@ namespace OneWireAPI data[dataCount++] = 0xFF; // Send the data block - owAdapter.SendBlock(data, dataCount); + Adapter.SendBlock(data, dataCount); // 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 var sentCrc = data[4] << 8; @@ -154,23 +154,23 @@ namespace OneWireAPI if (calculatedCrc != sentCrc) { // 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 - 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); try { // Send the byte and start strong pullup - owAdapter.SendByte(nTransmitByte); + Adapter.SendByte(nTransmitByte); } catch { // 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 throw; @@ -180,13 +180,13 @@ namespace OneWireAPI System.Threading.Thread.Sleep(6); // 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 - owAdapter.ReadByte(); + Adapter.ReadByte(); // Select and access the ID of the device we want to talk to - owAdapter.Select(DeviceId); + Adapter.Select(DeviceId); // Reinitialize the data count dataCount = 0; @@ -203,10 +203,10 @@ namespace OneWireAPI data[dataCount++] = 0xFF; // Send the block to the device - owAdapter.SendBlock(data, dataCount); + Adapter.SendBlock(data, dataCount); // 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 sentCrc = data[dataCount - 1] << 8; @@ -217,7 +217,7 @@ namespace OneWireAPI if (calculatedCrc != sentCrc) { // Throw a CRC exception - throw new owException(owException.ExceptionFunction.Crc, DeviceId); + throw new OneWireException(OneWireException.ExceptionFunction.Crc, DeviceId); } // Voltage values to return diff --git a/owDeviceFamily26.cs b/DeviceFamily26.cs similarity index 81% rename from owDeviceFamily26.cs rename to DeviceFamily26.cs index 3e0a505..9888c8d 100644 --- a/owDeviceFamily26.cs +++ b/DeviceFamily26.cs @@ -1,8 +1,8 @@ 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) { // Just call the base constructor @@ -19,7 +19,7 @@ namespace OneWireAPI short busy; // 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 var data = new byte[30]; @@ -34,13 +34,13 @@ namespace OneWireAPI data[dataCount++] = 0x00; // Send the data block - owAdapter.SendBlock(data, dataCount); + Adapter.SendBlock(data, dataCount); // Clear the data count dataCount = 0; // Access the device we want to talk to - owAdapter.Access(); + Adapter.Access(); // Set the command to read the scratchpad data[dataCount++] = 0xBE; @@ -53,23 +53,23 @@ namespace OneWireAPI data[dataCount++] = 0xFF; // Send the data block - owAdapter.SendBlock(data, dataCount); + Adapter.SendBlock(data, dataCount); // 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 (crc != data[10]) { // 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 if (true) { // Access the device we want to talk to - owAdapter.Access(); + Adapter.Access(); // Reset the data count dataCount = 0; @@ -91,13 +91,13 @@ namespace OneWireAPI data[dataCount++] = data[index + 4]; // Send the data block - owAdapter.SendBlock(data, dataCount); + Adapter.SendBlock(data, dataCount); // Reset the data count dataCount = 0; // Access the device we want to talk to - owAdapter.Access(); + Adapter.Access(); // Set the command to copy the scratchpad data[dataCount++] = 0x48; @@ -106,26 +106,26 @@ namespace OneWireAPI data[dataCount++] = 0x00; // Send the data block - owAdapter.SendBlock(data, dataCount); + Adapter.SendBlock(data, dataCount); // Loop until the data copy is complete do { - busy = owAdapter.ReadByte(); + busy = Adapter.ReadByte(); } while (busy == 0); } // Access the device we want to talk to - owAdapter.Access(); + Adapter.Access(); // Send the voltage conversion command - owAdapter.SendByte(0xB4); + Adapter.SendByte(0xB4); // Loop until conversion is complete do { - busy = owAdapter.ReadByte(); + busy = Adapter.ReadByte(); } while (busy == 0); @@ -139,16 +139,16 @@ namespace OneWireAPI data[dataCount++] = 0x00; // Access the device we want to talk to - owAdapter.Access(); + Adapter.Access(); // Send the data block - owAdapter.SendBlock(data, dataCount); + Adapter.SendBlock(data, dataCount); // Clear the data count dataCount = 0; // Access the device we want to talk to - owAdapter.Access(); + Adapter.Access(); // Set the command to read the scratchpad data[dataCount++] = 0xBE; @@ -161,16 +161,16 @@ namespace OneWireAPI data[dataCount++] = 0xFF; // Send the data block - owAdapter.SendBlock(data, dataCount); + Adapter.SendBlock(data, dataCount); // 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 (crc != data[10]) { // Throw a CRC exception - throw new owException(owException.ExceptionFunction.Crc, DeviceId); + throw new OneWireException(OneWireException.ExceptionFunction.Crc, DeviceId); } // Assemble the voltage data @@ -193,16 +193,16 @@ namespace OneWireAPI public double GetTemperature() { // Select and access the ID of the device we want to talk to - owAdapter.Select(DeviceId); + Adapter.Select(DeviceId); // Send the conversion command byte - owAdapter.SendByte(0x44); + Adapter.SendByte(0x44); // Sleep while the data is converted System.Threading.Thread.Sleep(10); // Access the device we want to talk to - owAdapter.Access(); + Adapter.Access(); // Data buffer to send over the network var data = new byte[30]; @@ -217,13 +217,13 @@ namespace OneWireAPI data[dataCount++] = 0x00; // Send the data block - owAdapter.SendBlock(data, dataCount); + Adapter.SendBlock(data, dataCount); // Clear the data count dataCount = 0; // Access the device we want to talk to - owAdapter.Access(); + Adapter.Access(); // Set the command to read the scratchpad data[dataCount++] = 0xBE; @@ -236,16 +236,16 @@ namespace OneWireAPI data[dataCount++] = 0xFF; // Send the data block - owAdapter.SendBlock(data, dataCount); + Adapter.SendBlock(data, dataCount); // 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 (crc != data[10]) { // 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 diff --git a/owDeviceFamilyFF.cs b/DeviceFamilyFF.cs similarity index 81% rename from owDeviceFamilyFF.cs rename to DeviceFamilyFF.cs index b3b4995..a5c2272 100644 --- a/owDeviceFamilyFF.cs +++ b/DeviceFamilyFF.cs @@ -1,11 +1,12 @@ namespace OneWireAPI { - public class owDeviceFamilyFF : owDevice + // ReSharper disable once InconsistentNaming + public class DeviceFamilyFF : Device { private int _width = 20; private int _height = 4; - public owDeviceFamilyFF(owSession session, short[] id) + public DeviceFamilyFF(Session session, short[] id) : base(session, id) { // Just call the base constructor @@ -20,28 +21,28 @@ namespace OneWireAPI public void SetBackLight(bool state) { // Select the device - owAdapter.Select(DeviceId); + Adapter.Select(DeviceId); // Set the state of the backlight - owAdapter.SendByte((short) (state ? 0x8 : 0x7)); + Adapter.SendByte((short) (state ? 0x8 : 0x7)); } public void SetText(string text) { // Line number - var line = 1; + var lineNumber = 1; // Replace any CRLF pairs with just a newline text = text.Replace("\r\n", "\n"); // 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 - foreach (var sLine in sLines) + foreach (var line in lines) { // Set the text of this line - SetText(sLine, line++); + SetText(line, lineNumber++); } } @@ -86,7 +87,7 @@ namespace OneWireAPI if (_width > 16) { // Select the device - owAdapter.Select(DeviceId); + Adapter.Select(DeviceId); // Set the data block to just the first 16 characters sendData = text.Substring(0, 16); @@ -105,16 +106,16 @@ namespace OneWireAPI data[dataCount++] = bChar; // Set the block - owAdapter.SendBlock(data, dataCount); + Adapter.SendBlock(data, dataCount); // Select the device - owAdapter.Select(DeviceId); + Adapter.Select(DeviceId); // Send the scratchpad data to the LCD - owAdapter.SendByte(0x48); + Adapter.SendByte(0x48); // Reset the device - owAdapter.Reset(); + Adapter.Reset(); // Increment the memory position memoryPosition += 16; @@ -129,7 +130,7 @@ namespace OneWireAPI } // Select the device - owAdapter.Select(DeviceId); + Adapter.Select(DeviceId); // Initialize the data array data = new byte[18]; @@ -148,25 +149,25 @@ namespace OneWireAPI data[dataCount++] = bChar; // Set the block - owAdapter.SendBlock(data, dataCount); + Adapter.SendBlock(data, dataCount); // Select the device - owAdapter.Select(DeviceId); + Adapter.Select(DeviceId); // Send the scratchpad data to the LCD - owAdapter.SendByte(0x48); + Adapter.SendByte(0x48); // Reset the device - owAdapter.Reset(); + Adapter.Reset(); } public void Clear() { // Select the device - owAdapter.Select(DeviceId); + Adapter.Select(DeviceId); // Clear the display - owAdapter.SendByte(0x49); + Adapter.SendByte(0x49); } } } diff --git a/owIdentifer.cs b/Identifer.cs similarity index 92% rename from owIdentifer.cs rename to Identifer.cs index d6d53fd..10f64ba 100644 --- a/owIdentifer.cs +++ b/Identifer.cs @@ -2,19 +2,19 @@ using System.Text; namespace OneWireAPI { - public class owIdentifier + public class Identifier { private readonly short[] _rawId; // The raw ID array private readonly string _friendlyName; // Friendly display name private readonly int _familyCode; // Family code - public owIdentifier() + public Identifier() { // Create a blank ID _rawId = new short[8]; } - public owIdentifier(byte[] deviceId) + public Identifier(byte[] deviceId) { // Create a blank ID _rawId = new short[8]; @@ -30,7 +30,7 @@ namespace OneWireAPI _familyCode = _rawId[0]; } - public owIdentifier(short[] deviceId) + public Identifier(short[] deviceId) { // Store the ID supplied _rawId = deviceId; diff --git a/owNetwork.cs b/Network.cs similarity index 69% rename from owNetwork.cs rename to Network.cs index 3f398ef..1cbc727 100644 --- a/owNetwork.cs +++ b/Network.cs @@ -2,19 +2,19 @@ using System.Collections.Generic; namespace OneWireAPI { - public class owNetwork + public class Network { - private owSession _session; // Current session - private Dictionary _deviceList; // List of current devices + private Session _session; // Current session + private Dictionary _deviceList; // List of current devices - public owNetwork(owSession session) + public Network(Session session) { _session = session; - _deviceList = new Dictionary(); + _deviceList = new Dictionary(); } - public delegate void DeviceEventDelegate(owDevice device); + public delegate void DeviceEventDelegate(Device device); public event DeviceEventDelegate DeviceAdded; @@ -36,33 +36,33 @@ namespace OneWireAPI if (nResult == 1) { // Get the deviceID - var deviceId = new owIdentifier(id); + var deviceId = new Identifier(id); // Create a new device object - owDevice device; - + Device device; + switch (deviceId.Family) { case 0x10: - device = new owDeviceFamily10(_session, id); + device = new DeviceFamily10(_session, id); break; case 0x1D: - device = new owDeviceFamily1D(_session, id); + device = new DeviceFamily1D(_session, id); break; case 0x20: - device = new owDeviceFamily20(_session, id); + device = new DeviceFamily20(_session, id); break; case 0x26: - device = new owDeviceFamily26(_session, id); + device = new DeviceFamily26(_session, id); break; case 0x12: - device = new owDeviceFamily12(_session, id); + device = new DeviceFamily12(_session, id); break; case 0xFF: - device = new owDeviceFamilyFF(_session, id); + device = new DeviceFamilyFF(_session, id); break; default: - device = new owDevice(_session, id); + device = new Device(_session, id); break; } @@ -75,7 +75,7 @@ namespace OneWireAPI // Raise the device added event if (DeviceAdded != null) DeviceAdded(device); - } + } } // Try to get the next device @@ -83,7 +83,7 @@ namespace OneWireAPI } } - public Dictionary Devices + public Dictionary Devices { get { return _deviceList; } } @@ -103,5 +103,5 @@ namespace OneWireAPI // Get rid of the session _session = null; } - } + } } diff --git a/OneWireAPI.csproj b/OneWireAPI.csproj index 0e98847..8148c37 100644 --- a/OneWireAPI.csproj +++ b/OneWireAPI.csproj @@ -107,57 +107,51 @@ 3.5 - - System.Data - - - System.XML - Code - + Code - + Code - + Code - + Code - + Code - + Code - + Code - + Code - + Code - + Code - + Code - + Code - + Code - + Code diff --git a/owException.cs b/OneWireException.cs similarity index 87% rename from owException.cs rename to OneWireException.cs index 4eb1727..9eb56f8 100644 --- a/owException.cs +++ b/OneWireException.cs @@ -3,7 +3,7 @@ using System; namespace OneWireAPI { [Serializable] - public class owException : Exception + public class OneWireException : Exception { public enum ExceptionFunction { @@ -20,9 +20,9 @@ namespace OneWireAPI private readonly int _errorNumber; 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 _errorFunction = function; @@ -31,7 +31,7 @@ namespace OneWireAPI _errorNumber = number; } - public owException(ExceptionFunction function, owIdentifier deviceId) + public OneWireException(ExceptionFunction function, Identifier deviceId) { // Store the exception function _errorFunction = function; @@ -40,7 +40,7 @@ namespace OneWireAPI _deviceId = deviceId; } - public owException(ExceptionFunction function, owIdentifier deviceId, int number) + public OneWireException(ExceptionFunction function, Identifier deviceId, int number) { // Store the exception function _errorFunction = function; @@ -52,7 +52,7 @@ namespace OneWireAPI _errorNumber = number; } - public owIdentifier DeviceId + public Identifier DeviceId { get { return _deviceId; } } diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index c942d06..0d3a40d 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -1,11 +1,5 @@ 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: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] @@ -13,46 +7,6 @@ using System.Runtime.CompilerServices; [assembly: AssemblyProduct("")] [assembly: AssemblyCopyright("")] [assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] +[assembly: AssemblyCulture("")] -// -// 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\. 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("")] +[assembly: AssemblyVersion("1.0.*")] diff --git a/owSession.cs b/Session.cs similarity index 92% rename from owSession.cs rename to Session.cs index ad25690..8568df9 100644 --- a/owSession.cs +++ b/Session.cs @@ -3,16 +3,16 @@ using System; namespace OneWireAPI { - public class owSession + public class Session { private int _sessionHandle; // Session handle - private owNetwork _network; // Network object - + private Network _network; // Network object + private readonly short _portNumber; // Port number private readonly short _portType; // Port type private readonly byte[] _stateBuffer; // Global state buffer - public owSession() + public Session() { // Create the global state buffer _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); } - public owSession(short portNumber, short portType) + public Session(short portNumber, short portType) { // Create the global state buffer _stateBuffer = new byte[(int) TMEX.StateBufferSize.NoEpromWriting]; @@ -48,7 +48,7 @@ namespace OneWireAPI get { return _sessionHandle; } } - public owNetwork Network + public Network Network { get { return _network; } } @@ -100,13 +100,13 @@ namespace OneWireAPI } // Create the network object and pass ourself as the session - _network = new owNetwork(this); + _network = new Network(this); // Initialize the network _network.Initialize(); // Initialize the static adapter code with the session - owAdapter.Initialize(this); + Adapter.Initialize(this); return true; } diff --git a/TMEX.cs b/TMEX.cs index 0a4c4c4..009282a 100644 --- a/TMEX.cs +++ b/TMEX.cs @@ -3,6 +3,7 @@ using System.Runtime.InteropServices; namespace OneWireAPI { + // ReSharper disable once InconsistentNaming public class TMEX { // Size of the global state buffer