from can import Listener
import socket

class UDPSender(Listener):
    dataConvert = {"0x600": {"String":"RPM:",
                             "Slot":0,
                             "Conversion":1},
                   "0x601": {"String":"OIL:",
                             "Slot":2,
                             "Conversion":(1/81.92)}}
    
    def __init__(self, IP="10.0.0.4", PORT=5555):
        self.ip = IP
        self.port = PORT
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        
    def on_message_received(self, msg):
        udpMessage = self.can_to_udp_message(msg)
        if udpMessage:
            self.sock.sendto(udpMessage.encode(), (self.ip, self.port))
        
    def can_to_udp_message(self, msg):
        hexId = msg.arbritation_id
        if self.dataConvert.get(hexId):
            dataId = self.dataConvert[hexId]["String"]
            dataSlot = self.dataConvert[hexId]["Slot"]
            dataConversion = self.dataConvert[hexID]["Conversion"]
            data = ( (msg.data[dataSlot] << 8) + msg.data[dataSlot + 1] ) * dataConversion
            udpMessage = dataId + data
            return udpMessage
        else:
            return None
        
    def __del__(self):
        self.sock.close()

from can import Listener
from socket import socket

class UDPSender(Listener):
    dataConvert = {"0x600": {"String":"RPM:",
                             "Slot":0,
                             "Conversion":1},
                   "0x601": {"String":"OIL:",
                             "Slot":2,
                             "Conversion":(1/81.92)}}
    
    def __init__(self, IP="10.0.0.4", PORT=5555):
        self.ip = IP
        self.port = PORT
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        
    def on_message_received(self, msg):
        udpMessage = self.can_to_udp_message(msg)
        if udpMessage:
            self.sock.sendto(udpMessage.encode(), (self.ip, self.port))
        
    def can_to_udp_message(self, msg):
        hexId = msg.arbritation_id
        if self.dataConvert.get(hexId):
            dataId = self.dataConvert[hexId]["String"]
            dataSlot = self.dataConvert[hexId]["Slot"]
            dataConversion = self.dataConvert[hexID]["Conversion"]
            data = ( (msg.data[dataSlot] << 8) + msg.data[dataSlot + 1] ) * dataConversion
            udpMessage = dataId + data
            return udpMessage
        else:
            return None
        
    def __del__(self):
        self.sock.close()

Change of import of libraries.
Change of import of libraries.

Tried to fix issue displayed below.

[root@alarm BeagleDash]# python3.3 CANtoUDP.py
Traceback (most recent call last):
File "CANtoUDP.py", line 10, in <module>
listeners = [csv, UDPSender()]
TypeError: 'module' object is not callable
Exception AttributeError: "'super' object has no attribute '__del__'" in
<bound method CSVWriter.__del__ of <can.CAN.CSVWriter object at
0xb6867730>> ignored
