Click or drag to resize
Solid Soils Solutions

ArduinoSession Class

[This is preliminary documentation and is subject to change.]

Represents an active layer for serial communication with an Arduino board.
Inheritance Hierarchy
SystemObject
  Solid.ArduinoArduinoSession

Namespace:  Solid.Arduino
Assembly:  Solid.Arduino (in Solid.Arduino.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
C#
public class ArduinoSession : IFirmataProtocol, 
	IServoProtocol, II2CProtocol, IStringProtocol, IDisposable

The ArduinoSession type exposes the following members.

Constructors
  NameDescription
Public methodArduinoSession(ISerialConnection)
Initializes a new instance of the ArduinoSession class.
Public methodArduinoSession(ISerialConnection, Int32)
Initializes a new instance of the ArduinoSession class.
Top
Properties
  NameDescription
Public propertyNewLine
Gets or sets the value used to interpret the end of strings received and sent.
Public propertyTimeOut
Gets or sets the number of milliseconds before a time-out occurs when a read operation does not finish.
Top
Methods
  NameDescription
Public methodClear
Closes and reopens the underlying connection and clears all buffers and queues.
Public methodConfigureServo
Configures the minimum and maximum pulse length for a servo pin.
Public methodCreateAnalogStateMonitor
Creates an observable object tracking AnalogState messages.
Public methodCreateAnalogStateMonitor(Int32)
Creates an observable object tracking AnalogState messages for a specific channel.
Public methodCreateDigitalStateMonitor
Creates an observable object tracking DigitalPortState messages.
Public methodCreateDigitalStateMonitor(Int32)
Creates an observable object tracking DigitalPortState messages for a specific port.
Public methodCreateI2CReplyMonitor
Creates an observable object tracking I2CReply messages.
Public methodCreateReceivedStringMonitor
Creates an observable object tracking received ASCII String messages.
Public methodDispose
Public methodGetBoardAnalogMapping
Gets the channel-to-pin mappings of the party system's analog lines.
Public methodGetBoardAnalogMappingAsync
Asynchronously gets the channel-to-pin mappings of the party system's analog lines.
Public methodGetBoardCapability
Gets a summary of the party system's capabilities.
Public methodGetBoardCapabilityAsync
Asynchronously gets a summary of the party system's capabilities.
Public methodGetFirmware
Gets the firmware signature of the party system.
Public methodGetFirmwareAsync
Asynchronously gets the firmware signature of the party system.
Public methodGetI2CReply(Int32, Int32)
Gets byte data from the party system, read from the given memory address.
Public methodGetI2CReply(Int32, Int32, Int32)
Gets byte data from the party system, read from the given memory address and register.
Public methodGetI2CReplyAsync(Int32, Int32)
Asynchronously gets byte data from the party system, read from the given memory address.
Public methodGetI2CReplyAsync(Int32, Int32, Int32)
Asynchronously gets byte data from the party system, read from the given memory address and register.
Public methodGetPinState
Gets a pin's mode (digital input/output, analog etc.) and actual value.
Public methodGetPinStateAsync
Asynchronously gets a pin's mode (digital input/output, analog etc.) and actual value.
Public methodGetProtocolVersion
Gets the protocol version implemented on the party system.
Public methodGetProtocolVersionAsync
Asynchronously gets the protocol version implemented on the party system.
Public methodRead
Reads a specified number of characters.
Public methodReadAsync
Reads a specified number of characters asynchronous.
Public methodReadI2CContinuous(Int32, Int32)
Requests the party system to repeatedly send bytes read from the given memory address.
Public methodReadI2CContinuous(Int32, Int32, Int32)
Requests the party system to repeatedly send bytes read from the given memory address and register.
Public methodReadI2COnce(Int32, Int32)
Requests the party system to send bytes read from the given memory address.
Public methodReadI2COnce(Int32, Int32, Int32)
Requests the party system to send bytes read from the given memory address and register.
Public methodReadLine
Reads a string up to the next NewLine character.
Public methodReadLineAsync
Reads a string asynchronous up to the next NewLine character.
Public methodReadTo
Reads a string up to the first terminating character.
Public methodReadToAsync
Reads a string asynchronous up to the first terminating character.
Public methodRequestBoardAnalogMapping
Requests the party system to send the channel-to-pin mappings of its analog lines.
Public methodRequestBoardCapability
Requests the party system to send a summary of its capabilities.
Public methodRequestFirmware
Requests the party system to send a firmware message.
Public methodRequestPinState
Requests the party system to send the state of a given pin.
Public methodRequestProtocolVersion
Requests the party system to send a protocol version message.
Public methodResetBoard
Sends a reset message to the party system.
Public methodSendStringData
Sends a message string.
Public methodSetAnalogReportMode
Enables or disables analog sampling reporting.
Public methodSetDigitalPin(Int32, Boolean)
Sets a HI or LO value on a digital output pin.
Public methodSetDigitalPin(Int32, Int64)
Sets an analog value on a PWM or Servo enabled analog output pin.
Public methodSetDigitalPinMode
Sets a pin's mode (digital input/digital output/analog/PWM/servo etc.).
Public methodSetDigitalPort
Sets the digital output pins of a given port LOW or HIGH.
Public methodSetDigitalReportMode
Enables or disables digital input pin reporting for the given port.
Public methodSetI2CReadInterval
Sets the frequency at which data is read in the continuous mode.
Public methodSetSamplingInterval
Sets the frequency at which analog samples must be reported.
Public methodStopI2CReading
Commands the party system to stop sending I2C_REPLY messages.
Public methodWrite
Writes a string to the serial output data stream.
Public methodWriteI2C
Writes an arbitrary array of bytes to the given memory address.
Public methodWriteLine
Writes the specified string and the NewLine value to the serial output stream.
Top
Events
  NameDescription
Public eventAnalogStateReceived
Event, raised when an analog state message (command 0xE0) is received.
Public eventDigitalStateReceived
Event, raised when a digital I/O message (command 0x90) is received.
Public eventI2CReplyReceived
Event, raised for every SYSEX I2C message not handled by an II2CProtocol's Get method.
Public eventMessageReceived
Event, raised for every SysEx (0xF0) and ProtocolVersion (0xF9) message not handled by an IFirmataProtocol's Get method.
Public eventStringReceived
Event, raised for every ASCII stringmessage not handled by an IStringProtocol's Read, ReadAsync, ReadLine, ReadLineAsync, ReadTo or ReadToAsync method
Top
Remarks
This class supports a few common protocols used for communicating with Arduino boards. The protocols can be used simultaneous and independently of each other.
Examples
C#
 1var connection = new SerialConnection("COM3", SerialBaudRate.Bps_57600);
 2var session = new ArduinoSession(connection, timeOut: 250);
 3// Cast to interface done, just for the sake of this demo.
 4IFirmataProtocol firmata = (IFirmataProtocol)session;
 5
 6Firmware firm = firmata.GetFirmware();
 7Console.WriteLine("Firmware: {0} {1}.{2}", firm.Name, firm.MajorVersion, firm.MinorVersion);
 8
 9ProtocolVersion version = firmata.GetProtocolVersion();
10Console.WriteLine("Protocol version: {0}.{1}", version.Major, version.Minor);
11
12BoardCapability caps = firmata.GetBoardCapability();
13Console.WriteLine("Board Capabilities:");
14
15foreach (var pincap in caps.PinCapabilities)
16{
17   Console.WriteLine("Pin {0}: Input: {1}, Output: {2}, Analog: {3}, Analog-Res: {4}, PWM: {5}, PWM-Res: {6}, Servo: {7}, Servo-Res: {8}",
18       pincap.PinNumber,
19       pincap.DigitalInput,
20       pincap.DigitalOutput,
21       pincap.Analog,
22       pincap.AnalogResolution,
23       pincap.Pwm,
24       pincap.PwmResolution,
25       pincap.Servo,
26       pincap.ServoResolution);
27}
28Console.WriteLine();
29Console.ReadLine();
See Also