CANhack.de CAN-Interface RKS+CAN
Diesel technology, engine technology, vehicle diagnostics, repair & maintenance.

C# Beispiel

 
New Topic 🔒 Locked 🔗 🖨 CANhack.de - Index » CANhack.de CAN-USB System: RKS+CAN

Wie wichtig ist euch ein C# API (Programmierschnittstelle) für das CAN-Interface?
Unwichtig, ich programmiere in C oder C++
0%
 0%  [ 0 ]
Ich finde C# super und will so etwas!
100%
 100%  [ 2 ]
Unwichtig, ich nutze nur KCANMonitor.
0%
 0%  [ 0 ]
Total votes : 2

Author Message
CAN-Diagnose
Administrator
Administrator
Avatar-CAN-Diagnose

Joined: 06/07/2011
Posts: 573
Karma: +29 / -0   Thank you, like it!
Location: Ländle



Post05-04-2017, 17:55    Subject: C# Beispiel Translating...

[Translating...]

Noch nicht ganz fertig, prinzipiell geht die C++ DLL zur Nutzung des RKS+CAN Interface so zu nutzen.
Kann man natürlich noch schöner programmieren und es wird auch nur Seriennummer und Versionsinfo vom Interface dargestellt.

Wenn jemand ein C# Crack ist, bitte bezüglich Verbesserungen bei mir melden. Sinnvoll wäre eine eigene C# Datei zum Einbinden, welche die DLL-API kapselt. Alles kein Hexenwerk.

Viele Grüsse, Rainer



Example-Net.rar
 Description:
 Beispiel, verbesserte Versionen siehe im Laufe des Themas.
Beispiel, verbesserte Versionen siehe im Laufe des Themas.
Download
 File name:  Example-Net.rar
 File size:  500.96 KB
 Downloaded:  1108 times
Dipl.-Ing. (FH) Rainer Kaufmann - Embedded Software Freelancer
System RKS+CAN: CANHack.de CAN-Bus Interface


Last edited on 27-04-2018, 13:05, edited 9 times in total.
Back to top Profile PM WWW
dunt
Hacker
Hacker


Joined: 11/06/2015
Posts: 11
Karma: +0 / -0   Thank you, like it!


Premium Support

Post11-06-2017, 12:29    Subject: C# Beispiel Translating...

[Translating...]

Hat diesbezüglich schon jemand etwas? Habe das Projekt mal um Ub erweitert was auch soweit funktioniert hat.

Hänge jetzt aber beim empfange der CAN Messages.

Code:
if(RKSCANRx(&sRx))
- genau hier wie muss ich diese von der DLL übernehmen.

es wird folgender fehler angezeigt "Zusätzliche Informationen: "parameter #1" kann nicht gemarshallt werden: Zeiger dürfen nicht auf gemarshallte Strukturen verweisen. Verwenden Sie stattdessen ByRef.."


evtl. kann mir jemand helfen icon_wink.gif



2017-06-06_RKS CAN USB.rar
 Description:
 C# Beispiel
C# Beispiel
Download
 File name:  2017-06-06_RKS CAN USB.rar
 File size:  988.74 KB
 Downloaded:  1387 times
Back to top Profile PM
CAN-Diagnose
Administrator
Administrator
Avatar-CAN-Diagnose

Joined: 06/07/2011
Posts: 573
Karma: +29 / -0   Thank you, like it!
Location: Ländle



Post16-06-2017, 13:37    Subject: C# Beispiel Translating...

[Translating...]

Gnarf... zum C# Hacker wider Willen. Das Leben könnte so einfach sein, bin dran und bald wieder urlaubsreif.

Hier ist erklärt wie es geht:
http://andyrushton.co.uk/csharp-calling-c-functions-marshalling-structs/
https://docs.microsoft.com/en-us/dotnet/framework/interop/passing-structures

Anstatt jeden einzelnen Funktionsaufruf der C/C++-DLL kompliziert zu verpacken, wäre es wohl sinnvoll die C# RKS-USB Klasse um Wrapperfunktionen zu erweitern, die man stattdessen aufruft. So hat man den Aufwand nur einmal.

Viele Grüsse, Rainer
Dipl.-Ing. (FH) Rainer Kaufmann - Embedded Software Freelancer
System RKS+CAN: CANHack.de CAN-Bus Interface


Last edited on 09-12-2017, 13:17, edited 5 times in total.
Back to top Profile PM WWW
CAN-Diagnose
Administrator
Administrator
Avatar-CAN-Diagnose

Joined: 06/07/2011
Posts: 573
Karma: +29 / -0   Thank you, like it!
Location: Ländle



Post10-01-2018, 20:58    Subject: C# Beispiel Translating...

[Translating...]

Code:
using System.Runtime.InteropServices;

// CAN frame types

// CAN data structure
public class can_data_t
{
  public uint dwID;
  public byte byDLC;
  public byte[] abyData = new byte[8]; // max 8 data bytes
}

// CAN error information structure
public class can_err_t
{
  public byte byError;
}

// CAN information structure
//C++ TO C# CONVERTER TODO TASK: Unions are not supported in C#, but the following union can be replicated with the StructLayout and FieldOffset attributes:
//ORIGINAL LINE: union can_union_t
[StructLayout(LayoutKind.Explicit)]
public struct can_union_t
{
  [FieldOffset(0)]
  public can_data_t sData;
  [FieldOffset(0)]
  public can_err_t sErr;
}

// The final CAN frame structure used for send/receive
public class can_msg_t
{
  public byte byType;
  public uint dwTimeStamp;
  public can_union_t uFrm = new can_union_t();
}


internal static class DefineConstants
{
   public const int FRAME_TYPE_NORMAL = 0x1;
   public const int FRAME_TYPE_RTR = 0x2;
   public const int FRAME_TYPE_NORMAL_EXT = 0x3;
   public const int FRAME_TYPE_RTR_EXT = 0x4;
   public const int FRAME_TYPE_ERR = 0x5;
}
Dipl.-Ing. (FH) Rainer Kaufmann - Embedded Software Freelancer
System RKS+CAN: CANHack.de CAN-Bus Interface
Back to top Profile PM WWW
CAN-Diagnose
Administrator
Administrator
Avatar-CAN-Diagnose

Joined: 06/07/2011
Posts: 573
Karma: +29 / -0   Thank you, like it!
Location: Ländle



Post27-04-2018, 13:15    Subject: C# Beispiel Translating...

[Translating...]

C# Wrapper von Alexander Schmidt auf Github:
https://www.canhack.de/en/viewtopic.php?t=2400
Dipl.-Ing. (FH) Rainer Kaufmann - Embedded Software Freelancer
System RKS+CAN: CANHack.de CAN-Bus Interface
Back to top Profile PM WWW

Ratings - C# Beispiel

Average rating: 0.00 - worst rating: 0 - best rating: 0 - number of ratings: 0 - View ratings

You are not authorized to rate this topic. Danke sagen
New Topic 🔒 Locked 🔗 🖨 CANhack.de - Index » CANhack.de CAN-USB System: RKS+CAN
Jump to:  
You cannot post new topics in this forum.