Using Pyuavcan on Windows

Hello, is it at the moment possible to use Pyuavcan library on a Windows PC? I have tried to install it and found out, that usage of python-can library is not implemented yet. I have some CAN adapters (Kvaser and Peak) but probably can’t use them to connect to a pyuavcan script. Is there any solution for Windows users?

2 Likes

Yes, but not with CAN. The library is continuously tested against Windows and is known to work there. The problem is that the only CAN bus media backend implementation we have at the moment – that is, SocketCAN – works only under GNU/Linux.

We need someone to help us get it working on Windows by writing the glue logic between the PyUAVCAN transport model and the Python-CAN library. Can you lend us a hand here?

(we chatted with you on Habr didn’t we?)

Hello, yes, we had a conversation on Habr.
I will try to add python-can support but I’m not a big Python expert, so it needs time to understand the structure.

1 Like

Ref: Pyuavcan 1.1.0.dev1, Windows 10, Python 3.7.7, CAN/python-can.

Hello again, I have started to implement python-can support, it seems to throw no errors now, but I have some other issues.

I would like to get some kind of communication and used some commands from the manual, but it didn’t work. I am pretty sure it’s not a problem of the transport layer, because the error message gives some info about the problem:

uvc call 42 --tr="CAN(can.media.pythoncan.PythonCANMedia('pcan','PCAN_USBBUS1',8),10)" uavcan.node.GetInfo.1.0 '{}'

Error: ValueError: dictionary update sequence element #0 has length 1; 2 is required

Probably something is wrong with the structure of the command, but I have just copied it from the manual and don’t see any errors there.

Could you please give me some explanation about the error?

Errors from the string-to-object conversion logic are always fun. The readability issue is tracked at https://github.com/UAVCAN/pyuavcan/issues/116.

I can’t reproduce your problem if I just copy-paste the string from your post replacing the transport specification with vcan0:

uvc call 42 --tr="CAN(can.media.socketcan.SocketCANMedia('vcan0',8),10)" uavcan.node.GetInfo.1.0 '{}'
The request has timed out after 1.0 seconds

But if I replace the ASCII quotes with fancy Unicode quotes, I get your error:

uvc call 42 --tr="CAN(can.media.socketcan.SocketCANMedia('vcan0',8),10)" uavcan.node.GetInfo.1.0 ”{}”
Error: ValueError: dictionary update sequence element #0 has length 1; 2 is required

No, these are definitely not Unicode symbols, I have checked the string with a Hex-editor, the code for this quote is #27.

Here is a screenshot with the message:

Please ignore messages about CAN filters, I haven’t implemented them yet.

Can you please run it with -vv (V for Verbose, twice for extra) like uvc -vv pub ... so that we could see the stack trace?

Yes, sure, here is the log:
error_log.txt (8.8 KB)

Sorry, it was actually the screenshot for the second problem from another thread, here is the screenshot with dictionary parameters:

And the corresponding log:
error_log2.txt (9.2 KB)

Okay this is getting interesting. Let’s see if you can reproduce the problem in isolation from your custom media driver because I can’t. Please run the following and make sure you don’t get any errors (you will get warned about a node-ID conflict but that’s because the node sees its own reflection in the Loopback transport):

[pavel@deep-thought demo]$ uvc call 42 --tr="Loopback(123)" uavcan.node.GetInfo.1.0 '{}'
2020-08-06 13:53:49 90329 WARNING  pyuavcan.application.heartbeat_publisher: NODE-ID CONFLICT: There is another node on the network that uses the same node-ID 123. Its latest heartbeat is uavcan.node.Heartbeat.1.0(uptime=0, health=0, mode=0, vendor_specific_status_code=90329) with transfer metadata TransferFrom(timestamp=Timestamp(system_ns=1596711229162567409, monotonic_ns=232711769237893), priority=<Priority.NOMINAL: 4>, transfer_id=0, fragmented_payload=[<memory at 0x7fe88aaccb80>], source_node_id=123)
The request has timed out after 1.0 seconds

Edit: also please try moving the --tr=... argument towards the end of the string.

Still the same message:

uvc call 42 uavcan.node.GetInfo.1.0 '{}' --tr="Loopback(123)"
Error: ValueError: dictionary update sequence element #0 has length 1; 2 is required

Maybe you could try double quotes or launch a debugger to see the context where the error occurs? This is not reproducible on my end.

1 Like

Thank you, double quotes have solved the problem! But why?

No idea. Why don’t we just blame Microsoft for this?

2 Likes

Hello, I could finally finish a raw python-can implementation that seems to work.
I can see packets with my CAN adapter and don’t find any problems there, but simple GetInfo request stays unanswered for the pyuavcan. Could you please take a look at the following log?

uvc call 42 --tr=“CAN(can.media.pythoncan.PythonCANMedia(‘pcan’,‘PCAN_USBBUS1’,8),10)” uavcan.node.GetInfo.1.0 “{}”

Set filters: [{‘can_id’: 33555712, ‘can_mask’: 41959296, ‘extended’: True}, {‘can_id’: 10, ‘can_mask’: 8388735, ‘extended’: True}, {‘can_id’: 8213760, ‘can_mask’: 50331520, ‘extended’: True}]
TX: Timestamp: 0.000000 ID: 107d550a X DLC: 8 00 00 00 00 00 7f 02 e0
TX: Timestamp: 0.000000 ID: 136b950a X DLC: 1 e2
RX: Timestamp: 23127.501678 ID: 126b852a X DLC: 8 01 00 01 00 00 01 00 a2
RX: Timestamp: 23127.501971 ID: 126b852a X DLC: 8 00 00 00 00 00 00 00 02
RX: Timestamp: 23127.502262 ID: 126b852a X DLC: 8 01 00 00 00 00 00 00 22
RX: Timestamp: 23127.502555 ID: 126b852a X DLC: 8 00 00 00 00 00 00 00 02
RX: Timestamp: 23127.502830 ID: 126b852a X DLC: 8 00 00 0a 76 6f 6c 7a 22
RX: Timestamp: 23127.503105 ID: 126b852a X DLC: 8 2d 73 65 72 76 6f 00 02
RX: Timestamp: 23127.503297 ID: 126b852a X DLC: 3 8b fc 62
RX: Timestamp: 23128.051938 ID: 107d552a X DLC: 8 48 a6 0c 00 00 00 00 fc
TX: Timestamp: 0.000000 ID: 107d550a X DLC: 8 01 00 00 00 00 7f 02 e1
The request has timed out after 1.0 seconds
Set filters: [{‘can_id’: 33555712, ‘can_mask’: 41959296, ‘extended’: True}, {‘can_id’: 10, ‘can_mask’: 8388735, ‘extended’: True}]
RX: Timestamp: 23129.054787 ID: 107d552a X DLC: 8 30 aa 0c 00 00 00 00 fd

I guess that fields software_image_crc and certificate_of_authenticity are optional and must not be added to an answer?
Thank you in advance!

I can’t immediately see any issues here. How the answering node (whose node-ID is 10 here) is implemented? Have you tried looking at verbose logs (-vv)?

Correct.

May be I understand the purpose of the pyuavcan wrong, but I thought it has to implement the node with node-ID 10.
I mean I have started pyuavcan with CAN as transport layer, pcan as CAN adapter and 10 as node-ID with this parameter:

–tr=“CAN(can.media.pythoncan.PythonCANMedia(‘pcan’,‘PCAN_USBBUS1’,8),10)”

And then I try to get info from a node with node-ID 42 using:

call 42 uavcan.node.GetInfo.1.0 “{}”

Or is this suppose wrong? Does pyuavcan act as a real UAVCAN node?

I have some more info now. I have installed the library on a Linux PC and it is works there as I supposed. uvc works as a UAVCAN-node, sends/receives messages and displays them!
So there is probably a problem with Windows support. I am pretty sure the part I wrote sends and receives messages via python-can (I have shown the logs here and I see these messages with a sniffer), so the problem is on the side of handling messages that were received.
I will check it once more and write here again.

Yes. Sorry, you are correct here. I meant to ask about node 42, not 10. Is it the demo app from the documentation?

Please do. Also don’t forget to check verbose logs (-vv or just set the environment variable PYUAVCAN_LOGLEVEL=debug).

Hello again, I have had some issues with timestamps, now it seems to be everything ok. But I have no messages from pyuavcan script anyway. Linux version works good, but Windows version with python-can doesn’t work properly, I think the problem is not the python-can support from my side. Here is the log for the Win version and my UAVCAN node running with ID 42 (I just print TimestampedDataFrame):

uvc sub uavcan.node.Heartbeat.1.0 --tr=“CAN(can.media.pythoncan.PythonCANMedia(‘pcan’,‘PCAN_USBBUS1’,8),10)”
2020-08-11T10:48:59.383532/12295.546000000: 0x107d552a 80 41 bb 00 00 00 00 ef ‘.A…’
2020-08-11T10:49:00.386530/12296.546000000: 0x107d552a 68 45 bb 00 00 00 00 f0 ‘hE…’
2020-08-11T10:49:01.389677/12297.546000000: 0x107d552a 50 49 bb 00 00 00 00 f1 ‘PI…’

and so on.
And here is the Linux log for the same node:

uvc sub uavcan.node.Heartbeat.1.0 --tr=“CAN(can.media.socketcan.SocketCANMedia(‘can0’,8),111)”
2020-08-11T10:23:57.996792/9309.854723523: 0x107d552a d8 69 a4 00 00 00 00 f6 ‘.i…’

32085:
uptime: 10775000
health: 0
mode: 0
vendor_specific_status_code: 0

2020-08-11T10:23:58.999695/9310.857592968: 0x107d552a c0 6d a4 00 00 00 00 f7 ‘.m…’

32085:
uptime: 10776000
health: 0
mode: 0
vendor_specific_status_code: 0

2020-08-11T10:24:00.002547/9311.860905444: 0x107d552a a8 71 a4 00 00 00 00 f8 ‘.q…’

32085:
uptime: 10777000
health: 0
mode: 0
vendor_specific_status_code: 0

As you see, same data, similar timestamps, but I get the info I need.
What could be a reason for such a behavior?