Modbus over TCP/IP to read registers from a PLC
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello everyone, I am trying to communicate with a PLC using modbus over TCP/IP. I would like to read and write on some registers and I hope someone can suggest something I could be missing.
From the command prompt in Windows7 I can ping the address and it responds. From the tmtoool in MATLAB, I can communicate with the device and it is usually connected. However, I have a Register Map (excel file) provided that says what is the register and the values it holds.
The following script is my session log. The PLC address is 192.168.225.12 and the port is 502. The IP address for the PC I am using is 192.168.225.15 (I am not sure if this is required or not). If I try specifying the communication from MATLAB as Master, it takes forever and never connects. SO I assume that the PLC is the master.
Do you have any suggestions or ideas? Do you have another script that can implement this function? Steven Edmund has done the same thing over RS232 ASCII communication as in this link
https://www.mathworks.com/matlabcentral/fileexchange/27815-modbus-rs232-ascii-communication-functions
%% Instrument Connection % Find a tcpip object. obj1 = instrfind('Type', 'tcpip', 'RemoteHost', '192.168.225.12', 'RemotePort', 502, 'Tag', '');
% Create the tcpip object if it does not exist % otherwise use the object that was found. if isempty(obj1) obj1 = tcpip('192.168.225.12', 502); else fclose(obj1); obj1 = obj1(1); end % Connect to instrument object, obj1.
fopen(obj1); data1 = query(obj1, '*IDN?'); %% Check if there is anything!
%% Disconnect and Clean Up
% Disconnect from instrument object, obj1. fclose(obj1);
%% Instrument Configuration and Control % Configure instrument object, obj1. set(obj1, 'Name', 'TCPIP-192.168.225.12'); set(obj1, 'RemoteHost', '192.168.225.12'); delete(obj1); %% End of script
Thank you
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Modbus Communication finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!