Code covered by the BSD License  

Highlights from
Eurotherm Modbus RS232 Control

5.0

5.0 | 1 rating Rate this file 21 Downloads (last 30 days) File Size: 8.63 KB File ID: #24696

Eurotherm Modbus RS232 Control

by Geoffrey Akien

 

11 Jul 2009

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

| Watch this File

File Information
Description

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).

To use it:

1. Generate the serial object (this one is done on COM7)

serialObject = tempobj(7);

2. Connect to the object:

tempobjconnect(serialObject)

3. Start sending commands!

format:
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 got 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.

MATLAB release MATLAB 7.1.0 (R14SP3)
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  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (6)
01 Sep 2011 Trae

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?

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 ( http://www.mathworks.com/help/techdoc/matlab_prog/f4-70666.html ).

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.

11 Mar 2012 Geoffrey Akien

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

http://www.mathworks.com/help/techdoc/learn_matlab/f4-1931.html#brbss8u-1

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

This does not scale very well at all - so learn to use the timer objects if you intend to build something more complicated:
http://www.mathworks.com/help/techdoc/matlab_prog/f9-38055.html

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!!

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.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
eurotherm Geoffrey Akien 13 Jul 2009 10:51:12
modbus Geoffrey Akien 13 Jul 2009 10:51:12
serial Geoffrey Akien 13 Jul 2009 10:51:12
rs232 Geoffrey Akien 13 Jul 2009 10:51:12
modbus Steven 22 Jan 2010 13:25:55
modbus Peter Zieger 27 Jun 2011 06:12:01

Contact us at files@mathworks.com