Closed robogeek closed 7 years ago
I changed typeof data == "object"
to typeof data === "object"
and now get this:
$ sudo node mstemp.js
<< automaton-123 0x[ 01, 04, 00, 01, 00, 01, 60, 0A ]
>> automaton-123 0x[ 01, 04, 02, 0C, 0F, FC, 34 ]
{ slaveId: 1,
crc: 13564,
expected_crc: 13564,
pdu: <Buffer 04 02 0c 0f>,
callback: [Function],
response: { code: 'ReadInputRegisters', data: [ <Buffer 0c 0f> ] } }
This looks like a successful query -- I just need to do a bit of work to decode the value.
The same issue, using ==
instead of ===
, exists in both the Request and Response functions.
There's something missing there. It seems you might have replied in a way the module is not expecting. Do you have a complete example? Also, try the latest version as I fixed some bugs lately.
I changed typeof data == "object" to typeof data === "object" and now get this:
This shouldn't be the reason you now get a valid response.
In your initial comment you had this:
>> automaton-123 0x[ 01, 04, 02, 0C ]
Which is an incomplete response. In your last comment you have the complete one:
>> automaton-123 0x[ 01, 04, 02, 0C, 0F, FC, 34 ]
Your data is there (0x0C, 0x0F
), you can also see it in the object your printed. If that's a complete register and it is (u)int16 big endian, that would be 3087
(or 308,7
or 30,87
or .... if it's not in engineering units). You can read this data using the common Buffer methods.
Please reopen if you find any problems.
I have a USB RS485 adapter connected to a MODBUS temperature sensor. I have a C program using libmodbus successfully reading the device. I want to use Node.js, of course.
I'm getting this error:
The line of code is here in modbus-pdu:
So.. going by the crash, somehow
data
isnull
but by the test it has typeof ==object
and it is not an array.My code is adapted from your examples:
Something I see missing -- not setting the device ID to connect to. The device is at ID=1 and I see in the protocol dump that is the address which was requested.