我想将一些C / C ++代码转换为C#,以便我可以在Linux上使用MONO而不是使用带有* .so的DLLImport。
似乎System.Net.Sockets不支持CAN总线通信,但我不确定这是否意味着我们无法解决它?
// Create a socket with the CAN-protocol.
int _canSocket = socket(PF_CAN, SOCK_RAW, CAN_RAW);
// Get current flags for the socket and add non-blocking to it.
int flags = fcntl(_canSocket, F_GETFL, 0);
fcntl(_canSocket, F_SETFL, flags | O_NONBLOCK);
// Name the interface structure "can0" so that we can get the interface index for the interface named "can0".
struct ifreq ifr;
strcpy(ifr.ifr_name, "can0");
ioctl(_canSocket, SIOCGIFINDEX, &ifr);
// Create a local address for the socket.
struct sockaddr_can addr;
addr.can_family = AF_CAN;
addr.can_ifindex = ifr.ifr_ifindex;
// Bind the socket to the address and we're ready to receive / send information on the CAN-bus.
bind(_canSocket, (struct sockaddr *)&addr, sizeof(addr));
我可以使用此代码获取界面
NetworkInterface can = NetworkInterface.GetAllNetworkInterfaces().First(i => i.Name == "can0");
但是我如何设置一个套接字,如果.NET不支持它就会说“CAN”。我在想,因为在这种情况下CAN实际上是说RAW,只是按正确顺序推送字节的问题!?
或者我误解了一切?
有人可以对此有所了解。