How can I connect MATLAB with MODBUS RTU gas stream analyzer?
3 次查看(过去 30 天)
显示 更早的评论
Goal: To send the following message to a MODBUS RTU-enabled X-stream gas analyzer using 16-bit low bit first, using a test message and response to retrieve device serial number (Address 3141-3147, String Output) over RS-232 serial communication port, 16-bit (Low-byte, High-byte) format. The device is an Emerson Process Management XSTREAM X2GP Gas Stream Analyzer that accepts RTU format and either 32-bit Daniel mode or 16-big High or Low (is this same as high byte first or low byte first?).
[Address, Mode, 2xAddress, 2xCoilCount , 2x CRC]
Where:
[ 01, 03, ‘3141’,’0007’,CRC]
Should I use:
[01 03 49 65 00 07 90 224]
Or
[01 03 31 41 00 07 210 20] ?
Since for the test file, I want to retrieve the serial number, I expect 7 coils to be returned (3141-3147) correct?
,
Then fwrite(s,messagevector) does not find a response from fread(s, 2) within specified timeout. The following connection setup was used in MATLAB to conform with device settings:
opt.serial=’COM1’;
s=serial(opt.serial);
set(s,’BaudRate’,9600,’DataBits’,8,’StopBits’,1,’Parity’,’even’,Timeout’,3);
set(s,’readasyncmode’,’continous’);
3141 is given as the address code per documentation
Append CRC Code:
N = length(message);
crc = hex2dec('ffff');
polynomial = hex2dec('a001');
for i = 1:N
crc = bitxor(crc,message(i));
for j = 1:8
if bitand(crc,1)
crc = bitshift(crc,-1);
crc = bitxor(crc,polynomial);
else
crc = bitshift(crc,-1);
end
end
end
lowByte = bitand(crc,hex2dec('ff'));
highByte = bitshift(bitand(crc,hex2dec('ff00')),-8);
amsg = message;
amsg(N+1) = lowByte;
amsg(N+2) = highByte;
0 个评论
回答(3 个)
Walter Roberson
2016-2-19
My suspicion would be that you should use
[01, 03, typecast(uint16([3141, 7]),'uint8')]
followed by the CRC.
This relies upon the fact that in all currently supported MATLAB versions, the architecture is Intel x86 or x64, both of which are "little-endian", which is the same order that the destination wants.
In decimal this would be [01, 03, 69, 12, 07, 00] followed by the CRC
0 个评论
Camilo Cárdenas
2022-5-16
Hello,
I am trying to carry out a such communication with a x-stream XEGK-Analyzator.
Therefore I would like to ask you if you have reached it and if you ca share some tips and or codes?
regards!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Modbus Communication 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!