View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Eurotherm Modbus RS232 Control

5.0 | 1 rating Rate this file 16 Downloads (last 30 days) File Size: 451 KB File ID: #24696 Version: 1.73

Eurotherm Modbus RS232 Control



11 Jul 2009 (Updated )

Reads and writes information to Eurotherm controllers via Modbus RTU protocols.

| Watch this File

File Information

Reads and writes information to Eurotherm controllers via Modbus RTU protocols. Currently only tested with serial RS232, but should work the same with RS485 if wired correctly. So far only tested with Eurotherm 2416 and 3216 temperature controllers but they all use the same language so it should be widely applicable. The code is well commented so you should be able to modify it easily. I've currently only implemented it using read and write n words (codes 3 and 16), but I'd be happy to implement the other features, such as fast status read etc. (code 7). This code is derived from that in CO2gui, but is implemented using the native MATLAB serial interface only.
To use it:
1. Generate the serial object (this one is done on COM7)
serialObject = tempobj(7);
2. Connect to the object:
3. Start sending commands!
tempobjcomm(commandType, serialObject, deviceAddress, parameterAddress, values)

e.g. to get the set temperature and the current temperature (process variable) in one go, do:

(assuming a default device address of 1)

data = tempobjcomm('read', serialObject, 1, 1, 2);

where data(1) is the current temperature and data(2) is the set temperature. Note that if your temperature controller has decimal places on the front panel, the outputs using 'read' will be scaled. E.g. if 1 decimal place, 24.2 will be returned as 242.

Higher resolution can be obtained using 'readfullres' instead, and also avoids any scaling issues.

To set a new set temperature:

tempobjcomm('write', serialObject, 1, 2, newTemperature)

'writefullres' can be used again if required for higher resolution. The same scaling issues apply as above for reading temperatures.


A deviceAddress can included in the initial serial object (see notes) for persistence' sake.

A host of sample settings files for Eurotherm controllers are included (with a device address of 1, but these can be easily modified).

MATLAB release MATLAB 7.1.0 (R14SP3)
MATLAB Search Path
Other requirements Should be fine on most platforms but there may be issues with byte ordering on non-x86 platforms using readfullres and writefullres - if it doesn't work for you let me know and I can add in a more systematic way on deciding on the byte ordering.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (12)
14 Feb 2017 Geoffrey Akien

Hi Lior,

Updated the package with the missing files - unfortunately I no longer have access to the hardware so am unable to properly test this anymore!

Comment only
13 Feb 2017 Lior Ella

Hello, thanks.

The function isrunning, serialflush, serialwrite, serialread are not included in the package...

Comment only
10 Feb 2017 Geoffrey Akien

Hi Prashant,

That was my fault - I've updated the file with the missing isserial.m now packaged. Hopefully it now works for you.



Comment only
11 Jan 2017 Prashant Sahu

Hi. Thanks for the Eurotherm 2416 MATLAB driver files.

I am running R2015b, and have Data Aquisition Toolbox, as well as Instrument Control Toolbox.
However, when I run the code below:
data = tempobjcomm('read', serialObject, 1, 1, 2)

I get an error:
data = tempobjcomm('read', serialObject, 1, 1, 2)
Undefined function or variable 'isserial'.

Error in tempobjcomm (line 129)
elseif ~isserial(serialObject) || (~isfield(serialObject.UserData, 'realTermHandle') && ~isrunning(serialObject))

Please help me. Where is the file/function "isserial" located ?

Comment only
18 May 2013 Geoffrey Akien

In response to Richard's command (FEX didn't notify me):

1) This is a deliberate feature related to how Modbus works. If you provide a deviceAddress of 0, then this is a broadcast, and modbus devices do not respond to it. So if you wanted to broadcast then then (~~0) would evaluate as true and this section (encapsulating all of the code to do with receiving data) would be run. This does not impact the sending of commands because this is run before the if ~deviceAddress section. I agree that on reflection using a double negative is not the most readable way to have done it, but it does work :).

2. I think what you've done to get round that problem is definitely one way to do it. If all the devices on that two-wire bus are using modbus then you could filter out only the responses from that particular deviceAddress. The whole deviceAddress thing is designed into Modbus exactly for multidrop instruments on the same bus. More info here:

Comment only
24 Sep 2012 Richard

I have this code working with a Eurotherm 3216 over two-wire RS-485. Two things needed to be fixed. Neither has been rigorously debugged but it should at least be a helpful start.

1) The NOT operator (~) needs to be removed from the line "if ~deviceAddress" in tempobjcomm.m". I don't really see how anything could have worked in its original state ...

2) As it is a two-wire bus, Matlab receives all outgoing commands. I circumvented that by adding the line " "fread(serialObject, length(command));" immediately after the line described in 1). There may be a way to do this in the serial-port settings but this way seems to work fine.

Comment only
28 Mar 2012 Geoffrey Akien

I didn't test it on RS422 so you may have to edit the code to make it work for you.

The message is for your information, and not an error. Modbus allows you to send more than one command per communication, and different Eurotherm devices have different maximum amounts of commands. When it connects tempobjconnect tries to ask what device it is so it knows what the maximum is for future communications (it has a list of known devices). In your case it is either an unknown device, or it didn't respond at all to the request.

Comment only
28 Mar 2012 Yu Wang

I'm using the RS422. But it seems like the program is not working for RS422.

when I type "tempobjconnect(serialObject)" in the command window.

It shows this:
"Warning: Could not retrieve Eurotherm controller type - read and write commands will be limited to the minimum allowed for series 2000 controllers for this serialObject."

Thank you sir!!

Comment only
11 Mar 2012 Geoffrey Akien

If you *only* want to measure temperature and nothing else then you could use a forever loop:

for i = 1:100
temperature(i) = tempobjcomm('read', serialObject, 1, 1, 2);

This does not scale very well at all - so learn to use the timer objects if you intend to build something more complicated:

Comment only
11 Mar 2012 Yu Wang

Your entry is really helpful to me.

Now I want read temperature every 5 seconds, in other words, I wanna monitor how the temperature goes up. I'm thinking using a forever loop and put a "timeout" function in it. Could you give a hint on this?

Thank you very much.

01 Sep 2011 Geoffrey Akien

"split" is a subfunction within tempobjcomm for converting 16 bit integers into 8 bit integers in the right format for modbus communication. I wasn't aware that it was also the name for a FileExchange submission (searching for "split" turns up 96 results), and this is only a subfunction, which means that only tempobjcomm can see that it exists, and if split exists as an M-file or whatever in your own path, subfunctions take precedence (within tempobjcomm.m) so that it will not interfere with its operation ( ).

Comment only
01 Sep 2011 Trae

Trae (view profile)

You use 'split' function in your command that you send to your device. 'split' is not part of the standard MATLAB library and your usage doesn't follow the 'split' on FileExchange and it's usage. Can you fill in some information there?

Comment only
20 May 2013 1.2

Cleaned up commenting and some MLint messages (2012b), abstracted some functions for future use, and added capability to specify deviceAddress in tempobj. Also bundled a range of m.files for reading specific parameters.

21 May 2013 1.3

Updated description.

14 Mar 2014 1.4

tempobjcomm.m bugfix: isvaliddeviceaddress is now isvalidtempobjdeviceaddress.

24 Mar 2014 1.5


01 Apr 2014 1.6

Added attribution to CRC append (used to be there, not quite sure where it went).

03 Apr 2014 1.7

Bugfix, now allows parameter addresses of 0 (formally not supported by Eurotherm, but other modbus devices e.g. Omron do use it).

25 Aug 2016 1.71

Bugfix for tempobjcomm allowing NaN values through when using write/writefullres

10 Feb 2017 1.72

Bugfix: added the missing isserial into the package

14 Feb 2017 1.73

Bugfix: added missing files serialread, serialwrite, serialflush, isrunning

Contact us