C# sample code.
C# sample code.
I can see we have C# sample code for ISOTP and PCAN basic. Do you or anyone have a sample code for client side C# UDS sample?
Re: C# sample code.
Hello,
Sorry, we don't have any sample in C# for UDS at the moment. This is still in our todo list.
Sorry, we don't have any sample in C# for UDS at the moment. This is still in our todo list.
Best regards,
Keneth
Keneth
Re: C# sample code.
Thank you for letting me know.
i was trying to initialize the device like this but i am getting an exception like below
i was trying to initialize the device like this but i am getting an exception like below
Code: Select all
private void buttonInit_Click(object sender, EventArgs e)
{
TPUDSCANHandle p_handle;
TPUDSStatus sts;
p_handle = UDSApi.PUDS_USBBUS1;
sts = UDSApi.Initialize(p_handle, TPUDSBaudrate.PUDS_BAUD_1M, 0, 0, 0);
if(sts == TPUDSStatus.PUDS_ERROR_OK)
{
TextSts.Text = "initilize";
}
}
please let me know what wrong is happening?System.BadImageFormatException
HResult=0x8007000B
Message=An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
Source=PcanIsoTpExample
StackTrace:
at Peak.Can.Uds.UDSApi.Initialize(UInt16 CanChannel, TPUDSBaudrate Baudrate, TPUDSHWType HwType, UInt32 IOPort, UInt16 Interrupt)
at PcanIsoTpExample.udsForm.buttonInit_Click(Object sender, EventArgs e) in F:\Projects\traction_inverter\Pcan\UDS\Mycodes\Delta_UDS_boot\udsForm.cs:line 793
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Re: C# sample code.
Hello,
this error means, that your application is loading the wrong version of the PCAN-UDS.dll. Either your application is configured to work as 64 bit, and the dll you are using is the 32 bit version, or your application is a 32 bit one and the loaded dll the 64 bit version.
Check the build options of your application and be sure that it matches the platform of the dlls you are copying in your output folder. All three have to be the same platform, PCAN-Basic.dll, PCAN-ISO-TP.dll, and PCAN-USB.dll. FYI, the details tab of the file properties of each dll shows also the platform for which they were compiled (right mouse click on the file, then select properties, then select the tab Details)
this error means, that your application is loading the wrong version of the PCAN-UDS.dll. Either your application is configured to work as 64 bit, and the dll you are using is the 32 bit version, or your application is a 32 bit one and the loaded dll the 64 bit version.
Check the build options of your application and be sure that it matches the platform of the dlls you are copying in your output folder. All three have to be the same platform, PCAN-Basic.dll, PCAN-ISO-TP.dll, and PCAN-USB.dll. FYI, the details tab of the file properties of each dll shows also the platform for which they were compiled (right mouse click on the file, then select properties, then select the tab Details)
Best regards,
Keneth
Keneth
Re: C# sample code.
thank you so much for the reply. it works now.
i followed this below url
https://www.peak-system.com/forum/viewt ... 182&t=2912
i followed this below url
https://www.peak-system.com/forum/viewt ... 182&t=2912
-
- Posts: 2
- Joined: Thu 19. Sep 2019, 12:23
Re: C# sample code.
Hi,
I keep on trying to run the c# sample code for PCAN ISO TP, but I always get this error:
Any clue how to solve this? The PCANBasic worked fine for me, but trying to use the CanTpApi is quite challenging even after I pasted both dlls on my System32 and SysWOW64 folder.
I keep on trying to run the c# sample code for PCAN ISO TP, but I always get this error:
Code: Select all
System.BadImageFormatException was unhandled
HResult=-2147024885
Message=An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
Source=PcanIsoTpExample
StackTrace:
at Peak.Can.IsoTp.CanTpApi.GetValue(UInt16 CanChannel, TPCANTPParameter Parameter, StringBuilder StringBuffer, UInt32 BufferLength)
at PcanIsoTpExample.FormMain..ctor() in D:\iTester\TEST_PROGRAMS\Team20\Google_Jolt\PCAN-ISO-TP\PCAN-ISO-TP\Samples\PcanIsoTpExample\C#\FormMain.cs:line 89
at PcanIsoTpExample.Program.Main() in D:\iTester\TEST_PROGRAMS\Team20\Google_Jolt\PCAN-ISO-TP\PCAN-ISO-TP\Samples\PcanIsoTpExample\C#\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Last edited by K.Wagner on Thu 19. Sep 2019, 12:32, edited 1 time in total.
Reason: Code formatting for better reading
Reason: Code formatting for better reading
Re: C# sample code.
Hello,
this is the same problem (mixed up Dlls in Windows\System32 vs Windows\SysWOW64). Follow the instructions in the link mentioned by laktej, to copy all API dlls:
this is the same problem (mixed up Dlls in Windows\System32 vs Windows\SysWOW64). Follow the instructions in the link mentioned by laktej, to copy all API dlls:
laktej wrote:thank you so much for the reply. it works now.
i followed this below url
https://www.peak-system.com/forum/viewt ... 182&t=2912
Best regards,
Keneth
Keneth
-
- Posts: 2
- Joined: Thu 19. Sep 2019, 12:23
Re: C# sample code.
Hi,
Thanks for clarifying the copying procedure of the dlls. I can now initialize smoothly.
Thanks for clarifying the copying procedure of the dlls. I can now initialize smoothly.
