Hi everyone,
I have converted the C++ sample applications from the PCAN-UDS package into C#:
PCUServer : https://github.com/Evilpaul/PCUServer
PCUClient : https://github.com/Evilpaul/PCUClient
I have done a quick comparison using combinations of the C++ and C# applications and the behaviour appears to be the same.
The one difference is that I have not been able to get the testUsingEvent function to work due to getting an AccessViolationException when passing a handle to UDSApi.SetValue, so this is disabled for the moment.
Hope someone finds these useful.
regards,
Paul
UDS sample apps - converted to C#
Re: UDS sample apps - converted to C#
Hello,
thank you for your interest and your effort in porting the sample projects to C# and for sharing them to the community.
The problem seems to be in the overloading of UDS_SetValue for an IntPtr buffer.It doesn't use the "ref" keyword. Try declaring it in this way:
We will need to adjust the header files. Thanks for bringing this to our attention.
EDIT: The events should be passed as an integer value, as done in PCAN-Basic (note this api use PCAN-Basic internally).
thank you for your interest and your effort in porting the sample projects to C# and for sharing them to the community.
The problem seems to be in the overloading of UDS_SetValue for an IntPtr buffer.
Code: Select all
[DllImport("PCAN-UDS.dll", EntryPoint = "UDS_SetValue")]
public static extern TPUDSStatus SetValue(
[MarshalAs(UnmanagedType.U2)]
TPUDSCANHandle CanChannel,
[MarshalAs(UnmanagedType.U1)]
TPUDSParameter Parameter,
ref IntPtr Buffer,
UInt32 BufferLength);
EDIT: The events should be passed as an integer value, as done in PCAN-Basic (note this api use PCAN-Basic internally).
Best regards,
Keneth
Keneth
Re: UDS sample apps - converted to C#
Hello again,
after checking this deeper, it is now clear that the overload:
is not intended to be used with AutoreceiveEvent or ManualresetEvent. It is intended to be used with the parameter PUDS_PARAM_MAPPING_ADD.
The Events are to be set using the overload version for numeric values of SetValue,
The way how you do this is as follow:
We will add a note in the documentation.
after checking this deeper, it is now clear that the overload:
Code: Select all
SetValue(TPUDSCANHandle,TPUDSParameter, IntPtr, UInt32)
The Events are to be set using the overload version for numeric values of SetValue,
Code: Select all
SetValue(TPUDSCANHandle, TPUDSParameter, ref UInt32, UInt32)
Code: Select all
TPUDSStatus status;
ManualResetEvent hEvent;
uint myEventAsInt;
hEvent = new ManualResetEvent(false);
myEventAsInt = (uint)hEvent.SafeWaitHandle.DangerousGetHandle().ToInt32();
status = SetValue(CanChannel, Parameter, ref myEventAsInt, sizeof(uint));
Best regards,
Keneth
Keneth
Re: UDS sample apps - converted to C#
Hi Keneth,
Thanks for the information, I have committed the change to the PCUClient repo.
regards,
Paul
Thanks for the information, I have committed the change to the PCUClient repo.
regards,
Paul