Class ZlgCanChannel
Represents a ZLG CAN channel (supports all ZLG device types)
public class ZlgCanChannel : ICanChannel, IDisposable
- Inheritance
-
ZlgCanChannel
- Implements
- Inherited Members
Properties
ChannelIndex
Channel index (0-based)
public int ChannelIndex { get; }
Property Value
Configuration
Channel configuration
public ChannelConfig Configuration { get; }
Property Value
IsStarted
Whether the channel is currently started
public bool IsStarted { get; }
Property Value
Methods
ClearBuffer()
Clears the receive buffer
public void ClearBuffer()
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
~ZlgCanChannel()
Finalizer to ensure proper cleanup of native resources.
protected ~ZlgCanChannel()
GetErrorInfo()
Reads channel error information
public ChannelErrorInfo GetErrorInfo()
Returns
- ChannelErrorInfo
Channel error information
GetReceiveCount()
Gets the number of frames in the receive buffer
public uint GetReceiveCount()
Returns
- uint
Number of available frames
Receive(int)
Receives available CAN frames (non-blocking)
public CanFrame[] Receive(int maxCount = 100)
Parameters
maxCountintMaximum number of frames to receive
Returns
- CanFrame[]
Array of received frames
Reset()
Resets the channel
public void Reset()
Send(CanFrame)
Sends a CAN frame
public int Send(CanFrame frame)
Parameters
frameCanFrameFrame to send
Returns
- int
Number of frames sent (1 on success, 0 on failure)
Exceptions
- TransmitException
Thrown when transmission fails
SendAsync(CanFrame, CancellationToken)
Sends a CAN frame asynchronously
public Task<int> SendAsync(CanFrame frame, CancellationToken cancellationToken = default)
Parameters
frameCanFrameFrame to send
cancellationTokenCancellationTokenCancellation token
Returns
SendBatch(IEnumerable<CanFrame>)
Sends multiple CAN frames
public int SendBatch(IEnumerable<CanFrame> frames)
Parameters
framesIEnumerable<CanFrame>Frames to send
Returns
- int
Number of frames successfully sent
Exceptions
- TransmitException
Thrown when transmission fails
SendBatchAsync(IEnumerable<CanFrame>, CancellationToken)
Sends multiple CAN frames asynchronously
public Task<int> SendBatchAsync(IEnumerable<CanFrame> frames, CancellationToken cancellationToken = default)
Parameters
framesIEnumerable<CanFrame>Frames to send
cancellationTokenCancellationTokenCancellation token
Returns
Start()
Starts the channel (begins receiving frames)
public void Start()
Stop()
Stops the channel
public void Stop()
Events
ErrorOccurred
Event raised when a channel error occurs
public event EventHandler<ChannelErrorEventArgs>? ErrorOccurred
Event Type
MessageReceived
Event raised when a CAN frame is received
public event EventHandler<CanFrame>? MessageReceived