Skip to content

Commit

Permalink
update v1.4.4.1
Browse files Browse the repository at this point in the history
Add propertie for time out transaction
Add propertie for SLA
  • Loading branch information
WebGE committed May 25, 2017
1 parent dda7953 commit 2ff6abe
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 18 deletions.
1 change: 1 addition & 0 deletions PCF8574/PCF8574/PCF8574.csproj
Expand Up @@ -38,6 +38,7 @@
<Reference Include="Microsoft.SPOT.Native" />
</ItemGroup>
<ItemGroup>
<None Include="ClassDiagram1.cd" />
<None Include="pcf8574.cd" />
</ItemGroup>
<Import Condition="EXISTS('$(NetMfTargetsBaseDir)$(TargetFrameworkVersion)\CSharp.Targets')" Project="$(NetMfTargetsBaseDir)$(TargetFrameworkVersion)\CSharp.Targets" />
Expand Down
4 changes: 2 additions & 2 deletions PCF8574/PCF8574/Properties/AssemblyInfo.cs
Expand Up @@ -21,5 +21,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.4.3.1")]
[assembly: AssemblyFileVersion("1.4.3.1")]
[assembly: AssemblyVersion("1.4.4.1")]
[assembly: AssemblyFileVersion("1.4.4.1")]
60 changes: 44 additions & 16 deletions PCF8574/PCF8574/pcf8574.cs
Expand Up @@ -15,32 +15,60 @@ namespace IO
/// </remarks>
public class PCF8574
{
/// <summary>
/// Transaction time out = 1s before throwing System.IO.IOException
/// </summary>
private UInt16 _transactionTimeOut = 1000;

/// <summary>
/// Slave Adress and frequency configuration
/// </summary>
private I2CDevice.Configuration config;
private I2CDevice.Configuration _config;

private I2CDevice i2cBus;
private I2CDevice _i2cBus;

/// <summary>
/// Transaction time out = 1s before throwing System.IO.IOException
/// 7-bit Slave Adress
/// </summary>
const UInt16 TRANSACTION_TIME_OUT = 1000;
private UInt16 _sla;

/// <summary>
/// 7-bit Slave Adress
/// Get or set time before System IO Exception if transaction failed (in ms).
/// </summary>
UInt16 sla;
/// <remarks>
/// 1000ms by default
/// </remarks>
public UInt16 TransactionTimeOut
{
get
{
return _transactionTimeOut;
}

set
{
_transactionTimeOut = value;
}
}
/// <summary>
/// Get Slave Adress
/// </summary>
public UInt16 SLA
{
get
{
return _sla;
}
}
/// <summary>
/// PCF8574 8-bit I/O expander
/// </summary>
/// <param name="SLA">PCF8574(@=0x20 to 0x27) or PCF8574A(@=0x38 to 0x3f), 0x38 by default</param>
/// <param name="Frequency">100khz to 400kHz, 100kHz by default </param>
public PCF8574(UInt16 SLA = 0x38, Int16 Frequency = 100)
{
sla = SLA;
config = new I2CDevice.Configuration(SLA, Frequency);
_sla = SLA;
_config = new I2CDevice.Configuration(SLA, Frequency);
}

/// <summary>
Expand All @@ -55,11 +83,11 @@ public void Write(Byte value)
byte[] outbuffer = new byte[] { value };

I2CDevice.I2CTransaction[] XAction = new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(outbuffer) };
i2cBus = new I2CDevice(config);
int transferred = i2cBus.Execute(XAction, TRANSACTION_TIME_OUT);
i2cBus.Dispose();
_i2cBus = new I2CDevice(_config);
int transferred = _i2cBus.Execute(XAction, _transactionTimeOut);
_i2cBus.Dispose();
if (transferred < (outbuffer.Length))
throw new System.IO.IOException("I2CBus error:" + sla.ToString());
throw new System.IO.IOException("I2CBus error:" + _sla.ToString());
}

/// <summary>
Expand All @@ -73,11 +101,11 @@ public byte Read()
byte[] inbuffer = new byte[1];

I2CDevice.I2CTransaction[] XAction = new I2CDevice.I2CTransaction[] { I2CDevice.CreateReadTransaction(inbuffer) };
i2cBus = new I2CDevice(config);
int transferred = i2cBus.Execute(XAction, 1000);
i2cBus.Dispose();
_i2cBus = new I2CDevice(_config);
int transferred = _i2cBus.Execute(XAction, _transactionTimeOut);
_i2cBus.Dispose();
if (transferred < (inbuffer.Length))
throw new System.IO.IOException("I2CBus error" + sla.ToString());
throw new System.IO.IOException("I2CBus error" + _sla.ToString());
else
return inbuffer[0];
}
Expand Down
Binary file modified img/pcf8574.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2ff6abe

Please sign in to comment.