I'm using dotnet core on a Linux platform and would like to set up communication with a CAN device. SocketCan is available on the Linux platform, but is there a way to use the UnixDomainSocketEndPoint and Socket classes in dotnet core to access SocketCan directly?
When trying to create an instance of Socket with this test program on Linux (Debian9) environment:
using System;
using System.Net.Sockets;
namespace SocketScan
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Scan for available ProtocolType values");
ScanForProtocolTypes(SocketType.Stream);
ScanForProtocolTypes(SocketType.Raw);
}
private static void ScanForProtocolTypes(SocketType socketType)
{
for (var i = 0; i < 1000000; i++)
{
try
{
var socket = new Socket(AddressFamily.Unix, socketType, (ProtocolType)i);
Console.WriteLine($"Succeeded creating socket with SocketType={socketType} ProtocolType={((ProtocolType)i)}");
}
catch (SocketException)
{ }
}
}
}
}
The output is:
$ dotnet run SocketTest.csproj
Scan for available ProtocolType values
Succeeded creating socket with SocketType=Stream ProtocolType=Unspecified
Succeeded creating socket with SocketType=Stream ProtocolType=Icmp
Succeeded creating socket with SocketType=Raw ProtocolType=Unspecified
Succeeded creating socket with SocketType=Raw ProtocolType=Icmp
What values for the enums AdressFamily, SocketType and ProtocolType will match a SocketCan socket?