public bool PauseBroadcast(
int index
)
Public Function PauseBroadcast (
index As Integer
) As Boolean
public:
bool PauseBroadcast(
int index
)
The following example shows how to deactivate/pause a Broadcast object.
In case of failure, an error messages is written to the console output using English as output language.
// Create the object using the default configuration
//
Worker myWorker = new Worker();
// Create the CAN message to broadcast
//
PcanMessage message = new PcanMessage(0x100, MessageType.Standard, 3, new byte[] { 1, 2, 3 }, false);
// Add the new broadcast using a CAN message and its interval
//
int index = myWorker.AddBroadcast(message, 100);
if (index < 0)
{
Console.WriteLine("The broadcast couldn't be configured.");
}
else
{
Console.WriteLine($"The broadcast object with index '{index}' was configured successfully.");
try
{
// Activate the worker object
//
myWorker.Start();
Console.WriteLine("The Worker object was activated successfully.");
// Wait sometime for the message to be sent several times
//
Console.WriteLine("Broadcast is working....");
System.Threading.Thread.Sleep(5000);
// Stop sending the CAN message
//
if (myWorker.PauseBroadcast(index))
{
Console.WriteLine($"The broadcast object with index '{index}' was successfully paused.");
// Wait sometime to validate that the message is not sent anymore
//
System.Threading.Thread.Sleep(3000);
// Resume sending the CAN message
//
if (myWorker.ResumeBroadcast(index))
{
// Wait sometime for the message to be sent several times
//
Console.WriteLine($"The broadcast object with index '{index}' was successfully resumed.");
System.Threading.Thread.Sleep(5000);
}
else
{
Console.WriteLine($"The broadcast object with index '{index}' couldn't be resumed.");
}
}
else
{
Console.WriteLine($"The broadcast object with index '{index}' couldn't be paused.");
}
// Deactivate the worker object, when it is no longer needed
//
myWorker.Stop();
Console.WriteLine("The Worker object was deactivated.");
}
catch(Exception ex)
{
Console.WriteLine($"An exception occurred by activating the Worker object. {ex.Message}");
}
}
' Create the object using the default configuration
'
Dim myWorker As Worker = New Worker()
' Create the CAN message to broadcast
'
Dim message As PcanMessage = New PcanMessage(&H100, MessageType.Standard, 3, New Byte() {1, 2, 3}, False)
' Add the new broadcast using a CAN message and its interval
'
Dim index As Integer = myWorker.AddBroadcast(message, 100)
If index < 0 Then
Console.WriteLine("The broadcast couldn't be configured.")
Else
Console.WriteLine($"The broadcast object with index '{index}' was configured successfully.")
Try
' Activate the worker object
'
myWorker.Start()
Console.WriteLine("The Worker object was activated successfully.")
' Wait sometime for the message to be sent several times
'
Console.WriteLine("Broadcast is working....")
Threading.Thread.Sleep(5000)
' Stop sending the CAN message
'
If myWorker.PauseBroadcast(index) Then
Console.WriteLine($"The broadcast object with index '{index}' was successfully paused.")
' Wait sometime to validate that the message is not sent anymore
'
Threading.Thread.Sleep(3000)
' Resume sending the CAN message
'
If myWorker.ResumeBroadcast(index) Then
' Wait sometime for the message to be sent several times
'
Console.WriteLine($"The broadcast object with index '{index}' was successfully resumed.")
Threading.Thread.Sleep(5000)
Else
Console.WriteLine($"The broadcast object with index '{index}' couldn't be resumed.")
End If
Else
Console.WriteLine($"The broadcast object with index '{index}' couldn't be paused.")
End If
' Deactivate the worker object, when it is no longer needed
'
myWorker.[Stop]()
Console.WriteLine("The Worker object was deactivated.")
Catch ex As Exception
Console.WriteLine($"An exception occurred by activating the Worker object. {ex.Message}")
End Try
End If
// Create the object using the default configuration
//
Worker^ myWorker = gcnew Worker();
// Create the CAN message to broadcast
//
PcanMessage^ message = gcnew PcanMessage(0x100, MessageType::Standard, 3, gcnew array<Byte>{ 1, 2, 3 }, false);
// Add the new broadcast using a CAN message and its interval
//
int index = myWorker->AddBroadcast(message, 100);
if (index < 0)
{
Console::WriteLine("The broadcast couldn't be configured.");
}
else
{
Console::WriteLine("The broadcast object with index '{0}' was configured successfully.", index);
try
{
// Activate the worker object
//
myWorker->Start(false, false, false);
Console::WriteLine("The Worker object was activated successfully.");
// Wait sometime for the message to be sent several times
//
Console::WriteLine("Broadcast is working....");
System::Threading::Thread::Sleep(5000);
// Stop sending the CAN message
//
if (myWorker->PauseBroadcast(index))
{
Console::WriteLine("The broadcast object with index '{0}' was successfully paused.", index);
// Wait sometime to validate that the message is not sent anymore
//
System::Threading::Thread::Sleep(3000);
// Resume sending the CAN message
//
if (myWorker->ResumeBroadcast(index))
{
// Wait sometime for the message to be sent several times
//
Console::WriteLine("The broadcast object with index '{0}' was successfully resumed.", index);
System::Threading::Thread::Sleep(5000);
}
else
{
Console::WriteLine("The broadcast object with index '{0}' couldn't be resumed.", index);
}
}
else
{
Console::WriteLine("The broadcast object with index '{0}' couldn't be paused.", index);
}
// Deactivate the worker object, when it is no longer needed
//
myWorker->Stop(false, false, false);
Console::WriteLine("The Worker object was deactivated.");
}
catch (Exception^ ex)
{
Console::WriteLine("An exception occurred by activating the Worker object. {0}", ex->Message);
}
}
IndexOutOfRangeException | The index parameter value is out of range. This must be in the range [0...MaximumBroadcastCount-1]. |