Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Sending HEX command to serial device (via RS-485)
Replies: 2   Last Post: Nov 27, 2013 12:37 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Vahe

Posts: 2
Registered: 11/25/13
Sending HEX command to serial device (via RS-485)
Posted: Nov 25, 2013 4:06 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hello,

I'm trying to send hex command to serial device. Connection type is RS-485. The command has the following format:

STX ':'

ADR 1 '0'
ADR 2 '1'

CMD 1 '0'
CMD 0 '3'

starting '4'
addres '7 '
of date '0'
'0'

Number '0'
of data '0'
(in words) '0'
'2'

LRC CHK 1 'B'
LRC CHK 0 '3'

END 1 CR
END 0 LF

The code I'm using is following
st = serial('COM5', 'Baudrate', 9600, 'Databits',7, 'Stopbits', 1, 'Parity', 'Even','Terminator', 'CR/LF')
fopen(st);
data = ['0';'1';'0';'3';'4';'7';'0';'0';'0';'0';'0';'2';'B';'3'];
data_dec = hex2dec(data);
fwrite(st,data_dec,'uint8');
data_dec = fread(st)
fclose(st);

but I got the answer

Warning: Unsuccessful read: The specified amount of data was not returned within the Timeout
period.

data_dec =

Empty matrix: 1-by-0

Can some one advice possible solutions to this problem?

Thanks, in advance.



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.