Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not Reading the Input Registers #2

Open
V3NK47 opened this issue Jan 28, 2018 · 1 comment
Open

Not Reading the Input Registers #2

V3NK47 opened this issue Jan 28, 2018 · 1 comment

Comments

@V3NK47
Copy link

V3NK47 commented Jan 28, 2018

This is the code I'm trying to retrieve data from the register.

require 'PhpSerialModbus.php';

$modbus = new PhpSerialModbus;

$modbus->deviceInit('COM3',19200,'none',8,1,'none');

$modbus->deviceOpen();

$startaddress = 3371;

while($startaddress!=3380)
{
$modbus->debug = true;
echo $hex_addr = strval(dechex($startaddress));
echo "
";
echo $startaddress;
echo "
";
$result=$modbus->sendQuery(11,3,$hex_addr,2);
if(print_r($result)){
echo "
";
$startaddress++;
}

}

Output : I receive null output.

The datasheet of the device I'm trying to connect.

I'm not sure what I'm missing. There are not a lot of community on internet to research about.

Kindly help me through. Thanks in advance.

@menardany
Copy link

$hex_addr = "D2B"
The way sendQuery() parses the data, it sends "D20B" (53771)

will need to add str_pad($hex_addr,4,"0",STR_PAD_LEFT); in your code to make it a 4 character string

or add $registerAddress = str_pad($registerAddress,4,"0",STR_PAD_LEFT); at line 111 of PhpSerialModbus.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants