Oakrey.Vector.Lin
4.0.4
dotnet add package Oakrey.Vector.Lin --version 4.0.4
NuGet\Install-Package Oakrey.Vector.Lin -Version 4.0.4
<PackageReference Include="Oakrey.Vector.Lin" Version="4.0.4" />
<PackageVersion Include="Oakrey.Vector.Lin" Version="4.0.4" />
<PackageReference Include="Oakrey.Vector.Lin" />
paket add Oakrey.Vector.Lin --version 4.0.4
#r "nuget: Oakrey.Vector.Lin, 4.0.4"
#:package Oakrey.Vector.Lin@4.0.4
#addin nuget:?package=Oakrey.Vector.Lin&version=4.0.4
#tool nuget:?package=Oakrey.Vector.Lin&version=4.0.4
Oakrey.Vector.Lin
LIN master and slave client library for Vector hardware (XL Driver Library). Built on Oakrey.Vector.Base
and Oakrey.Vector.Wrapper, it provides VectorLinClient and VectorLinChannel with IObservable
message streams (Rx.NET), a slave answer table, a software LIN scheduler, master request sending, and
per-channel LinConfig.
Main features
- Static factory creation -
VectorLinClient.Create(serialNumber, appName)discovers all LIN channels on the target device and initializes each one automatically (opens the port and applies the defaultLinConfig). - Slave answer table -
AddSlaveAnswerregisters aVectorFrameas a slave response for a given LIN ID.RemoveSlaveAnswerandClearAllAnswersmanage the table at runtime; removing an answer reopens and reconfigures the port transparently. - LIN scheduler -
AddSchedulerRequestqueues frames for cyclic master transmission.StartSchedule/StopSchedulerun the scheduler on a backgroundTaskwith per-frameDelay(milliseconds) between header requests.ClearScheduleempties the queue and stops the scheduler. - Master requests -
SendMasterRequestissues a single LIN header request on demand, independent of the scheduler. - Per-channel configuration -
ConfigureChannel(channelNumber, LinConfig)applies a newLinConfig(baud rate, master/slave mode, etc.) at runtime. Changing the mode resets the DLC table and frame list. - Rx.NET observable streams -
IVectorLinClient.ReceivedDataexposes anIObservable<ReceivedLinMessage>that merges frames from all channels. Subscribe using standard Rx operators. - Enable / disable lifecycle -
EnableChannel/DisableChannelcontrol hardware activation without closing or reinitializing the port. VectorFramedata type - carries LIN frame ID, data bytes, DLC, enhanced-checksum flag, and inter-frame delay for scheduler use. A copy constructor (GetCopy) is provided to avoid shared-state bugs when the scheduler iterates queued frames.
Architecture
classDiagram
direction TB
class IVectorLinClient {
<<interface>>
+IObservable~ReceivedLinMessage~ ReceivedData
+uint SerialNumber
+AddSlaveAnswer(byte channelNumber, VectorFrame frame)
+AddSchedulerRequest(byte channelNumber, VectorFrame frame)
+ClearAllAnswers(byte channelNumber)
+ClearSchedule(byte channelNumber)
+ConfigureChannel(byte channelNumber, LinConfig config)
+RemoveSlaveAnswer(byte channelNumber, byte id)
+SendMasterRequest(byte channelNumber, VectorFrame frame)
+StartSchedule(byte channelNumber)
+StopSchedule(byte channelNumber)
+EnableChannel(byte channelNumber)
+DisableChannel(byte channelNumber)
}
class IVectorLinChannel {
<<interface>>
+IObservable~ReceivedLinMessage~ ReceivedData
+byte ChannelNumber
+AddSlaveAnswer(VectorFrame frame)
+AddSchedulerRequest(VectorFrame frame)
+ClearAllAnswers()
+ClearSchedule()
+Configure(LinConfig config)
+RemoveSlaveAnswer(byte id)
+SendMasterRequest(VectorFrame frame)
+StartSchedule()
+StopSchedule()
}
class VectorLinClient {
+Create(uint serialNumber, string appName) IVectorLinClient$
}
class VectorLinChannel {
-byte[] dlcs
-List~VectorFrame~ frames
-LinConfig currentLinConfig
}
class VectorFrame {
+byte Id
+byte[] Data
+byte Dlc
+bool EnhancedChecksum
+ushort Delay
+GetCopy(VectorFrame) VectorFrame$
}
IVectorLinClient <|.. VectorLinClient
IVectorLinChannel <|.. VectorLinChannel
VectorLinClient o-- VectorLinChannel
VectorLinChannel ..> VectorFrame
VectorLinClient extends VectorClientBase from Oakrey.Vector.Base.
VectorLinChannel extends VectorChannelBase from Oakrey.Vector.Base.
Requirements
- .NET 10 or higher
- Vector XL Driver Library installed on the host machine
Oakrey.Vector.BaseandOakrey.Vector.Wrapper(pulled automatically as transitive dependencies)
Build instructions
dotnet build VectorLin/VectorLin.csproj
To produce a NuGet package:
dotnet pack VectorLin/VectorLin.csproj -c Release
Installation
.NET CLI
dotnet add package Oakrey.Vector.Lin
Package Manager Console
Install-Package Oakrey.Vector.Lin
Configuration
LinConfig (from Oakrey.Vector.Wrapper) controls the channel operating mode and baud rate.
LinConfig.GetDefault() is applied automatically at channel construction; call ConfigureChannel to
override it at any point after creation.
LinConfig config = LinConfig.GetDefault(); // adjust baud rate, master/slave mode, etc.
client.ConfigureChannel(channelNumber: 1, config);
Changing LinConfig.Mode resets the DLC table and clears all queued frames for that channel.
Example usage
Receive LIN frames
using IVectorLinClient client = VectorLinClient.Create(serialNumber: 12345, appName: "MyApp");
using IDisposable subscription = client.ReceivedData
.Subscribe(msg => Console.WriteLine($"LIN id=0x{msg.Id:X2} data={BitConverter.ToString(msg.Data)}"));
client.EnableChannel(channelNumber: 1);
Console.ReadLine();
client.DisableChannel(channelNumber: 1);
Send a master request
using IVectorLinClient client = VectorLinClient.Create(serialNumber: 12345, appName: "MyApp");
client.EnableChannel(channelNumber: 1);
VectorFrame request = new VectorFrame(id: 0x10, dlc: 8, enhancedChecksum: false, delay: 0);
client.SendMasterRequest(channelNumber: 1, request);
Register slave answers
using IVectorLinClient client = VectorLinClient.Create(serialNumber: 12345, appName: "MyApp");
client.EnableChannel(channelNumber: 1);
VectorFrame answer = new VectorFrame(id: 0x20, data: [0xAA, 0xBB, 0xCC, 0xDD], enhancedChecksum: true, delay: 0);
client.AddSlaveAnswer(channelNumber: 1, answer);
// Remove one answer at runtime
client.RemoveSlaveAnswer(channelNumber: 1, id: 0x20);
// Clear all answers
client.ClearAllAnswers(channelNumber: 1);
Run the LIN scheduler
using IVectorLinClient client = VectorLinClient.Create(serialNumber: 12345, appName: "MyApp");
client.EnableChannel(channelNumber: 1);
// Queue frames; Delay is the pause in ms after each header request
client.AddSchedulerRequest(channelNumber: 1, new VectorFrame(id: 0x01, dlc: 2, enhancedChecksum: false, delay: 10));
client.AddSchedulerRequest(channelNumber: 1, new VectorFrame(id: 0x02, dlc: 4, enhancedChecksum: false, delay: 20));
client.StartSchedule(channelNumber: 1);
Console.ReadLine();
client.StopSchedule(channelNumber: 1);
Development notes
VectorLinClienthas a private constructor; always useVectorLinClient.Create(...)which returnsIVectorLinClientfor easy mocking and dependency injection.- The channel port is opened and configured automatically during
VectorLinClientconstruction. There is no separateInitstep unlikeVectorCanChannel. - The scheduler runs on a background
Taskand iterates a snapshot (GetCopy) of the frame list taken atStartScheduletime. Changes to the frame list afterStartScheduleare not reflected until the scheduler is restarted. ClearAllAnswersreopens and reconfigures the port to flush slave registrations from the driver; expect a brief interruption on the bus.- The RX queue size is 256 events per channel.
License
MIT - Copyright (c) Oakrey 2016-present. See the LICENSE file for details.
- Author: Oakrey
- Repository: https://dev.azure.com/oakrey/OpenPackages/_git/Drivers
- Package URL: https://www.oakrey.cz/opkg_drivers_vector
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Oakrey.Vector.Base (>= 4.0.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.