Материал из Module developer
Перейти к: навигация, поиск

SubDevice.WriteCharacteristic

RewriteBLE characteristic of a device

Синтаксис

SubDevice.WriteCharacteristic(Characteristic)

Название Пример Описание
Characteristic type: Object
Characteristic object
На выходе

-


Пример

var l_oDevice = module.CreateDevice(IR.DEVICE_BLE_DEVICE, "Kettle", UUID); //Creating a BLE device 
var l_oSubDevice = module.AddSubDevice("SubDevice 1", l_oDevice); //creating a subdevice
l_oSubDevice.DiscoverServices(); //discovering services
module.AddListener(IR.EVENT_SERVICES_DISCOVERED, l_oSubDevice, function(){
 
	var l_aServices = l_oSubDevice.GetServices(); //Getting services 
	for (var i = 0; i < l_aServices.length; i++) {
		var l_aCharacteristics = l_aServices[i].GetCharacteristics();
		for (var j = 0; j < l_aCharacteristics.length; j++) {
			l_aCharacteristics[j].Value = [...]; //writing a new value
			l_oSubDevice.WriteCharacteristic(l_aCharacteristics[j]); //Rewriting a characteristic
		}
	}
});
module.AddListener(IR.EVENT_CHARACTERISTIC_WRITE, l_oSubDevice, function(in_serviceUuid, in_characteristicUuid, in_status){
 
	IR.Log(in_serviceUuid);
    IR.Log(in_characteristicUuid);
	IR.Log(in_status);
 
})

Calls the following event: IR.EVENT_CHARACTERISTIC_WRITE - characteristic is written.
Note:

  • Value property of a characteristic is used as a container on a new value to send to a device ;
  • The format of a byte array to write may differ from the array format that can be received when reading;
  • The characteristic must have the following properties CharacteristicPropertyWrite or similar.

Characteristic properties:

  • UUID - characteristic uuid
  • Permissions - permission level
  • Properties - properties
  • Value - value