hardbyte / hardbyte/python-can

USB2CAN Korlan on Windows

Đang mở
#964 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
1.6k
Fork
697
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

I am trying to use an 8devices Korlan usb2can adapter in Windows 10 64bit. The adapter is using the WinUSB driver and sucessfully captures CAN traffic inside wireshark, so I assume it to be functional.

Then I made a simple test in Python 3.8, to open the bus as instance of Usb2canBus. Initially this did not work because find_serial_devices() inside serial_selector.py tries to match with the legacy usb2can devices that had a serial number starting with "ED".
I modified the code as such:

```
def find_serial_devices(serial_matcher="ED"):
"""
...
"""
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(".", "root\cimv2")
items = objSWbemServices.ExecQuery("SELECT * FROM Win32_USBControllerDevice")
ids1 = (item.Dependent for item in items if "VID_0483&PID_1234" in item.Dependent)
ids = (d.strip('"')[-8:] for d in ids1)
return [id for id in ids]
```

Now the call to CanalOpen returned 0 until I swapped .dll's from the 8devices website. The tools/doc page at the 8devices wiki is a bit of a mess and very confusing. Some files are for the older usb2can. Eventually a non-zero Canal dll handle was returned with the dll from https://www.8devices.com/media/products/usb2can_korlan/downloads/usb2can_winusb.zip

However, now the code is running without errors, but I do not see any traffic on the bus while sending.
When I put the device in loopback mode and send, python-can receives a message with length of 0.

```
import os
import ctypes
from can.message import Message
import time

if __name__ == '__main__':
check = ctypes.WinDLL(r'./usb2can.dll')
from can.interfaces.usb2can.usb2canInterface import Usb2canBus

bus = Usb2canBus(bitrate=500000, flags=0x00000001)#Loopback
# bus = Usb2canBus(bitrate=500000, flags=0x00000008)

data = bytearray([1,2,3,4,5,6,7,8])
msg = Message(arbitration_id=1872, is_extended_id=False, data=data, extended_id=False)

while True:
bus.send(msg)
print(msg)
rcv_msg = bus.recv(timeout=1000)
if rcv_msg is not None:
print(rcv_msg)
time.sleep(1)
```
Output of this code is:
```
Timestamp: 0.000000 ID: 0750 S DLC: 8 01 02 03 04 05 06 07 08
Timestamp: 0.000000 ID: 0000 S DLC: 0
Timestamp: 0.000000 ID: 0750 S DLC: 8 01 02 03 04 05 06 07 08
Timestamp: 0.000000 ID: 0000 S DLC: 0
```

At this point I'm out of ideas on how to get the Korlan usb2can to work on Windows, but I'm willing to try any suggestions :)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.