Utility Functions
This section will explain the utility functions provided by VergeLink SDK, such as the array filter function.
Filter Function
To prefilter the messages from the subscribeMeasurements function, you can use the VL.filter method. This function has the "messages" as first and the "filterOption" as second.
(Optional) 1.1 Create a filterOption object
The filterOption object is a customizable parameter that allows you to refine the type of data you receive when subscribing to events using the VergeLink SDK. It acts as a rule-set, controlling which pieces of data meet the criteria for inclusion.
The structure of the filterOption object is as follows:
const filterOption = {
filter: {
dataSource: {
protocol: string,
},
data: string[],
},
};
Allowed protocol values
'opcua'
's7'
'modbustcp'
'ifmvse'
'simatic_io_shield'
'ethernetip'
'modbusrtu'
'ifmiolink'
'ftp'
'wincc_miniweb'
'sinumerik_840d'
;
1.2 Creating a Filter Option example
This example shows how you could set up a filter to only receive data from an S7 protocol data source and only for specific data points.
const myFilterOptions = {
filter: {
dataSource: { protocol: 's7' },
data: ['temperature', 'humidity', 'pressure']
}
};
We have provided a global Protocol
object for easy access to protocol values. Simply type Protocol.
followed by the desired protocol key to retrieve its value. For example:
const myFilterOptions = {
filter: {
dataSource: { protocol: Protocol.OPCUA },
data: ['temperature', 'humidity', 'pressure']
}
};
2.1 Use the Filter Function
const myFilterOptions = {
filter: {
dataSource: { protocol: 's7' },
data: ['temperature', 'humidity', 'pressure']
}
};
VL.subscribeMeasurements = (message) => {
const filteredMessage = VL.filter(message, myFilterOptions);
};
2.2 Use the Filter Function directly
VL.subscribeMeasurements = (message) => {
const filteredMessage = VL.filter(message, {
filter: {
dataSource: { protocol: 's7' },
data: ['temperature', 'humidity', 'pressure']
}
});
};
Hovering over a method in the editor will also display its information.