General Discussions
MODBUS in MATLAB

Hi,

Has anyone have experience on retrieving readings from DataTaker using Matlab?

I have open the ethernet port using the following:
t=tcpip('....IP ADDRESS...',7700)
fopen(t)

I have no idea how to continue when comes to retrieving the readings in MODBUS.

In the DT program, I have defined the following
1MODBUS(AD2,R3:29,=1..10CV) %Address 2, starting address 3000, register 29 to 38 , store in 1...10CV

Please advise.

Thanks.

Hi, Has anyone have experience on retrieving readings from DataTaker using Matlab? I have open the ethernet port using the following: t=tcpip('....IP ADDRESS...',7700) fopen(t) I have no idea how to continue when comes to retrieving the readings in MODBUS. In the DT program, I have defined the following 1MODBUS(AD2,R3:29,=1..10CV) %Address 2, starting address 3000, register 29 to 38 , store in 1...10CV Please advise. Thanks.

Good morning Jianhui,

Sending you Modbus command will cause the DT80 to read the registers and save the values to the channel variables.
The DT80 will then return a number that reflects the status of the read attempt. 0 = Ok etc.

To read the actual values then simply send the commands to read the CV's and the DT80 will return the data.

eg.
1..10CV<Cr> 'Will read cv 1 to 10
or
1CV<Cr>
2CV<Cr>
etc.

Cheers
Roger

Good morning Jianhui, Sending you Modbus command will cause the DT80 to read the registers and save the values to the channel variables. The DT80 will then return a number that reflects the status of the read attempt. 0 = Ok etc. To read the actual values then simply send the commands to read the CV&#039;s and the DT80 will return the data. eg. 1..10CV&lt;Cr&gt; &#039;Will read cv 1 to 10 or 1CV&lt;Cr&gt; 2CV&lt;Cr&gt; etc. Cheers Roger

Dear Roger,

I've tried reading the packets by using MATLAB, but it returns zero matrix and it says "A timeout occurred before the terminator was reached"

I have to try several attempts and only once in a while, I am able to see a return value "1MODBUS 10". Do you have any idea what commands should I be sending to DT82I to read the data?

Please advise.

Thanks.

Dear Roger, I&#039;ve tried reading the packets by using MATLAB, but it returns zero matrix and it says &quot;A timeout occurred before the terminator was reached&quot; I have to try several attempts and only once in a while, I am able to see a return value &quot;1MODBUS 10&quot;. Do you have any idea what commands should I be sending to DT82I to read the data? Please advise. Thanks.

Good morning Jianhui,

The commands are listed above.
The error E10 is a syntax error, please check the commands are entered correctly (Note <Cr> is a carriage return enter key)

Cheers

Roger

Good morning Jianhui, The commands are listed above. The error E10 is a syntax error, please check the commands are entered correctly (Note &lt;Cr&gt; is a carriage return enter key) Cheers Roger

Dear Roger,

Good Morning, the problem is solved. I can read DataTaker from MATLAB.

Thanks for the effort. smile

Appreciate that.

Regards,
Jianhui

Dear Roger, Good Morning, the problem is solved. I can read DataTaker from MATLAB. Thanks for the effort. :smile: Appreciate that. Regards, Jianhui

Dear Roger,

As per request,

The MATLAB Code is written as follows:

t = tcpip('169.254.60.152',7700); %Change IP address accordingly
%Connect the TCPIP object to the host.
fopen(t);
%Write to the host and read from the host.
t.terminator='CR/LF';
%Greet the device
fwrite(t, 'hello');
%Read from DataTaker
A=fscanf(t, '%s')
end
%Disconnect the TCPIP object from the host and stop the echo server.
fclose(t)

Regards,
Jianhui

Dear Roger, As per request, The MATLAB Code is written as follows: t = tcpip(&#039;169.254.60.152&#039;,7700); %Change IP address accordingly %Connect the TCPIP object to the host. fopen(t); %Write to the host and read from the host. t.terminator=&#039;CR/LF&#039;; %Greet the device fwrite(t, &#039;hello&#039;); %Read from DataTaker A=fscanf(t, &#039;%s&#039;) end %Disconnect the TCPIP object from the host and stop the echo server. fclose(t) Regards, Jianhui
72
5
2
live preview
enter atleast 10 characters
WARNING: You mentioned %MENTIONS%, but they cannot see this message and will not be notified
Saving...
Saved
With selected deselect posts show selected posts
All posts under this topic will be deleted ?
Pending draft ... Click to resume editing
Discard draft