我正在尝试访问运行Android的系统上的CAN端口。
在Java JNI中,我可以打电话:
int s=socket(29 /*PF_CAN*/, 3 /*SOCK_RAW*/ , 1 /*CAN_RAW*/);
一切正常。但我需要让它在Unity中运行,C#。
在C#中,我尝试:
Socket sock = new Socket((AddressFamily)29 , (SockType)3 , (ProtocolType)1);
并获取SocketException
ADB:
01-01 04:48:38.183 1568-1587/com.xxx.xxx W/mono: System.Net.Sockets.AddressFamily has unknown value 0x1d
01-01 04:48:38.253 1568-1587/com.xxx.xxx I/Unity: SocketException: An address incompatible with the requested protocol was used
at System.Net.Sockets.Socket..ctor (AddressFamily family, SocketType type, ProtocolType proto) [0x00000] in <filename unknown>:0
at CANPortScript.Start () [0x00000] in <filename unknown>:0
我发现29,3和1的等效枚举值是有效的Socket()参数,但我仍然得到了Exception。 29是枚举AddressFamily.Max。
任何强制它的方法即使它不能识别29作为有效的AddressFamily?或者,有没有更好的方法来访问它?