Modbus communication data problems

조회 수: 6 (최근 30일)
Sneha Cheruvattath
Sneha Cheruvattath 2017년 7월 5일
편집: Walter Roberson 2017년 7월 17일
I am working on using modbus TCP to remotely read data. Each data value is obtained in the form of 4 registers. However, while running the code, instead of getting one value in the 4 registers, I seem to be getting the value of the next data as well. How can I rectify this? I am including a copy of the code:
test=read(t,'inputregs',1,4,'uint32')
test =
1.0e+09 *
1.0454 0 1.0446 0
>> test1=uint32(test)
test1 =
1×4 uint32 row vector
1045374906 0 1044558328 0
>> typecast(test1,'single')
ans =
1×4 single row vector
0.2023 0 0.1901 0

답변 (1개)

Nagarjuna Manchineni
Nagarjuna Manchineni 2017년 7월 17일
편집: Walter Roberson 2017년 7월 17일
The command
test=read(t,'inputregs',1,4,'uint32')
reads 4 registers starting from 1 in 'uint32' format. I believe you would like to read a single register value in 'single' precision. For achieving the same you can use the following command:
test = read(t, 'inputregs', 1, 1, 'single'); % If you want to read second register value update the third argument (address from where the value is being read) with value 2
Refer the following link for more information:
I hope this helps!

카테고리

Help CenterFile Exchange에서 Modbus Communication에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by