Page 1 of 1

C# sample code.

Posted: Fri 5. Apr 2019, 09:02
by laktej
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.

Posted: Fri 5. Apr 2019, 14:17
by K.Wagner
Hello,

Sorry, we don't have any sample in C# for UDS at the moment. This is still in our todo list.

Re: C# sample code.

Posted: Mon 8. Apr 2019, 13:04
by laktej
Thank you for letting me know.

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";
            }
        }

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)
please let me know what wrong is happening?

Re: C# sample code.

Posted: Mon 8. Apr 2019, 13:23
by K.Wagner
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)

Re: C# sample code.

Posted: Mon 8. Apr 2019, 15:23
by laktej
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

Re: C# sample code.

Posted: Thu 19. Sep 2019, 12:27
by jaclyncruz
Hi,

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: 
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.

Re: C# sample code.

Posted: Thu 19. Sep 2019, 12:35
by K.Wagner
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:
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

Re: C# sample code.

Posted: Fri 20. Sep 2019, 07:52
by jaclyncruz
Hi,
Thanks for clarifying the copying procedure of the dlls. I can now initialize smoothly. :)

Re: C# sample code.

Posted: Fri 20. Sep 2019, 08:38
by K.Wagner
hello,

you're welcome.

Closed.