OptoMMP2
Opto22.StreamsHelper.OptoMMPStream Class Reference

Encapsulation class for streaming implementations using the Opto MMP Streaming brain capability. More...

Public Member Functions

delegate void ProcessStream (StreamMessage Message)
 Delegate to process the stream message. More...
 
 OptoMMPStream ()
 Constructor More...
 
void Open (int i32UdpPort, ProcessStream MessageHandler)
 Open the OptoMMPStream object More...
 
int Start ()
 Start the stream object on the PC side. More...
 
void Stop ()
 Stop the background thread. More...
 
void Close ()
 Close the whole object. More...
 
void Example ()
 Example of using the OptoMMPStream assembly More...
 

Static Public Member Functions

static bool ProcessMessageasBrainStream (StreamMessage Message, out EndPoint endpoint, out short i16SequenceId, out Single[] faryAnalog, out uint[] u32aryCounters, out long u64DigitalStates, out long u64OnLatches, out long u64OffLatches, out long u64ActiveCounters)
 Process a message returned as a callback. This handles the default "streaming" configuration of the Opto MMP device. More...
 
static bool ProcessMessageasBrainStreamUint32Array (StreamMessage Message, out EndPoint endpoint, out short i16SequenceId, out int i32ExpectedMmpAddress, int i32ExpectedU32Ints, out uint[] u32aryValues)
 Process a message returned as a callback. This handles a customer stream of just 32-bit unsigned integers. The data may be casted as 32-bit signed integers too. More...
 
static bool ProcessMessageasBrainStreamSingleArray (StreamMessage Message, out EndPoint endpoint, out short i16SequenceId, out int i32ExpectedMmpAddress, int i32ExpectedSingles, out Single[] f32aryValues)
 Process a message returned as a callback. This handles a custom stream of floats (aka Singles). More...
 
static bool ProcessMessageasBrainStreamRawBytes (StreamMessage Message, out EndPoint endpoint, out int i32DataLength, out byte[] byary)
 Process a message returned as a callback. This handles a custom stream of floats (aka Singles). More...
 

Detailed Description

Encapsulation class for streaming implementations using the Opto MMP Streaming brain capability.

Please note that this functionality does not support I/O modules with more than 4-channels per module. If you need to have streaming with what are called "high-density" I/O modules, please see the OptoStrategyStream assembly.

This functionality is available with any Ethernet based I/O brain.

This library is currently built with the 3.5 SP1 .Net Framework.

This library supports Vista Business and Windows 7 Professional.

You should use an Intel "Core 2" or AMD Athlon II or Phenom (or newer) microprocessor.

Constructor & Destructor Documentation

Opto22.StreamsHelper.OptoMMPStream.OptoMMPStream ( )

Constructor

Member Function Documentation

void Opto22.StreamsHelper.OptoMMPStream.Close ( )

Close the whole object.

void Opto22.StreamsHelper.OptoMMPStream.Example ( )

Example of using the OptoMMPStream assembly

class Program { ///

/// This is a message handler call-back example. ///

/// Each time a message arrives, this method is invoked by a background thread. ///

///

/// Since this function is called within the scope of a background thread, this function should not block, /// nor take an amount of time longer than the rate of incoming UDP stream messages. If this method /// is too slow, the incoming UDP queue will fill up and drop incoming messages. ///

///

///

Parameters
NewMessageThe current message the background thread received.

static void MyDefaultStreamMessageHandler(StreamMessage NewMessage) { // items needed to buffer the messsage EndPoint endpoint = new IPEndPoint(IPAddress.Any, 0); byte[] byary = null; int i32Length = 0;

// get the message object components NewMessage.Get(out endpoint, out byary, out i32Length);

// process the message received short i16SequenceId; Single[] fary = null; uint[] u32aryCounters; long i64DigitalStates; long i64OnDigitalLatches; long i64OffDigitalLatches; long i64CounterStates;

// for the index of digital states and channel numbers, use this equation: // index = (module number [0 to 15] * 4 + channel number [0 to 3]).

// process the message bool bState = OptoMMPStream.ProcessMessageasBrainStream(NewMessage, out endpoint, out i16SequenceId, out fary, out u32aryCounters, out i64DigitalStates, out i64OnDigitalLatches, out i64OffDigitalLatches, out i64CounterStates);

// print some output and an indication of the result. if (bState) { // todo, add your code here, the data is available Console.WriteLine("Source [IP Address:Udp Port] {0} MMP Sequence Id {1}", endpoint.ToString(), i16SequenceId.ToString()); } else { // with UDP this either means a misconfigured Opto MMP device or some other data that // happens to arrive on the UDP port (this is possible with UDP and when connected to a large // largely unknown network). Console.WriteLine("False Return"); } }

static void Main(string[] args) { // example for the OptoMMP stream OptoMMPStream MMPStream = new OptoMMPStream();

// this configures the MMPStream object to handle a default stream message handler MMPStream.Open(5001, new OptoMMPStream.ProcessStream(MyDefaultStreamMessageHandler));

Console.WriteLine("Starting Thread"); // this starts the background thread and initiates the application to being receiving messages MMPStream.Start();

// a loop to run the background thread for about 15 seconds int i32Counter = 0; while (i32Counter < 15) { Thread.Sleep(1000); i32Counter++; }

// stop the stream MMPStream.Stop();

Console.WriteLine("Second Starting Thread"); // this starts the background thread and initiates the application to being receiving messages MMPStream.Start();

// a loop to run the background thread for about 15 seconds i32Counter = 0; while (i32Counter < 15) { Thread.Sleep(1000); i32Counter++; }

// stop the stream MMPStream.Stop(); MMPStream.Close(); MMPStream.Open(5001, new OptoMMPStream.ProcessStream(MyDefaultStreamMessageHandler));

Console.WriteLine("Third Restarting Thread");

// this starts the background thread and initiates the application to being receiving messages MMPStream.Start();

// a loop to run the background thread for about 15 seconds i32Counter = 0; while (i32Counter < 15) { Thread.Sleep(1000); i32Counter++; }

// stop the stream MMPStream.Stop(); } }

void Opto22.StreamsHelper.OptoMMPStream.Open ( int  i32UdpPort,
ProcessStream  MessageHandler 
)

Open the OptoMMPStream object

Parameters
i32UdpPortThe PC UDP port to receive data on.
MessageHandlerDelegate call-back routine to handle the received message.
static bool Opto22.StreamsHelper.OptoMMPStream.ProcessMessageasBrainStream ( StreamMessage  Message,
out EndPoint  endpoint,
out short  i16SequenceId,
out Single[]  faryAnalog,
out uint[]  u32aryCounters,
out long  u64DigitalStates,
out long  u64OnLatches,
out long  u64OffLatches,
out long  u64ActiveCounters 
)
static

Process a message returned as a callback. This handles the default "streaming" configuration of the Opto MMP device.

Many Opto MMP devices may be configured to stream at one thread. Each device may be determined by comparing the "EndPoint" information.

Since this is UDP, the receiver should inspect the "endpoint" address to ensure it can identify the correct sender of this message.

Parameters
MessageThe message given by the callback.
endpointThe source of the message.
i16SequenceIdSequence ID of this message, a value from 0 to 15.
faryAnalog64 analog values of the brain.
u32aryCountersValue of the enabled digital input counters (from 64 point map)
u64DigitalStates64-bit compressed value of all the 64-point digital states. 1 == on.
u64OnLatches64-bit compressed value of all the 64-point digital on latches. 1 == latched.
u64OffLatches64-bit compressed value of all the 64-point digital off latches. 1 == latched.
u64ActiveCounters64-bit compressed value of all the active counter states. 1 == enabled.
Returns
true if the received message is a valid default stream message, false if it is not.
static bool Opto22.StreamsHelper.OptoMMPStream.ProcessMessageasBrainStreamRawBytes ( StreamMessage  Message,
out EndPoint  endpoint,
out int  i32DataLength,
out byte[]  byary 
)
static

Process a message returned as a callback. This handles a custom stream of floats (aka Singles).

Many Opto MMP devices may be configured to stream at one thread. Each device may be determined by comparing the "EndPoint" information.

Since this is UDP, the receiver should inspect the "endpoint" address to ensure it can identify the correct sender of this message.

Parameters
MessageThe message given by the callback.
endpointThe source of the message.
i32DataLengthLength of the data in bytes.
byaryThe data received.
Returns
true if the received message is a valid default stream message, false if it is not.
static bool Opto22.StreamsHelper.OptoMMPStream.ProcessMessageasBrainStreamSingleArray ( StreamMessage  Message,
out EndPoint  endpoint,
out short  i16SequenceId,
out int  i32ExpectedMmpAddress,
int  i32ExpectedSingles,
out Single[]  f32aryValues 
)
static

Process a message returned as a callback. This handles a custom stream of floats (aka Singles).

Many Opto MMP devices may be configured to stream at one thread. Each device may be determined by comparing the "EndPoint" information.

Since this is UDP, the receiver should inspect the "endpoint" address to ensure it can identify the correct sender of this message.

Parameters
MessageThe message given by the callback.
endpointThe source of the message.
i16SequenceIdSequence ID of this message, a value from 0 to 15.
i32ExpectedMmpAddressThe OptoMMP address reported.
i32ExpectedSinglesThe number of expected singles in the response.
f32aryValues
Returns
true if the received message is a valid default stream message, false if it is not.
static bool Opto22.StreamsHelper.OptoMMPStream.ProcessMessageasBrainStreamUint32Array ( StreamMessage  Message,
out EndPoint  endpoint,
out short  i16SequenceId,
out int  i32ExpectedMmpAddress,
int  i32ExpectedU32Ints,
out uint[]  u32aryValues 
)
static

Process a message returned as a callback. This handles a customer stream of just 32-bit unsigned integers. The data may be casted as 32-bit signed integers too.

Many Opto MMP devices may be configured to stream at one thread. Each device may be determined by comparing the "EndPoint" information.

Since this is UDP, the receiver should inspect the "endpoint" address to ensure it can identify the correct sender of this message.

Parameters
MessageThe message given by the callback.
endpointThe source of the message.
i16SequenceIdSequence ID of this message, a value from 0 to 15.
i32ExpectedMmpAddressThe expected Opto MMP address of the packet.
i32ExpectedU32IntsExpected number of 32-bit integers to receive.
u32aryValuesThe values received.
Returns
true if the received message is a valid default stream message, false if it is not.
delegate void Opto22.StreamsHelper.OptoMMPStream.ProcessStream ( StreamMessage  Message)

Delegate to process the stream message.

Parameters
MessageA raw message buffer containing the data that arrived on the UDP socket.
int Opto22.StreamsHelper.OptoMMPStream.Start ( )

Start the stream object on the PC side.

Returns
Negative value for error, probably for overlapping UDP service ports. Zero for okay.
void Opto22.StreamsHelper.OptoMMPStream.Stop ( )

Stop the background thread.


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