1
1
SAE J1939 for Python
2
2
====================
3
3
4
- |release | |docs | | build |
4
+ |release | |docs |
5
5
6
- .. |release | image :: https://img.shields.io/pypi/v/j1939.svg
7
- :target: https://pypi.python.org/pypi/j1939/
6
+ .. |release | image :: https://img.shields.io/pypi/v/can- j1939
7
+ :target: https://pypi.python.org/pypi/can- j1939/
8
8
:alt: Latest Version on PyPi
9
9
10
10
.. |docs | image :: https://readthedocs.org/projects/j1939/badge/?version=latest
11
11
:target: https://j1939.readthedocs.io/en/latest/
12
12
:alt: Documentation build Status
13
-
14
- .. |build | image :: https://travis-ci.com/benkfra/j1939.svg?branch=master
15
- :target: https://travis-ci.com/benkfra/j1939/branches
16
- :alt: Travis CI Server for master branch
17
13
18
- A new implementation of the CAN SAE J1939 standard for Python.
19
14
20
- WARNING: Currently this project is in alpha-state! Some of the features are not completely working!
15
+ A implementation of the CAN SAE J1939 standard for Python.
16
+ This implementation was taken from https://github.com/benkfra/j1939, as no
17
+ further development took place.
21
18
22
19
If you experience a problem or think the stack would not behave properly, do
23
20
not hesitate to open a ticket or write an email.
@@ -28,12 +25,14 @@ At the time of writing the supported interfaces are
28
25
29
26
* CAN over Serial
30
27
* CAN over Serial / SLCAN
28
+ * CANalyst-II
31
29
* IXXAT Virtual CAN Interface
32
30
* Kvaser’s CANLIB
33
31
* NEOVI Interface
34
32
* NI-CAN
35
33
* PCAN Basic API
36
34
* Socketcan
35
+ * SYSTEC interface
37
36
* USB2CAN Interface
38
37
* Vector
39
38
* Virtual
@@ -78,26 +77,16 @@ Features
78
77
Installation
79
78
------------
80
79
81
- As soon the package is available in your distro, it's as easy as ::
80
+ Install can-j1939 with pip ::
82
81
83
- $ pip install j1939
84
-
85
- In the meanwhile you can either download the wheel-package and issue the command::
86
-
87
- $ pip install j1939-0.1.0.dev1-py2.py3-none-any.whl
82
+ $ pip install can-j1939
88
83
89
84
or do the trick with::
90
85
91
- $ git clone https://github.com/benkfra/ j1939.git
86
+ $ git clone https://github.com/juergenH87/can- j1939.git
92
87
$ cd j1939
93
88
$ pip install .
94
89
95
- If you want to be able to change the code while using it, clone it then install it in `develop mode `_::
96
-
97
- $ git clone https://github.com/benkfra/j1939.git
98
- $ cd j1939
99
- $ pip install -e .
100
-
101
90
102
91
Quick start
103
92
-----------
@@ -114,11 +103,17 @@ To simply receive all passing (public) messages on the bus you can subscribe to
114
103
logging.getLogger(' j1939' ).setLevel(logging.DEBUG )
115
104
logging.getLogger(' can' ).setLevel(logging.DEBUG )
116
105
117
- def on_message (pgn , data ):
106
+ def on_message (priority , pgn , sa , timestamp , data ):
118
107
""" Receive incoming messages from the bus
119
108
109
+ :param int priority:
110
+ Priority of the message
120
111
:param int pgn:
121
112
Parameter Group Number of the message
113
+ :param int sa:
114
+ Source Address of the message
115
+ :param int timestamp:
116
+ Timestamp of the message
122
117
:param bytearray data:
123
118
Data of the PDU
124
119
"""
@@ -189,18 +184,24 @@ A more sophisticated example in which the CA class was overloaded to include its
189
184
"""
190
185
self ._ecu.remove_timer(self .timer_callback)
191
186
192
- def on_message (self , pgn , data ):
187
+ def on_message (self , priority , pgn , sa , timestamp , data ):
193
188
""" Feed incoming message to this CA.
194
189
(OVERLOADED function)
190
+ :param int priority:
191
+ Priority of the message
195
192
:param int pgn:
196
193
Parameter Group Number of the message
194
+ :param intsa:
195
+ Source Address of the message
196
+ :param int timestamp:
197
+ Timestamp of the message
197
198
:param bytearray data:
198
199
Data of the PDU
199
200
"""
200
201
print (" PGN {} length {} " .format(pgn, len (data)))
201
202
202
203
def timer_callback (self , cookie ):
203
- """ Callback for sending the IEC1 message
204
+ """ Callback for sending messages
204
205
205
206
This callback is registered at the ECU timer event mechanism to be
206
207
executed every 500ms.
@@ -213,24 +214,23 @@ A more sophisticated example in which the CA class was overloaded to include its
213
214
# returning true keeps the timer event active
214
215
return True
215
216
216
- pgn = j1939.ParameterGroupNumber(0 , 0x FE , 0x F6 )
217
- data = [
218
- j1939.ControllerApplication.FieldValue.NOT_AVAILABLE_8 , # Particulate Trap Inlet Pressure (SPN 81)
219
- j1939.ControllerApplication.FieldValue.NOT_AVAILABLE_8 , # Boost Pressure (SPN 102)
220
- j1939.ControllerApplication.FieldValue.NOT_AVAILABLE_8 , # Intake Manifold 1 Temperature (SPN 105)
221
- j1939.ControllerApplication.FieldValue.NOT_AVAILABLE_8 , # Air Inlet Pressure (SPN 106)
222
- j1939.ControllerApplication.FieldValue.NOT_AVAILABLE_8 , # Air Filter 1 Differential Pressure (SPN 107)
223
- j1939.ControllerApplication.FieldValue.NOT_AVAILABLE_16_ARR [0 ], # Exhaust Gas Temperature (SPN 173)
224
- j1939.ControllerApplication.FieldValue.NOT_AVAILABLE_16_ARR [1 ],
225
- j1939.ControllerApplication.FieldValue.NOT_AVAILABLE_8 , # Coolant Filter Differential Pressure (SPN 112)
226
- ]
227
-
228
- # SPN 105, Range -40..+210
229
- # (Offset -40)
230
- receiverTemperature = 30
231
- data[2 ] = receiverTemperature + 40
232
-
233
- self .send_message(6 , pgn.value, data)
217
+ # create data with 8 bytes
218
+ data = [j1939.ControllerApplication.FieldValue.NOT_AVAILABLE_8 ] * 8
219
+
220
+ # sending normal broadcast message
221
+ self .send_pgn(0 , 0x FE , 0x F6 , 6 , data)
222
+
223
+ # sending normal peer-to-peer message, destintion address is 0x04
224
+ self .send_pgn(0 , 0x D0 , 0x 04 , 6 , data)
225
+
226
+ # create data with 100 bytes
227
+ data = [j1939.ControllerApplication.FieldValue.NOT_AVAILABLE_8 ] * 100
228
+
229
+ # sending multipacket message with TP-BAM
230
+ self .send_pgn(0 , 0x FE , 0x F6 , 6 , data)
231
+
232
+ # sending multipacket message with TP-CMDT, destination address is 0x05
233
+ self .send_pgn(0 , 0x D0 , 0x 05 , 6 , data)
234
234
235
235
# returning true keeps the timer event active
236
236
return True
0 commit comments