---
title: "BACnet Gateway"
canonical: "https://docs.cuesystem.com/space/CVCDD/572686399/BACnet%20Gateway"
format: markdown
---
> Macro (toc)

---

# Introduction

Ver 0.01

The driver works both as a BACnetIP Server and Client.

The Server part is presented by the BACnet device with its own Device ID. It includes 10 objects of the type  AnalogValue. All these objects can be accessed from external BACnet clients both for reading and writing.

The Client part has functions providing access to objects of remote BACnet servers. 

# Properties

|  |  |  |  |
| --- | --- | --- | --- |
| Property name | Data type | Default value | Description |
| Me |
| UDP Port | Long | 47808 | UDP port used for BacnetIP |
| Device Instance Number | Long | 7000 | BACnet Device ID |
| Device Name | Text | “CD” | BACnet Device Name |
| Broadcast | Boolean | Local | - 'Global' := True, means Broadcast IP: 255.255.255.255
- 'Local' := False", means Broadcast for Local network  
based on IP and Mask   
calculated: (myIP BitOr (Not myMask)) |
| MyObjects |
| AnalogValueX Name | Text | “AnalogValueX” | - Name for AnalogValue object with objectID:X
- X= 1 .. 10 |
| Default Device |
| IP Address | Text | “192.168.1.100” | Default Device IP |
| UDP Port | Long | 47808 | Default Device UDP port |

Note: The BACnet Default Device parameters are used if not other values are specified by each BACnet client command

# BACnet device

The BACnet server Device object is supporting the following BACnet properties:

Note that these values are available from BACnet only for reading**  **

- OBJECT_NAME - value defined by Property "Device Name" (Property group “Me“)
- MODEL_NAME - "10 AnalogValue Registers"
- APPLICATION_SOFTWARE_VERSION - "1.0"
- PROTOCOL_REVISION - “7“
- OBJECT_IDENTIFIER - defined by OBJECT_TYPE_DEVICE and "Device Instance Number" property.

Each instance of this driver is presented as a BACnet device defined by properties in the group “Me“ above. The device is equipped with 10 AnalogValue objects with Instance numbers 1-10. These objects' properties “PRESENT_VALUE“ are accessible by the following commands:

### GetMyAnalogValue

#### Syntax

```
GetMyAnalogValue (instance as Long) As Double
```

### SetMyAnalogValue

#### Syntax

```
SetMyAnalogValue(instance As Long, newvalue  As Double)
```


When any of these Analog Value objects “PRESENT_VALUE“ properties are written from any external BACnet client then the **event **is generated:

### OnAnalogValuePresentValueWrite

#### Syntax

```
Global OnAnalogValuePresentValueWrite As Process(newvalue As Double, instance As Long)
```

Where the “newvalue” is the latest value written into  “PRESENT_VALUE“ property of my AnalogValue object identified by the Instance number stored in the “instance” parameter.

> 📝 Note at this place that all these included  Analog Values objects are “WRITABLE” (not “COMANDABLE”) BACnet object types. That means that message with any priority can rewrite current value in “PRESENT_VALUE“ property.
> 📝 
> 📝 (while “COMMANDABLE” objects “PRESENT_VALUE“ property can be rewritten only by the same or higher priority comparing with message which had written its current value)


The following properties of AnalogValue objects are supported

- OBJECT_NAME - default:“AnalogValue1“-“ AnalogValue10“ – see [https://cue.atlassian.net/wiki/spaces/CVCDD/pages/572686399/BACnet+Gateway#Properties](https://cue.atlassian.net/wiki/spaces/CVCDD/pages/572686399/BACnet+Gateway#Properties)
- MODEL_NAME - “av“
- APPLICATION_SOFTWARE_VERSION - "1.0"
- PROTOCOL_REVISION - “7“
- PRESENT_VALUE - Double

# Client functions

Read&Write “PRESENT_VALUE“ property to/from BACnet objects:

- Analog Input, Analog Output, Analog Value
- Binary Input, Binary Output, Binary Value
- Multistate Input, Multistate Output, Multistate Value

## Parameters

**iInstanceNumber**

Instance number of particular BACnet object

Optional **tDeviceIP**

optional parameter - IP of target BACnet Device 

**-** when not specified then values set in PropertyGroup **:"Default Device"** are used

Optional **iDeviceUDPport**

optional parameter -  UDP port of target BACnet Device used for BACnetIP

**-** when not specified then values set in PropertyGroup **:"Default Device"** are used

 **iPropertyNewValue**

the new value to be written into property “PRESENT_VALUE” -  this param datatype is according to the object type

 Optional** iPriority**

optional parameter - BACnet message priority which provides this write operation. Param valid range is 1-16 (where value 1 is highest” Manual Life Safety”…) – if not in range or not specified then the message will be sent as a message without priority.

> 📝 Note that in following list there are present also functions for writing the Input object types – these functions are possible to use but some devices would respond to them only if in service mode! – Depends on real implementation in particular product.

## Functions for Analog Input-Output-Value objects

### AnalogInputPresentValueRead

#### Syntax

```visualbasic
AnalogInputPresentValueRead(
  iInstanceNumber As Long, 
  Optional tDeviceIP As Text :="" ,
  Optional iDeviceUDPport As Long := 0) 
As Double
```

### AnalogOutputPresentValueRead

#### Syntax

```visualbasic
AnalogOutputPresentValueRead(
  iInstanceNumber As Long, 
  Optional tDeviceIP As Text :="",
  Optional iDeviceUDPport As Long := 0) 
As Double
```

### AnalogValuePresentValueRead

#### Syntax

```visualbasic
AnalogValuePresentValueRead(
  iInstanceNumber As Long, 
  Optional tDeviceIP As Text :="",
  Optional iDeviceUDPport As Long := 0)
As Double
```

### AnalogInputPresentValueWrite

#### Syntax

```visualbasic
AnalogInputPresentValueWrite(
  iInstanceNumber As Long, 
  iPropertyNewValue As Double,
  Optional tDeviceIP As Text :="", 
  Optional iDeviceUDPport As Long := 0,
  Optional iPriority As Long := -1)
```

### AnalogOutputPresentValueWrite

#### Syntax

```visualbasic
AnalogOutputPresentValueWrite(
  iInstanceNumber As Long, 
  iPropertyNewValue As Double,
  Optional tDeviceIP As Text :="", 
  Optional iDeviceUDPport As Long := 0,
  Optional iPriority As Long := -1)
```

### AnalogValuePresentValueWrite

#### Syntax

```visualbasic
AnalogValuePresentValueWrite(
  iInstanceNumber As Long,
  iPropertyNewValue As Double,
  Optional tDeviceIP As Text :="",
  Optional iDeviceUDPport As Long := 0,
  Optional iPriority As Long := -1)
```

---

## Functions for Binary Input-Output-Value objects

### BinaryInputPresentValueRead

#### Syntax

```visualbasic
BinaryInputPresentValueRead(
  iInstanceNumber As Long, 
  Optional tDeviceIP As Text :="",
  Optional iDeviceUDPport As Long := 0) 
As Long
```

### BinaryOutputPresentValueRead

#### Syntax

```visualbasic
BinaryOutputPresentValueRead(
  iInstanceNumber As Long, 
  Optional tDeviceIP As Text :="",
  Optional iDeviceUDPport As Long := 0) 
As Long
```

### BinaryValuePresentValueRead

#### Syntax

```visualbasic
BinaryValuePresentValueRead(
  iInstanceNumber As Long, 
  Optional tDeviceIP As Text :="",
  Optional iDeviceUDPport As Long := 0) 
As Long
```

### BinaryInputPresentValueWrite

#### Syntax

```visualbasic
BinaryInputPresentValueWrite(
  iInstanceNumber As Long, 
  iPropertyNewValue As Long,
  Optional tDeviceIP As Text :="", 
  Optional iDeviceUDPport As Long := 0,
  Optional iPriority As Long := -1)
```

### BinaryOutputPresentValueWrite

#### Syntax

```visualbasic
BinaryOutputPresentValueWrite(
  iInstanceNumber As Long, 
  iPropertyNewValue As Long,
  Optional tDeviceIP As Text :="", 
  Optional iDeviceUDPport As Long := 0,
  Optional iPriority As Long := -1)
```

### BinaryValuePresentValueWrite

#### Syntax

```visualbasic
BinaryValuePresentValueWrite(
  iInstanceNumber As Long, 
  iPropertyNewValue As Long,
  Optional tDeviceIP As Text :="" , 
  Optional iDeviceUDPport As Long := 0,
  Optional iPriority As Long := -1)
```

## Functions for Multistate Input-Output-Value objects

### MultistateInputPresentValueRead

#### Syntax

```visualbasic
MultistateInputPresentValueRead(
  iInstanceNumber As Long, 
  Optional tDeviceIP As Text :="",
  Optional iDeviceUDPport As Long := 0) 
As Long
```

### MultistateOutputPresentValueRead

#### Syntax

```visualbasic
MultistateOutputPresentValueRead(
  iInstanceNumber As Long, 
  Optional tDeviceIP As Text :="",
  Optional iDeviceUDPport As Long := 0) 
As Long
```

### MultistateValuePresentValueRead

#### Syntax

```visualbasic
MultistateValuePresentValueRead(
  iInstanceNumber As Long, 
  Optional tDeviceIP As Text :="",
  Optional iDeviceUDPport As Long := 0)
As Long
```

### MultistateInputPresentValueWrite

#### Syntax

```visualbasic
MultistateInputPresentValueWrite(
  iInstanceNumber As Long, 
  iPropertyNewValue As Long,
  Optional tDeviceIP As Text :="", 
  Optional iDeviceUDPport As Long := 0,
  Optional iPriority As Long := -1)
```

### MultistateOutputPresentValueWrite

#### Syntax

```visualbasic
MultistateOutputPresentValueWrite(
  iInstanceNumber As Long, 
  iPropertyNewValue As Long,
  Optional tDeviceIP As Text :="", 
  Optional iDeviceUDPport As Long := 0,
  Optional iPriority As Long := -1)
```

### MultistateValuePresentValueWrite

#### Syntax

```visualbasic
MultistateValuePresentValueWrite(
  iInstanceNumber As Long, 
  iPropertyNewValue As Long,
  Optional tDeviceIP As Text :="", 
  Optional iDeviceUDPport As Long := 0,
  Optional iPriority As Long := -1)
```