Another question… Since I am new to the company and nobody ever has experience about python or the device, I need help here. I am trying to read canbus data using Connectport X5, I find the J1939 sample code here: http://www.digi.com/wiki/developer/index.php/J1939_Sample. When I run the program, the screen can print “====PDU received====” and the opt in the program. However, I cannot get the attribute of one message by using “print opt + " = " + str(PDU.getattribute(opt))”. Does anyone has this kind of problem?
What error message are you seeing?
Actually there is no error message, just cannot print the attribute’s value
Unfortunately, I don’t have an X5 or J1939 device.
I also don’t understand your comment “there is no error message, just cannot print the attribute’s value”. Do you mean your fingers just can’t press the right keys or something
The Wiki page you referecnce is called “code samples”, so it might not even run as-is.
If you are new to Python and the X5 (and J1939/Vehcile Bus) then diving into this is like trying to learn to ski on a triple-diamond death ski-run! You may want to try simplier things first, get a feel for running Python on the X5 first.
I can run “hello world” on the device. And I need to change my word, actually there is no error message. However, I think there is an exception when the program runs at the code “print opt + " = " + str(PDU.getattribute(opt))”. I even cannot find the documentation about what PDU class is…
That was one of my concerns as well!
Even though I have 9 years of Python experience, I didn’t see where PDU comes from either. Also, the callback_1 may be called by a seperate task/thread, so one should do some form of context protection. Plus the callbak_1 seems to send, not receive/parse.
I assume PDU is supposed to be of class J1939_PDU - see http://www.digi.com/wiki/developer/index.php/Module:digicanbus
It should be.When I delete the words “+ " = " + str(PDU.getattribute(opt))” in the sentence, it can prints ‘DA’, ‘DP’, ‘EDP’, ‘GE’, ‘PF’, ‘PGN’, ‘PS’, ‘SA’, ‘priority’, ‘payload’. So the device should receive the message I send to. However, I cannot print the attribute of these parameters. I really need to see if the message is sent correctly to the device.
Everyone I’ve asked says the sample code appears to be wrong. But no one’s stepped to offer a solution.
You could call Digi tech support and try to get a ‘case’ opened to have someone fix it. Otherwise it might take a while to get a fix.