Problem with function CAN_InitializeFD()

This forum covers issues concerning multiple software products.
Post Reply
Fojtik
Posts: 30
Joined: Thu 8. Feb 2018, 13:06

Problem with function CAN_InitializeFD()

Post by Fojtik » Mon 8. Nov 2021, 17:05

I have big troubles with this function. There is undocumented behavior who deallocates the string passed.

If I do this:

Code: Select all

 TPCANStatus stsResult = CAN_InitializeFD(Channel, BitrateFD);
  free(BitrateFD);
It causes program to crash.

When I toss away a pointer, it could cause leak. Who releases the string passed and when it is safe to release it?

Code: Select all

/// <summary>
/// Initializes a FD capable PCAN Channel  
/// </summary>
/// <param name="Channel">"The handle of a FD capable PCAN Channel"</param>
/// <param name="BitrateFD">"The speed for the communication (FD bit rate string)"</param>
/// <remarks>See PCAN_BR_* values
/// * Parameter and values must be separated by '='
/// * Couples of Parameter/value must be separated by ','
/// * Following Parameter must be filled out: f_clock, data_brp, data_sjw, data_tseg1, data_tseg2,
///   nom_brp, nom_sjw, nom_tseg1, nom_tseg2.
/// * Following Parameters are optional (not used yet): data_ssp_offset, nom_sam
///</remarks>
/// <example>f_clock=80000000,nom_brp=10,nom_tseg1=5,nom_tseg2=2,nom_sjw=1,data_brp=4,data_tseg1=7,data_tseg2=2,data_sjw=1</example>
/// <returns>"A TPCANStatus error code"</returns>

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

Re: Problem with function CAN_InitializeFD()

Post by M.Maidhof » Tue 9. Nov 2021, 10:04

Hi,

which OS (Windows/Linux), driver and PCANBasic Version do you use?

regards

Michael

Fojtik
Posts: 30
Joined: Thu 8. Feb 2018, 13:06

Re: Problem with function CAN_InitializeFD()

Post by Fojtik » Thu 11. Nov 2021, 12:05

I am using PCAN-Basic under Windows.

The problem was related to allocation within Matlab and not from PEAK. Now the code works.

But still the documentation of "CAN_InitializeFD" mislead me to false expectation that a string pointer is used longer than during function call itself and immediate deallocation could cause program to crash. As far as I do not see source code I do not know.

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

Re: Problem with function CAN_InitializeFD()

Post by M.Maidhof » Thu 11. Nov 2021, 13:19

Hi,

well, sometimes it will be better to search for errors in your own system, before posting "big problems" here in the forum :D

regards

Michael

Post Reply