-
Notifications
You must be signed in to change notification settings - Fork 86
/
ExampleDeviceSettings.java
87 lines (74 loc) · 3.35 KB
/
ExampleDeviceSettings.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package com.inductiveautomation.ignition.examples.tagdriver.configuration.settings;
import com.inductiveautomation.ignition.gateway.localdb.persistence.Category;
import com.inductiveautomation.ignition.gateway.localdb.persistence.IntField;
import com.inductiveautomation.ignition.gateway.localdb.persistence.LongField;
import com.inductiveautomation.ignition.gateway.localdb.persistence.PersistentRecord;
import com.inductiveautomation.ignition.gateway.localdb.persistence.RecordMeta;
import com.inductiveautomation.ignition.gateway.localdb.persistence.ReferenceField;
import com.inductiveautomation.ignition.gateway.opcua.server.api.DeviceSettingsRecord;
import simpleorm.dataset.SFieldFlags;
/**
* Implements all functionality needed to save a device and its settings in the internal database.
*/
public class ExampleDeviceSettings extends PersistentRecord {
private static final long serialVersionUID = 1L;
/**
* Needed so that the device record can be saved in the internal database.
*/
public static final RecordMeta<ExampleDeviceSettings> META =
new RecordMeta<>(ExampleDeviceSettings.class, "ExampleDeviceSettings");
/**
* Reference to parent DeviceSettingsRecord: holds items like Device Name setting and Enabled setting.
* These fields also appear in the General category section when creating a new driver in the Gateway.
*/
public static final LongField DEVICE_SETTINGS_ID =
new LongField(META, "DeviceSettingsId", SFieldFlags.SPRIMARY_KEY);
/**
* Needed to link a device settings record to the device record in the internal database.
*/
public static final ReferenceField<DeviceSettingsRecord> DEVICE_SETTINGS = new ReferenceField<>(
META,
DeviceSettingsRecord.META,
"DeviceSettings",
DEVICE_SETTINGS_ID
);
@Override
public RecordMeta<?> getMeta() {
return META;
}
/**
* Settings specific to the ExampleDevice; each one must be placed in a Category.
*/
public static final IntField TAG_COUNT = new IntField(META, "TagCount", SFieldFlags.SMANDATORY);
/**
* Categories specific to the ExampleDevice; each category appears below the General category in the Gateway
* when creating a new driver.
* <p>
* In this case, the displayKey below is referencing ExampleDeviceSettings.properties, which should be located
* in the same package as the class file on the file system. You must put the actual category name into this file.
* <p>
* The order number determines the order in which multiple categories are displayed on the page.
*/
public static final Category EXAMPLE_CATEGORY =
new Category("ExampleDeviceSettings.ExampleCategory", 1001).include(TAG_COUNT);
static {
// Hides some generic ReferenceField settings that are not needed in our driver example.
DEVICE_SETTINGS.getFormMeta().setVisible(false);
}
/**
* Get the number of tags that will be exposed to the driver
*
* @return an int with the saved tag count
*/
public int getTagCount() {
return getInt(TAG_COUNT);
}
/**
* Set the number of tags that will be exposed to the driver
*
* @param tagCount an int that represents the tag count to save
*/
public void setTagCount(int tagCount) {
setInt(TAG_COUNT, tagCount);
}
}