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

Can readProperty but can't writeProperty #58

Closed
Panibrat opened this issue Sep 3, 2017 · 5 comments
Closed

Can readProperty but can't writeProperty #58

Panibrat opened this issue Sep 3, 2017 · 5 comments

Comments

@Panibrat
Copy link

Panibrat commented Sep 3, 2017

Read function works fine:
Code:
client.readProperty('192.168.0.127', 2, 3000052, 85, null, function(err, value) {
console.log('readPropertyAV: ', value);
});
Console:
readPropertyAV: { len: 14,
objectId: { type: 2, instance: 3000052 },
property: { propertyIdentifier: 85, propertyArrayIndex: 4294967295 },
valueList: [ { len: 5, type: 4, value: 12.6 } ] }

But I can't write the same point:

Code:
client.writeProperty('192.168.0.127', 2, 3000052, 85, 12, [
{type: bacnet.enum.BacnetApplicationTags.BACNET_APPLICATION_TAG_REAL, value: 77}
], function(err, value) {
console.log('writeProperty: ', value);
console.log('writePropertyError: ', err);
});
Console:
D:\PANIBRAT\WEB-2\NodeJS\BACnet\test\node_modules\bacstack\lib\bacnet-asn1.js:496
throw 'Unknown type';
^
Unknown type

What wrong?
Any suggestions?

@fh1ch
Copy link
Owner

fh1ch commented Sep 3, 2017

Hi @Panibrat

Thanks for reporting an issue 👍

The error message is generated by node-bacstack itself if he is not able to encode a write-property telegram.

The root cause for this issue is a breaking change, which is not yet available on NPM but already updated in the documentation (see 35a46ce). Could you therefore change your code as following and retry it:

client.writeProperty('192.168.0.127', 2, 3000052, 85, 12, [
{tag: bacnet.enum.BacnetApplicationTags.BACNET_APPLICATION_TAG_REAL, value: 77}
], function(err, value) { // NOTE: `type` changed to `tag`
console.log('writeProperty: ', value);
console.log('writePropertyError: ', err);
});

This issue/inconsistency should be solved in the upcoming beta.10 release in a couple of days.

Thanks!

@fh1ch fh1ch self-assigned this Sep 3, 2017
@fh1ch fh1ch added this to the 0.0.1-beta.10 milestone Sep 3, 2017
@Panibrat
Copy link
Author

Panibrat commented Sep 3, 2017

Now it works! :)

@Panibrat
Copy link
Author

Panibrat commented Sep 3, 2017

The same issue with Binary Value:
Code:

client.readProperty('192.168.0.222', 5, 11, 104, null, function(err, value) {
    console.log('readPropertyBV: ', value);
});

Console:

readPropertyBV:  { len: 11,
  objectId: { type: 5, instance: 11 },
  property: { propertyIdentifier: 104, propertyArrayIndex: 4294967295 },
  valueList: [ { len: 2, type: 9, value: 1 } ] }

Try to write:
Code:
client.writeProperty('192.168.0.222', 5, 11, 104, 12, [ {tag: bacnet.enum.BacnetApplicationTags.BACNET_APPLICATION_TAG_UNSIGNED_INT, value: 0} ], function(err, value) { // NOTE: typechanged totag console.log('writeProperty: ', value); if(err){ console.log('writePropertyError: ', err); } });
Console:

writeProperty:  undefined
writePropertyError:  Error: BacnetError - Class:2 - Code:9
    at processError (D:\PANIBRAT\WEB-2\NodeJS\BACnet\test\node_modules\bacstack\lib\bacnet-client.js:71:30)
    at handlePdu (D:\PANIBRAT\WEB-2\NodeJS\BACnet\test\node_modules\bacstack\lib\bacnet-client.js:201:9)
    at handleNpdu (D:\PANIBRAT\WEB-2\NodeJS\BACnet\test\node_modules\bacstack\lib\bacnet-client.js:235:5)
    at self.receiveData (D:\PANIBRAT\WEB-2\NodeJS\BACnet\test\node_modules\bacstack\lib\bacnet-client.js:246:7)
    at Socket.<anonymous> (D:\PANIBRAT\WEB-2\NodeJS\BACnet\test\node_modules\bacstack\lib\bacnet-transport.js:13:25)
    at emitTwo (events.js:106:13)
    at Socket.emit (events.js:191:7)
    at UDP.onMessage (dgram.js:548:8)

Please advise!

@fh1ch
Copy link
Owner

fh1ch commented Sep 3, 2017

Hi @Panibrat

The two exceptions BacnetError and BacnetAbort are errors on application level, meaning both node-bacstack and your device are working propperly, but something in your code is wrong. This error can be interpreted by taking a look at BacnetErrorClasses and BacnetErrorCodes, in your case ERROR_CLASS_PROPERTY - ERROR_CODE_INVALID_DATA_TYPE, which means you're trying to write a BACNET property with a wrong data type.

If we compare the console output of your readProperty command (valueList: [ { len: 2, type: 9, value: 1 } ]) with the writeProperty command [ {tag: bacnet.enum.BacnetApplicationTags.BACNET_APPLICATION_TAG_UNSIGNED_INT, value: 0} ], we see that type 9 is actually BACNET_APPLICATION_TAG_ENUMERATED. You therefore have to adapt your code to:

client.writeProperty('192.168.0.222', 5, 11, 104, 12, [ {tag: bacnet.enum.BacnetApplicationTags.BACNET_APPLICATION_TAG_ENUMERATED, value: 0} ], function(err, value) { // NOTE: type changed to correct value
  console.log('writeProperty: ', value); 
  if(err) { console.log('writePropertyError: ', err); } 
});

This should then be accepted by your device.

I will therefore close this issue, feel free to re-open it if something is still not working.

Cheers

@fh1ch fh1ch closed this as completed Sep 3, 2017
@Panibrat
Copy link
Author

Panibrat commented Sep 3, 2017

Everything OK for now!
Thank you!

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

No branches or pull requests

2 participants