Modbus response

M

Thread Starter

Michael

Hello everybody. This is my first post.

I've a problem. I need to communicate with a modbus device. i know all the parametrs (function id,address,etc). I put this script in matlab an a receive a message: "The specified amount of data was not returned within the Timeout period.", and the output its empty.
Code:
S = serial('COM1','Baudrate',9600,'DataBits',8,'StopBits',1,'Parity','none','Timeout',10)

fopen(S);

aa='00041036004014E5';

fwrite(S,aa);

output=fread(S);

fclose(S)

Thanks to all
Regards
 
B

Bob Peterson

I am not going to waste time looking up what this message is supposed to do.

Is this ASCII or RTU? It looks like RTU but it appears like a string variable is being used. I don't know anything about matlab so that part of it is foreign to me.

How did you determine the message string?
 
It's RTU. I determined the string with other application , and i had a correct response by the device.

Thanks

Regards
 
B

bob peterson

I think that may be your problem. i think you are sending it an ascii string when it should be hex.

--
Bob
 
C

curt wuollet

That looks like either a complete failure to communicate or possibly you aren't waiting long enough. The port timeout may not be the same as the reply timeout. Try putting a delay between writing and reading. I don't do matlab, but I do know some devices take their time in responding.

Regards
cww
 
I think it would be more precise to say that the "string" should be an array of raw binary bytes. That is often represented on a monitor as escaped hexadecimal, but it's raw binary data.

It is important to make this distinction in this particular case, because while Modbus/RTU uses binary data, Modbus ASCII messages are of course hexadecimal ASCII digits. It's important not to confuse the two.
 
I think that you have the right idea. My problem it's how do i send the values in hex from matlab! I didn't see any information about that.

Thanks for helping me
Regards
 
Ok. Thanks for the sugestion. My question is: in matlab i send that array of bytes in hex type or i convert that array in hex to binary and then, send to the device?!

Thanks

regards
 
But i dont get any error message. My big problem it's how to send data form matlab. I dont know how to put the data to send. If the data type it's hex or convert to binary?!

Thanks
Regards
 
V
Though this thread is very old, but I came across the same problem so writing the solution over here, which I found on web.

Slightly modified version of your program will work.
S = serial('COM1','Baudrate',9600,'DataBits',8,'StopBits',1,'Parity','none ','Timeout',10)

fopen(S);

aa=uint8(hex2dec(['00';'04';'10';'36';'00';'40';'14';'E5']));

fwrite(S,aa);

output=dec2hex(fread(S));

fclose(S);

--
Thanks
 
Top