このページは機械翻訳を使用して翻訳されました。最新版の英語を参照するには、ここをクリックします。
MATLAB での J1939 パラメータ グループ入門
この例では、DBC ファイルに保存されている情報を使用して J1939 パラメータ グループを作成および管理する方法を示します。この例では、ファイル J1939.dbc を使用します。J1939 ネットワークにデータを送信する必要がある場合は、この方法でパラメータ グループを作成して使用することをお勧めします。
DBCファイルを開く
定義にアクセスするには、canDatabase を使用して DBC ファイルを開きます。
db = canDatabase("J1939.dbc")db =
Database with properties:
Name: 'J1939'
Path: 'C:\Users\michellw\OneDrive - MathWorks\Documents\MATLAB\Examples\vnt-ex46196345\J1939.dbc'
Nodes: {2×1 cell}
NodeInfo: [2×1 struct]
Messages: {2×1 cell}
MessageInfo: [2×1 struct]
Attributes: {3×1 cell}
AttributeInfo: [3×1 struct]
UserData: []
パラメータグループを作成する
j1939ParameterGroup 関数を使用して、データベース内に含まれる情報を使用してパラメータ グループを作成します。
pg = j1939ParameterGroup(db, "VehicleDataSingle")pg =
ParameterGroup with properties:
Protocol Data Unit Details:
---------------------------
Name: 'VehicleDataSingle'
PGN: 40192
Priority: 6
PDUFormatType: 'Peer-to-Peer (Type 1)'
SourceAddress: 254
DestinationAddress: 254
Data Details:
-------------
Timestamp: 0
Data: [255 255 255 255 255 255 255 255]
Signals: [1×1 struct]
Other Information:
------------------
UserData: []
送信元アドレスと送信先アドレスを設定する
パラメータ グループを完全に定義し、ネットワーク上での送信のロジスティクスを決定するには、送信元アドレスと送信先アドレスを設定します。
pg.SourceAddress = 30
pg =
ParameterGroup with properties:
Protocol Data Unit Details:
---------------------------
Name: 'VehicleDataSingle'
PGN: 40192
Priority: 6
PDUFormatType: 'Peer-to-Peer (Type 1)'
SourceAddress: 30
DestinationAddress: 254
Data Details:
-------------
Timestamp: 0
Data: [255 255 255 255 255 255 255 255]
Signals: [1×1 struct]
Other Information:
------------------
UserData: []
pg.DestinationAddress = 50
pg =
ParameterGroup with properties:
Protocol Data Unit Details:
---------------------------
Name: 'VehicleDataSingle'
PGN: 40192
Priority: 6
PDUFormatType: 'Peer-to-Peer (Type 1)'
SourceAddress: 30
DestinationAddress: 50
Data Details:
-------------
Timestamp: 0
Data: [255 255 255 255 255 255 255 255]
Signals: [1×1 struct]
Other Information:
------------------
UserData: []
優先順位を設定する
トランスミッションをさらにカスタマイズするには、Priority プロパティを設定します。
pg.Priority = 5;
信号情報を見る
このパラメータ グループの信号値を確認するには、Signals プロパティを使用します。これらの信号に直接書き込み、直接読み取りを行うことで、パラメータ グループ内のデータをパックまたはアンパックできます。
pg.Signals
ans = struct with fields:
VehicleSignal4: -1
VehicleSignal3: -1
VehicleSignal2: -1
VehicleSignal1: -1
信号情報の変更
信号に直接書き込んで値を変更し、現在の値を読み取ります。
pg.Signals.VehicleSignal1 = 10
pg =
ParameterGroup with properties:
Protocol Data Unit Details:
---------------------------
Name: 'VehicleDataSingle'
PGN: 40192
Priority: 5
PDUFormatType: 'Peer-to-Peer (Type 1)'
SourceAddress: 30
DestinationAddress: 50
Data Details:
-------------
Timestamp: 0
Data: [10 0 255 255 255 255 255 255]
Signals: [1×1 struct]
Other Information:
------------------
UserData: []
pg.Signals.VehicleSignal2 = 100
pg =
ParameterGroup with properties:
Protocol Data Unit Details:
---------------------------
Name: 'VehicleDataSingle'
PGN: 40192
Priority: 5
PDUFormatType: 'Peer-to-Peer (Type 1)'
SourceAddress: 30
DestinationAddress: 50
Data Details:
-------------
Timestamp: 0
Data: [10 0 100 0 255 255 255 255]
Signals: [1×1 struct]
Other Information:
------------------
UserData: []
pg.Signals.VehicleSignal3 = 1000
pg =
ParameterGroup with properties:
Protocol Data Unit Details:
---------------------------
Name: 'VehicleDataSingle'
PGN: 40192
Priority: 5
PDUFormatType: 'Peer-to-Peer (Type 1)'
SourceAddress: 30
DestinationAddress: 50
Data Details:
-------------
Timestamp: 0
Data: [10 0 100 0 232 3 255 255]
Signals: [1×1 struct]
Other Information:
------------------
UserData: []
pg.Signals.VehicleSignal4 = 10000
pg =
ParameterGroup with properties:
Protocol Data Unit Details:
---------------------------
Name: 'VehicleDataSingle'
PGN: 40192
Priority: 5
PDUFormatType: 'Peer-to-Peer (Type 1)'
SourceAddress: 30
DestinationAddress: 50
Data Details:
-------------
Timestamp: 0
Data: [10 0 100 0 232 3 16 39]
Signals: [1×1 struct]
Other Information:
------------------
UserData: []
pg.Signals
ans = struct with fields:
VehicleSignal4: 10000
VehicleSignal3: 1000
VehicleSignal2: 100
VehicleSignal1: 10
新しい直接データを書き込む
Data プロパティに直接値を書き込むこともできますが、通常は Signals を介して値を設定することが推奨され、好まれます。
pg.Data(1:2) = [50 0]
pg =
ParameterGroup with properties:
Protocol Data Unit Details:
---------------------------
Name: 'VehicleDataSingle'
PGN: 40192
Priority: 5
PDUFormatType: 'Peer-to-Peer (Type 1)'
SourceAddress: 30
DestinationAddress: 50
Data Details:
-------------
Timestamp: 0
Data: [50 0 100 0 232 3 16 39]
Signals: [1×1 struct]
Other Information:
------------------
UserData: []
pg.Signals
ans = struct with fields:
VehicleSignal4: 10000
VehicleSignal3: 1000
VehicleSignal2: 100
VehicleSignal1: 50