I am trying to figure out how to use a SocketCAN connection in Java.
As stated in the SocketCAN doc, SocketCAN is designed very similar to TCP and UDP Sockets. It also provides a network interface for each connected CAN bus. These are also listed for example by ifconfig
:
can0: flags=193<UP,RUNNING,NOARP> mtu 16
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 1000 (UNSPEC)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
But the can0
interface is not listed by NetworkInterface.networkInterfaces()
in Java for example. I guess, because it's not a TCP/UDP interface with an IP. CAN is a different network, without addresses.
I would like give it a try by using the Unix Domain Socket support in Java. But I couldn't find out the file path of the CAN interface to build a UnixDomainSocketAddress
.
I know there are tools that route the SocketCAN to a network connection, like socketcand. And also I found libs that make SocketCAN usage possible via JNI or JNA. But I would like to give it a try without extra JNI/JNA implementations and extra tools.