How can I connect MATLAB with MODBUS RTU gas stream analyzer?
Mostra commenti meno recenti
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;
Risposte (3)
Walter Roberson
il 19 Feb 2016
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
Matthew Inoue
il 22 Feb 2016
Modificato: Walter Roberson
il 24 Feb 2016
1 Commento
Walter Roberson
il 24 Feb 2016
I will try to return to this when my eyes are more rested.
Camilo Cárdenas
il 16 Mag 2022
0 voti
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!
Categorie
Scopri di più su Modbus Communication in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!