mirror of
https://github.com/ckaczor/OneWireAPI.git
synced 2026-01-13 17:23:02 -05:00
Code modernization
This commit is contained in:
70
TMEX.cs
70
TMEX.cs
@@ -5,24 +5,22 @@ namespace OneWireAPI
|
|||||||
{
|
{
|
||||||
public class TMEX
|
public class TMEX
|
||||||
{
|
{
|
||||||
#region TMEX function enumerations
|
|
||||||
|
|
||||||
// Size of the global state buffer
|
// Size of the global state buffer
|
||||||
public enum TMStateBufferSize
|
public enum StateBufferSize
|
||||||
{
|
{
|
||||||
NoEPROMWriting = 5120,
|
NoEpromWriting = 5120,
|
||||||
EPROMWriting = 15360
|
EpromWriting = 15360
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type of operation for the TMOneWireLevel function
|
// Type of operation for the TMOneWireLevel function
|
||||||
public enum TMOneWireLevelOperation : short
|
public enum LevelOperation : short
|
||||||
{
|
{
|
||||||
Write = 0,
|
Write = 0,
|
||||||
Read = 1
|
Read = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// TMOneWireLevel operation mode
|
// TMOneWireLevel operation mode
|
||||||
public enum TMOneWireLevelMode : short
|
public enum LevelMode : short
|
||||||
{
|
{
|
||||||
Normal = 0x0,
|
Normal = 0x0,
|
||||||
StrongPullup = 0x1,
|
StrongPullup = 0x1,
|
||||||
@@ -31,7 +29,7 @@ namespace OneWireAPI
|
|||||||
}
|
}
|
||||||
|
|
||||||
// When the mode from the TMOneWireLevel is to activate
|
// When the mode from the TMOneWireLevel is to activate
|
||||||
public enum TMOneWireLevelPrime : short
|
public enum LevelPrime : short
|
||||||
{
|
{
|
||||||
Immediate = 0,
|
Immediate = 0,
|
||||||
AfterNextBit = 1,
|
AfterNextBit = 1,
|
||||||
@@ -39,16 +37,12 @@ namespace OneWireAPI
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Type of CRC to be calculated
|
// Type of CRC to be calculated
|
||||||
public enum TMCRCType : short
|
public enum CrcType : short
|
||||||
{
|
{
|
||||||
EightBit = 0,
|
EightBit = 0,
|
||||||
SixteenBit = 1
|
SixteenBit = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region TMEX function structures
|
|
||||||
|
|
||||||
[StructLayoutAttribute(LayoutKind.Sequential, Pack = 1)]
|
[StructLayoutAttribute(LayoutKind.Sequential, Pack = 1)]
|
||||||
public struct FileEntry
|
public struct FileEntry
|
||||||
{
|
{
|
||||||
@@ -62,73 +56,67 @@ namespace OneWireAPI
|
|||||||
public byte[] Bitmap; /* current bitmap of the device */
|
public byte[] Bitmap; /* current bitmap of the device */
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
[DllImport("IBFS64.DLL")]
|
||||||
|
public static extern short Get_Version(byte[] version);
|
||||||
#region TMEX DLL function imports
|
|
||||||
|
|
||||||
[DllImport("IBFS64.DLL")]
|
[DllImport("IBFS64.DLL")]
|
||||||
public static extern short Get_Version(byte[] baVersion);
|
public static extern int TMExtendedStartSession(short portNumber, short portType, IntPtr enhancedOptions);
|
||||||
|
|
||||||
[DllImport("IBFS64.DLL")]
|
[DllImport("IBFS64.DLL")]
|
||||||
public static extern int TMExtendedStartSession(short nPortNumber, short nPortType, IntPtr nEnhancedOptions);
|
public static extern short TMEndSession(int session);
|
||||||
|
|
||||||
[DllImport("IBFS64.DLL")]
|
[DllImport("IBFS64.DLL")]
|
||||||
public static extern short TMEndSession(int iSession);
|
public static extern short TMReadDefaultPort(out short portNumber, out short portType);
|
||||||
|
|
||||||
[DllImport("IBFS64.DLL")]
|
[DllImport("IBFS64.DLL")]
|
||||||
public static extern short TMReadDefaultPort(out short nPortNumber, out short nPortType);
|
public static extern short TMSetup(int session);
|
||||||
|
|
||||||
[DllImport("IBFS64.DLL")]
|
[DllImport("IBFS64.DLL")]
|
||||||
public static extern short TMSetup(int iSession);
|
public static extern short TMClose(int session);
|
||||||
|
|
||||||
[DllImport("IBFS64.DLL")]
|
[DllImport("IBFS64.DLL")]
|
||||||
public static extern short TMClose(int iSession);
|
public static extern short TMRom(int session, byte[] stateBuffer, short[] rom);
|
||||||
|
|
||||||
[DllImport("IBFS64.DLL")]
|
[DllImport("IBFS64.DLL")]
|
||||||
public static extern short TMRom(int iSession, byte[] bStateBuffer, short[] nROM);
|
public static extern short TMAccess(int session, byte[] stateBuffer);
|
||||||
|
|
||||||
[DllImport("IBFS64.DLL")]
|
[DllImport("IBFS64.DLL")]
|
||||||
public static extern short TMAccess(int iSession, byte[] bStateBuffer);
|
public static extern short TMOneWireLevel(int session, LevelOperation operation, LevelMode levelMode, LevelPrime primed);
|
||||||
|
|
||||||
[DllImport("IBFS64.DLL")]
|
[DllImport("IBFS64.DLL")]
|
||||||
public static extern short TMOneWireLevel(int iSession, TMOneWireLevelOperation nOperation, TMOneWireLevelMode nLevelMode, TMOneWireLevelPrime nPrimed);
|
public static extern short TMTouchBit(int session, short output);
|
||||||
|
|
||||||
[DllImport("IBFS64.DLL")]
|
[DllImport("IBFS64.DLL")]
|
||||||
public static extern short TMTouchBit(int iSession, short nOutput);
|
public static extern short TMTouchByte(int session, short output);
|
||||||
|
|
||||||
[DllImport("IBFS64.DLL")]
|
[DllImport("IBFS64.DLL")]
|
||||||
public static extern short TMTouchByte(int iSession, short nOutput);
|
public static extern short TMTouchReset(int session);
|
||||||
|
|
||||||
[DllImport("IBFS64.DLL")]
|
[DllImport("IBFS64.DLL")]
|
||||||
public static extern short TMTouchReset(int iSession);
|
public static extern short TMBlockStream(int session, byte[] data, short byteCount);
|
||||||
|
|
||||||
[DllImport("IBFS64.DLL")]
|
[DllImport("IBFS64.DLL")]
|
||||||
public static extern short TMBlockStream(int iSession, byte[] aData, short nByteCount);
|
public static extern short TMBlockIO(int session, byte[] data, short byteCount);
|
||||||
|
|
||||||
[DllImport("IBFS64.DLL")]
|
[DllImport("IBFS64.DLL")]
|
||||||
public static extern short TMBlockIO(int iSession, byte[] aData, short nByteCount);
|
public static extern short TMCRC(short length, byte[] data, ushort seed, CrcType type);
|
||||||
|
|
||||||
[DllImport("IBFS64.DLL")]
|
[DllImport("IBFS64.DLL")]
|
||||||
public static extern short TMCRC(short nLength, byte[] aData, ushort nSeed, TMCRCType nType);
|
public static extern short TMFirst(int session, byte[] stateBuffer);
|
||||||
|
|
||||||
[DllImport("IBFS64.DLL")]
|
[DllImport("IBFS64.DLL")]
|
||||||
public static extern short TMFirst(int iSession, byte[] bStateBuffer);
|
public static extern short TMNext(int session, byte[] stateBuffer);
|
||||||
|
|
||||||
[DllImport("IBFS64.DLL")]
|
[DllImport("IBFS64.DLL")]
|
||||||
public static extern short TMNext(int iSession, byte[] bStateBuffer);
|
public static extern short TMFirstFile(int session, byte[] stateBuffer, ref FileEntry fileEntry);
|
||||||
|
|
||||||
[DllImport("IBFS64.DLL")]
|
[DllImport("IBFS64.DLL")]
|
||||||
public static extern short TMFirstFile(int iSession, byte[] bStateBuffer, ref FileEntry uFileEntry);
|
public static extern short TMOpenFile(int session, byte[] stateBuffer, ref FileEntry fileEntry);
|
||||||
|
|
||||||
[DllImport("IBFS64.DLL")]
|
[DllImport("IBFS64.DLL")]
|
||||||
public static extern short TMOpenFile(int iSession, byte[] bStateBuffer, ref FileEntry uFileEntry);
|
public static extern short TMReadFile(int session, byte[] stateBuffer, short fileHandle, byte[] readBuffer, short bufferSize);
|
||||||
|
|
||||||
[DllImport("IBFS64.DLL")]
|
[DllImport("IBFS64.DLL")]
|
||||||
public static extern short TMReadFile(int iSession, byte[] bStateBuffer, short nFileHandle, byte[] baReadBuffer, short nBufferSize);
|
public static extern short TMCloseFile(int session, byte[] stateBuffer, short fileHandle);
|
||||||
|
|
||||||
[DllImport("IBFS64.DLL")]
|
|
||||||
public static extern short TMCloseFile(int iSession, byte[] bStateBuffer, short nFileHandle);
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
101
owAdapter.cs
101
owAdapter.cs
@@ -1,38 +1,30 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace OneWireAPI
|
namespace OneWireAPI
|
||||||
{
|
{
|
||||||
public class owAdapter
|
public class owAdapter
|
||||||
{
|
{
|
||||||
#region Member variables
|
private static owSession _session;
|
||||||
|
private static owIdentifier _lastId;
|
||||||
|
|
||||||
private static owSession m_oSession; // The current session
|
public static void Initialize(owSession session)
|
||||||
private static owIdentifier m_oLastID; // Last ID selected
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Methods
|
|
||||||
|
|
||||||
public static void Initialize(owSession Session)
|
|
||||||
{
|
{
|
||||||
// Store the session we are dealing with
|
// Store the session we are dealing with
|
||||||
m_oSession = Session;
|
_session = session;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Select(owIdentifier ID)
|
public static void Select(owIdentifier id)
|
||||||
{
|
{
|
||||||
// Set the ID of the device we want to talk to
|
// Set the ID of the device we want to talk to
|
||||||
short nResult = TMEX.TMRom(m_oSession.SessionHandle, m_oSession.StateBuffer, ID.RawID);
|
var result = TMEX.TMRom(_session.SessionHandle, _session.StateBuffer, id.RawId);
|
||||||
|
|
||||||
// Check the result
|
// Check the result
|
||||||
if (nResult != 1)
|
if (result != 1)
|
||||||
{
|
{
|
||||||
// Throw a ROM exception
|
// Throw a ROM exception
|
||||||
throw new owException(owException.owExceptionFunction.Select, ID, nResult);
|
throw new owException(owException.ExceptionFunction.Select, id, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy the ID as the last selected ID
|
// Copy the ID as the last selected ID
|
||||||
m_oLastID = ID;
|
_lastId = id;
|
||||||
|
|
||||||
// Access the device
|
// Access the device
|
||||||
Access();
|
Access();
|
||||||
@@ -41,125 +33,118 @@ namespace OneWireAPI
|
|||||||
public static void Access()
|
public static void Access()
|
||||||
{
|
{
|
||||||
// Attempt to access the device
|
// Attempt to access the device
|
||||||
short nResult = TMEX.TMAccess(m_oSession.SessionHandle, m_oSession.StateBuffer);
|
var result = TMEX.TMAccess(_session.SessionHandle, _session.StateBuffer);
|
||||||
|
|
||||||
// Check to see if we could access the device
|
// Check to see if we could access the device
|
||||||
if (nResult != 1)
|
if (result != 1)
|
||||||
{
|
{
|
||||||
// Throw an access exception
|
// Throw an access exception
|
||||||
throw new owException(owException.owExceptionFunction.Access, m_oLastID, nResult);
|
throw new owException(owException.ExceptionFunction.Access, _lastId, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static short SendBlock(byte[] Data, short ByteCount)
|
public static short SendBlock(byte[] data, short byteCount)
|
||||||
{
|
{
|
||||||
// Send the block and return the result
|
// Send the block and return the result
|
||||||
short nResult = TMEX.TMBlockStream(m_oSession.SessionHandle, Data, ByteCount);
|
var result = TMEX.TMBlockStream(_session.SessionHandle, data, byteCount);
|
||||||
|
|
||||||
// Check to see if the bytes sent matches the value returned
|
// Check to see if the bytes sent matches the value returned
|
||||||
if (nResult != ByteCount)
|
if (result != byteCount)
|
||||||
{
|
{
|
||||||
// Throw an access exception
|
// Throw an access exception
|
||||||
throw new owException(owException.owExceptionFunction.SendBlock, m_oLastID, nResult);
|
throw new owException(owException.ExceptionFunction.SendBlock, _lastId, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the result
|
// Return the result
|
||||||
return nResult;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static short SendBlock(byte[] Data, short ByteCount, bool Reset)
|
public static short SendBlock(byte[] data, short byteCount, bool reset)
|
||||||
{
|
{
|
||||||
short nResult;
|
|
||||||
|
|
||||||
// Send the block and return the result
|
// Send the block and return the result
|
||||||
if (Reset)
|
var result = reset ? TMEX.TMBlockStream(_session.SessionHandle, data, byteCount) : TMEX.TMBlockIO(_session.SessionHandle, data, byteCount);
|
||||||
nResult = TMEX.TMBlockStream(m_oSession.SessionHandle, Data, ByteCount);
|
|
||||||
else
|
|
||||||
nResult = TMEX.TMBlockIO(m_oSession.SessionHandle, Data, ByteCount);
|
|
||||||
|
|
||||||
// Check to see if the bytes sent matches the value returned
|
// Check to see if the bytes sent matches the value returned
|
||||||
if (nResult != ByteCount)
|
if (result != byteCount)
|
||||||
{
|
{
|
||||||
// Throw an access exception
|
// Throw an access exception
|
||||||
throw new owException(owException.owExceptionFunction.SendBlock, m_oLastID, nResult);
|
throw new owException(owException.ExceptionFunction.SendBlock, _lastId, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the result
|
// Return the result
|
||||||
return nResult;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static short ReadBit()
|
public static short ReadBit()
|
||||||
{
|
{
|
||||||
// Send the byte and get back what was sent
|
// Send the byte and get back what was sent
|
||||||
short nResult = TMEX.TMTouchBit(m_oSession.SessionHandle, 0xFF);
|
var result = TMEX.TMTouchBit(_session.SessionHandle, 0xFF);
|
||||||
|
|
||||||
// Return the result
|
// Return the result
|
||||||
return nResult;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static short SendBit(short Output)
|
public static short SendBit(short output)
|
||||||
{
|
{
|
||||||
// Send the byte and get back what was sent
|
// Send the byte and get back what was sent
|
||||||
short nResult = TMEX.TMTouchBit(m_oSession.SessionHandle, Output);
|
var result = TMEX.TMTouchBit(_session.SessionHandle, output);
|
||||||
|
|
||||||
// Check that the value was sent correctly
|
// Check that the value was sent correctly
|
||||||
if (nResult != Output)
|
if (result != output)
|
||||||
{
|
{
|
||||||
// Throw an exception
|
// Throw an exception
|
||||||
throw new owException(owException.owExceptionFunction.SendBit, m_oLastID);
|
throw new owException(owException.ExceptionFunction.SendBit, _lastId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the result
|
// Return the result
|
||||||
return nResult;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static short ReadByte()
|
public static short ReadByte()
|
||||||
{
|
{
|
||||||
// Send the byte and get back what was sent
|
// Send the byte and get back what was sent
|
||||||
short nResult = TMEX.TMTouchByte(m_oSession.SessionHandle, 0xFF);
|
var result = TMEX.TMTouchByte(_session.SessionHandle, 0xFF);
|
||||||
|
|
||||||
// Return the result
|
// Return the result
|
||||||
return nResult;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static short Reset()
|
public static short Reset()
|
||||||
{
|
{
|
||||||
// Reset all devices
|
// Reset all devices
|
||||||
return TMEX.TMTouchReset(m_oSession.SessionHandle);
|
return TMEX.TMTouchReset(_session.SessionHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static short SendByte(short Output)
|
public static short SendByte(short output)
|
||||||
{
|
{
|
||||||
// Send the byte and get back what was sent
|
// Send the byte and get back what was sent
|
||||||
short nResult = TMEX.TMTouchByte(m_oSession.SessionHandle, Output);
|
var result = TMEX.TMTouchByte(_session.SessionHandle, output);
|
||||||
|
|
||||||
// Check that the value was sent correctly
|
// Check that the value was sent correctly
|
||||||
if (nResult != Output)
|
if (result != output)
|
||||||
{
|
{
|
||||||
// Throw an exception
|
// Throw an exception
|
||||||
throw new owException(owException.owExceptionFunction.SendByte, m_oLastID);
|
throw new owException(owException.ExceptionFunction.SendByte, _lastId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the result
|
// Return the result
|
||||||
return nResult;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static short SetLevel(TMEX.TMOneWireLevelOperation nOperation, TMEX.TMOneWireLevelMode nLevelMode, TMEX.TMOneWireLevelPrime nPrimed)
|
public static short SetLevel(TMEX.LevelOperation nOperation, TMEX.LevelMode nLevelMode, TMEX.LevelPrime nPrimed)
|
||||||
{
|
{
|
||||||
// Set the level
|
// Set the level
|
||||||
short nResult = TMEX.TMOneWireLevel(m_oSession.SessionHandle, TMEX.TMOneWireLevelOperation.Write, TMEX.TMOneWireLevelMode.Normal, TMEX.TMOneWireLevelPrime.Immediate);
|
var result = TMEX.TMOneWireLevel(_session.SessionHandle, TMEX.LevelOperation.Write, TMEX.LevelMode.Normal, TMEX.LevelPrime.Immediate);
|
||||||
|
|
||||||
// Check the result
|
// Check the result
|
||||||
if (nResult < 0)
|
if (result < 0)
|
||||||
{
|
{
|
||||||
// Throw an exception
|
// Throw an exception
|
||||||
throw new owException(owException.owExceptionFunction.SetLevel, nResult);
|
throw new owException(owException.ExceptionFunction.SetLevel, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the result
|
// Return the result
|
||||||
return nResult;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
38
owCRC16.cs
38
owCRC16.cs
@@ -1,16 +1,8 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace OneWireAPI
|
namespace OneWireAPI
|
||||||
{
|
{
|
||||||
internal class owCRC16
|
internal class owCRC16
|
||||||
{
|
{
|
||||||
#region CRC lookup table
|
private static readonly short[] OddParity = { 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0 };
|
||||||
|
|
||||||
private static short[] m_aOddParity = { 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0 };
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Methods
|
|
||||||
|
|
||||||
public static int Calculate(byte[] nData, int iStart, int iEnd)
|
public static int Calculate(byte[] nData, int iStart, int iEnd)
|
||||||
{
|
{
|
||||||
@@ -19,7 +11,7 @@ namespace OneWireAPI
|
|||||||
|
|
||||||
public static int Calculate(byte nData, int iInitialValue)
|
public static int Calculate(byte nData, int iInitialValue)
|
||||||
{
|
{
|
||||||
byte[] aData = new byte[1];
|
var aData = new byte[1];
|
||||||
|
|
||||||
aData[0] = nData;
|
aData[0] = nData;
|
||||||
|
|
||||||
@@ -28,34 +20,32 @@ namespace OneWireAPI
|
|||||||
|
|
||||||
public static int Calculate(byte[] nData, int iStart, int iEnd, int iInitialValue)
|
public static int Calculate(byte[] nData, int iStart, int iEnd, int iInitialValue)
|
||||||
{
|
{
|
||||||
int iIndex; // Loop index
|
int index; // Loop index
|
||||||
int iCurrentCRC = iInitialValue; // Current CRC accumulator
|
var currentCrc = iInitialValue; // Current CRC accumulator
|
||||||
|
|
||||||
// Loop over all bytes in the input array
|
// Loop over all bytes in the input array
|
||||||
for (iIndex = iStart; iIndex <= iEnd; iIndex++)
|
for (index = iStart; index <= iEnd; index++)
|
||||||
{
|
{
|
||||||
// Get the current element of data
|
// Get the current element of data
|
||||||
int iBuffer = nData[iIndex];
|
int iBuffer = nData[index];
|
||||||
|
|
||||||
// Calculate the current CRC for this position
|
// Calculate the current CRC for this position
|
||||||
iBuffer = (iBuffer ^ (iCurrentCRC & 0xFF)) & 0xFF;
|
iBuffer = (iBuffer ^ (currentCrc & 0xFF)) & 0xFF;
|
||||||
|
|
||||||
iCurrentCRC >>= 8;
|
currentCrc >>= 8;
|
||||||
|
|
||||||
if ((m_aOddParity[iBuffer & 0xF] ^ m_aOddParity[iBuffer >> 4]) != 0)
|
if ((OddParity[iBuffer & 0xF] ^ OddParity[iBuffer >> 4]) != 0)
|
||||||
iCurrentCRC ^= 0xC001;
|
currentCrc ^= 0xC001;
|
||||||
|
|
||||||
iBuffer <<= 6;
|
iBuffer <<= 6;
|
||||||
iCurrentCRC ^= iBuffer;
|
currentCrc ^= iBuffer;
|
||||||
|
|
||||||
iBuffer <<= 1;
|
iBuffer <<= 1;
|
||||||
iCurrentCRC ^= iBuffer;
|
currentCrc ^= iBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the final CRC value
|
// Return the final CRC value
|
||||||
return iCurrentCRC;
|
return currentCrc;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
62
owCRC8.cs
62
owCRC8.cs
@@ -1,76 +1,52 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace OneWireAPI
|
namespace OneWireAPI
|
||||||
{
|
{
|
||||||
internal class owCRC8
|
internal class owCRC8
|
||||||
{
|
{
|
||||||
#region Member variables
|
private static byte[] _dataTable; // Lookup table of CRC8 values
|
||||||
|
|
||||||
private static byte[] m_aDataTable; // Lookup table of CRC8 values
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructor
|
|
||||||
|
|
||||||
static owCRC8()
|
static owCRC8()
|
||||||
{
|
{
|
||||||
// Initialize the CRC lookup table
|
// Initialize the CRC lookup table
|
||||||
InitializeCRCTable();
|
InitializeCrcTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
private static void InitializeCrcTable()
|
||||||
|
|
||||||
#region Private methods
|
|
||||||
|
|
||||||
private static void InitializeCRCTable()
|
|
||||||
{
|
{
|
||||||
int iAccumulator; // Accumulator value
|
|
||||||
int iCRC; // CRC value
|
|
||||||
int iOuter; // Outer loop control
|
|
||||||
int iInner; // Inner loop control
|
|
||||||
|
|
||||||
// Initialize the size of the lookup table
|
// Initialize the size of the lookup table
|
||||||
m_aDataTable = new byte[256];
|
_dataTable = new byte[256];
|
||||||
|
|
||||||
for (iOuter = 0; iOuter < 256; iOuter++)
|
for (var outer = 0; outer < 256; outer++)
|
||||||
{
|
{
|
||||||
iAccumulator = iOuter;
|
var accumulator = outer; // Accumulator value
|
||||||
iCRC = 0;
|
var crc = 0; // CRC value
|
||||||
|
|
||||||
for (iInner = 0; iInner < 8; iInner++)
|
for (var inner = 0; inner < 8; inner++)
|
||||||
{
|
{
|
||||||
if (((iAccumulator ^ iCRC) & 0x01) == 0x01)
|
if (((accumulator ^ crc) & 0x01) == 0x01)
|
||||||
iCRC = ((iCRC ^ 0x18) >> 1) | 0x80;
|
crc = ((crc ^ 0x18) >> 1) | 0x80;
|
||||||
else
|
else
|
||||||
iCRC = iCRC >> 1;
|
crc = crc >> 1;
|
||||||
|
|
||||||
iAccumulator = iAccumulator >> 1;
|
accumulator = accumulator >> 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_aDataTable[iOuter] = (byte) iCRC;
|
_dataTable[outer] = (byte) crc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
public static short Calculate(byte[] data, int start, int end)
|
||||||
|
|
||||||
#region Public methods
|
|
||||||
|
|
||||||
public static short Calculate(byte[] nData, int iStart, int iEnd)
|
|
||||||
{
|
{
|
||||||
int iIndex; // Loop index
|
var currentCrc = (short) 0; // Current CRC accumulator
|
||||||
short nCurrentCRC = 0; // Current CRC accumulator
|
|
||||||
|
|
||||||
// Loop over all bytes in the input array
|
// Loop over all bytes in the input array
|
||||||
for (iIndex = iStart; iIndex <= iEnd; iIndex++)
|
for (var index = start; index <= end; index++)
|
||||||
{
|
{
|
||||||
// Calculate the current CRC for this position
|
// Calculate the current CRC for this position
|
||||||
nCurrentCRC = m_aDataTable[nCurrentCRC ^ nData[iIndex]];
|
currentCrc = _dataTable[currentCrc ^ data[index]];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the final CRC value
|
// Return the final CRC value
|
||||||
return nCurrentCRC;
|
return currentCrc;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
32
owDevice.cs
32
owDevice.cs
@@ -1,41 +1,27 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace OneWireAPI
|
namespace OneWireAPI
|
||||||
{
|
{
|
||||||
public class owDevice
|
public class owDevice
|
||||||
{
|
{
|
||||||
#region Member variables
|
protected owSession Session;
|
||||||
|
protected owIdentifier DeviceId;
|
||||||
|
|
||||||
protected owSession _session; // The current session
|
public owDevice(owSession session, short[] rawId)
|
||||||
protected owIdentifier _deviceID; // The ID of this device
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructor
|
|
||||||
|
|
||||||
public owDevice(owSession 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 owIdentifier(rawId);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
public owIdentifier Id
|
||||||
|
|
||||||
#region Properties
|
|
||||||
|
|
||||||
public owIdentifier ID
|
|
||||||
{
|
{
|
||||||
get { return _deviceID; }
|
get { return DeviceId; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Family
|
public int Family
|
||||||
{
|
{
|
||||||
get { return _deviceID.Family; }
|
get { return DeviceId.Family; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,36 +1,20 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace OneWireAPI
|
namespace OneWireAPI
|
||||||
{
|
{
|
||||||
public class owDeviceFamily10 : owDevice
|
public class owDeviceFamily10 : owDevice
|
||||||
{
|
{
|
||||||
#region Constructor
|
public owDeviceFamily10(owSession session, short[] id)
|
||||||
|
: base(session, id)
|
||||||
public owDeviceFamily10(owSession Session, short[] ID) : base(Session, ID)
|
|
||||||
{
|
{
|
||||||
// Just call the base constructor
|
// Just call the base constructor
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Methods
|
|
||||||
|
|
||||||
public double GetTemperature()
|
public double GetTemperature()
|
||||||
{
|
{
|
||||||
short nResult; // Result of method calls
|
|
||||||
byte[] aData = new byte[30]; // Data buffer to send over the network
|
|
||||||
short nDataCount = 0; // How many bytes of data to send
|
|
||||||
double dCountRemaining; // How many counters remain in the temperature conversion
|
|
||||||
double dCountPerDegreeC; // How many counters per degree C
|
|
||||||
int iTemperatureLSB; // The LSB of the temperature
|
|
||||||
double dTemperature; // double version of the temperature
|
|
||||||
short nCRC; // Result of the CRC check
|
|
||||||
|
|
||||||
// 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);
|
owAdapter.Select(DeviceId);
|
||||||
|
|
||||||
// Setup for for power delivery after the next byte
|
// Setup for for power delivery after the next byte
|
||||||
nResult = owAdapter.SetLevel(TMEX.TMOneWireLevelOperation.Write, TMEX.TMOneWireLevelMode.StrongPullup, TMEX.TMOneWireLevelPrime.AfterNextByte);
|
owAdapter.SetLevel(TMEX.LevelOperation.Write, TMEX.LevelMode.StrongPullup, TMEX.LevelPrime.AfterNextByte);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -40,7 +24,7 @@ namespace OneWireAPI
|
|||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
// Stop the strong pullup
|
// Stop the strong pullup
|
||||||
owAdapter.SetLevel(TMEX.TMOneWireLevelOperation.Write, TMEX.TMOneWireLevelMode.Normal, TMEX.TMOneWireLevelPrime.Immediate);
|
owAdapter.SetLevel(TMEX.LevelOperation.Write, TMEX.LevelMode.Normal, TMEX.LevelPrime.Immediate);
|
||||||
|
|
||||||
// Re-throw the exception
|
// Re-throw the exception
|
||||||
throw;
|
throw;
|
||||||
@@ -50,53 +34,57 @@ namespace OneWireAPI
|
|||||||
System.Threading.Thread.Sleep(1000);
|
System.Threading.Thread.Sleep(1000);
|
||||||
|
|
||||||
// Stop the strong pullup
|
// Stop the strong pullup
|
||||||
nResult = owAdapter.SetLevel(TMEX.TMOneWireLevelOperation.Write, TMEX.TMOneWireLevelMode.Normal, TMEX.TMOneWireLevelPrime.Immediate);
|
owAdapter.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();
|
owAdapter.Access();
|
||||||
|
|
||||||
|
// Data buffer to send over the network
|
||||||
|
var data = new byte[30];
|
||||||
|
|
||||||
|
// How many bytes of data to send
|
||||||
|
short dataCount = 0;
|
||||||
|
|
||||||
// Set the command to get the temperature from the scatchpad
|
// Set the command to get the temperature from the scatchpad
|
||||||
aData[nDataCount++] = 0xBE;
|
data[dataCount++] = 0xBE;
|
||||||
|
|
||||||
// Setup the rest of the bytes that we want
|
// Setup the rest of the bytes that we want
|
||||||
for (int i = 0; i < 9; i++)
|
for (var i = 0; i < 9; i++)
|
||||||
aData[nDataCount++] = 0xFF;
|
data[dataCount++] = 0xFF;
|
||||||
|
|
||||||
// Send the data block and get data back
|
// Send the data block and get data back
|
||||||
nResult = owAdapter.SendBlock(aData, nDataCount);
|
owAdapter.SendBlock(data, dataCount);
|
||||||
|
|
||||||
// Calculate the CRC of the first eight bytes of data
|
// Calculate the CRC of the first eight bytes of data
|
||||||
nCRC = owCRC8.Calculate(aData, 1, 8);
|
var crc = owCRC8.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 (nCRC != aData[9])
|
if (crc != data[9])
|
||||||
{
|
{
|
||||||
// Throw a CRC exception
|
// Throw a CRC exception
|
||||||
throw new owException(owException.owExceptionFunction.CRC, _deviceID);
|
throw new owException(owException.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
|
||||||
iTemperatureLSB = aData[1] / 2;
|
var temperatureLsb = data[1] / 2;
|
||||||
|
|
||||||
// If the data is negative then flip the bits
|
// If the data is negative then flip the bits
|
||||||
if ((aData[2] & 0x01) == 0x01) iTemperatureLSB |= -128;
|
if ((data[2] & 0x01) == 0x01) temperatureLsb |= -128;
|
||||||
|
|
||||||
// Convert the temperature into a double
|
// Convert the temperature into a double
|
||||||
dTemperature = (double) iTemperatureLSB;
|
var temperature = (double) temperatureLsb;
|
||||||
|
|
||||||
// Get the number of counts remaining
|
// Get the number of counts remaining
|
||||||
dCountRemaining = aData[7];
|
double countRemaining = data[7];
|
||||||
|
|
||||||
// Get the number of counts per degree C
|
// Get the number of counts per degree C
|
||||||
dCountPerDegreeC = aData[8];
|
double countPerDegreeC = data[8];
|
||||||
|
|
||||||
// Use the "counts remaining" data to calculate the temperaure to greater accuracy
|
// Use the "counts remaining" data to calculate the temperaure to greater accuracy
|
||||||
dTemperature = dTemperature - 0.25F + (dCountPerDegreeC - dCountRemaining) / dCountPerDegreeC;
|
temperature = temperature - 0.25F + (countPerDegreeC - countRemaining) / countPerDegreeC;
|
||||||
|
|
||||||
// Return the temperature
|
// Return the temperature
|
||||||
return dTemperature;
|
return temperature;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,199 +1,184 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace OneWireAPI
|
namespace OneWireAPI
|
||||||
{
|
{
|
||||||
public class owDeviceFamily12 : owDevice
|
public class owDeviceFamily12 : owDevice
|
||||||
{
|
{
|
||||||
#region Constants
|
private const byte ChannelAccessCommand = 0xF5;
|
||||||
|
private const byte WriteStatusCommand = 0x55;
|
||||||
|
private const byte ReadStatusCommand = 0xAA;
|
||||||
|
|
||||||
private const byte CHANNEL_ACCESS_COMMAND = 0xF5; // Command value to access a channel
|
public owDeviceFamily12(owSession session, short[] id)
|
||||||
private const byte WRITE_STATUS_COMMAND = 0x55; // Command value to write the status
|
: base(session, id)
|
||||||
private const byte READ_STATUS_COMMAND = 0xAA; // Command value to read the status
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructor
|
|
||||||
|
|
||||||
public owDeviceFamily12(owSession Session, short[] ID) : base(Session, ID)
|
|
||||||
{
|
{
|
||||||
// Just call the base constructor
|
// Just call the base constructor
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
public bool IsPowered(byte[] state)
|
||||||
|
|
||||||
#region Methods
|
|
||||||
|
|
||||||
public bool IsPowered(byte[] State)
|
|
||||||
{
|
{
|
||||||
return ((State[0] & 0x80) == 0x80);
|
return ((state[0] & 0x80) == 0x80);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool GetLevel(int Channel, byte[] State)
|
public bool GetLevel(int channel, byte[] state)
|
||||||
{
|
{
|
||||||
if (Channel == 0)
|
if (channel == 0)
|
||||||
return ((State[0] & 0x04) == 0x04);
|
return ((state[0] & 0x04) == 0x04);
|
||||||
else
|
|
||||||
return ((State[0] & 0x08) == 0x08);
|
return ((state[0] & 0x08) == 0x08);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool GetLatchState(int Channel, byte[] State)
|
public bool GetLatchState(int channel, byte[] state)
|
||||||
{
|
{
|
||||||
if (Channel == 0)
|
if (channel == 0)
|
||||||
|
return ((state[1] & 0x20) != 0x20);
|
||||||
|
|
||||||
|
return ((state[1] & 0x40) != 0x40);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetLatchState(int channel, bool latchState, byte[] state)
|
||||||
{
|
{
|
||||||
return ((State[1] & 0x20) != 0x20);
|
if (channel == 0)
|
||||||
|
{
|
||||||
|
state[1] &= 0xDF;
|
||||||
|
|
||||||
|
if (!latchState)
|
||||||
|
state[1] = (byte) (state[1] | 0x20);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return ((State[1] & 0x40) != 0x40);
|
state[1] &= 0xBF;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetLatchState(int Channel, bool LatchState, byte[] State)
|
if (!latchState)
|
||||||
{
|
state[1] = (byte) (state[1] | 0x40);
|
||||||
if (Channel == 0)
|
|
||||||
{
|
|
||||||
State[1] &= 0xDF;
|
|
||||||
|
|
||||||
if (!LatchState) State[1] = (byte) (State[1] | 0x20);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
State[1] &= 0xBF;
|
|
||||||
|
|
||||||
if (!LatchState) State[1] = (byte) (State[1] | 0x40);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] ReadDevice()
|
public byte[] ReadDevice()
|
||||||
{
|
{
|
||||||
byte[] State = new byte[2];
|
|
||||||
byte[] aData = new byte[30]; // Data buffer to send over the network
|
|
||||||
short nDataCount = 0; // How many bytes of data to send
|
|
||||||
int iCRCResult; // Result of the CRC calculation
|
|
||||||
int iMatchCRC; // CRC retrieved from the device
|
|
||||||
|
|
||||||
// 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);
|
owAdapter.Select(DeviceId);
|
||||||
|
|
||||||
|
// Data buffer to send over the network
|
||||||
|
var data = new byte[30];
|
||||||
|
|
||||||
|
// How many bytes of data to send
|
||||||
|
short dataCount = 0;
|
||||||
|
|
||||||
// Set the commmand to execute
|
// Set the commmand to execute
|
||||||
aData[nDataCount++] = CHANNEL_ACCESS_COMMAND;
|
data[dataCount++] = ChannelAccessCommand;
|
||||||
|
|
||||||
// Set the data
|
// Set the data
|
||||||
aData[nDataCount++] = 0x55;
|
data[dataCount++] = 0x55;
|
||||||
aData[nDataCount++] = 0xFF;
|
data[dataCount++] = 0xFF;
|
||||||
|
|
||||||
// Read the info, dummy data and CRC16
|
// Read the info, dummy data and CRC16
|
||||||
for (int i = 3; i < 7; i++)
|
for (var i = 3; i < 7; i++)
|
||||||
aData[nDataCount++] = 0xFF;
|
data[dataCount++] = 0xFF;
|
||||||
|
|
||||||
// Send the data
|
// Send the data
|
||||||
owAdapter.SendBlock(aData, nDataCount);
|
owAdapter.SendBlock(data, dataCount);
|
||||||
|
|
||||||
// Calculate the CRC
|
// Calculate the CRC
|
||||||
iCRCResult = owCRC16.Calculate(aData, 0, 4);
|
var crcResult = owCRC16.Calculate(data, 0, 4);
|
||||||
|
|
||||||
// Assemble the CRC provided by the device
|
// Assemble the CRC provided by the device
|
||||||
iMatchCRC = aData[6] << 8;
|
var matchCrc = data[6] << 8;
|
||||||
iMatchCRC |= aData[5];
|
matchCrc |= data[5];
|
||||||
iMatchCRC ^= 0xFFFF;
|
matchCrc ^= 0xFFFF;
|
||||||
|
|
||||||
// Make sure the CRC values match
|
// Make sure the CRC values match
|
||||||
if (iCRCResult != iMatchCRC)
|
if (crcResult != matchCrc)
|
||||||
{
|
{
|
||||||
// Throw a CRC exception
|
// Throw a CRC exception
|
||||||
throw new owException(owException.owExceptionFunction.CRC, _deviceID);
|
throw new owException(owException.ExceptionFunction.Crc, DeviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var state = new byte[2];
|
||||||
|
|
||||||
// Store the state data
|
// Store the state data
|
||||||
State[0] = aData[3];
|
state[0] = data[3];
|
||||||
|
|
||||||
// Reset the data count
|
// Reset the data count
|
||||||
nDataCount = 0;
|
dataCount = 0;
|
||||||
|
|
||||||
// Set the command
|
// Set the command
|
||||||
aData[nDataCount++] = READ_STATUS_COMMAND;
|
data[dataCount++] = ReadStatusCommand;
|
||||||
|
|
||||||
// Set the address to read
|
// Set the address to read
|
||||||
aData[nDataCount++] = 7;
|
data[dataCount++] = 7;
|
||||||
aData[nDataCount++] = 0;
|
data[dataCount++] = 0;
|
||||||
|
|
||||||
// Add data for the CRC
|
// Add data for the CRC
|
||||||
for (int i = 3; i < 6; i++)
|
for (var i = 3; i < 6; i++)
|
||||||
aData[nDataCount++] = 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);
|
owAdapter.Select(DeviceId);
|
||||||
|
|
||||||
// Send the data
|
// Send the data
|
||||||
owAdapter.SendBlock(aData, nDataCount);
|
owAdapter.SendBlock(data, dataCount);
|
||||||
|
|
||||||
// Calculate the CRC
|
// Calculate the CRC
|
||||||
iCRCResult = owCRC16.Calculate(aData, 0, 3);
|
crcResult = owCRC16.Calculate(data, 0, 3);
|
||||||
|
|
||||||
// Assemble the CRC provided by the device
|
// Assemble the CRC provided by the device
|
||||||
iMatchCRC = aData[5] << 8;
|
matchCrc = data[5] << 8;
|
||||||
iMatchCRC |= aData[4];
|
matchCrc |= data[4];
|
||||||
iMatchCRC ^= 0xFFFF;
|
matchCrc ^= 0xFFFF;
|
||||||
|
|
||||||
// Make sure the CRC values match
|
// Make sure the CRC values match
|
||||||
if (iCRCResult != iMatchCRC)
|
if (crcResult != matchCrc)
|
||||||
{
|
{
|
||||||
// Throw a CRC exception
|
// Throw a CRC exception
|
||||||
throw new owException(owException.owExceptionFunction.CRC, _deviceID);
|
throw new owException(owException.ExceptionFunction.Crc, DeviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store the state data
|
// Store the state data
|
||||||
State[1] = aData[3];
|
state[1] = data[3];
|
||||||
|
|
||||||
return State;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WriteDevice(byte[] State)
|
public void WriteDevice(byte[] state)
|
||||||
{
|
{
|
||||||
short nResult; // Result of method calls
|
|
||||||
byte[] aData = new byte[30]; // Data buffer to send over the network
|
|
||||||
short nDataCount = 0; // How many bytes of data to send
|
|
||||||
int iCRCResult; // Result of the CRC calculation
|
|
||||||
int iMatchCRC; // CRC retrieved from the device
|
|
||||||
|
|
||||||
// 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);
|
owAdapter.Select(DeviceId);
|
||||||
|
|
||||||
|
// Data buffer to send over the network
|
||||||
|
var data = new byte[30];
|
||||||
|
|
||||||
|
// How many bytes of data to send
|
||||||
|
short dataCount = 0;
|
||||||
|
|
||||||
// Set the commmand to execute
|
// Set the commmand to execute
|
||||||
aData[nDataCount++] = WRITE_STATUS_COMMAND;
|
data[dataCount++] = WriteStatusCommand;
|
||||||
|
|
||||||
// Set the address
|
// Set the address
|
||||||
aData[nDataCount++] = 0x07;
|
data[dataCount++] = 0x07;
|
||||||
aData[nDataCount++] = 0x00;
|
data[dataCount++] = 0x00;
|
||||||
|
|
||||||
// Add the state
|
// Add the state
|
||||||
aData[nDataCount++] = State[1];
|
data[dataCount++] = state[1];
|
||||||
|
|
||||||
// Add bytes for the CRC result
|
// Add bytes for the CRC result
|
||||||
aData[nDataCount++] = 0xFF;
|
data[dataCount++] = 0xFF;
|
||||||
aData[nDataCount++] = 0xFF;
|
data[dataCount++] = 0xFF;
|
||||||
|
|
||||||
// Send the data
|
// Send the data
|
||||||
nResult = owAdapter.SendBlock(aData, nDataCount);
|
owAdapter.SendBlock(data, dataCount);
|
||||||
|
|
||||||
// Calculate the CRC
|
// Calculate the CRC
|
||||||
iCRCResult = owCRC16.Calculate(aData, 0, 3);
|
var crcResult = owCRC16.Calculate(data, 0, 3);
|
||||||
|
|
||||||
// Assemble the CRC provided by the device
|
// Assemble the CRC provided by the device
|
||||||
iMatchCRC = aData[5] << 8;
|
var matchCrc = data[5] << 8;
|
||||||
iMatchCRC |= aData[4];
|
matchCrc |= data[4];
|
||||||
iMatchCRC ^= 0xFFFF;
|
matchCrc ^= 0xFFFF;
|
||||||
|
|
||||||
// Make sure the CRC values match
|
// Make sure the CRC values match
|
||||||
if (iCRCResult != iMatchCRC)
|
if (crcResult != matchCrc)
|
||||||
{
|
{
|
||||||
// Throw a CRC exception
|
// Throw a CRC exception
|
||||||
throw new owException(owException.owExceptionFunction.CRC, _deviceID);
|
throw new owException(owException.ExceptionFunction.Crc, DeviceId);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,76 +1,67 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace OneWireAPI
|
namespace OneWireAPI
|
||||||
{
|
{
|
||||||
public class owDeviceFamily1D : owDevice
|
public class owDeviceFamily1D : owDevice
|
||||||
{
|
{
|
||||||
#region Constructor
|
public owDeviceFamily1D(owSession session, short[] id)
|
||||||
|
: base(session, id)
|
||||||
public owDeviceFamily1D(owSession Session, short[] ID) : base(Session, ID)
|
|
||||||
{
|
{
|
||||||
// Just call the base constructor
|
// Just call the base constructor
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
public uint GetCounter(int counterPage)
|
||||||
|
|
||||||
#region Methods
|
|
||||||
|
|
||||||
public uint GetCounter(int CounterPage)
|
|
||||||
{
|
{
|
||||||
short nResult; // Result of method calls
|
|
||||||
byte[] aData = new byte[30]; // Data buffer to send over the network
|
|
||||||
short nDataCount = 0; // How many bytes of data to send
|
|
||||||
int iLastByte; // Address of the last byte in the requested page
|
|
||||||
uint iCounter = 0; // Counter value
|
|
||||||
int iCRCResult; // Result of the CRC calculation
|
|
||||||
int iMatchCRC; // CRC retrieved from the device
|
|
||||||
|
|
||||||
// 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);
|
owAdapter.Select(DeviceId);
|
||||||
|
|
||||||
|
// Data buffer to send over the network
|
||||||
|
var data = new byte[30];
|
||||||
|
|
||||||
|
// How many bytes of data to send
|
||||||
|
short dataCount = 0;
|
||||||
|
|
||||||
// Set the "read memory and counter" command into the data array
|
// Set the "read memory and counter" command into the data array
|
||||||
aData[nDataCount++] = 0xA5;
|
data[dataCount++] = 0xA5;
|
||||||
|
|
||||||
// Calculate the position of the last byte in the page
|
// Calculate the position of the last byte in the page
|
||||||
iLastByte = (CounterPage << 5) + 31;
|
var lastByte = (counterPage << 5) + 31;
|
||||||
|
|
||||||
// Copy the lower byte of the last byte into the data array
|
// Copy the lower byte of the last byte into the data array
|
||||||
aData[nDataCount++] = (byte) (iLastByte & 0xFF);
|
data[dataCount++] = (byte) (lastByte & 0xFF);
|
||||||
|
|
||||||
// Copy the upper byte of the last byte into the data array
|
// Copy the upper byte of the last byte into the data array
|
||||||
aData[nDataCount++] = (byte) (iLastByte >> 8);
|
data[dataCount++] = (byte) (lastByte >> 8);
|
||||||
|
|
||||||
// Add byte for the data byate, counter, zero bits, and CRC16 result
|
// Add byte for the data byate, counter, zero bits, and CRC16 result
|
||||||
for (int i = 0; i < 11; i++) aData[nDataCount++] = 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
|
||||||
nResult = owAdapter.SendBlock(aData, nDataCount);
|
owAdapter.SendBlock(data, dataCount);
|
||||||
|
|
||||||
// Calculate the CRC based on the data
|
// Calculate the CRC based on the data
|
||||||
iCRCResult = owCRC16.Calculate(aData, 0, 11);
|
var crcResult = owCRC16.Calculate(data, 0, 11);
|
||||||
|
|
||||||
// Assemble the CRC provided by the device
|
// Assemble the CRC provided by the device
|
||||||
iMatchCRC = aData[13] << 8;
|
var matchCrc = data[13] << 8;
|
||||||
iMatchCRC |= aData[12];
|
matchCrc |= data[12];
|
||||||
iMatchCRC ^= 0xFFFF;
|
matchCrc ^= 0xFFFF;
|
||||||
|
|
||||||
// Make sure the CRC values match
|
// Make sure the CRC values match
|
||||||
if (iCRCResult != iMatchCRC)
|
if (crcResult != matchCrc)
|
||||||
{
|
{
|
||||||
// Throw a CRC exception
|
// Throw a CRC exception
|
||||||
throw new owException(owException.owExceptionFunction.CRC, _deviceID);
|
throw new owException(owException.ExceptionFunction.Crc, DeviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint counter = 0;
|
||||||
|
|
||||||
// Assemble the counter data from the bytes retrieved
|
// Assemble the counter data from the bytes retrieved
|
||||||
for (int i = nDataCount - 7; i >= nDataCount - 10; i--)
|
for (var i = dataCount - 7; i >= dataCount - 10; i--)
|
||||||
{
|
{
|
||||||
iCounter <<= 8;
|
counter <<= 8;
|
||||||
iCounter |= aData[i];
|
counter |= data[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
return iCounter;
|
return counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,183 +1,166 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace OneWireAPI
|
namespace OneWireAPI
|
||||||
{
|
{
|
||||||
public class owDeviceFamily20 : owDevice
|
public class owDeviceFamily20 : owDevice
|
||||||
{
|
{
|
||||||
#region Member variables
|
private readonly byte[] _control = new byte[16];
|
||||||
|
|
||||||
byte[] m_aControl = new byte[16];
|
public enum Range : byte
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Enumerations
|
|
||||||
|
|
||||||
public enum owDeviceFamily20Range : byte
|
|
||||||
{
|
{
|
||||||
Range_512 = 0x01,
|
Range512 = 0x01,
|
||||||
Range_256 = 0x00
|
Range256 = 0x00
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum owDeviceFamily20Resolution : byte
|
public enum Resolution : byte
|
||||||
{
|
{
|
||||||
EightBits = 0x08,
|
EightBits = 0x08,
|
||||||
SixteenBits = 0x00
|
SixteenBits = 0x00
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
public owDeviceFamily20(owSession session, short[] id)
|
||||||
|
: base(session, id)
|
||||||
#region Constructor
|
|
||||||
|
|
||||||
public owDeviceFamily20(owSession Session, short[] ID) : base(Session, ID)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Methods
|
|
||||||
|
|
||||||
public void Initialize()
|
public void Initialize()
|
||||||
{
|
{
|
||||||
short nResult; // Result of method calls
|
const int startAddress = 0x8; // Starting data page address
|
||||||
byte[] aData = new byte[30]; // Data buffer to send over the network
|
const int endAddress = 0x11; // Ending data page address
|
||||||
short nDataCount = 0; // How many bytes of data to send
|
|
||||||
int iIndex; // Loop index
|
|
||||||
int iStartAddress = 0x8; // Starting data page address
|
|
||||||
int iEndAddress = 0x11; // Ending data page address
|
|
||||||
int iCalculatedCRC; // CRC we calculated from sent data
|
|
||||||
int iSentCRC; // CRC retrieved from the device
|
|
||||||
|
|
||||||
// Setup the control page
|
// Setup the control page
|
||||||
for (iIndex = 0; iIndex < 8; iIndex += 2)
|
for (var index = 0; index < 8; index += 2)
|
||||||
{
|
{
|
||||||
m_aControl[iIndex] = (byte) owDeviceFamily20Resolution.EightBits;
|
_control[index] = (byte) Resolution.EightBits;
|
||||||
m_aControl[iIndex + 1] = (byte) owDeviceFamily20Range.Range_512;
|
_control[index + 1] = (byte) Range.Range512;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear the alarm page
|
// Clear the alarm page
|
||||||
for (iIndex = 8; iIndex < 16; iIndex++)
|
for (var index = 8; index < 16; index++)
|
||||||
{
|
{
|
||||||
m_aControl[iIndex] = 0;
|
_control[index] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Data buffer to send over the network
|
||||||
|
var data = new byte[30];
|
||||||
|
|
||||||
|
// How many bytes of data to send
|
||||||
|
short dataCount = 0;
|
||||||
|
|
||||||
// Set the command into the data array
|
// Set the command into the data array
|
||||||
aData[nDataCount++] = 0x55;
|
data[dataCount++] = 0x55;
|
||||||
|
|
||||||
// Set the starting address of the data to write
|
// Set the starting address of the data to write
|
||||||
aData[nDataCount++] = (byte) (iStartAddress & 0xFF);
|
data[dataCount++] = startAddress & 0xFF;
|
||||||
aData[nDataCount++] = (byte) ((iStartAddress >> 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);
|
owAdapter.Select(DeviceId);
|
||||||
|
|
||||||
// Write to the data pages specified
|
// Write to the data pages specified
|
||||||
for (iIndex = iStartAddress; iIndex <= iEndAddress; iIndex++)
|
for (var index = startAddress; index <= endAddress; index++)
|
||||||
{
|
{
|
||||||
// Copy the control data into our output buffer
|
// Copy the control data into our output buffer
|
||||||
aData[nDataCount++] = m_aControl[iIndex - iStartAddress];
|
data[dataCount++] = _control[index - startAddress];
|
||||||
|
|
||||||
// Add two bytes for the CRC results
|
// Add two bytes for the CRC results
|
||||||
aData[nDataCount++] = 0xFF;
|
data[dataCount++] = 0xFF;
|
||||||
aData[nDataCount++] = 0xFF;
|
data[dataCount++] = 0xFF;
|
||||||
|
|
||||||
// Add a byte for the control byte echo
|
// Add a byte for the control byte echo
|
||||||
aData[nDataCount++] = 0xFF;
|
data[dataCount++] = 0xFF;
|
||||||
|
|
||||||
// Send the block
|
// Send the block
|
||||||
nResult = owAdapter.SendBlock(aData, nDataCount);
|
owAdapter.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 (aData[nDataCount - 1] != m_aControl[iIndex - iStartAddress])
|
if (data[dataCount - 1] != _control[index - startAddress])
|
||||||
{
|
{
|
||||||
// Throw an exception
|
// Throw an exception
|
||||||
throw new owException(owException.owExceptionFunction.SendBlock, _deviceID);
|
throw new owException(owException.ExceptionFunction.SendBlock, DeviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int calculatedCrc; // CRC we calculated from sent data
|
||||||
|
int sentCrc; // CRC retrieved from the device
|
||||||
|
|
||||||
// Calculate the CRC values
|
// Calculate the CRC values
|
||||||
if (iIndex == iStartAddress)
|
if (index == startAddress)
|
||||||
{
|
{
|
||||||
// Calculate the CRC16 of the data sent
|
// Calculate the CRC16 of the data sent
|
||||||
iCalculatedCRC = owCRC16.Calculate(aData, 0, 3);
|
calculatedCrc = owCRC16.Calculate(data, 0, 3);
|
||||||
|
|
||||||
// Reconstruct the CRC sent by the device
|
// Reconstruct the CRC sent by the device
|
||||||
iSentCRC = aData[nDataCount - 2] << 8;
|
sentCrc = data[dataCount - 2] << 8;
|
||||||
iSentCRC |= aData[nDataCount - 3];
|
sentCrc |= data[dataCount - 3];
|
||||||
iSentCRC ^= 0xFFFF;
|
sentCrc ^= 0xFFFF;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Calculate the CRC16 of the data sent
|
// Calculate the CRC16 of the data sent
|
||||||
iCalculatedCRC = owCRC16.Calculate(m_aControl[iIndex - iStartAddress], iIndex);
|
calculatedCrc = owCRC16.Calculate(_control[index - startAddress], index);
|
||||||
|
|
||||||
// Reconstruct the CRC sent by the device
|
// Reconstruct the CRC sent by the device
|
||||||
iSentCRC = aData[nDataCount - 2] << 8;
|
sentCrc = data[dataCount - 2] << 8;
|
||||||
iSentCRC |= aData[nDataCount - 3];
|
sentCrc |= data[dataCount - 3];
|
||||||
iSentCRC ^= 0xFFFF;
|
sentCrc ^= 0xFFFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the CRC doesn't match then throw an exception
|
// If the CRC doesn't match then throw an exception
|
||||||
if (iCalculatedCRC != iSentCRC)
|
if (calculatedCrc != sentCrc)
|
||||||
{
|
{
|
||||||
// Throw a CRC exception
|
// Throw a CRC exception
|
||||||
throw new owException(owException.owExceptionFunction.CRC, _deviceID);
|
throw new owException(owException.ExceptionFunction.Crc, DeviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset the byte count
|
// Reset the byte count
|
||||||
nDataCount = 0;
|
dataCount = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public double[] GetVoltages()
|
public double[] GetVoltages()
|
||||||
{
|
{
|
||||||
short nResult; // Result of method calls
|
|
||||||
byte[] aData = new byte[30]; // Data buffer to send over the network
|
|
||||||
short nDataCount = 0; // How many bytes of data to send
|
|
||||||
int iCalculatedCRC; // CRC we calculated from sent data
|
|
||||||
int iSentCRC; // CRC retrieved from the device
|
|
||||||
short nTransmitByte; // Byte of data with the strong pull-up
|
|
||||||
short nCheckByte = 0; // Byte of data read to see if conversion is done
|
|
||||||
int iIndex; // Loop index
|
|
||||||
int iVoltageReadout; // Restructed voltage value from memory
|
|
||||||
double[] dVoltages = new double[4]; // Voltage values to return
|
|
||||||
|
|
||||||
// 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);
|
owAdapter.Select(DeviceId);
|
||||||
|
|
||||||
|
// Data buffer to send over the network
|
||||||
|
var data = new byte[30];
|
||||||
|
|
||||||
|
// How many bytes of data to send
|
||||||
|
short dataCount = 0;
|
||||||
|
|
||||||
// Set the convert command into the transmit buffer
|
// Set the convert command into the transmit buffer
|
||||||
aData[nDataCount++] = 0x3C;
|
data[dataCount++] = 0x3C;
|
||||||
|
|
||||||
// Set the input mask to get all channels
|
// Set the input mask to get all channels
|
||||||
aData[nDataCount++] = 0x0F;
|
data[dataCount++] = 0x0F;
|
||||||
|
|
||||||
// Set the read-out control to leave things as they are
|
// Set the read-out control to leave things as they are
|
||||||
aData[nDataCount++] = 0x00;
|
data[dataCount++] = 0x00;
|
||||||
|
|
||||||
// Add two bytes for the CRC results
|
// Add two bytes for the CRC results
|
||||||
aData[nDataCount++] = 0xFF;
|
data[dataCount++] = 0xFF;
|
||||||
aData[nDataCount++] = 0xFF;
|
data[dataCount++] = 0xFF;
|
||||||
|
|
||||||
// Send the data block
|
// Send the data block
|
||||||
owAdapter.SendBlock(aData, nDataCount);
|
owAdapter.SendBlock(data, dataCount);
|
||||||
|
|
||||||
// Calculate the CRC based on the transmit buffer
|
// Calculate the CRC based on the transmit buffer
|
||||||
iCalculatedCRC = owCRC16.Calculate(aData, 0, 2);
|
var calculatedCrc = owCRC16.Calculate(data, 0, 2);
|
||||||
|
|
||||||
// Reconstruct the CRC sent by the device
|
// Reconstruct the CRC sent by the device
|
||||||
iSentCRC = aData[4] << 8;
|
var sentCrc = data[4] << 8;
|
||||||
iSentCRC |= aData[3];
|
sentCrc |= data[3];
|
||||||
iSentCRC ^= 0xFFFF;
|
sentCrc ^= 0xFFFF;
|
||||||
|
|
||||||
// If the CRC doesn't match then throw an exception
|
// If the CRC doesn't match then throw an exception
|
||||||
if (iCalculatedCRC != iSentCRC)
|
if (calculatedCrc != sentCrc)
|
||||||
{
|
{
|
||||||
// Throw a CRC exception
|
// Throw a CRC exception
|
||||||
throw new owException(owException.owExceptionFunction.CRC, _deviceID);
|
throw new owException(owException.ExceptionFunction.Crc, DeviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup for for power delivery after the next byte
|
// Setup for for power delivery after the next byte
|
||||||
nResult = owAdapter.SetLevel(TMEX.TMOneWireLevelOperation.Write, TMEX.TMOneWireLevelMode.StrongPullup, TMEX.TMOneWireLevelPrime.AfterNextByte);
|
owAdapter.SetLevel(TMEX.LevelOperation.Write, TMEX.LevelMode.StrongPullup, TMEX.LevelPrime.AfterNextByte);
|
||||||
|
|
||||||
nTransmitByte = (short) ((nDataCount - 1) & 0x1F);
|
var nTransmitByte = (short) ((dataCount - 1) & 0x1F);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -187,7 +170,7 @@ namespace OneWireAPI
|
|||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
// Stop the strong pullup
|
// Stop the strong pullup
|
||||||
owAdapter.SetLevel(TMEX.TMOneWireLevelOperation.Write, TMEX.TMOneWireLevelMode.Normal, TMEX.TMOneWireLevelPrime.Immediate);
|
owAdapter.SetLevel(TMEX.LevelOperation.Write, TMEX.LevelMode.Normal, TMEX.LevelPrime.Immediate);
|
||||||
|
|
||||||
// Re-throw the exception
|
// Re-throw the exception
|
||||||
throw;
|
throw;
|
||||||
@@ -197,62 +180,63 @@ namespace OneWireAPI
|
|||||||
System.Threading.Thread.Sleep(6);
|
System.Threading.Thread.Sleep(6);
|
||||||
|
|
||||||
// Stop the strong pullup
|
// Stop the strong pullup
|
||||||
nResult = owAdapter.SetLevel(TMEX.TMOneWireLevelOperation.Write, TMEX.TMOneWireLevelMode.Normal, TMEX.TMOneWireLevelPrime.Immediate);
|
owAdapter.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
|
||||||
nCheckByte = owAdapter.ReadByte();
|
owAdapter.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);
|
owAdapter.Select(DeviceId);
|
||||||
|
|
||||||
// Reinitialize the data count
|
// Reinitialize the data count
|
||||||
nDataCount = 0;
|
dataCount = 0;
|
||||||
|
|
||||||
// Set the read command into the transmit buffer
|
// Set the read command into the transmit buffer
|
||||||
aData[nDataCount++] = 0xAA;
|
data[dataCount++] = 0xAA;
|
||||||
|
|
||||||
// Set the address to get the conversion results
|
// Set the address to get the conversion results
|
||||||
aData[nDataCount++] = 0x00;
|
data[dataCount++] = 0x00;
|
||||||
aData[nDataCount++] = 0x00;
|
data[dataCount++] = 0x00;
|
||||||
|
|
||||||
// Add 10 bytes to be read - 8 for the data and 2 for the CRC
|
// Add 10 bytes to be read - 8 for the data and 2 for the CRC
|
||||||
for (iIndex = 0; iIndex < 10; iIndex++)
|
for (var index = 0; index < 10; index++)
|
||||||
aData[nDataCount++] = 0xFF;
|
data[dataCount++] = 0xFF;
|
||||||
|
|
||||||
// Send the block to the device
|
// Send the block to the device
|
||||||
nResult = owAdapter.SendBlock(aData, nDataCount);
|
owAdapter.SendBlock(data, dataCount);
|
||||||
|
|
||||||
// Calculate the CRC of the transmitted data
|
// Calculate the CRC of the transmitted data
|
||||||
iCalculatedCRC = owCRC16.Calculate(aData, 0, 10);
|
calculatedCrc = owCRC16.Calculate(data, 0, 10);
|
||||||
|
|
||||||
// Reconstruct the CRC sent by the device
|
// Reconstruct the CRC sent by the device
|
||||||
iSentCRC = aData[nDataCount - 1] << 8;
|
sentCrc = data[dataCount - 1] << 8;
|
||||||
iSentCRC |= aData[nDataCount - 2];
|
sentCrc |= data[dataCount - 2];
|
||||||
iSentCRC ^= 0xFFFF;
|
sentCrc ^= 0xFFFF;
|
||||||
|
|
||||||
// If the CRC doesn't match then throw an exception
|
// If the CRC doesn't match then throw an exception
|
||||||
if (iCalculatedCRC != iSentCRC)
|
if (calculatedCrc != sentCrc)
|
||||||
{
|
{
|
||||||
// Throw a CRC exception
|
// Throw a CRC exception
|
||||||
throw new owException(owException.owExceptionFunction.CRC, _deviceID);
|
throw new owException(owException.ExceptionFunction.Crc, DeviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Voltage values to return
|
||||||
|
var voltages = new double[4];
|
||||||
|
|
||||||
// Convert the data into a double
|
// Convert the data into a double
|
||||||
for (iIndex = 3; iIndex < 11; iIndex += 2)
|
for (var index = 3; index < 11; index += 2)
|
||||||
{
|
{
|
||||||
// Reconstruct the two bytes into the 16-bit values
|
// Reconstruct the two bytes into the 16-bit values
|
||||||
iVoltageReadout = ((aData[iIndex + 1] << 8) | aData[iIndex]) & 0x0000FFFF;
|
var iVoltageReadout = ((data[index + 1] << 8) | data[index]) & 0x0000FFFF;
|
||||||
|
|
||||||
// Figure out the percentage of the top voltage is present
|
// Figure out the percentage of the top voltage is present
|
||||||
dVoltages[(iIndex - 3) / 2] = iVoltageReadout / 65535.0;
|
voltages[(index - 3) / 2] = iVoltageReadout / 65535.0;
|
||||||
|
|
||||||
// Apply the percentage to the maximum voltage range
|
// Apply the percentage to the maximum voltage range
|
||||||
dVoltages[(iIndex - 3) / 2] *= ((m_aControl[(iIndex - 3) + 1] & 0x01) == 0x01 ? 5.12 : 2.56);
|
voltages[(index - 3) / 2] *= ((_control[(index - 3) + 1] & 0x01) == 0x01 ? 5.12 : 2.56);
|
||||||
}
|
}
|
||||||
|
|
||||||
return dVoltages;
|
return voltages;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,75 +1,68 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace OneWireAPI
|
namespace OneWireAPI
|
||||||
{
|
{
|
||||||
public class owDeviceFamily26 : owDevice
|
public class owDeviceFamily26 : owDevice
|
||||||
{
|
{
|
||||||
#region Constructor
|
public owDeviceFamily26(owSession session, short[] id)
|
||||||
|
: base(session, id)
|
||||||
public owDeviceFamily26(owSession Session, short[] ID) : base(Session, ID)
|
|
||||||
{
|
{
|
||||||
// Just call the base constructor
|
// Just call the base constructor
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Methods
|
|
||||||
|
|
||||||
public enum VoltageType : short
|
public enum VoltageType : short
|
||||||
{
|
{
|
||||||
Supply,
|
Supply,
|
||||||
Output
|
Output
|
||||||
}
|
}
|
||||||
|
|
||||||
private double GetVoltage(VoltageType Type)
|
private double GetVoltage(VoltageType type)
|
||||||
{
|
{
|
||||||
short nResult; // Result of method calls
|
short busy;
|
||||||
byte[] aData = new byte[30]; // Data buffer to send over the network
|
|
||||||
short nDataCount = 0; // How many bytes of data to send
|
|
||||||
short nCRC; // Result of the CRC check
|
|
||||||
int iIndex;
|
|
||||||
short nBusy;
|
|
||||||
double dVoltage;
|
|
||||||
|
|
||||||
// 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);
|
owAdapter.Select(DeviceId);
|
||||||
|
|
||||||
|
// Data buffer to send over the network
|
||||||
|
var data = new byte[30];
|
||||||
|
|
||||||
|
// How many bytes of data to send
|
||||||
|
short dataCount = 0;
|
||||||
|
|
||||||
// Set the command to recall the status/configuration page to the scratchpad
|
// Set the command to recall the status/configuration page to the scratchpad
|
||||||
aData[nDataCount++] = 0xB8;
|
data[dataCount++] = 0xB8;
|
||||||
|
|
||||||
// Set the page number to recall
|
// Set the page number to recall
|
||||||
aData[nDataCount++] = 0x00;
|
data[dataCount++] = 0x00;
|
||||||
|
|
||||||
// Send the data block
|
// Send the data block
|
||||||
nResult = owAdapter.SendBlock(aData, nDataCount);
|
owAdapter.SendBlock(data, dataCount);
|
||||||
|
|
||||||
// Clear the data count
|
// Clear the data count
|
||||||
nDataCount = 0;
|
dataCount = 0;
|
||||||
|
|
||||||
// Access the device we want to talk to
|
// Access the device we want to talk to
|
||||||
owAdapter.Access();
|
owAdapter.Access();
|
||||||
|
|
||||||
// Set the command to read the scratchpad
|
// Set the command to read the scratchpad
|
||||||
aData[nDataCount++] = 0xBE;
|
data[dataCount++] = 0xBE;
|
||||||
|
|
||||||
// Set the page number to read
|
// Set the page number to read
|
||||||
aData[nDataCount++] = 0x00;
|
data[dataCount++] = 0x00;
|
||||||
|
|
||||||
// Add 9 bytes to be read - 8 for the data and 1 for the CRC
|
// Add 9 bytes to be read - 8 for the data and 1 for the CRC
|
||||||
for (iIndex = 0; iIndex < 9; iIndex++)
|
for (var index = 0; index < 9; index++)
|
||||||
aData[nDataCount++] = 0xFF;
|
data[dataCount++] = 0xFF;
|
||||||
|
|
||||||
// Send the data block
|
// Send the data block
|
||||||
nResult = owAdapter.SendBlock(aData, nDataCount);
|
owAdapter.SendBlock(data, dataCount);
|
||||||
|
|
||||||
// Calculate the CRC of the scratchpad data
|
// Calculate the CRC of the scratchpad data
|
||||||
nCRC = owCRC8.Calculate(aData, 2, 9);
|
var crc = owCRC8.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 (nCRC != aData[10])
|
if (crc != data[10])
|
||||||
{
|
{
|
||||||
// Throw a CRC exception
|
// Throw a CRC exception
|
||||||
throw new owException(owException.owExceptionFunction.CRC, _deviceID);
|
throw new owException(owException.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
|
||||||
@@ -79,48 +72,48 @@ namespace OneWireAPI
|
|||||||
owAdapter.Access();
|
owAdapter.Access();
|
||||||
|
|
||||||
// Reset the data count
|
// Reset the data count
|
||||||
nDataCount = 0;
|
dataCount = 0;
|
||||||
|
|
||||||
// Set the command to write the scratchpad
|
// Set the command to write the scratchpad
|
||||||
aData[nDataCount++] = 0x4E;
|
data[dataCount++] = 0x4E;
|
||||||
|
|
||||||
// Set the page number to write
|
// Set the page number to write
|
||||||
aData[nDataCount++] = 0x00;
|
data[dataCount++] = 0x00;
|
||||||
|
|
||||||
// Set or clear the AD bit based on the type requested
|
// Set or clear the AD bit based on the type requested
|
||||||
if (Type == VoltageType.Supply)
|
if (type == VoltageType.Supply)
|
||||||
aData[nDataCount++] = (byte) (aData[2] | 0x08);
|
data[dataCount++] = (byte) (data[2] | 0x08);
|
||||||
else
|
else
|
||||||
aData[nDataCount++] = (byte) (aData[2] & 0xF7);
|
data[dataCount++] = (byte) (data[2] & 0xF7);
|
||||||
|
|
||||||
// Move the existing data down in the array
|
// Move the existing data down in the array
|
||||||
for (iIndex = 0; iIndex < 7; iIndex++)
|
for (var index = 0; index < 7; index++)
|
||||||
aData[nDataCount++] = aData[iIndex + 4];
|
data[dataCount++] = data[index + 4];
|
||||||
|
|
||||||
// Send the data block
|
// Send the data block
|
||||||
nResult = owAdapter.SendBlock(aData, nDataCount);
|
owAdapter.SendBlock(data, dataCount);
|
||||||
|
|
||||||
// Reset the data count
|
// Reset the data count
|
||||||
nDataCount = 0;
|
dataCount = 0;
|
||||||
|
|
||||||
// Access the device we want to talk to
|
// Access the device we want to talk to
|
||||||
owAdapter.Access();
|
owAdapter.Access();
|
||||||
|
|
||||||
// Set the command to copy the scratchpad
|
// Set the command to copy the scratchpad
|
||||||
aData[nDataCount++] = 0x48;
|
data[dataCount++] = 0x48;
|
||||||
|
|
||||||
// Set the page number to copy to
|
// Set the page number to copy to
|
||||||
aData[nDataCount++] = 0x00;
|
data[dataCount++] = 0x00;
|
||||||
|
|
||||||
// Send the data block
|
// Send the data block
|
||||||
nResult = owAdapter.SendBlock(aData, nDataCount);
|
owAdapter.SendBlock(data, dataCount);
|
||||||
|
|
||||||
// Loop until the data copy is complete
|
// Loop until the data copy is complete
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
nBusy = owAdapter.ReadByte();
|
busy = owAdapter.ReadByte();
|
||||||
}
|
}
|
||||||
while (nBusy == 0);
|
while (busy == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Access the device we want to talk to
|
// Access the device we want to talk to
|
||||||
@@ -132,56 +125,56 @@ namespace OneWireAPI
|
|||||||
// Loop until conversion is complete
|
// Loop until conversion is complete
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
nBusy = owAdapter.ReadByte();
|
busy = owAdapter.ReadByte();
|
||||||
}
|
}
|
||||||
while (nBusy == 0);
|
while (busy == 0);
|
||||||
|
|
||||||
// Clear the data count
|
// Clear the data count
|
||||||
nDataCount = 0;
|
dataCount = 0;
|
||||||
|
|
||||||
// Set the command to recall the status/configuration page to the scratchpad
|
// Set the command to recall the status/configuration page to the scratchpad
|
||||||
aData[nDataCount++] = 0xB8;
|
data[dataCount++] = 0xB8;
|
||||||
|
|
||||||
// Set the page number to recall
|
// Set the page number to recall
|
||||||
aData[nDataCount++] = 0x00;
|
data[dataCount++] = 0x00;
|
||||||
|
|
||||||
// Access the device we want to talk to
|
// Access the device we want to talk to
|
||||||
owAdapter.Access();
|
owAdapter.Access();
|
||||||
|
|
||||||
// Send the data block
|
// Send the data block
|
||||||
nResult = owAdapter.SendBlock(aData, nDataCount);
|
owAdapter.SendBlock(data, dataCount);
|
||||||
|
|
||||||
// Clear the data count
|
// Clear the data count
|
||||||
nDataCount = 0;
|
dataCount = 0;
|
||||||
|
|
||||||
// Access the device we want to talk to
|
// Access the device we want to talk to
|
||||||
owAdapter.Access();
|
owAdapter.Access();
|
||||||
|
|
||||||
// Set the command to read the scratchpad
|
// Set the command to read the scratchpad
|
||||||
aData[nDataCount++] = 0xBE;
|
data[dataCount++] = 0xBE;
|
||||||
|
|
||||||
// Set the page number to read
|
// Set the page number to read
|
||||||
aData[nDataCount++] = 0x00;
|
data[dataCount++] = 0x00;
|
||||||
|
|
||||||
// Add 9 bytes to be read - 8 for the data and 1 for the CRC
|
// Add 9 bytes to be read - 8 for the data and 1 for the CRC
|
||||||
for (iIndex = 0; iIndex < 9; iIndex++)
|
for (var index = 0; index < 9; index++)
|
||||||
aData[nDataCount++] = 0xFF;
|
data[dataCount++] = 0xFF;
|
||||||
|
|
||||||
// Send the data block
|
// Send the data block
|
||||||
nResult = owAdapter.SendBlock(aData, nDataCount);
|
owAdapter.SendBlock(data, dataCount);
|
||||||
|
|
||||||
// Calculate the CRC of the scratchpad data
|
// Calculate the CRC of the scratchpad data
|
||||||
nCRC = owCRC8.Calculate(aData, 2, 9);
|
crc = owCRC8.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 (nCRC != aData[10])
|
if (crc != data[10])
|
||||||
{
|
{
|
||||||
// Throw a CRC exception
|
// Throw a CRC exception
|
||||||
throw new owException(owException.owExceptionFunction.CRC, _deviceID);
|
throw new owException(owException.ExceptionFunction.Crc, DeviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assemble the voltage data
|
// Assemble the voltage data
|
||||||
dVoltage = (double) ((aData[6] << 8) | aData[5]);
|
var dVoltage = (double) ((data[6] << 8) | data[5]);
|
||||||
|
|
||||||
return dVoltage / 100;
|
return dVoltage / 100;
|
||||||
}
|
}
|
||||||
@@ -199,17 +192,8 @@ namespace OneWireAPI
|
|||||||
|
|
||||||
public double GetTemperature()
|
public double GetTemperature()
|
||||||
{
|
{
|
||||||
short nResult; // Result of method calls
|
|
||||||
byte[] aData = new byte[30]; // Data buffer to send over the network
|
|
||||||
short nDataCount = 0; // How many bytes of data to send
|
|
||||||
short nCRC; // Result of the CRC check
|
|
||||||
int iTemperatureLSB; // The LSB of the temperature data
|
|
||||||
int iTemperatureMSB; // The MSB of the temperature data
|
|
||||||
int iTemperature; // Complete temperature data
|
|
||||||
double dTemperature; // double version of the temperature
|
|
||||||
|
|
||||||
// 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);
|
owAdapter.Select(DeviceId);
|
||||||
|
|
||||||
// Send the conversion command byte
|
// Send the conversion command byte
|
||||||
owAdapter.SendByte(0x44);
|
owAdapter.SendByte(0x44);
|
||||||
@@ -220,58 +204,59 @@ namespace OneWireAPI
|
|||||||
// Access the device we want to talk to
|
// Access the device we want to talk to
|
||||||
owAdapter.Access();
|
owAdapter.Access();
|
||||||
|
|
||||||
|
// Data buffer to send over the network
|
||||||
|
var data = new byte[30];
|
||||||
|
|
||||||
|
// How many bytes of data to send
|
||||||
|
short dataCount = 0;
|
||||||
|
|
||||||
// Set the command to recall the status/configuration page to the scratchpad
|
// Set the command to recall the status/configuration page to the scratchpad
|
||||||
aData[nDataCount++] = 0xB8;
|
data[dataCount++] = 0xB8;
|
||||||
|
|
||||||
// Set the page number to recall
|
// Set the page number to recall
|
||||||
aData[nDataCount++] = 0x00;
|
data[dataCount++] = 0x00;
|
||||||
|
|
||||||
// Send the data block
|
// Send the data block
|
||||||
nResult = owAdapter.SendBlock(aData, nDataCount);
|
owAdapter.SendBlock(data, dataCount);
|
||||||
|
|
||||||
// Clear the data count
|
// Clear the data count
|
||||||
nDataCount = 0;
|
dataCount = 0;
|
||||||
|
|
||||||
// Access the device we want to talk to
|
// Access the device we want to talk to
|
||||||
owAdapter.Access();
|
owAdapter.Access();
|
||||||
|
|
||||||
// Set the command to read the scratchpad
|
// Set the command to read the scratchpad
|
||||||
aData[nDataCount++] = 0xBE;
|
data[dataCount++] = 0xBE;
|
||||||
|
|
||||||
// Set the page number to read
|
// Set the page number to read
|
||||||
aData[nDataCount++] = 0x00;
|
data[dataCount++] = 0x00;
|
||||||
|
|
||||||
// Add 9 bytes to be read - 8 for the data and 1 for the CRC
|
// Add 9 bytes to be read - 8 for the data and 1 for the CRC
|
||||||
for (int iIndex = 0; iIndex < 9; iIndex++)
|
for (var iIndex = 0; iIndex < 9; iIndex++)
|
||||||
aData[nDataCount++] = 0xFF;
|
data[dataCount++] = 0xFF;
|
||||||
|
|
||||||
// Send the data block
|
// Send the data block
|
||||||
nResult = owAdapter.SendBlock(aData, nDataCount);
|
owAdapter.SendBlock(data, dataCount);
|
||||||
|
|
||||||
// Calculate the CRC of the scratchpad data
|
// Calculate the CRC of the scratchpad data
|
||||||
nCRC = owCRC8.Calculate(aData, 2, 9);
|
var crc = owCRC8.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 (nCRC != aData[10])
|
if (crc != data[10])
|
||||||
{
|
{
|
||||||
// Throw a CRC exception
|
// Throw a CRC exception
|
||||||
throw new owException(owException.owExceptionFunction.CRC, _deviceID);
|
throw new owException(owException.ExceptionFunction.Crc, DeviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the two bytes of temperature data
|
// Get the two bytes of temperature data
|
||||||
iTemperatureLSB = aData[3];
|
int temperatureLsb = data[3];
|
||||||
iTemperatureMSB = aData[4];
|
int temperatureMsb = data[4];
|
||||||
|
|
||||||
// Shift the data into the right order
|
// Shift the data into the right order
|
||||||
iTemperature = ((iTemperatureMSB << 8) | iTemperatureLSB) >> 3;
|
var iTemperature = ((temperatureMsb << 8) | temperatureLsb) >> 3;
|
||||||
|
|
||||||
// Figure out the temperature
|
|
||||||
dTemperature = iTemperature * 0.03125F;
|
|
||||||
|
|
||||||
// Return the temperature
|
// Return the temperature
|
||||||
return dTemperature;
|
return iTemperature * 0.03125F;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,112 +1,114 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace OneWireAPI
|
namespace OneWireAPI
|
||||||
{
|
{
|
||||||
public class owDeviceFamilyFF : owDevice
|
public class owDeviceFamilyFF : owDevice
|
||||||
{
|
{
|
||||||
#region Member variables
|
private int _width = 20;
|
||||||
|
private int _height = 4;
|
||||||
|
|
||||||
private int m_iWidth = 20;
|
public owDeviceFamilyFF(owSession session, short[] id)
|
||||||
private int m_iHeight = 4;
|
: base(session, id)
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructor
|
|
||||||
|
|
||||||
public owDeviceFamilyFF(owSession Session, short[] ID) : base(Session, ID)
|
|
||||||
{
|
{
|
||||||
// Just call the base constructor
|
// Just call the base constructor
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
public void SetSize(int width, int height)
|
||||||
|
{
|
||||||
|
_width = width;
|
||||||
|
_height = height;
|
||||||
|
}
|
||||||
|
|
||||||
#region Methods
|
public void SetBackLight(bool state)
|
||||||
|
|
||||||
public void SetBackLight(bool State)
|
|
||||||
{
|
{
|
||||||
// Select the device
|
// Select the device
|
||||||
owAdapter.Select(_deviceID);
|
owAdapter.Select(DeviceId);
|
||||||
|
|
||||||
// Set the state of the backlight
|
// Set the state of the backlight
|
||||||
owAdapter.SendByte((short) (State ? 0x8 : 0x7));
|
owAdapter.SendByte((short) (state ? 0x8 : 0x7));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetText(string Text)
|
public void SetText(string text)
|
||||||
{
|
{
|
||||||
string[] sLines = null; // Array of lines
|
// Line number
|
||||||
int iLine = 1; // Line number
|
var line = 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
|
||||||
sLines = Text.Split("\n".ToCharArray(), m_iHeight);
|
var sLines = text.Split("\n".ToCharArray(), _height);
|
||||||
|
|
||||||
// Loop over each line
|
// Loop over each line
|
||||||
foreach (string sLine in sLines)
|
foreach (var sLine in sLines)
|
||||||
{
|
{
|
||||||
// Set the text of this line
|
// Set the text of this line
|
||||||
SetText(sLine, iLine++);
|
SetText(sLine, line++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetText(string Text, int Line)
|
public void SetText(string text, int line)
|
||||||
{
|
{
|
||||||
short nMemoryPosition = 0x00; // Position at which to write the new string data
|
// Position at which to write the new string data
|
||||||
string sSendData = ""; // String data to send
|
short memoryPosition = 0x00;
|
||||||
byte[] baData; // Byte array of data to send
|
|
||||||
short nDataCount = 0; // Amount of data to send
|
// String data to send
|
||||||
|
string sendData;
|
||||||
|
|
||||||
|
// Byte array of data to send
|
||||||
|
byte[] data;
|
||||||
|
|
||||||
|
// Amount of data to send
|
||||||
|
short dataCount = 0;
|
||||||
|
|
||||||
// Figure out the initial memory position based on the line number
|
// Figure out the initial memory position based on the line number
|
||||||
switch (Line)
|
switch (line)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
nMemoryPosition = 0x00;
|
memoryPosition = 0x00;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
nMemoryPosition = 0x40;
|
memoryPosition = 0x40;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
nMemoryPosition = 0x14;
|
memoryPosition = 0x14;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
nMemoryPosition = 0x54;
|
memoryPosition = 0x54;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pad the text to the right width
|
// Pad the text to the right width
|
||||||
Text = Text.PadRight(m_iWidth);
|
text = text.PadRight(_width);
|
||||||
|
|
||||||
// The scratchpad is only 16 bytes long so we need to split it up
|
// The scratchpad is only 16 bytes long so we need to split it up
|
||||||
if (m_iWidth > 16)
|
if (_width > 16)
|
||||||
{
|
{
|
||||||
// Select the device
|
// Select the device
|
||||||
owAdapter.Select(_deviceID);
|
owAdapter.Select(DeviceId);
|
||||||
|
|
||||||
// Set the data block to just the first 16 characters
|
// Set the data block to just the first 16 characters
|
||||||
sSendData = Text.Substring(0, 16);
|
sendData = text.Substring(0, 16);
|
||||||
|
|
||||||
// Initialize the data array
|
// Initialize the data array
|
||||||
baData = new byte[18];
|
data = new byte[18];
|
||||||
|
|
||||||
// Set the command to write to the scratchpad
|
// Set the command to write to the scratchpad
|
||||||
baData[nDataCount++] = 0x4E;
|
data[dataCount++] = 0x4E;
|
||||||
|
|
||||||
// Set the memory position
|
// Set the memory position
|
||||||
baData[nDataCount++] = (byte) nMemoryPosition;
|
data[dataCount++] = (byte) memoryPosition;
|
||||||
|
|
||||||
// Add the text data to the data
|
// Add the text data to the data
|
||||||
foreach (byte bChar in System.Text.Encoding.Default.GetBytes(sSendData))
|
foreach (var bChar in System.Text.Encoding.Default.GetBytes(sendData))
|
||||||
baData[nDataCount++] = bChar;
|
data[dataCount++] = bChar;
|
||||||
|
|
||||||
// Set the block
|
// Set the block
|
||||||
owAdapter.SendBlock(baData, nDataCount);
|
owAdapter.SendBlock(data, dataCount);
|
||||||
|
|
||||||
// Select the device
|
// Select the device
|
||||||
owAdapter.Select(_deviceID);
|
owAdapter.Select(DeviceId);
|
||||||
|
|
||||||
// Send the scratchpad data to the LCD
|
// Send the scratchpad data to the LCD
|
||||||
owAdapter.SendByte(0x48);
|
owAdapter.SendByte(0x48);
|
||||||
@@ -115,41 +117,41 @@ namespace OneWireAPI
|
|||||||
owAdapter.Reset();
|
owAdapter.Reset();
|
||||||
|
|
||||||
// Increment the memory position
|
// Increment the memory position
|
||||||
nMemoryPosition += 16;
|
memoryPosition += 16;
|
||||||
|
|
||||||
// Set the data to the rest of the line
|
// Set the data to the rest of the line
|
||||||
sSendData = Text.Substring(16, m_iWidth - 16);
|
sendData = text.Substring(16, _width - 16);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Just set the data string to whatever was passed in
|
// Just set the data string to whatever was passed in
|
||||||
sSendData = Text;
|
sendData = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Select the device
|
// Select the device
|
||||||
owAdapter.Select(_deviceID);
|
owAdapter.Select(DeviceId);
|
||||||
|
|
||||||
// Initialize the data array
|
// Initialize the data array
|
||||||
baData = new byte[18];
|
data = new byte[18];
|
||||||
|
|
||||||
// Reset the data count
|
// Reset the data count
|
||||||
nDataCount = 0;
|
dataCount = 0;
|
||||||
|
|
||||||
// Set the command to write to the scratchpad
|
// Set the command to write to the scratchpad
|
||||||
baData[nDataCount++] = 0x4E;
|
data[dataCount++] = 0x4E;
|
||||||
|
|
||||||
// Set the memory position
|
// Set the memory position
|
||||||
baData[nDataCount++] = (byte) nMemoryPosition;
|
data[dataCount++] = (byte) memoryPosition;
|
||||||
|
|
||||||
// Add the text data to the data
|
// Add the text data to the data
|
||||||
foreach (byte bChar in System.Text.Encoding.Default.GetBytes(sSendData))
|
foreach (var bChar in System.Text.Encoding.Default.GetBytes(sendData))
|
||||||
baData[nDataCount++] = bChar;
|
data[dataCount++] = bChar;
|
||||||
|
|
||||||
// Set the block
|
// Set the block
|
||||||
owAdapter.SendBlock(baData, nDataCount);
|
owAdapter.SendBlock(data, dataCount);
|
||||||
|
|
||||||
// Select the device
|
// Select the device
|
||||||
owAdapter.Select(_deviceID);
|
owAdapter.Select(DeviceId);
|
||||||
|
|
||||||
// Send the scratchpad data to the LCD
|
// Send the scratchpad data to the LCD
|
||||||
owAdapter.SendByte(0x48);
|
owAdapter.SendByte(0x48);
|
||||||
@@ -161,12 +163,10 @@ namespace OneWireAPI
|
|||||||
public void Clear()
|
public void Clear()
|
||||||
{
|
{
|
||||||
// Select the device
|
// Select the device
|
||||||
owAdapter.Select(_deviceID);
|
owAdapter.Select(DeviceId);
|
||||||
|
|
||||||
// Clear the display
|
// Clear the display
|
||||||
owAdapter.SendByte(0x49);
|
owAdapter.SendByte(0x49);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,10 @@ namespace OneWireAPI
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
public class owException : Exception
|
public class owException : Exception
|
||||||
{
|
{
|
||||||
#region Enumerations
|
public enum ExceptionFunction
|
||||||
|
|
||||||
public enum owExceptionFunction
|
|
||||||
{
|
{
|
||||||
Access,
|
Access,
|
||||||
CRC,
|
Crc,
|
||||||
ReadBit,
|
ReadBit,
|
||||||
ReadByte,
|
ReadByte,
|
||||||
Select,
|
Select,
|
||||||
@@ -20,19 +18,11 @@ namespace OneWireAPI
|
|||||||
SetLevel
|
SetLevel
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Private member variables
|
|
||||||
|
|
||||||
private readonly int _errorNumber;
|
private readonly int _errorNumber;
|
||||||
private readonly owExceptionFunction _errorFunction;
|
private readonly ExceptionFunction _errorFunction;
|
||||||
private readonly owIdentifier _deviceID;
|
private readonly owIdentifier _deviceId;
|
||||||
|
|
||||||
#endregion
|
public owException(ExceptionFunction function, int number)
|
||||||
|
|
||||||
#region Constructors
|
|
||||||
|
|
||||||
public owException(owExceptionFunction function, int number)
|
|
||||||
{
|
{
|
||||||
// Store the exception function
|
// Store the exception function
|
||||||
_errorFunction = function;
|
_errorFunction = function;
|
||||||
@@ -41,37 +31,33 @@ namespace OneWireAPI
|
|||||||
_errorNumber = number;
|
_errorNumber = number;
|
||||||
}
|
}
|
||||||
|
|
||||||
public owException(owExceptionFunction function, owIdentifier deviceID)
|
public owException(ExceptionFunction function, owIdentifier deviceId)
|
||||||
{
|
{
|
||||||
// Store the exception function
|
// Store the exception function
|
||||||
_errorFunction = function;
|
_errorFunction = function;
|
||||||
|
|
||||||
// Store the device ID
|
// Store the device ID
|
||||||
_deviceID = deviceID;
|
_deviceId = deviceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public owException(owExceptionFunction function, owIdentifier deviceID, int number)
|
public owException(ExceptionFunction function, owIdentifier deviceId, int number)
|
||||||
{
|
{
|
||||||
// Store the exception function
|
// Store the exception function
|
||||||
_errorFunction = function;
|
_errorFunction = function;
|
||||||
|
|
||||||
// Store the device ID
|
// Store the device ID
|
||||||
_deviceID = deviceID;
|
_deviceId = deviceId;
|
||||||
|
|
||||||
// Store the exception number
|
// Store the exception number
|
||||||
_errorNumber = number;
|
_errorNumber = number;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
public owIdentifier DeviceId
|
||||||
|
|
||||||
#region Properties
|
|
||||||
|
|
||||||
public owIdentifier DeviceID
|
|
||||||
{
|
{
|
||||||
get { return _deviceID; }
|
get { return _deviceId; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public owExceptionFunction Function
|
public ExceptionFunction Function
|
||||||
{
|
{
|
||||||
get { return _errorFunction; }
|
get { return _errorFunction; }
|
||||||
}
|
}
|
||||||
@@ -82,16 +68,26 @@ namespace OneWireAPI
|
|||||||
{
|
{
|
||||||
switch (_errorFunction)
|
switch (_errorFunction)
|
||||||
{
|
{
|
||||||
case owExceptionFunction.Access: return "Unable to access device";
|
case ExceptionFunction.Access:
|
||||||
case owExceptionFunction.CRC: return "CRC mismatch";
|
return "Unable to access device";
|
||||||
case owExceptionFunction.ReadBit: return "Error reading bit";
|
case ExceptionFunction.Crc:
|
||||||
case owExceptionFunction.ReadByte: return "Error reading byte";
|
return "CRC mismatch";
|
||||||
case owExceptionFunction.Select: return "Unable to select device";
|
case ExceptionFunction.ReadBit:
|
||||||
case owExceptionFunction.SendBit: return "Error sending bit";
|
return "Error reading bit";
|
||||||
case owExceptionFunction.SendBlock: return "Error sending block";
|
case ExceptionFunction.ReadByte:
|
||||||
case owExceptionFunction.SendByte: return "Error sending byte";
|
return "Error reading byte";
|
||||||
case owExceptionFunction.SetLevel: return "Error setting level";
|
case ExceptionFunction.Select:
|
||||||
default: return "Unknown error in function" + _errorFunction;
|
return "Unable to select device";
|
||||||
|
case ExceptionFunction.SendBit:
|
||||||
|
return "Error sending bit";
|
||||||
|
case ExceptionFunction.SendBlock:
|
||||||
|
return "Error sending block";
|
||||||
|
case ExceptionFunction.SendByte:
|
||||||
|
return "Error sending byte";
|
||||||
|
case ExceptionFunction.SetLevel:
|
||||||
|
return "Error setting level";
|
||||||
|
default:
|
||||||
|
return "Unknown error in function" + _errorFunction;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -100,7 +96,5 @@ namespace OneWireAPI
|
|||||||
{
|
{
|
||||||
get { return _errorNumber; }
|
get { return _errorNumber; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,80 +1,65 @@
|
|||||||
using System;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace OneWireAPI
|
namespace OneWireAPI
|
||||||
{
|
{
|
||||||
public class owIdentifier
|
public class owIdentifier
|
||||||
{
|
{
|
||||||
#region Member variables
|
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
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructors
|
|
||||||
|
|
||||||
public owIdentifier()
|
public owIdentifier()
|
||||||
{
|
{
|
||||||
// Create a blank ID
|
// Create a blank ID
|
||||||
_rawID = new short[8];
|
_rawId = new short[8];
|
||||||
}
|
}
|
||||||
|
|
||||||
public owIdentifier(byte[] deviceID)
|
public owIdentifier(byte[] deviceId)
|
||||||
{
|
{
|
||||||
// Create a blank ID
|
// Create a blank ID
|
||||||
_rawID = new short[8];
|
_rawId = new short[8];
|
||||||
|
|
||||||
// Copy the byte array to the short array
|
// Copy the byte array to the short array
|
||||||
for (int i = 0; i < deviceID.Length; i++)
|
for (var i = 0; i < deviceId.Length; i++)
|
||||||
_rawID[i] = deviceID[i];
|
_rawId[i] = deviceId[i];
|
||||||
|
|
||||||
// Get the friendly name
|
// Get the friendly name
|
||||||
_friendlyName = ConvertToString(_rawID);
|
_friendlyName = ConvertToString(_rawId);
|
||||||
|
|
||||||
// Get the family code
|
// Get the family code
|
||||||
_familyCode = _rawID[0];
|
_familyCode = _rawId[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public owIdentifier(short[] deviceID)
|
public owIdentifier(short[] deviceId)
|
||||||
{
|
{
|
||||||
// Store the ID supplied
|
// Store the ID supplied
|
||||||
_rawID = deviceID;
|
_rawId = deviceId;
|
||||||
|
|
||||||
// Get the friendly name
|
// Get the friendly name
|
||||||
_friendlyName = ConvertToString(_rawID);
|
_friendlyName = ConvertToString(_rawId);
|
||||||
|
|
||||||
// Get the family code
|
// Get the family code
|
||||||
_familyCode = _rawID[0];
|
_familyCode = _rawId[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
private static string ConvertToString(short[] rawId)
|
||||||
|
|
||||||
#region Private methods
|
|
||||||
|
|
||||||
private static string ConvertToString(short[] rawID)
|
|
||||||
{
|
{
|
||||||
StringBuilder friendlyID = new StringBuilder();
|
var friendlyId = new StringBuilder();
|
||||||
|
|
||||||
// Loop backwards over the ID array
|
// Loop backwards over the ID array
|
||||||
for (int iIndex = rawID.Length - 1; iIndex >= 0; iIndex--)
|
for (var iIndex = rawId.Length - 1; iIndex >= 0; iIndex--)
|
||||||
{
|
{
|
||||||
// Convert the short value into a hex string and append it to the ID string
|
// Convert the short value into a hex string and append it to the ID string
|
||||||
friendlyID.AppendFormat("{0:X2}", rawID[iIndex]);
|
friendlyId.AppendFormat("{0:X2}", rawId[iIndex]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the ID string
|
// Return the ID string
|
||||||
return friendlyID.ToString();
|
return friendlyId.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
public short[] RawId
|
||||||
|
|
||||||
#region Properties
|
|
||||||
|
|
||||||
public short[] RawID
|
|
||||||
{
|
{
|
||||||
get { return _rawID; }
|
get { return _rawId; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name
|
public string Name
|
||||||
@@ -87,15 +72,9 @@ namespace OneWireAPI
|
|||||||
get { return _familyCode; }
|
get { return _familyCode; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Methods
|
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return _friendlyName;
|
return _friendlyName;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
65
owNetwork.cs
65
owNetwork.cs
@@ -1,95 +1,76 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace OneWireAPI
|
namespace OneWireAPI
|
||||||
{
|
{
|
||||||
public class owNetwork
|
public class owNetwork
|
||||||
{
|
{
|
||||||
#region Member variables
|
|
||||||
|
|
||||||
private owSession _session; // Current session
|
private owSession _session; // Current session
|
||||||
private Dictionary<string, owDevice> _deviceList; // List of current devices
|
private Dictionary<string, owDevice> _deviceList; // List of current devices
|
||||||
|
|
||||||
#endregion
|
public owNetwork(owSession session)
|
||||||
|
|
||||||
#region Constructor
|
|
||||||
|
|
||||||
public owNetwork(owSession Session)
|
|
||||||
{
|
{
|
||||||
_session = Session;
|
_session = session;
|
||||||
|
|
||||||
_deviceList = new Dictionary<string, owDevice>();
|
_deviceList = new Dictionary<string, owDevice>();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Delegates
|
|
||||||
|
|
||||||
public delegate void DeviceEventDelegate(owDevice device);
|
public delegate void DeviceEventDelegate(owDevice device);
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Events
|
|
||||||
|
|
||||||
public event DeviceEventDelegate DeviceAdded;
|
public event DeviceEventDelegate DeviceAdded;
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Private methods
|
|
||||||
|
|
||||||
private void LoadDevices()
|
private void LoadDevices()
|
||||||
{
|
{
|
||||||
owDevice device; // Current device object
|
|
||||||
|
|
||||||
// Get the first device on the network
|
// Get the first device on the network
|
||||||
short nResult = TMEX.TMFirst(_session.SessionHandle, _session.StateBuffer);
|
var nResult = TMEX.TMFirst(_session.SessionHandle, _session.StateBuffer);
|
||||||
|
|
||||||
// Keep looping while we get good device data
|
// Keep looping while we get good device data
|
||||||
while (nResult == 1)
|
while (nResult == 1)
|
||||||
{
|
{
|
||||||
// Create a new device ID buffer
|
// Create a new device ID buffer
|
||||||
short[] nROM = new short[8];
|
var id = new short[8];
|
||||||
|
|
||||||
// Get the ROM from the device
|
// Get the ROM from the device
|
||||||
nResult = TMEX.TMRom(_session.SessionHandle, _session.StateBuffer, nROM);
|
nResult = TMEX.TMRom(_session.SessionHandle, _session.StateBuffer, id);
|
||||||
|
|
||||||
// If the ROM was read correctly then add the device to the list
|
// If the ROM was read correctly then add the device to the list
|
||||||
if (nResult == 1)
|
if (nResult == 1)
|
||||||
{
|
{
|
||||||
// Get the deviceID
|
// Get the deviceID
|
||||||
owIdentifier deviceID = new owIdentifier(nROM);
|
var deviceId = new owIdentifier(id);
|
||||||
|
|
||||||
// Create a new device object
|
// Create a new device object
|
||||||
switch (deviceID.Family)
|
owDevice device;
|
||||||
|
|
||||||
|
switch (deviceId.Family)
|
||||||
{
|
{
|
||||||
case 0x10:
|
case 0x10:
|
||||||
device = new owDeviceFamily10(_session, nROM);
|
device = new owDeviceFamily10(_session, id);
|
||||||
break;
|
break;
|
||||||
case 0x1D:
|
case 0x1D:
|
||||||
device = new owDeviceFamily1D(_session, nROM);
|
device = new owDeviceFamily1D(_session, id);
|
||||||
break;
|
break;
|
||||||
case 0x20:
|
case 0x20:
|
||||||
device = new owDeviceFamily20(_session, nROM);
|
device = new owDeviceFamily20(_session, id);
|
||||||
break;
|
break;
|
||||||
case 0x26:
|
case 0x26:
|
||||||
device = new owDeviceFamily26(_session, nROM);
|
device = new owDeviceFamily26(_session, id);
|
||||||
break;
|
break;
|
||||||
case 0x12:
|
case 0x12:
|
||||||
device = new owDeviceFamily12(_session, nROM);
|
device = new owDeviceFamily12(_session, id);
|
||||||
break;
|
break;
|
||||||
case 0xFF:
|
case 0xFF:
|
||||||
device = new owDeviceFamilyFF(_session, nROM);
|
device = new owDeviceFamilyFF(_session, id);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
device = new owDevice(_session, nROM);
|
device = new owDevice(_session, id);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we've seen this device before
|
// Check if we've seen this device before
|
||||||
if (!_deviceList.ContainsKey(device.ID.Name))
|
if (!_deviceList.ContainsKey(device.Id.Name))
|
||||||
{
|
{
|
||||||
// Add the device to the device list
|
// Add the device to the device list
|
||||||
_deviceList[device.ID.Name] = device;
|
_deviceList[device.Id.Name] = device;
|
||||||
|
|
||||||
// Raise the device added event
|
// Raise the device added event
|
||||||
if (DeviceAdded != null)
|
if (DeviceAdded != null)
|
||||||
@@ -102,19 +83,11 @@ namespace OneWireAPI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Properties
|
|
||||||
|
|
||||||
public Dictionary<string, owDevice> Devices
|
public Dictionary<string, owDevice> Devices
|
||||||
{
|
{
|
||||||
get { return _deviceList; }
|
get { return _deviceList; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Public methods
|
|
||||||
|
|
||||||
public void Initialize()
|
public void Initialize()
|
||||||
{
|
{
|
||||||
// Load the device list
|
// Load the device list
|
||||||
@@ -130,7 +103,5 @@ namespace OneWireAPI
|
|||||||
// Get rid of the session
|
// Get rid of the session
|
||||||
_session = null;
|
_session = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
39
owSession.cs
39
owSession.cs
@@ -1,13 +1,10 @@
|
|||||||
using Common.Debug;
|
using Common.Debug;
|
||||||
using System;
|
using System;
|
||||||
using System.Threading;
|
|
||||||
|
|
||||||
namespace OneWireAPI
|
namespace OneWireAPI
|
||||||
{
|
{
|
||||||
public class owSession
|
public class owSession
|
||||||
{
|
{
|
||||||
#region Member variables
|
|
||||||
|
|
||||||
private int _sessionHandle; // Session handle
|
private int _sessionHandle; // Session handle
|
||||||
private owNetwork _network; // Network object
|
private owNetwork _network; // Network object
|
||||||
|
|
||||||
@@ -15,35 +12,27 @@ namespace OneWireAPI
|
|||||||
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
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructor
|
|
||||||
|
|
||||||
public owSession()
|
public owSession()
|
||||||
{
|
{
|
||||||
// Create the global state buffer
|
// Create the global state buffer
|
||||||
_stateBuffer = new byte[(int) TMEX.TMStateBufferSize.NoEPROMWriting];
|
_stateBuffer = new byte[(int) TMEX.StateBufferSize.NoEpromWriting];
|
||||||
|
|
||||||
// Get the default port number and type from the system
|
// Get the default port number and type from the system
|
||||||
short result = TMEX.TMReadDefaultPort(out _portNumber, out _portType);
|
var result = TMEX.TMReadDefaultPort(out _portNumber, out _portType);
|
||||||
|
|
||||||
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 owSession(short portNumber, short portType)
|
||||||
{
|
{
|
||||||
// Create the global state buffer
|
// Create the global state buffer
|
||||||
_stateBuffer = new byte[(int) TMEX.TMStateBufferSize.NoEPROMWriting];
|
_stateBuffer = new byte[(int) TMEX.StateBufferSize.NoEpromWriting];
|
||||||
|
|
||||||
// Store the port number and type specified
|
// Store the port number and type specified
|
||||||
_portNumber = PortNumber;
|
_portNumber = portNumber;
|
||||||
_portType = PortType;
|
_portType = portType;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Properties
|
|
||||||
|
|
||||||
public short PortNumber
|
public short PortNumber
|
||||||
{
|
{
|
||||||
get { return _portNumber; }
|
get { return _portNumber; }
|
||||||
@@ -69,23 +58,19 @@ namespace OneWireAPI
|
|||||||
get { return _stateBuffer; }
|
get { return _stateBuffer; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Methods
|
|
||||||
|
|
||||||
public bool Acquire()
|
public bool Acquire()
|
||||||
{
|
{
|
||||||
// Create a byte array to hold the version information
|
// Create a byte array to hold the version information
|
||||||
byte[] version = new byte[80];
|
var version = new byte[80];
|
||||||
|
|
||||||
// Get the version
|
// Get the version
|
||||||
TMEX.Get_Version(version);
|
TMEX.Get_Version(version);
|
||||||
|
|
||||||
// Decode the version
|
// Decode the version
|
||||||
string sVersion = System.Text.Encoding.Default.GetString(version, 0, version.Length);
|
var sVersion = System.Text.Encoding.Default.GetString(version, 0, version.Length);
|
||||||
|
|
||||||
// Strip everything up to the first null character
|
// Strip everything up to the first null character
|
||||||
sVersion = sVersion.Substring(0, sVersion.IndexOf("\0"));
|
sVersion = sVersion.Substring(0, sVersion.IndexOf("\0", StringComparison.Ordinal));
|
||||||
|
|
||||||
Tracer.WriteLine("Version: {0}", sVersion);
|
Tracer.WriteLine("Version: {0}", sVersion);
|
||||||
|
|
||||||
@@ -101,7 +86,7 @@ namespace OneWireAPI
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Setup the port for the current session
|
// Setup the port for the current session
|
||||||
short result = TMEX.TMSetup(_sessionHandle);
|
var result = TMEX.TMSetup(_sessionHandle);
|
||||||
|
|
||||||
Tracer.WriteLine("TMSetup - Return: {0}", result);
|
Tracer.WriteLine("TMSetup - Return: {0}", result);
|
||||||
|
|
||||||
@@ -138,7 +123,7 @@ namespace OneWireAPI
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Close the session
|
// Close the session
|
||||||
short result = TMEX.TMClose(_sessionHandle);
|
var result = TMEX.TMClose(_sessionHandle);
|
||||||
|
|
||||||
Tracer.WriteLine("TMClose - Return: {0}", result);
|
Tracer.WriteLine("TMClose - Return: {0}", result);
|
||||||
|
|
||||||
@@ -150,7 +135,5 @@ namespace OneWireAPI
|
|||||||
// Clear the session variable
|
// Clear the session variable
|
||||||
_sessionHandle = 0;
|
_sessionHandle = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user