Mio Class Reference

Class for interfacing the MIO board. More...

List of all members.

Classes

struct  CpuPortAndPin
struct  PWMInSubchannelConfig
 PWM input subchannel configuration. More...
struct  PWMOutSubchannelConfig
 PWM output subchannel configuration. More...
struct  PWMOutSubchannelConfig2
 PWM output subchannel configuration 2. More...

Public Types

enum  Port {
  P1 = 0,
  P2,
  P3,
  P4,
  P5,
  P6,
  P7,
  P8,
  P9,
  P10,
  P11,
  P12,
  P13,
  P14,
  P15,
  P16,
  P17,
  P18,
  P19,
  P20,
  P21,
  P22,
  P23,
  P24,
  P25,
  P26,
  P27,
  P28,
  P29,
  P30,
  P31,
  P32,
  P33,
  P34,
  P35,
  P36,
  P37,
  P38,
  P39,
  P40,
  NumOfItems,
  First = P1,
  Last = P40,
  Inv = NumOfItems
}
 Physical ports on the MIO board. More...
enum  PortMode {
  DigIn = 0,
  DigInOut,
  Vref,
  AnaIn,
  NumOfItems,
  First = DigIn,
  Last = NumOfItems - 1
}
 Port mode for physical ports on the MIO board. More...
enum  PortDigInOut {
  In = 0,
  Out0,
  Out1
}
 Additional parameter for Mio.PortMode.DigInOut. More...
enum  TaskType {
  DS18x20 = 0,
  NumOfItems,
  First = DS18x20,
  Last = NumOfItems - 1,
  Inv = NumOfItems
}
 MIO (background) task types. More...
enum  DS18x20Type {
  Auto = 0,
  S,
  B
}
 DS18x20 sensor type. More...
enum  DS18x20Error {
  None = 0,
  NotPresent,
  Error,
  StartFail,
  BadCrc
}
 DS18x20 error codes. More...
enum  PWMMode {
  None = 0,
  Out,
  In
}
 PWM mode. More...
enum  PWMClockSpeed {
  f20MHz = 0,
  f10MHz = 1,
  f5MHz = 2,
  f2500kHz = 3,
  f625kHz = 4
}
 PWM clock speed. More...
enum  PWMInMode {
  Idle = 0,
  Active,
  ActivateIfIdle
}
 PWM input measurement mode. More...
enum  Rc {
  OK = 0,
  OS_DeviceNotOpen,
  OS_DeviceBusy,
  OS_DeviceWriteError,
  OS_DeviceReadError,
  OS_DeviceReadTimeout,
  API_BadInputParam,
  API_NullInputParam,
  API_BadPort,
  API_BadMode,
  API_MessageCorrupt,
  API_MessageCrc,
  API_MessageSyntax,
  API_WrongMessage,
  MIO_UartOvr,
  MIO_UartOer,
  MIO_UartFer,
  MIO_UartPer,
  MIO_MessageTimeout,
  MIO_MessageCorrupt,
  MIO_MessageCrc,
  MIO_MessageSyntax,
  MIO_BadPort,
  MIO_BadPortOrMode,
  MIO_WrongMode,
  MIO_BadTaskId,
  MIO_BadTaskType,
  MIO_WrongTaskType,
  MIO_BadTaskConfig,
  MIO_TaskNotActive,
  NumOfItems,
  First = OK,
  Last = NumOfItems - 1
}
 Result & error codes. More...
enum  HostMsgId {
  Reset = 0,
  Loopback,
  SetMioPortsModes,
  GetMioPortsModes,
  GetDigPortValue,
  SetDigPortValue,
  SetDigPortsValues,
  GetDigPortsValues,
  GetAnaPortsValues,
  StartTask,
  StopTask,
  GetDS18x20TaskTemp,
  StartPWMOut,
  AdjustPWMOut,
  StartPWMIn,
  SetPWMInMode,
  GetPWMInResult,
  StopPWM,
  NumOfItems,
  First = Loopback,
  Last = NumOfItems - 1
}
enum  MioMsgId {
  ResetResp = 0,
  LoopbackResp,
  SetMioPortsModesResp,
  GetMioPortsModesResp,
  SetDigPortValueResp,
  GetDigPortValueResp,
  SetDigPortsValuesResp,
  GetDigPortsValuesResp,
  GetAnaPortsValuesResp,
  ErrorResp,
  StartTask,
  StopTask,
  GetDS18x20TaskTemp,
  StartPWMOut,
  AdjustPWMOut,
  StartPWMIn,
  SetPWMInMode,
  GetPWMInResult,
  StopPWM,
  NumOfItems,
  First = LoopbackResp,
  Last = NumOfItems - 1
}
enum  CpuPort {
  P0 = 0,
  P1,
  P2,
  P3,
  P4,
  P6,
  NumOfItems,
  First = P0,
  Last = P6
}

Public Member Functions

void SetReceiveTimeout (uint timeout_ms)
 Set receive timeout in ms (milli-seconds).
uint GetReceiveTimeout ()
 Get receive timeout in ms (milli-seconds).
void SetDrainTime (uint drain_time_ms)
 Set drain time in ms (milli-seconds).
uint GetDrainTime ()
 Get drain time in ms (milli-seconds).
virtual string ResultCodeToText (Rc rc)
 Convert MIO API result code to text string.
Rc Reset ()
 Reset MIO board.
Rc Loopback (byte[] out_data, out int out_data_len, byte[] in_data, int in_data_len)
 Loopback test.
Rc SetMioPortsModes (PortMode[] modes, byte[] prms, Port[] ports, int num_ports)
 Set Mio.PortMode for 1...40 Mio.Port's.
Rc SetMioPortMode (PortMode mode, byte prm, Port port)
 Set Mio.PortMode for a single Mio.Port.
Rc GetMioPortsModes (PortMode[] modes, byte[] prms, Port[] ports, int num_ports)
 Get Mio.PortModes and params for 1...40 Mio.Ports at a time.
Rc GetMioPortMode (out PortMode mode, out byte prm, Port port)
 Get Mio.PortMode and param for a single Mio.Port.
Rc SetDigitalOutputValue (byte value, Port port)
 Set digital output value (0 or 1) for a Mio.Port.
Rc GetDigitalInputValue (out byte value, Port port)
 Get digital input value (0 or 1) from a single Mio.Port.
Rc SetDigitalOutputsValues (byte[] values, Port[] ports, int num_ports)
 Set digital output value (0 or 1) for 1...39 Mio.Ports.
Rc GetDigitalInputsValues (byte[] values, Port[] ports, int num_ports)
 Get digital input value (0 or 1) for 1...40 Mio.Ports.
Rc GetAnalogInputsValues (int[] values, Port[] ports, int num_ports)
 Get analog input value from 1...8 Mio.Ports.
Rc GetAnalogInputValue (out int value, Port port)
 Get analog input value from a single Mio.Port.
Rc StartDS18x20Task (int task_id, Port mio_port, DS18x20Type sensor_type, uint conversion_time_x100ms)
 Start a DS18x20 temperature sensor measurement task.
Rc GetDS18x20TaskTemperature (out int temperature, out byte sn, out DS18x20Error error, int task_id)
 Get DS18x20 temperature.
Rc StopTask (int task_id)
 Stop a task.
Rc StartPWMOut (int pwm_clock_channel, PWMClockSpeed pwm_clock_speed, int pwm_period, PWMOutSubchannelConfig[] subchannels)
 Start PWM output (generation) on 1...3 PWM subchannels.
Rc StartPWMOut (int pwm_clock_channel, float pwm_frequency, PWMOutSubchannelConfig2[] subchannels)
 Start PWM output (generation) on 1...3 PWM subchannels.
Rc AdjustPWMOut (int pwm_clock_channel, PWMClockSpeed pwm_clock_speed, int pwm_period, PWMOutSubchannelConfig[] subchannels)
 Adjust ongoing PWM output (genration) on 1...3 PWM subchannels.
Rc AdjustPWMOut (int pwm_clock_channel, float pwm_frequency, PWMOutSubchannelConfig2[] subchannels)
 Adjust ongoing PWM output (genration) on 1...3 PWM subchannels.
Rc StartPWMIn (int pwm_clock_channel, PWMInSubchannelConfig[] subchannels)
 Start PWM input (measurement) on 1...4 PWM subchannels.
Rc SetPWMInMode (int pwm_clock_channel, int pwm_subchannel, PWMInMode mode)
 Set mode for a PWM input subchannel.
Rc GetPWMInResult (out uint total_halfperiod_time, out uint total_period_time, out int edges_captured, int pwm_clock_channel, int pwm_subchannel)
 Get measurement result from a PWM input subchannel.
Rc StopPWM (int pwm_clock_channel)
 Stop all PWM input/output on the selected PWM clock channel.
bool OpenComPort (string port)
 Open communication port to MIO board.
void CloseComPort ()
 Close communication port to MIO board.
bool IsOpen ()
 Check if the communication port is open.

Static Public Member Functions

static bool PortIsValid (uint mio_port)
 Check if Port is valid.
static bool PortIsInvalid (uint mio_port)
 Check if Port is invalid.
static bool PortModeIsValid (uint mio_port_mode)
 Check if PortMode is valid.
static bool PortModeIsInvalid (uint mio_port_mode)
 Check if MioPortMode is invalid.
static bool TaskTypeIsValid (uint mio_task_type)
 Check if TaskType is valid.
static bool MioTaskTypeIsInvalid (uint mio_task_type)
 Check if MioTaskType is invalid.
static bool TaskIdIsValid (uint mio_task_id)
 Check if MIO task id is valid.
static bool TaskIdIsInvalid (uint mio_task_id)
 Check if MIO task id is invalid.
static bool RcIsValid (uint code)
 Check if Rc is valid.
static bool RcIsInvalid (uint code)
 Check if Rc is invalid.
static bool HostMsgIdIsValid (uint msg_id)
static bool HostMsgIdIsInvalid (uint msg_id)
static bool MioMsgIdIsValid (uint msg_id)
static bool MioMsgIdIsInvalid (uint msg_id)
static bool CpuPortIsValid (uint mio_cpu_port)
static bool CpuPortIsInvalid (uint mio_cpu_port)
static Rc ConvertPWMOutValues (out PWMClockSpeed pwm_clock_speed, out int pwm_period, PWMOutSubchannelConfig[] dst_subchannels, float pwm_frequency, PWMOutSubchannelConfig2[] src_subchannels)
 Convert from frequency/duty cycle PWM values to PWM clock tick values.

Public Attributes

const uint TaskMaxTaskId = 8
 Max number of simultaneous MIO tasks.
const int PWM_DISABLE = 0
 Disable PWM subchannel. The corresponding Mio.Port can be used for other things.
const int PWM_ENABLE = 0x01
 Enable PWM subchannel.
const int PWM_POL_0 = 0
 Polatiry 0. First halfperiod of PWM signal is 0.
const int PWM_POL_1 = 0x02
 Polarity 1. First halfperiod of PWM signal is 1.
const int PWM_IDLE = 0
 PWM input measurement is idle (not measuring).
const int PWM_ACTIVE = 0x04
 PWM input measurement is active.
const uint MessageMaxPayloadSize = 28
 Max message payload size in bytes.
const uint CommunicationSpeed = 125000

Protected Member Functions

virtual void DispatchOutOfBandMessage (MioMsgId msg_id, int payload_len, byte[] payload)
 "Call-back" for out-of-band messages received from MIO.


Detailed Description

Class for interfacing the MIO board.

The functionality in the MIO board is exposed through an API which is implemented in this class.

The Mio class translates the API function calls into messages that are sent/received to/from the MIO board.

The Mio class requires .NET framework version 2.0


Member Enumeration Documentation

enum Mio::Port

Physical ports on the MIO board.

Enumerator:
P1  P3_7.
P2  P3_5.
P3  P6_4.
P4  P6_5.
P5  P3_0.
P6  P6_0.
P7  P6_1.
P8  P6_2.
P9  P6_3.
P10  P4_2/VREF.
P11  P0_7/AN0.
P12  P0_6/AN1.
P13  P0_5/AN2.
P14  P0_4/AN3.
P15  P0_3/AN4.
P16  P0_2/AN5.
P17  P0_1/AN6.
P18  P0_0/AN7.
P19  P3_3.
P20  P3_4.
P21  P4_3.
P22  P4_4.
P23  P2_7.
P24  P2_6.
P25  P2_5.
P26  P2_4.
P27  P2_3.
P28  P2_2.
P29  P2_1.
P30  P2_0.
P31  P1_7.
P32  P1_6.
P33  P1_3.
P34  P4_5.
P35  P1_0.
P36  P3_1.
P37  (P6_6/TXD1)
P38  (P6_7/RXD1)
P39  (P1_2)
P40  (P1_1)
NumOfItems  Number of items in this enum.
First  First valid item in this enum.
Last  Last valid item in this enum.
Inv  Invalid port.

Port mode for physical ports on the MIO board.

Enumerator:
DigIn  Digital input (all ports).
DigInOut  Digital input and output (all ports except Mio.Port.P10) Parameter: PortDigInOut
Vref  ADC Vref input (only for Mio.Port.P10).
AnaIn  Analog input (only for Mio.Port.P11 ... Mio.Port.P18).
NumOfItems  Number of items in this enum.
First  First real item in this enum.
Last  Last real item in this enum.

Additional parameter for Mio.PortMode.DigInOut.

Enumerator:
In  Port is initially an input.
Out0  Port is initially an output set to 0.
Out1  Port is initially an output set to 1.

MIO (background) task types.

Enumerator:
DS18x20  DS18x20 1-wire temperature sensor measurement.
NumOfItems  Number of items in this enum.
First  First real item in this enum.
Last  Last real item in this enum.
Inv  Invalid task type.

DS18x20 sensor type.

Enumerator:
Auto  Auto detect sensor (DS18S20 or DS18B20) at initialization TODO: Implement "Auto detect" in firmware
S  DS18S20.
B  DS18B20.

DS18x20 error codes.

Enumerator:
None  No error, all okay.
NotPresent  Sensor not present.
Error  Memory function error (1-wire bus is busy).
StartFail  Starting measurement failed (1-wire bus is busy).
BadCrc  CRC error in data read from sensor.

PWM mode.

Enumerator:
None  No PWM active.
Out  PWM output (generation).
In  PWM input (measurement).

PWM clock speed.

Enumerator:
f20MHz  20 MHz (f1)
f10MHz  10 MHz (f2)
f5MHz  5 MHz (f4)
f2500kHz  2.5 MHz (f8)
f625kHz  625 kHz (f32)

PWM input measurement mode.

Enumerator:
Idle  Set subchannel in idle mode.
Active  Set subchannel in active mode (force start of a new measurement).
ActivateIfIdle  Set subchannel in active mode only if currently in idle mode.

enum Mio::Rc

Result & error codes.

Enumerator:
OK  Success (no error).
OS_DeviceNotOpen  OS: Device not open.
OS_DeviceBusy  OS: Error device busy.
OS_DeviceWriteError  OS: Error writing to device.
OS_DeviceReadError  OS: Error reading from device.
OS_DeviceReadTimeout  OS: Timeout while reading from device.
API_BadInputParam  API: Input parameter bad.
API_NullInputParam  API: Input pointer parameter NULL.
API_BadPort  API: Bad MioPort.
API_BadMode  API: Bad MioPortMode.
API_MessageCorrupt  API: Message from MIO was corrupt.
API_MessageCrc  API: Message from MIO had CRC error.
API_MessageSyntax  API: Message from MIO had syntax error.
API_WrongMessage  API: Wrong message received from MIO.
MIO_UartOvr  MIO: UART Rx software buffer overflow.
MIO_UartOer  MIO: UART Rx hardware buffer overrun.
MIO_UartFer  MIO: UART Rx framing error.
MIO_UartPer  MIO: UART Rx parity error.
MIO_MessageTimeout  MIO: Timeout while receiving host message.
MIO_MessageCorrupt  MIO: Message from host was corrupt.
MIO_MessageCrc  MIO: Message from host had CRC error.
MIO_MessageSyntax  MIO: Message from host had syntax error.
MIO_BadPort  MIO: Bad MioPort.
MIO_BadPortOrMode  MIO: Bad MioPort or MioPortMode.
MIO_WrongMode  MIO: Wrong MioPortMode for this context.
MIO_BadTaskId  MIO: Bad task id.
MIO_BadTaskType  MIO: Bad task type.
MIO_WrongTaskType  MIO: Wrong task type.
MIO_BadTaskConfig  MIO: Bad task configuration.
MIO_TaskNotActive  MIO: Task not active.
NumOfItems  Number of items in this enum.
First  First valid item in this enum.
Last  Last valid item in this enum.

For internal use only.

Message Id's for messages from Host to MIO board

Enumerator:
Reset  Reset MIO to startup state.
Loopback  Loopback test message.
SetMioPortsModes  Set modes of MioPorts.
GetMioPortsModes  Get modes of MioPorts.
GetDigPortValue  Get single digital input port value.
SetDigPortValue  Set single digital output port value.
SetDigPortsValues  Set multiple digital output ports values.
GetDigPortsValues  Get multiple digital input ports values.
GetAnaPortsValues  Get multiple analog input ports values.
StartTask  Start MioTask.
StopTask  Stop MioTask.
GetDS18x20TaskTemp  Get temperature from DS18x20 sensor task.
StartPWMOut  Start PWM output (generation).
AdjustPWMOut  Adjust PWM output (generation).
StartPWMIn  Start PWM input (measurement).
SetPWMInMode  Set PWM input (measurement) mode.
GetPWMInResult  Get PWM input (measurement) result.
StopPWM  Stop PWM input/output.
NumOfItems  Number of items in this enum.
First  First valid item in this enum.
Last  Last valid item in this enum.

For internal use only.

Message Id's for messages from MIO board to Host

Enumerator:
ResetResp  Reset MIO to startup state response.
LoopbackResp  Loopback test message response.
SetMioPortsModesResp  Set modes of MioPorts response.
GetMioPortsModesResp  Get modes of MioPorts response.
SetDigPortValueResp  Set single digital output port value response.
GetDigPortValueResp  Get single digital input port value response.
SetDigPortsValuesResp  Set multiple digital output ports values response.
GetDigPortsValuesResp  Get multiple digital input ports values response.
GetAnaPortsValuesResp  Get multiple analog input ports values response.
ErrorResp  Error response message from MIO.
StartTask  Start MioTask.
StopTask  Stop MioTask.
GetDS18x20TaskTemp  Get temperature from DS18x20 sensor task.
StartPWMOut  Start PWM output response.
AdjustPWMOut  Adjust PWM output response.
StartPWMIn  Start PWM input response.
SetPWMInMode  Set PWM input mode response.
GetPWMInResult  Get PWM input result response.
StopPWM  Stop PWM input/output response.
NumOfItems  Number of items in this enum.
First  First valid item in this enum.
Last  Last valid item in this enum.

For internal use only.

CPU ports. Each port may have up to 8 I/O pins

Enumerator:
P0  P0.
P1  P1.
P2  P2.
P3  P3.
P4  P4.
P6  P6.
NumOfItems  Number of items in this enum.
First  First valid item in this enum.
Last  Last valid item in this enum.


Member Function Documentation

static bool Mio::HostMsgIdIsValid ( uint  msg_id  )  [inline, static]

For internal use only.

Check if HostMsgId is valid

static bool Mio::HostMsgIdIsInvalid ( uint  msg_id  )  [inline, static]

For internal use only.

Check if HostMsgId is invalid

static bool Mio::MioMsgIdIsValid ( uint  msg_id  )  [inline, static]

For internal use only.

Check if MioMsgId is valid

static bool Mio::MioMsgIdIsInvalid ( uint  msg_id  )  [inline, static]

For internal use only.

Check if MioMsgId is invalid

static bool Mio::CpuPortIsValid ( uint  mio_cpu_port  )  [inline, static]

For internal use only.

Check if CpuPort is valid

static bool Mio::CpuPortIsInvalid ( uint  mio_cpu_port  )  [inline, static]

For internal use only.

Check if CpuPort is invalid

void Mio::SetReceiveTimeout ( uint  timeout_ms  )  [inline]

Set receive timeout in ms (milli-seconds).

The receive timeout specifies how long the API will wait for a response message from MIO, after a request message has been sent to it. If no response message is received within the specified timeout, the correspodning API function will return with the the error code Mio.Rc.OS_DeviceReadTimeout.

The default value (of about 1000 ms) should be good in most cases. Increase the timeout if the host OS is VERY busy with other tasks.

Parameters:
timeout_ms IN: Timeout in ms

uint Mio::GetReceiveTimeout (  )  [inline]

Get receive timeout in ms (milli-seconds).

See documentation for SetReceiveTimeout().

Returns:
Current receive timeout in ms

void Mio::SetDrainTime ( uint  drain_time_ms  )  [inline]

Set drain time in ms (milli-seconds).

The drain time specifies how long the communication channel should be cleared from possibly bad data after a communication error has been detected.

The default value (of about 200 ms) should be good in most cases.

Parameters:
drain_time_ms IN: Drain time in ms

uint Mio::GetDrainTime (  )  [inline]

Get drain time in ms (milli-seconds).

See documentation for SetDrainTime().

Returns:
Current drain time time in ms

virtual string Mio::ResultCodeToText ( Rc  rc  )  [inline, virtual]

Convert MIO API result code to text string.

Returns:
text string corresponding to rc
Parameters:
rc Error code to convert to string

Rc Mio::Reset (  )  [inline]

Reset MIO board.

The function resets MIO to the same state as when power was switched on to the board.

Returns:
Mio.Rc.OK if success, else some error code

Rc Mio::Loopback ( byte[]  out_data,
out int  out_data_len,
byte[]  in_data,
int  in_data_len 
) [inline]

Loopback test.

Loop the given data through the MIO board and back to the host. This function can be used as a basic communication test.

Returns:
Mio.Rc.OK if success, else some error code
Parameters:
out_data OUT: Output buffer (must be at least MessageMaxPayloadSize bytes long)
out_data_len OUT: Length of output data is stored here
in_data IN: Input data (max MessageMaxPayloadSize bytes long)
in_data_len IN: Length of input data (max MessageMaxPayloadSize bytes long)

Rc Mio::SetMioPortsModes ( PortMode[]  modes,
byte[]  prms,
Port[]  ports,
int  num_ports 
) [inline]

Set Mio.PortMode for 1...40 Mio.Port's.

The operating mode (Mio.PortMode) for a port (Mio.Port) must be set before the port can be used. The following modes can be set:

 Mio.PortMode.DigIn      // Digital input (default at MIO startup)
 Mio.PortMode.DigInOut   // Digital input and output
 Mio.PortMode.Vref       // Vref input for ADC
 Mio.PortMode.AnaIn      // Analog input

See definition of Mio.PortMode for more info.

Returns:
Mio.Rc.OK if success, else some error code
Parameters:
modes IN: 1...40 Mio.PortModes
prms IN: 1...40 extra paramerers for the Mio.PortModes. Set to null to apply default (0) for all ports
ports IN: 1...40 Mio.Ports
num_ports IN: Number of ports to configure

Rc Mio::SetMioPortMode ( PortMode  mode,
byte  prm,
Port  port 
) [inline]

Set Mio.PortMode for a single Mio.Port.

Same as SetMioPortsModes() but for a single Mio.Port.

Returns:
Mio.Rc.OK if success, else some error code
Parameters:
mode IN: Mio.PortMode
prm IN: Extra parameter for the Mio.PortMode. Set to 0 if not applicable
port IN: Mio.Port

Rc Mio::GetMioPortsModes ( PortMode[]  modes,
byte[]  prms,
Port[]  ports,
int  num_ports 
) [inline]

Get Mio.PortModes and params for 1...40 Mio.Ports at a time.

Returns:
Mio.Rc.OK if success, else some error code
Parameters:
modes OUT: Buffer where 1...40 Mio.PortModes are stored
prms OUT: Buffer where 1...40 extra params for the Mio.PortModes are stored
ports IN: 1...40 Mio.Ports
num_ports IN: Number of ports

Rc Mio::GetMioPortMode ( out PortMode  mode,
out byte  prm,
Port  port 
) [inline]

Get Mio.PortMode and param for a single Mio.Port.

Same as GetMioPortsModes() but for a single Mio.Port.

Returns:
Mio.Rc.OK if success, else some error code
Parameters:
mode OUT: Mio.PortMode
prm OUT: Extra param related to Mio.PortMode
port IN: Mio.Port

Rc Mio::SetDigitalOutputValue ( byte  value,
Port  port 
) [inline]

Set digital output value (0 or 1) for a Mio.Port.

The Mio.Port must be configured as Mio.PortMode.DigInOut. If the port currently is in input mode, it is automatically switched to output mode.

Returns:
Mio.Rc.OK if success, else some error code
Parameters:
value OUT: Output value (0 or 1) to be set
port OUT: Mio.Port

Rc Mio::GetDigitalInputValue ( out byte  value,
Port  port 
) [inline]

Get digital input value (0 or 1) from a single Mio.Port.

The Mio.Port must be configured as Mio.PortMode.DigInOut or Mio.PortMode.DigIn. If the port is Mio.PortMode.DigInOut and currently in output mode, it is automatically switched to input mode.

Returns:
Mio.Rc_OK if success, else some error code
Parameters:
value OUT: Input value (0 or 1) is stored here
port IN: Mio.Port

Rc Mio::SetDigitalOutputsValues ( byte[]  values,
Port[]  ports,
int  num_ports 
) [inline]

Set digital output value (0 or 1) for 1...39 Mio.Ports.

The ports must be configured as Mio.PortMode.DigInOut. This is an optimized version that sets the output values with minimum latency between the CPU I/O register writes. All Mio.Ports residing on the same 8 bit CPU I/O register are guaranteed to be updated simultaneously. The maximum update latency between any two Mio.Ports residing on different CPU I/O registers is ~5 us. Please check the MIO specifications for the exact latency.

Note:
Due to the optimized nature of this function; if a Mio.PortMode.DigInOut port currently is in input mode, the port will remain in input mode and the output value will not be set for that port. The function will not report this as an error.
Returns:
Mio.Rc.OK if success, else some error code
Parameters:
values IN: 1...39 output values (0 or 1) corresponding to the Mio.Ports
ports IN: 1...39 Mio.Ports
num_ports IN: Number of ports

Rc Mio::GetDigitalInputsValues ( byte[]  values,
Port[]  ports,
int  num_ports 
) [inline]

Get digital input value (0 or 1) for 1...40 Mio.Ports.

The ports must be configured as Mio.PortMode_DigIn or Mio.PortMode_DigInOut. This is an optimized version that gets the input values with minimum latency between the CPU input register reads. All Mio.Ports residing on the same 8 bit CPU input register are guaranteed to be read simultaneously. The maximum read latency between any two Mio.Ports residing on different CPU input registers is ~3 us. Please check the MIO specifications for the exact latency.

Note:
Due to the optimized nature of this function; if a Mio.PortMode.DigInOut port currently is in output mode, the port will remain in output mode and the input value will not be read. The function will not report this as an error.
Returns:
Mio.Rc.OK if success, else some error code
Parameters:
values IN: 1...40 input values (0 or 1) corresponding to the Mio.Ports
ports IN: 1...40 Mio.Ports
num_ports IN: Number of ports

Rc Mio::GetAnalogInputsValues ( int[]  values,
Port[]  ports,
int  num_ports 
) [inline]

Get analog input value from 1...8 Mio.Ports.

The ports must be configured as Mio.PortMode.AnaIn (only Mio.Port.P11 ... Mio.Port.P18 can be configured in this mode). The ports are sampled sequentially in the same order as specified in the 'ports' array. One sample takes ~6 us. When sampling more than one port, the samples are taken ~15 us apart giving a total of ~120 us for sampling all 8 analog input ports.

Note:
Mio.Port.P10 must be configured as Mio.PortMode.Vref and a Vref voltage supplied to Mio.Port.P10, othervice this function will not return meaningful values.
Returns:
Mio.Rc.OK if success, else some error code
Parameters:
values OUT: Array where analog input values are stored; 1...8 items
ports IN: Analog input ports; 1...8 ports (Mio.Port.P11 ... Mio.Port.P18)
num_ports IN: Number of ports in array; 1...8

Rc Mio::GetAnalogInputValue ( out int  value,
Port  port 
) [inline]

Get analog input value from a single Mio.Port.

Same as GetAnalogInputsValues() but for a single Mio.Port.

Returns:
Mio.Rc.OK if success, else some error code
Parameters:
value OUT: Analog input values is stored here
port IN: Analog input port (Mio.Port.P11 ... Mio.Port.P18)

Rc Mio::StartDS18x20Task ( int  task_id,
Port  mio_port,
DS18x20Type  sensor_type,
uint  conversion_time_x100ms 
) [inline]

Start a DS18x20 temperature sensor measurement task.

The function will internally configure the selected Mio.Port for temperature measurement. The temperature is measured periodically by a task. The measurement interval time is specified with 'conversion_time_x100ms' which can be from 0,1 - 25,5 seconds.

Note:
The DS18x20 sensor typically needs a temperature conversion time of 200 ms and in worst case up to 750 ms. Set 'conversion_time_x100ms' accordingly!

The DS18x20 sensor needs an external 4k7 pull-up resistor on the 1-wire data line. When only using the weak internal pull-ups of the MIO board, MIO will detect the sensor, but reading the temperature will give wrong results.

Returns:
Mio.Rc.OK if success, else some error code
Parameters:
task_id IN: Task id: 0 ... Mio.TaskMaxTaskId
mio_port IN: Mio.Port to be used as 1-wire data interface to the sensor
sensor_type IN: DS18x20 sensor type
conversion_time_x100ms IN: Temperature conversion interval [1...255] in multiples of 100 ms

Rc Mio::GetDS18x20TaskTemperature ( out int  temperature,
out byte  sn,
out DS18x20Error  error,
int  task_id 
) [inline]

Get DS18x20 temperature.

Get the latest temperature measurement result from the DS18x20 task that was started with StartDS18x20Task().

Returns:
Mio.Rc.OK if success, else some error code
Parameters:
temperature OUT: Temperature in deci-Celsius
sn OUT: Measurement sequence number. 0 = no measurement ready yet, after that sn is 1...255,1...255,1...
error OUT: Sensor error
task_id IN: Id of DS18x20 task

Rc Mio::StopTask ( int  task_id  )  [inline]

Stop a task.

The function stops the specified task that has been started with any of the StartXXXTask() functions.

Returns:
Mio.Rc.OK if success, else some error code
Parameters:
task_id IN: Task id: 0 ... Mio.TaskMaxTaskId

static Rc Mio::ConvertPWMOutValues ( out PWMClockSpeed  pwm_clock_speed,
out int  pwm_period,
PWMOutSubchannelConfig[]  dst_subchannels,
float  pwm_frequency,
PWMOutSubchannelConfig2[]  src_subchannels 
) [inline, static]

Convert from frequency/duty cycle PWM values to PWM clock tick values.

Returns:
Mio.Rc.OK if success, else some error code
Parameters:
pwm_clock_speed OUT: Calculated PWM clock speed is stored here
pwm_period OUT: Calculated PWM period width (in PWM clock ticks): 1 ... 65536 is stored here
dst_subchannels OUT: Calculated 3 PWM subchannel config info is stored here
pwm_frequency IN: PWM frequency (in Hz): ~10.0 ... ~400000.0
src_subchannels IN: 3 PWM subchannel config info to convert

Rc Mio::StartPWMOut ( int  pwm_clock_channel,
PWMClockSpeed  pwm_clock_speed,
int  pwm_period,
PWMOutSubchannelConfig[]  subchannels 
) [inline]

Start PWM output (generation) on 1...3 PWM subchannels.

Configure a PWM clock channel in PWM output mode, with one of the following clock speeds; 20MHz, 10MHz, 5MHz, 2.5MHz or 625 kHz. A PWM clock channel in output mode has 3 independent 16-bit PWM subchannels which can output PWM signals. The 3 subchannels are syncronised, i.e. their PWM periods start on the same PWM clock tick.

The subchannels are mapped onto the physical Mio.Ports as follows:

   PWM clock channel 0:
     subchannel 0   /* not available for PWM output */
     subchannel 1   Mio.Port.P29
     subchannel 2   Mio.Port.P28
     subchannel 3   Mio.Port.P27

   PWM clock channel 1:
     subchannel 0   /* not available for PWM output */
     subchannel 1   Mio.Port.P25
     subchannel 2   Mio.Port.P24
     subchannel 3   Mio.Port.P23

This function configures and starts 1..3 PWM subchannels on 1 PWM clock channel. The shape of the PWM signals are specified as number of PWM clock ticks.

Returns:
Mio.Rc.OK if success, else some error code
Parameters:
pwm_clock_channel IN: PWM clock channel: 0 or 1
pwm_clock_speed IN: PWM clock speed
pwm_period IN: PWM period width (in PWM clock ticks): 1 ... 65536
subchannels IN: 3 PWM subchannel config for subchannels 1, 2, 3

Rc Mio::StartPWMOut ( int  pwm_clock_channel,
float  pwm_frequency,
PWMOutSubchannelConfig2[]  subchannels 
) [inline]

Start PWM output (generation) on 1...3 PWM subchannels.

Configure a PWM clock channel in PWM output mode, with one of the following clock speeds; 20MHz, 10MHz, 5MHz, 2.5MHz or 625 kHz. A PWM clock channel in output mode has 3 independent 16-bit PWM subchannels which can output PWM signals. The 3 subchannels are syncronised, i.e. their PWM periods start on the same PWM clock tick.

The subchannels are mapped onto the physical Mio.Ports as follows:

   PWM clock channel 0:
     subchannel 0   /* not available for PWM output */
     subchannel 1   Mio.Port.P29
     subchannel 2   Mio.Port.P28
     subchannel 3   Mio.Port.P27

   PWM clock channel 1:
     subchannel 0   /* not available for PWM output */
     subchannel 1   Mio.Port.P25
     subchannel 2   Mio.Port.P24
     subchannel 3   Mio.Port.P23

This function configures and starts 1..3 PWM subchannels on 1 PWM clock channel. The shape of the PWM signals are specified with PWM frequency and duty cyckle.

Returns:
Rc.OK if success, else some error code
Parameters:
pwm_clock_channel IN: PWM clock channel: 0 or 1
pwm_frequency IN: PWM frequency (in Hz): ~10.0 ... ~400000.0
subchannels IN: 3 PWM subchannel config for subchannels 1, 2, 3

Rc Mio::AdjustPWMOut ( int  pwm_clock_channel,
PWMClockSpeed  pwm_clock_speed,
int  pwm_period,
PWMOutSubchannelConfig[]  subchannels 
) [inline]

Adjust ongoing PWM output (genration) on 1...3 PWM subchannels.

Adjust ongoing PWM genration period width and shape on 1...3 PWM subchannels. The adjustment is made after the current PWM period has ended and before the next PWM period starts, to minimize glitches in the generated signals.

Note:
'config' is ignored in the subchannel config.
Returns:
Mio.Rc.OK if success, else some error code
Parameters:
pwm_clock_channel IN: PWM clock channel: 0 or 1
pwm_clock_speed IN: PWM clock speed
pwm_period IN: PWM period width (in PWM clock ticks): 1 ... 65536
subchannels IN: PWM subchannel config for subchannels 1, 2, 3

Rc Mio::AdjustPWMOut ( int  pwm_clock_channel,
float  pwm_frequency,
PWMOutSubchannelConfig2[]  subchannels 
) [inline]

Adjust ongoing PWM output (genration) on 1...3 PWM subchannels.

Adjust ongoing PWM genration frequency and duty cycle on 1...3 PWM subchannels. The adjustment is made after the current PWM period has ended and before the next PWM period starts, to minimize glitches in the generated signals.

Note:
'config' is ignored in the subchannel config.
Returns:
Mio.Rc.OK if success, else some error code
Parameters:
pwm_clock_channel IN: PWM clock channel: 0 or 1
pwm_frequency IN: PWM frequency (in Hz): ~10.0 ... ~400000.0
subchannels IN: 3 PWM subchannel config for subchannels 1, 2, 3

Rc Mio::StartPWMIn ( int  pwm_clock_channel,
PWMInSubchannelConfig[]  subchannels 
) [inline]

Start PWM input (measurement) on 1...4 PWM subchannels.

Configure a PWM clock channel in PWM input mode with 20MHz clock speed. A PWM clock channel in input mode has 4 independent subchannels which can measure PWM signals.

The subchannels are mapped onto the physical Mio.Ports as follows:

   PWM clock channel 0:
     subchannel 0   Mio.Port.P30
     subchannel 1   Mio.Port.P29
     subchannel 2   Mio.Port.P28
     subchannel 3   Mio.Port.P27

   PWM clock channel 1:
     subchannel 0   Mio.Port.P26
     subchannel 1   Mio.Port.P25
     subchannel 2   Mio.Port.P24
     subchannel 3   Mio.Port.P23

When a measurement on a subchannel becomes active (using the 'config' bits in this function or using SetPWMInMode()), it will start to capture the edges of the PWM signal, up to the number of edges specified in 'edges'. When the specified number of edges has been captured, the subchannel enters idle mode. The number of edges captured so far, and the total halfperiod and period times can be polled with GetPWMInResult(). A new measurement on the subchannel can be started with SetPWMInMode().

The PWM input implementation in MIO is software assisted meaning that a software interrupt is generated in the MIO board for each edge that is captured. For reliable measurements, it's important not to overflow MIO with interrupts. MIO can reliably capture signals up to 10 kHz (minimum halfperiod pulse width is 50 us) on one subchannel. If two subchannels are used simultaneously, the maximum signal is 5 kHz, tree subchannels is 2.5 kHz, etc. If several high-frequency signals needs to be measured, the measurements should be done sequentially on one subchannel at a time. I.e. only one subchannel should be active at a time, and the other in idle mode. Sequential measurement can be acheived using SetPWMInMode().

Returns:
Mio.Rc.OK if success, else some error code
Parameters:
pwm_clock_channel IN: PWM clock channel: 0 or 1
subchannels IN: 4 PWM subchannel config for subchannels 0, 1, 2, 3

Rc Mio::SetPWMInMode ( int  pwm_clock_channel,
int  pwm_subchannel,
PWMInMode  mode 
) [inline]

Set mode for a PWM input subchannel.

Set the PWM input subchannel mode to one of the following:

   Mio.PWMInMode.Idle            // Set subchannel in idle mode
   Mio.PWMInMode.Active          // Set subchannel in active mode (force start of a new measurement)
   Mio.PWMInMode.ActivateIfIdle  // Set subchannel in active mode only if currently in idle mode

Returns:
Mio.Rc.OK if success, else some error code
Parameters:
pwm_clock_channel IN: PWM clock channel: 0 or 1
pwm_subchannel IN: PWM subchannel: 0, 1, 2 or 3
mode IN: PWM mode for this subchannel

Rc Mio::GetPWMInResult ( out uint  total_halfperiod_time,
out uint  total_period_time,
out int  edges_captured,
int  pwm_clock_channel,
int  pwm_subchannel 
) [inline]

Get measurement result from a PWM input subchannel.

GetPWMInResult() is used to check (poll) the current measurement result for a specific PWM input subchannel. The function returns the number of PWM edges captured so far, along with the total (accumulated) PWM halfperiod and period time in 50 ns ticks. The number of edges a measurement will capture was specified in StartPWMIn(). The following can be derived from the parameters received from GetPWMInResult():

Initial edge captured if: edges_captured >= 1
Measurement completed if: edges_captured >= subchannels[n].edges
Number of periods captured: (edges_captured - 1) / 2

The following can be calculated when at least 1 period (3 edges) has been captured:
Duty cycle in percent: (100.0 * total_halfperiod_time) / total_period_time
Frequency in Hz: ((edges_captured - 1) / 2) / (total_period_time * 50.0E-9)
Period time in ms: total_period_time * 50.0E-6 / ((edges_captured - 1) / 2)
First halfperiod time in ms: total_halfperiod_time * 50.0E-6 / ((edges_captured - 1) / 2)
Second halfperiod time in ms: (total_period_time - total_halfperiod_time) * 50.0E-6 / ((edges_captured - 1) / 2)

Apart from measuring PWM periods, PWM input mode can also be used to measure the width of single pulses. Number of edges should then be set to 2, and pulse polarity accordingly (Mio.PWM_POL_0 or Mio.PWM_POL_1) using StartPWMIn(). In this case, when 2 edges has been captured, total_halfperiod_time will contain the pulse width (in 50 ns ticks) and total_period_time will be zero. Please note that this is a special measurement case, as normally, when more than 2 edges are captured, total_halfperiod_time and total_period_time will only be updated at the end of each captured PWM period.

Returns:
Mio.Rc.OK if success, else some error code
Parameters:
total_halfperiod_time OUT: Total halfperiod time (in 50 ns ticks) of all halfperiods captured
total_period_time OUT: Total period time (in 50 ns ticks) of all halfperiods captured
edges_captured OUT: Number of edges in the PWM signal that has been captured
pwm_clock_channel IN: PWM clock channel: 0 or 1
pwm_subchannel IN: PWM subchannel: 0, 1, 2 or 3

Rc Mio::StopPWM ( int  pwm_clock_channel  )  [inline]

Stop all PWM input/output on the selected PWM clock channel.

Stop all PWM input/output on the slected PWM clock channel and release the Mio_Ports.

Returns:
Mio.Rc.OK if success, else some error code
Parameters:
pwm_clock_channel IN: PWM clock channel: 0 or 1

bool Mio::OpenComPort ( string  port  )  [inline]

Open communication port to MIO board.

Note:
According to .NET documentation: "The best practice for any application is to wait for some amount of time after calling the Close method before attempting to call the Open method, as the port may not be closed instantly."
Returns:
true if port opended, else false
Parameters:
port IN: COM-port name, e.g. "COM1"

bool Mio::IsOpen (  )  [inline]

Check if the communication port is open.

Returns:
true if port is open, else false

virtual void Mio::DispatchOutOfBandMessage ( MioMsgId  msg_id,
int  payload_len,
byte[]  payload 
) [inline, protected, virtual]

"Call-back" for out-of-band messages received from MIO.

This is a call-back for out-of-band messages received from MIO. Out-of-band messages are sent on MIO's own initiative and can be received by the host at any time. Implement this function in the derived class to handle the messages.

Parameters:
msg_id IN: Message id
payload_len IN: Payload length
payload IN: Ptr to payload


Member Data Documentation

const uint Mio::CommunicationSpeed = 125000

For internal use only.

MIO <--> host communication speed in bps


The documentation for this class was generated from the following file:

USB-MIO v1.0 C# API     Copyright (C) 2009 by Mats Byggmastar Consulting Ab