Note
If a Broadcast object represents a CAN FD message but the PCAN Channel used was not initialized with support for CAN FD,
it is automatically deactivated (paused), when this situation is detected.
public bool AddBroadcast(
ref Broadcast frame
)
Public Function AddBroadcast (
ByRef frame As Broadcast
) As Boolean
public:
bool AddBroadcast(
Broadcast^% frame
)
The amount of Broadcast that can be registered is limited by MaximumBroadcastCount. Trying to configure more than that causes this method to fail.
The accuracy of the transmission interval when using Broadcast objects depend on the amount of data being transmitted and fill state of the driver's transmit queue.
The transmit queue of the driver has a size of 1 MB, enough to allocate up to 32.768 classic CAN messages or 13.000 CAN FD messages. This queue is constantly in observation so that any new entry is processed and physically sent as fast as possible.
The Worker object uses a performance timer to check the time expiration of registered Broadcast objects. When a Broadcast object time outs, the associated CAN message is placed in the device driver's transmit queue, as if the Write method had just been called.
Single Broadcast objects can be temporarily deactivated using the PauseBroadcast method and reactivated again using the ResumeBroadcast method. Using the property MessageBroadcasting is possible to activate/deactivate the Broadcast object processing.
The following example shows how to configure 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 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 broadcast couldn't be configured");
}
else
{
Console.WriteLine($"The broadcast object with index '{broadcast.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);
// 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 broadcast couldn't be configured")
Else
Console.WriteLine($"The broadcast object with index '{broadcast.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)
' 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 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 broadcast couldn't be configured");
}
else
{
Console::WriteLine("The broadcast object with index '{0}' was configured successfully.", broadcast->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);
// 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);
}
}
ArgumentOutOfRangeException | The Interval value is out of range. This must be in the range [1...MaxValue]. |
ArgumentNullException | The Message value of the frame parameter is null. An object of type PcanMessage is required. |
ArgumentException | The Broadcast object represented by the frame parameter is already registered. |