public void ClearBroadcasts()
Public Sub ClearBroadcasts
public:
void ClearBroadcasts()
The following example shows how to clear the Worker object's broadcast list.
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 a Broadcast object using a CAN message and its interval
//
PcanMessage message = new PcanMessage(0x100, MessageType.Standard, 3, new byte[] { 1, 2, 3 }, false);
Broadcast broadcast = new Broadcast(message, 100);
// Add the new broadcast using a Broadcast object
//
if (!myWorker.AddBroadcast(ref broadcast))
{
Console.WriteLine("The first broadcast couldn't be configured.");
}
else
{
Console.WriteLine($"The broadcast object with index '{broadcast.Index}' was configured successfully.");
// add a second broadcast
//
PcanMessage message2 = new PcanMessage(0x200, MessageType.Standard, 8, new byte[] { 8, 7, 6, 5, 4, 3, 2, 1 }, false);
Broadcast broadcast2 = new Broadcast(message2, 500);
if (!myWorker.AddBroadcast(ref broadcast2))
{
Console.WriteLine("The second broadcast couldn't be configured.");
}
else
{
Console.WriteLine($"The broadcast object with index '{broadcast2.Index}' was configured successfully.");
try
{
// Activate the worker object
//
myWorker.Start();
Console.WriteLine("The Worker object was activated successfully.");
// Wait sometime for the messages to be sent several times
//
Console.WriteLine("Broadcasting ....");
System.Threading.Thread.Sleep(5000);
// Clear all broadcasts
//
myWorker.ClearBroadcasts();
Console.WriteLine("All broadcast objects were removed.");
// Wait sometime to validate that the message is not sent anymore
//
System.Threading.Thread.Sleep(3000);
// 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 a Broadcast object using a CAN message and its interval
'
Dim message As PcanMessage = New PcanMessage(&H100, MessageType.Standard, 3, New Byte() {1, 2, 3}, False)
Dim broadcast As Broadcast = New Broadcast(message, 100)
' Add the new broadcast using a Broadcast object
'
If Not myWorker.AddBroadcast(broadcast) Then
Console.WriteLine("The first broadcast couldn't be configured.")
Else
Console.WriteLine($"The broadcast object with index '{broadcast.Index}' was configured successfully.")
' add a second broadcast
'
Dim message2 As PcanMessage = New PcanMessage(&H200, MessageType.Standard, 8, New Byte() {8, 7, 6, 5, 4, 3, 2, 1}, False)
Dim broadcast2 As Broadcast = New Broadcast(message2, 500)
If Not myWorker.AddBroadcast(broadcast2) Then
Console.WriteLine("The second broadcast couldn't be configured.")
Else
Console.WriteLine($"The broadcast object with index '{broadcast2.Index}' was configured successfully.")
Try
' Activate the worker object
'
myWorker.Start()
Console.WriteLine("The Worker object was activated successfully.")
' Wait sometime for the messages to be sent several times
'
Console.WriteLine("Broadcasting ....")
Threading.Thread.Sleep(5000)
' Clear all broadcasts
'
myWorker.ClearBroadcasts()
Console.WriteLine("All broadcast objects were removed.")
' Wait sometime to validate that the message is not sent anymore
'
Threading.Thread.Sleep(3000)
' 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
End If
// Create the object using the default configuration
//
Worker^ myWorker = gcnew Worker();
// Create a Broadcast object using a CAN message and its interval
//
PcanMessage^ message = gcnew PcanMessage(0x100, MessageType::Standard, 3, gcnew array<Byte>{ 1, 2, 3 }, false);
Broadcast^ broadcast = gcnew Broadcast(message, 100);
// Add the new broadcast using a Broadcast object
//
if (!myWorker->AddBroadcast(broadcast))
{
Console::WriteLine("The first broadcast couldn't be configured.");
}
else
{
Console::WriteLine("The broadcast object with index '{0}' was configured successfully.", broadcast->Index);
// add a second broadcast
//
PcanMessage^ message2 = gcnew PcanMessage(0x200, MessageType::Standard, 8, gcnew array<Byte>{ 8, 7, 6, 5, 4, 3, 2, 1 }, false);
Broadcast^ broadcast2 = gcnew Broadcast(message2, 500);
if (!myWorker->AddBroadcast(broadcast2))
{
Console::WriteLine("The second broadcast couldn't be configured.");
}
else
{
Console::WriteLine("The broadcast object with index '{0}' was configured successfully.", broadcast2->Index);
try
{
// Activate the worker object
//
myWorker->Start(false, false, false);
Console::WriteLine("The Worker object was activated successfully.");
// Wait sometime for the messages to be sent several times
//
Console::WriteLine("Broadcasting ....");
System::Threading::Thread::Sleep(5000);
// Clear all broadcasts
//
myWorker->ClearBroadcasts();
Console::WriteLine("All broadcast objects were removed.");
// Wait sometime to validate that the message is not sent anymore
//
System::Threading::Thread::Sleep(3000);
// 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);
}
}
}