Background: Today we have a application that is doing some stuff on a CAN network using a Vector VN1630A dongle. It is working fine as it is on Windows, but the next step for us is to make it run as a Docker image, so we avoid cluttering the host computer with all different Python packages and versions. So as a first step I'm trying to build a Hello world image where I just send out some frames, but I'm running into some problems:
Could not import vxlapi: module 'ctypes' has no attribute 'windll'
Traceback (most recent call last):
File "./server.py", line 53, in <module>
canhandler = CANCommunication()
File "./server.py", line 17, in __init__
bus1 = can.interface.Bus(bustype=bus_type, channel=0, bitrate=250000)
File "/usr/local/lib/python3.8/site-packages/can/interface.py", line 120, in __new__
bus = cls(channel, *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/can/util.py", line 320, in wrapper
return f(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/can/interfaces/vector/canlib.py", line 147, in __init__
raise CanInterfaceNotImplementedError(
can.exceptions.CanInterfaceNotImplementedError: The Vector interface is only supported on Windows, but you are running "posix"
Code I'm using:
import can
import time
class CANCommunication:
"""
main test class for bus and message
"""
def __init__(self, bus_type='vector'):
bus1 = can.interface.Bus(bustype=bus_type, channel=0, bitrate=250000)
bus2 = can.interface.Bus(bustype=bus_type, channel=1, bitrate=250000)
self.bus = {'ch1': bus1, 'ch2': bus2}
self.last_message = None
def send_msg(self,
id=0,
channel='ch1',
message=[1, 2, 3, 4, 5, 6, 7, 8]):
self.last_message = message
msg = can.Message(arbitration_id=id, data=self.last_message, is_extended_id=False)
try:
self.bus[channel].send(msg)
print("Message sent on Channel {}".format(self.bus[channel]))
print(f'Message payload: {message}')
except can.CanError:
print("Message NOT sent")
if __name__ == "__main__":
canhandler = CANCommunication()
while True:
time.sleep(1)
canhandler.send_msg(id=0x8ff)
requirements.txt:
python-can==4.0.0
dockerfile:
# set base image (host OS)
FROM python:3.8
# set the working directory in the container
WORKDIR /code
# copy the dependencies file to the working directory
COPY requirements.txt .
# install dependencies
RUN pip install -r requirements.txt
# copy the content of the local src directory to the working directory
COPY src/ .
# command to run on container start
CMD [ "python", "./server.py" ]
I have no clue on what the next step would be to solve this problem. Is it now possible to do like this with Vector dongles?