MATLAB Answers

0

How can I acquire data from a temperature controller using serial comunication?

Asked by Fabrizio Errichiello on 16 May 2018 at 15:57
Latest activity Commented on by Fabrizio Errichiello on 18 May 2018 at 15:11

Hello everyone. I'm using a temperature controller from Ascon Tecnologic to set and read the temperature of a batch. This controller allows Modbus RTU serial communication RS485 to monitor the temperature via PC and I'm using an RS485 to USB converter from Microflex to convert the signal. My purpose is to write a Matlab program that reads the temperature and gives me a plot T versus time but, although the device is connected, I'm not able to read anything from it so I'd like to know if anyone as any hint on what I should do/verify in order to communicate with the controller. Thanks!

  0 Comments

Sign in to comment.

1 Answer

Answer by Ameer Hamza
on 16 May 2018 at 18:50

Your question description is not enough to reproduce the error or to exactly pinpoint the problem, therefore here are some suggestion:

1) Make sure you are specifying the correct port. You can also use a software such as RealTerm to see if any data is coming over the serial port.

2) Make sure you have specified the appropriate properties to serial() object e.g. Baud rate, Data bits etc.

3) Make sure that you have opened the serial port using fopen().

  5 Comments

I've changed some properties and now fopen doesn't give errors. The problem is I don't understand how i can get the information i want from the device, I found this manual where they explain how the controller comunicate with the master but I'm not sure which arguments I should put in fgets/read functions to get the temperature value ( Meseaured Value PV pag 11 of the manual). I've tried so far to write and read something but i get a "timeout error" which probably means I'm not really connected to the device. Here one of my tries:

s=serial('COM10','BaudRate', 9600 ,'DataBits',8,'Timeout',10)

   Serial Port Object : Serial-COM10
   Communication Settings 
      Port:               COM10
      BaudRate:           9600
      Terminator:         'LF'
   Communication State 
      Status:             closed
      RecordStatus:       off
   Read/Write State  
      TransferStatus:     idle
      BytesAvailable:     0
      ValuesReceived:     0
      ValuesSent:         0

>> fopen(s) >> fgets(s) Warning: Unexpected Warning: A timeout occurred before the Terminator was reached.

ans =

     ''

>> fprintf(s,'Test') >> fgets(s) Warning: Unexpected Warning: A timeout occurred before the Terminator was reached.

ans =

     ''

There can be two possibilities.

1) The serial port is not receiving the data.

2) fget() and fprint() are looking for a terminator character (probably newline). Which your serail port is not sening thus the return empty vector.

After fopen(s), check if any bytes are received by using

s.BytesAvailable

if it is greater then 0 then it means you are receiving the data. Then read the data using fread()

data = fread(s, s.BytesAvailable);

Dear Ameer, some updates:

- after I tried the bytes available command that you suggested I concluded that there wasn't communication cause the answer was zero.

-I found out that in a more recent Matlab release there is a Modbus command that seems to work in fact the communication status is 'open':

m = modbus('serialrtu','COM4','BaudRate', 9600 ,'DataBits',8,'Timeout',10)

m =

Modbus Serial RTU with properties:

             Port: 'COM4'
         BaudRate: 9600
         DataBits: 8
           Parity: 'none'
         StopBits: 1
           Status: 'open'
       NumRetries: 1
          Timeout: 10 (seconds)
        ByteOrder: 'big-endian'
        WordOrder: 'big-endian'
}

I also succeeded in some way to read data using the command

{data = read(m,'holdingregs',002)}

(which gives me the point value) but I can't find any correlation between the address I'm using and the ones in the manual.

In conclusion, I'm now able to read the parameters I wanted but I still can't modify them ( command write() gives me 'wrong address' error). I'm gonna work on what I achieved since now, if you have any other suggestion please let me know. Thanks for the time you spent to help me!

Sign in to comment.


Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today