modbus rtu communication

68 ビュー (過去 30 日間)
Ajay Soni
Ajay Soni 2011 年 2 月 24 日
コメント済み: Eric Wetjen 2022 年 3 月 15 日
hi, i want to know that is it possible to connect the matlab with a plc using modbus rtu protocol using m-code if yes then how can we do it and how can i get the proper format of the sending data to plc.
please help me.
  2 件のコメント
Eric Wetjen
Eric Wetjen 2017 年 3 月 10 日
MODBUS RTU support was added to Instrument Control Toolbox in R2017a. See this resource page for details.
Eric Wetjen
Eric Wetjen 2022 年 3 月 15 日
In R2022a, Modbus RTU support is now available in the new Industrial Communication Toolbox.

サインインしてコメントする。

回答 (6 件)

Gustavo Dacanal
Gustavo Dacanal 2016 年 9 月 9 日
Here is my code to Modbus RTU DataLogging. It works for me for a heater controller. (model NOVUS N1100). tks -Gustavo
instrreset;
clear all;
close all;
clc;
% remove any remaining serial objects to prevent serial issues
disp('BEGIN PROGRAM');
% Initialize Serial Port Object [s]
s = serial('COM3');
% Specify connection parameters
set(s,'BaudRate',9600,'DataBits',8,'StopBits',1,'Parity','None','Timeout',1);
%Open serial connection
fopen(s);
% Specify Terminator - not used for binary mode (RTU) writing
s.terminator = 'CR/LF';
% Set read mode
set(s,'readasyncmode','continuous');
%Check Open serial connection
s.Status
% RUN and COPY hexadecimal array from SimplyModbus software as example
% SimplyModbus IN [01 03 00 00 00 03 05 CB]
% Observe the output as result from SimplyModbus software
% SimplyModbus OUT [01 03 06 01 90 01 16 00 00 00 81]
request = uint8(hex2dec(['01'; '03'; '00'; '00'; '00'; '03'; '05'; 'CB']));
fwrite(s, request); %start in dec
outdec = fread(s);
outhex = dec2hex(outdec);
outstr = reshape(outhex.',1,[]); %return line string of array hexadecimal e.g.: '010306019000EB0000908D'
SP = hex2dec(outstr(7:10))*0.1 %Variable SetPoint de controler
PV = hex2dec(outstr(11:14))*0.1 %Real temperature PV
MV = hex2dec(outstr(15:18))*0.1 %Variable MV
fclose(s);
delete(s);
clear s
disp('STOP')

Robert Garnett
Robert Garnett 2012 年 12 月 8 日
Hi Steve,
It is possible and easy. The modbus spec is well described on the modbus.org site. I have written C Simulink functions for xPC and also a matlab m code system which runs in an M code gui.
I wrote the code for a power meter and also interfaced it with an ARM 7 processor which simulated a boiler cleaning water cannons. I wrote a interrupt driven program for the ARM which was mostly C with a little bit of assembler. I used the simulink coder (then the RTW) to generate the functionality of the cannons. It worked very well.
The S functions were the hardest to write because I was doing it for the xPC platform which doesn't have a debugger. S functions aren't the easiest things to understand, but once you get to grips with them by looking at the many examples available they are very doable.
I haven't bothered writing a modbus ASCII interface because it is limited and the RTU version with appropriate data formating will handle ascii characters anyway.
I can send you copies if you like.
My email addresses are:
rob.garnett@gdfsuezau.com
rjg@wideband.net.au
Regards
Rob

Steven Edmund
Steven Edmund 2011 年 3 月 7 日
I believe it should be possible to use the RTU protocol, however it will take a significant re-work of the code that you are referencing. modbus.org has some good resources for this, the best I found was this PDF. http://www.modbus.org/docs/PI_MBUS_300.pdf The primary thing with RTU is that you will have to change the coding and byte construction, the framing of the message and the checksum from an LRC to a CRC. Best of luck, -Steve

W.
W. 2012 年 4 月 4 日
Greetings,
I know this is an old post, but if you are still having problems, see my posing File ID: #36022. I used RTU to communicate with a power meter.

Raimundas Steponavicius
Raimundas Steponavicius 2017 年 3 月 3 日
Does anybody know how to implement MODBUS ASCII or RTU communication with MATLAB on the slave computer. I cannot find anything on that ! All cases (posts) that I found are when MATLAB is used as the host/master. Any info or references would be appreciated a lot.

Dogukan Kucukler
Dogukan Kucukler 2018 年 6 月 27 日
Hello friends,
I am currently looking for a solution how to implement slave device to Industrial Control Toolbox on MATLAB by using MODBUS RTU Protocol (RS485).Is there anyone that can help me about it ? Is there any tutorial or pdf to understand these process completely ?
Thank you, DK
  1 件のコメント
Shumin Jiang
Shumin Jiang 2018 年 9 月 30 日
HEY dude, have you done this? now I am in the exactly same situation as you are. Do you have have any tutorial or any other demos to understand this process? Many thanks!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeModbus Communication についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by