Avatar

Code samples for Add CustomDevice

0

Are there any .Net code samples for adding a CustonDevice or CustomVehicleDevice? Starting to create a third-party integration.

Adam Wilson

Please sign in to leave a comment.

3 comments

0
Avatar

Thank you for the reply.

I was able to Provision a third party device and get a serial number returned. Then I was able to add a Device using that example. However, I wanted to write the VIN along with other properties. I found that it needs to be a CustomDevice to have this property to set. However when I try to do it as a 'CustomDevice' it gives an error. This is the code I am using:

Device newDevice = Device.FromSerialNumber(vehicle.SerialNumber);

newDevice.PopulateDefaults();
newDevice.Name = vehicle.Description;
newDevice.Groups = vehicleGroups;
newDevice.WorkTime = new WorkTimeStandardHours();

 

But if I change to:

CustomDevice newDevice = CustomDevice.FromSerialNumber(vehicle.SerialNumber);

 

It throws an error that I "cannot convert type Device to type CustomDevice". The object that the serial number comes from is just an object built from a record in my database. So I am not sure why it's trying to convert.

Adam Wilson 0 votes
0
Avatar

Hi Adam,

You should be able to do something like:

Device newDevice = Device.FromSerialNumber(vehicle.SerialNumber);

...

if (newDevice is CustomVehicleDevice newCustomVehicleDevice) {

    newCustomVehicleDevice.VehicleIdentificationNumber = "vin";

}

The Using GO Devices section in the SDK illustrates device hierarchy. 

Steve Hansen 0 votes