1

Issue unbinding a driver from a unit with JavaScript API

Тема: Issue unbinding a driver from a unit with JavaScript API

Hi Wialon,

I am using the JavaScript API to bind drivers to units without any issues. I'm using the bindDriverToUnit() method.  In the documentation for this method (https://sdk.wialon.com/api/index.html#w … hod_public), in the parameters section, it says that for the "driver" parameter, it "can be null to unbind driver from unit." But when I pass null as the argument for this driver parameter I get an error back from Wialon about invalid input.

I am using the below code (which works fine for binding a driver to an empty or an already bound unit):

// attempt to bind the driver to a unit
pcbWialonResource.bindDriverToUnit(wialonDriverObjectToBind, wialonUnitObjectToBindDriverTo, 0, shouldBind,
                                        qx.lang.Function.bind(function(pcbWialonResource, wialonDriverObjectToBind, code, result) {
2

Issue unbinding a driver from a unit with JavaScript API

Re: Issue unbinding a driver from a unit with JavaScript API

I'm wondering if this has something to do with the data flags that need to be set for units/resources. Right now I have set:

var unitFlags = wialon.util.Number.or(wialon.item.Item.dataFlag.base, wialon.item.Item.dataFlag.customFields,
                            wialon.item.Item.dataFlag.adminFields, wialon.item.Unit.dataFlag.lastMessage, wialon.item.Unit.dataFlag.driverCode);
                        var resourceFlags = wialon.util.Number.or(wialon.item.Item.dataFlag.base, wialon.item.Resource.dataFlag.drivers);
3

Issue unbinding a driver from a unit with JavaScript API

Re: Issue unbinding a driver from a unit with JavaScript API

Hello!

benjamindpinder пишет:

Hi Wialon,

I am using the JavaScript API to bind drivers to units without any issues. I'm using the bindDriverToUnit() method.  In the documentation for this method (https://sdk.wialon.com/api/index.html#w … hod_public), in the parameters section, it says that for the "driver" parameter, it "can be null to unbind driver from unit." But when I pass null as the argument for this driver parameter I get an error back from Wialon about invalid input.

I am using the below code (which works fine for binding a driver to an empty or an already bound unit):

// attempt to bind the driver to a unit
pcbWialonResource.bindDriverToUnit(wialonDriverObjectToBind, wialonUnitObjectToBindDriverTo, 0, shouldBind,
                                        qx.lang.Function.bind(function(pcbWialonResource, wialonDriverObjectToBind, code, result) {

it seems like some driver hasn't been assigned to unit (bound), if you don't bind driver before, you cannot set up null as driver parameter. Please look at example here how function bindDriverToUnit()  works  Bind driver to unit
Also you can see required fata flags and library which needs to upload to session

Diana Cheley
Wialon Hosting Expert
Gurtam
4

Issue unbinding a driver from a unit with JavaScript API

Re: Issue unbinding a driver from a unit with JavaScript API

Hi Gurtam,

So the units are bound (at least they show as being bound in the user interface in our account at hosting.wialon.com). I am able to unbind them via the interface at hosting.wialon.com. I'm not sure if this maybe has something to do with the data flags I have set. Because in doing more testing, I cannot use the function wialon.item.Unit.getDriverCode() either. When I call that function, I get a null returned, even when there is a driver bound to the calling unit.

I know how to use the bindDriverToUnit() function in order to unbind a known driver from a unit (by passing false for the mode parameter). But I need to be able to unbind an unknown driver from a unit, and I was hoping to do so by using null to unbind the driver as in the documentation.

Can you show me the code for unbinding a driver from a unit, while passing null for the driver parameter?

5

Issue unbinding a driver from a unit with JavaScript API

Re: Issue unbinding a driver from a unit with JavaScript API

benjamindpinder пишет:

Hi Wialon,

I am using the JavaScript API to bind drivers to units without any issues. I'm using the bindDriverToUnit() method.  In the documentation for this method (https://sdk.wialon.com/api/index.html#w … hod_public), in the parameters section, it says that for the "driver" parameter, it "can be null to unbind driver from unit." But when I pass null as the argument for this driver parameter I get an error back from Wialon about invalid input.

I am using the below code (which works fine for binding a driver to an empty or an already bound unit):

// attempt to bind the driver to a unit
pcbWialonResource.bindDriverToUnit(wialonDriverObjectToBind, wialonUnitObjectToBindDriverTo, 0, shouldBind,
                                        qx.lang.Function.bind(function(pcbWialonResource, wialonDriverObjectToBind, code, result) {

There is no possibility to unbind current driver from unit. JS SDK API reference has a typo.

6

Issue unbinding a driver from a unit with JavaScript API

Re: Issue unbinding a driver from a unit with JavaScript API

Currently to unbind all bound drivers from unit you need to know their resourceId/driverId. They can be fetched by core/search_items with following params:

{
  "spec": {
    "itemsType": "avl_resource",
    "propName": "",
    "propValueMask": "",
    "sortType": "",
    "propType": "list"
  },
  "force": 1,
  "flags": 257,
  "from": 0,
  "to": 100000
}

You'll get all resources with drivers:

"items": [{
    "nm": "wialon",
    "cls": 3,
    "id": 6,
    "mu": 0,
    "drvrs": {
        "8": {
            "id": 8,
            "n": "Enoch Root",
            "c": "",
            "jp": {},
            "ej": {},
            "pwd": "",
            "ds": "",
            "p": "+375297000000",
            "r": 0,
            "f": 1,
            "ck": 0,
            "ct": 1525351891,
            "mt": 1525351891,
            "bu": 1037,
            "pu": 0,
            "bt": 1541160281,
            "bs": 0,
            "pos": {
                "y": 0,
                "x": 0
            }
        },
    },
    "drvrsmax": -1,
    "uacl": -1
}]

Then for all of them you need to find drivers, that have bu == unitId.