Receiving sent message in PLIN API with C#

CAN FD and LIN Interface for High-Speed USB 2.0
Post Reply
RoadieRich
Posts: 2
Joined: Fri 1. Sep 2023, 14:46

Receiving sent message in PLIN API with C#

Post by RoadieRich » Tue 8. Oct 2024, 16:19

I have the following code

Code: Select all

byte hClient = 0;
PLinApi.RegisterClient("LINQPad", 1, ref hClient);
PLinApi.ConnectClient(hClient, 1);
PLinApi.InitializeHardware(hClient, 1, TLINHardwareMode.modMaster, 16920);
PLinApi.SetClientFilter(hClient, 1, 0xffffffffffffffff);

var sendMsg = new TLINMsg
{
	FrameId = 0x3C,
	Data = new byte[8],
	Length = 8,
	ChecksumType = TLINChecksumType.cstClassic,
	Direction = TLINDirection.dirPublisher
};
PLinApi.CalculateChecksum(ref sendMsg);
PLinApi.Write(hClient, 1, ref sendMsg);

var recvMsg = new TLINMsg
{
	FrameId = 0x3D,
	Data = new byte[8],
	Length = 8,
	ChecksumType = TLINChecksumType.cstAuto,
	Direction = TLINDirection.dirSubscriberAutoLength
};
PLinApi.GetPID(ref recvMsg.FrameId);
PLinApi.CalculateChecksum(ref recvMsg);
PLinApi.Write(hClient, 1, ref recvMsg);

Thread.Sleep(1000);

var received = new TLINRcvMsg();

Console.Out.WriteLine(PLinApi.Read(hClient, ref received));
Console.Out.WriteLine($"{received.FrameId}: {String.Join(' ', received.Data.Select(b => b.ToString("X")))}");
The problem is, that I get the 0x3C message back when I call the Read method, when I'm expecting the 0x3D. I have verified this using different values in sendMsg.Data.

I based my code on the example provided in this thread, but without any luck. PLinApi is in a different (VB.net) project, unmodified from the example provided in the PLINApi.dll download.

My LIN Hardware should be good, since the DUT physically responds to a different message (which expects no LIN response) correctly.

Any help would be appreciated.

M.Maidhof
Support
Support
Posts: 1700
Joined: Wed 22. Sep 2010, 14:00

Re: Receiving sent message in PLIN API with C#

Post by M.Maidhof » Wed 9. Oct 2024, 12:17

Hi,

LIN is a master/slave system. So you won't receive any data from a LIN slave, as long as you don't send a subscriber frame for that LIN node. In your case please send a 3D subscriber after 10ms (or as defined in the ldf for master/slave diagnose frames) to get an answer on your 3C master request.

Example (when there is no active scheduler running):

- 3D subscriber as wake up
- Wait 100ms
- 3C with data as publisher
- Wait 10ms
- 3D as subscriber to get the slave diagnostic data.


regards

Michael

RoadieRich
Posts: 2
Joined: Fri 1. Sep 2023, 14:46

Re: Receiving sent message in PLIN API with C#

Post by RoadieRich » Wed 9. Oct 2024, 21:25

I got it working by calling Read twice, or using ReadMulti and filtering the resulting array. I'll be going with the latter in production code.

M.Maidhof
Support
Support
Posts: 1700
Joined: Wed 22. Sep 2010, 14:00

Re: Receiving sent message in PLIN API with C#

Post by M.Maidhof » Mon 14. Oct 2024, 09:12

ok, thank you for the feedback.

Michael

Post Reply