ASCII iPort .NET Class Library Reference (V2.6) |
The ASCIIiPortLib class library provides methods, properties, events, and enumerations that support the development of Microsoft Visual Studio .NET or National Instruments LabVIEW V7+ applications for I2C Bus communications. The library reference and executable files were created by the MCC Technical Support team, are owned solely by MCC, and are made available on a non-exclusive, royalty-free, basis for use with MCC I2C Bus host adapters. |
Name | Description | Return Value | Parameters | Exceptions |
|
---|---|---|---|---|---|
Close | Closes the adapter connection and sets the IsOpen property to false. | void |
|
InvalidOperationException | CloseComplete
AdapterEvent AdapterBusy ErrorDetect TimeOut |
GetMasterRxData | Get data received from a slave device. | (long):
number of bytes transferred. |
|
InvalidOperationException ArgumentException | None |
GetSlaveRxData | Get data received from a master device. | (long):
number of bytes transferred. |
|
InvalidOperationException ArgumentException | None |
MasterRx | Master read data from a slave device. | void |
|
InvalidOperationException ArgumentException | MRxComplete
AdapterEvent SlaveNotAcknowledging ArbitrationLoss AdapterBusy ErrorDetect TimeOut |
MasterTx | Master write data to a slave device. | void |
|
InvalidOperationException ArgumentException | MTxComplete
AdapterEvent SlaveNotAcknowledging ArbitrationLoss AdapterBusy ErrorDetect TimeOut |
MasterTxRx | Master write data to a slave device with repeated start and read. | void |
|
InvalidOperationException ArgumentException | MTxRxComplete
AdapterEvent SlaveNotAcknowledging ArbitrationLoss AdapterBusy ErrorDetect TimeOut |
Open | Open the connection to the adapter at fastest available serial port baud rate. | void |
|
InvalidOperationException
ArgumentException IOException UnauthorizedAccessException |
OpenComplete
AdapterEvent ErrorDetect TimeOut |
Open | Open the connection to the adapter at specified, or adapter maximum,
serial port baud rate.
Selectable baud rates are supported by iPort/AFM, iPort/USB, iPort/LAN, and i2cStick adapters only. |
void |
|
InvalidOperationException
ArgumentException IOException UnauthorizedAccessException |
OpenComplete
AdapterEvent ErrorDetect TimeOut |
SlaveTx | Slave transmit data to a requesting master device. | void |
|
InvalidOperationException ArgumentException | STxComplete
AdapterEvent ErrorDetect TimeOut |
Name | Description | Type | Read/Write | Exceptions |
---|---|---|---|---|
AdapterEventCode | Last adapter event code. | AdapterEventCodes | Read | None |
ClassName | Name of the library class ("iPortAI", "iPortAFM", "iPortUSB", "iPort/USB2", "iPortLAN", "i2cStick", "i2cStick2", "ASCII"). | string | Read | None |
ClassVersion | The class version ("XX.XX"). | string | Read | None |
ClockRate | I2C Bus master clock rate. Default value = 100kHz. Supported by iPort/AFM, AFM2, iPort/USB, USB2, iPort/LAN, LAN2, i2cStick, or i2cStick2 adapters only. | ClockRateValue | Read/Write | None |
DebugMode | Enable/disable debug report to console window. See DebugModeValue. | DebugModeValue | Read/Write | None |
DeviceType | Adapter type detected when connection is open. | AdapterTypeValue | Read | None |
FirmwareVersion | Adapter firmware version ("Unknown" or "XX.XX"). | string | Read | None |
GeneralCallEnable | Enable/disable reception of slave messages to general call address (0x00). Default value = False. | bool | Read/Write | None |
I2CBusTimeOut | I2C Bus Time-Out (0...32767 msec, 0 = No time-out). Maximum time between bus acknowledgment bits. Exceeding this time generates an BusTimeout Error event with no other action taken. Default value = 10000. Supported by iPort/AFM, AFM2, iPort/USB, USB2, iPort/LAN, LAN2, i2cStick, or i2cStick2 adapters only. | int | Read/Write | ArgumentException |
IntMonitorEnabled | Enable/disable, adapter monitoring of /INT signal state changes. Default = False. Supported by iPort/AFM, AFM2, iPort/USB, USB2, iPort/LAN, and iPort/LAN2 adapters only. | bool | Read/Write | None |
IntSignalState | /INT signal state. Supported by iPort/AFM, AFM2, iPort/USB, USB2, iPort/LAN, and LAN2 adapters only. | IntSignalValue | Read/Write | ArgumentException |
IsBusy | Indicates adapter busy state. | bool | Read | None |
IsOpen | Indicates adapter connection open state. | bool | Read | None |
MyAddress | Adapter's own I2C Bus slave address (0x02...0xFE (even), Default = 0x6E). Default = 0x6E. | short | Read/Write | ArgumentException |
PortList | A list of currently available ComPorts with I2C Bus adapter type and serial number (COMn, AdapterType or Unknown, SerialNumber or Unknown). | string array | Read | None |
PortName | Adapter serial port name ("COMn" or "Unknown" if not open). | string | Read | None |
SerialNumber | Adapter serial number (or "Unknown" if not available). Supported by iPort/USB, USB2, iPort/LAN, LAN2, i2cStick, or i2cStick2 adapters only. | string | Read | None |
All adapter events have a common application interface (sender, CmdID, and EventCode). Each adapter event can have a separate application event handler, although the common application interface permits the grouping of multiple adapter events with common application event handlers (i.e. many events into a few event handlers). The AdapterEvent event is raised for all adapter events, allowing a single application event handler method to handle all adapter events (i.e. many events into one event handler).
Note: Adapter event handling with user defined methods is not a requirement, although this technique may work better when an I2C Bus adapter operates as both master and slave device. An alternative to event handling is to use the AdapterEventCode property. This property can be polled by an application to determine appropriate program actions.
The adapter events common application interface includes:
Note: Events are raised on a secondary thread. Because events are
raised on a secondary thread, and not the main thread, attempting to modify
some elements in the main thread, such as User Interface elements, could
raise a threading exception. If it is necessary to modify elements in the
main Form or Control, post change requests back using Invoke (See MS Visual
Studio .NET Help), which will do the work on the proper thread.
Name | Description | Arguments |
---|---|---|
AdapterBusy | Indicates the adapter is busy, possibly with a slave operation. The command that initiated the event is not accepted. |
|
AdapterEvent | Represents the method that handles the AdapterEvent event. The AdapterEvent is generated for all adapter events. This event allows an application to handle all adapter events from a single event handler. See AdapterEventCodes to identify specific event. |
|
ArbitrationLoss | I2C Bus arbitration loss detected. Command in progress aborted. The adapter has lost bus arbitration to another bus master. |
|
CloseComplete | Adapter connection close complete. |
|
ErrorDetect | Adapter error detected. Command in progress aborted. See EventCode to identify specific event. |
|
GRxComplete | Adapter general call (slave) receive complete. Use GetSlaveRxData method to retrieve data. |
|
InterruptSignalChanged | Interrupt signal (/INT) change detected. Supported by iPort/AFM, AFM2, iPort/USB, USB2, iPort/LAN, and LAN2 adapters only. |
|
MRxComplete | Adapter master receive complete. Use GetMasterRxData method to retrieve data. |
|
MTxComplete | Adapter master transmit complete. |
|
MTxRxComplete | Adapter master transmit/receive complete. Use GetMasterRxData method to retrieve data. |
EventCode (object by value): MTxComplete. |
OpenComplete | Adapter open connection complete. |
|
SlaveNotAcknowledging | Slave target device not responding. |
|
SRxComplete | Adapter slave receive complete. Use GetSlaveRxData method to retrieve data. |
|
STxComplete | Adapter slave transmit complete. |
|
STxRequest | Adapter slave transmit request detected. Use SlaveTx method to send data to requesting bus master. |
|
TimedOut | Adapter operation not completed within the TimeOut specified in the initiating method call. Adapter connection closed. |
|
|
|
Unknown | Adapter type not known. |
iPortAI | iPort/AI (#MIIC-202) or iPort/AI2 (#MIIC-212). |
iPortAFM | iPort/AFM (#MIIC-203) or iPort/AFM2 (#MIIC-213). |
iPortUSB | iPort/USB (#MIIC-204) |
iPortLAN | iPort/LAN (#MIIC-205) or iPort/LAN2 (#MIIC-210). |
i2cStick | i2cStick (#MIIC-207) |
iPortUSB2 | iPort/USB2 (#MIIC-208) |
i2cStick2 | i2cStick2 (#MIIC-209) |
|
|
None | No console display (Default). |
Command_Response | Console display Commands and Responses. |
Command_Response_Threads | Console display Commands, Responses, and Threads. |
|
|
B19200 | 19.2K baud (Default). |
B57600 | 57.6K baud. |
B115200 | 115.2K baud. |
|
|
C23 | 23KHz. |
C86 | 86KHz. |
C100 | 100KHz (Default). |
C400 | 400KHz. |
|
|
Unknown | Signal state unknown. |
Release | Signal state released (High) (Default). |
Assert | Signal state asserted (Low). |
Sample Code Visual Basic.NET |
'MCC ASCII iPort .NET Class Library - Visual Basic.NET Sample Console
Application
' 'This application demonstrates use of the MCC.iPort.ASCII .NET Class Library ' 'Requires Microsoft .Net 2.0 or newer, and Microsoft Visual Studio 2005 Module iPortSampleApplication_Console
Sub Main()
While (True)
While
(True)
Console.WriteLine("Opening Adapter Connection on [" + ComPort + "]...")
While (iPort.IsBusy()) 'Wait for the operation to
complete
If (Not iPort.IsOpen()) Then 'if Open Failed
Console.WriteLine("Open Connection Complete.") 'Read/display
some adapter properties
While
(True)
While (True)
Console.WriteLine("Master Write in Progress, Slave Address [" _
While (iPort.IsBusy()) 'Wait for the operation to
complete
If (Not iPort.AdapterEventCode = MCC.iPort.ASCII.AdapterEventCodes.MTxComplete)
Then
Console.WriteLine("Master Read in Progress, Slave Address [" + SlaveAddress.ToString("X2")
+ "]")
While (iPort.IsBusy()) 'Wait for the operation to
complete
If (Not iPort.AdapterEventCode = MCC.iPort.ASCII.AdapterEventCodes.MRxComplete)
Then
Try
Console.WriteLine("Master Read Complete, Received Data [0x" + data(0).ToString("X2")
+ "]")
Console.WriteLine("Closing
Adapter Connection...")
While
(iPort.IsOpen()) 'Wait for the operation to complete
Console.WriteLine("Close
complete.")
|
|
Sample Code Visual C# (I2C Bus Master Device) |
'MCC ASCII iPort .NET Class Library - Visual C#.NET Sample Console
Application
' 'This application demonstrates use of the MCC.iPort.ASCII .NET Class Library ' 'Requires Microsoft .Net 2.0 or newer, and Microsoft Visual Studio 2005 using System; namespace iPortSampleApplication_Console2
//Welcome
messages
//Create
a new ASCII iPort with default settings
string
UserInput;
Console.WriteLine("Opening Adapter Connection on [" + ComPort + "]...");
//Wait for the operation to complete
//If open failed
Console.WriteLine("Open Connection Complete.");
//Read/display some adapter properties
while (true)
try //Convert input string to integer w/exception handling
if (ExitFlag == true) break;
//Data to write
while (true)
//Convert input string to byte array w/exception handling
if (ExitFlag == true) break;
//Master Tx
//Wait for the operation to complete
if (iPort.AdapterEventCode != (int)MCC.iPort.ASCII.AdapterEventCodes.MTxComplete)
Console.WriteLine("Master Write Complete");
//Master Rx
//Wait for the operation to complete
if (iPort.AdapterEventCode != (int)MCC.iPort.ASCII.AdapterEventCodes.MRxComplete)
//Get MasterRx data
Console.WriteLine("Master Read Complete, Received Data [0x" + data[0].ToString("X2")
+ "]");
//Close
//Wait for the operation to complete
Console.WriteLine("Close complete.");
|
Sample Code Visual C# (I2C Bus Slave Device) |
using System;
using System.Collections.Generic; using System.Text; // This sample C# I2C Bus Slave Rx/Tx program
namespace i2cSlaveCsConsoleApp1
// I2C Bus Message Arrays
// Application Command/Response
Arrays
static void Main(string[]
args)
//
Create a new ASCII iPort with default settings
string UserInput; // a place for user input while
(true)
iPort.MyAddress = 0x60; // Set My Slave Address
// Set Slave Event Handlers
// Show Available ComPorts
String[] AvailablePortList = iPort.PortList; // get PortList
for (int i = 0; i < (AvailablePortList.Length); i++)
if (AvailablePortList.Length == 0) // if NO ComPorts detected
// Open Adapter Connection
Console.WriteLine("Opening Adapter Connection on [" + ComPort + "]...");
// Wait for the operation to complete
if (!iPort.IsOpen) // if Open failed
Console.WriteLine("Open SUCCESS.");
//Read/display some adapter properties
while (true) // Slave Receive/Transmit Loop
// Close Adapter Connection
// Wait for the operation to complete
Console.WriteLine("Close SUCCESS.");
// SlaveRxComplete Event
Handler
try
// Save Received Application Command/Data
// SlaveTxRequest Event Handler
try
AppRspData[0] = AppCmdData[0]; // (Example: echo AppCmdData[0]) SlaveTxData[0] = AppRspData[0]; // setup Slave Tx Data
iPort.SlaveTx(1, ref SlaveTxData, 1, 100); // send
Slave Tx Data
}
|
|
Sample Code Visual C++ |
'MCC ASCII iPort .NET Class Library - Visual C++.NET Sample Console
Application
' 'This application demonstrates use of the MCC.iPort.ASCII .NET Class Library ' 'Requires Microsoft .Net 2.0 or newer, and Microsoft Visual Studio 2005 #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args)
//Welcome messages
String ^UserInput;
Console::WriteLine("Opening
Adapter Connection on [" + ComPort + "]...");
//Wait
for the operation to complete
//If
open failed
Console::WriteLine("Open Connection Complete."); //Read/display some adapter
properties
while (true)
try //Convert input string to integer w/exception handling
if (ExitFlag == true) break; //Data
to write
while (true)
//Convert input string to byte array w/exception handling
if (ExitFlag == true) break;
//Master Tx
//Wait for the operation to complete
if (iPort.AdapterEventCode != (int)MCC::iPort::ASCII::AdapterEventCodes::MTxComplete)
Console::WriteLine("Master Write Complete");
//Master Rx
//Wait for the operation to complete
if (iPort.AdapterEventCode != (int)MCC::iPort::ASCII::AdapterEventCodes::MRxComplete)
//Get MasterRx data
Console::WriteLine("Master Read Complete, Received Data [0x" + data[0].ToString("X2")
+ "]");
//Close
//Wait for the operation
to complete
Console::WriteLine("Close
complete.");
|
|
Sample Code Visual J# |
'MCC ASCII iPort .NET Class Library - Visual J#.NET Sample Console
Application
' 'This application demonstrates use of the MCC.iPort.ASCII .NET Class Library ' 'Requires Microsoft .Net 2.0 or newer, and Microsoft Visual Studio 2005 package iPortSampleApplication_Console2; import System.Console;
public class Program
//Welcome messages
//Create a new ASCII iPort
with default settings
String UserInput;
Console.WriteLine("Opening Adapter Connection on [" + ComPort + "]...");
//Wait for the operation to complete
//If open failed
Console.WriteLine("Open Connection Complete."); //Read/display
some adapter properties
while
(true)
try //Convert input string to integer w/exception handling
if (ExitFlag == true) break;
//Data to write
while (true)
//Convert input string to byte array w/exception handling
if (ExitFlag == true) break;
//Master Tx
//Wait for the operation to complete
if (iPort.get_AdapterEventCode() != (int)MCC.iPort.iPortAI.AdapterEventCodes.MTxComplete)
Console.WriteLine("Master Write Complete");
//Master Rx
//Wait for the operation to complete
if (iPort.get_AdapterEventCode() != (int)MCC.iPort.iPortAI.AdapterEventCodes.MRxComplete)
//Get MasterRx data
Console.WriteLine("Master Read Complete, Received Data [0x" + java.lang.Integer.toHexString(data[0])
+ "]");
//Close
//Wait
for the operation to complete
Console.WriteLine("Close
complete.");
|
Sample Code LabVIEW (LabVIEW 2010 Project: iPortAI_LV2010_dotNET_MasterTxRx_Demo) |
Can't find the answer to your question here? Then e-mail your question
to us at support@mcc-us.com
I2C is just a mouse click away TM