---
title: "Binary protocol"
canonical: "https://docs.cuesystem.com/space/CVCHELP/510591224/Binary%20protocol"
format: markdown
---
> Macro (toc)

---

Binary protocol commands are used when the programmer sends or receives frames in binary formats. The commands below are core functions to construct or parse binary protocols. 

# **Pop - receive functions**

# PopBinDouble

The function removes 4 or 8 bytes from the beginning of *inputdata. *The number of bytes* *depends on the required format. The bytes removed are converted into a float or double number and the value is returned in the *outputvalue* parameter. 

#### Syntax

```visualbasic
Function PopBinDouble(
  ByRef inputdata As ByteString, 
  ByRef outputvalue As Double, 
  Optional encodingformat As Long := _IEE754_64BITS, 
  Optional lsbfirst As Boolean := False) 
As Boolean
```

#### Parameters 

inputdata 

The input stream of bytes with the data of the received packet. 

outputvalue 

The converted value will be returned here. 

encodingformat 

The format of the input data. It can be _IEE754_64BITS or _IEE754_32BITS. 

lsbfirst 

If true, then in the input data is the LSB on the left. If false, then the MSB is on the left. 

#### Return value* *

True if successful, false otherwise. If true, the output value *outputvalue* contains the conversion result and the converted bytes are removed from the input stream *inputdata*. If false, then bytes are not removed from the input stream

The function <u>[GetLastError](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[185](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#185)</u>, <u>[186](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#186)</u>.

# PopBinInteger

The function reads integer number in binary complement from the input stream. The required format *encodingformat* specifies the number of bytes and the result of the operation. The parameter *lsbfirst* specifies the byte order of the input stream. 

#### Syntax

```visualbasic
Function PopBinInteger(
  ByRef inputdata As ByteString, 
  ByRef outputvalue As Long, 
  Optional encodingformat As Long := _SIGNED_INT_32BITS, 
  Optional lsbfirst As Boolean := False) 
As Boolean
```

#### Parameters 

inputdata 

The input stream of bytes with the data of the received packet. 

outputvalue 

The converted value will be returned here. 

encodingformat 

The format of the input data. It can be _SIGNED_INT_8BITS, _UNSIGNED_INT_8BITS, _SIGNED_INT_16BITS, _UNSIGNED_INT_16BITS, _SIGNED_INT_32BITS, _UNSIGNED_INT_32BITS. The last two formats are the same because of the size of the xpl Long number. 

lsbfirst 

If true, then in the input data is the LSB on the left. If false, then the MSB is on the left. 

#### Return value 

True if success, false otherwise. If true, the output value *outputvalue* contains the conversion result and the converted bytes are removed from the input stream *inputdata*. If false, then bytes are not removed from the input stream.

The function <u>[GetLastError](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[185](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#185)</u>, <u>[186](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#186)</u>.

# PopBinData

The function reads specified number of bytes from the input stream.  

#### Syntax

```visualbasic
Function PopBinData(
  ByRef inputdata As ByteString, 
  ByRef outputvalue As ByteString, 
  Optional numofbytes As Long := _LENGTH_UNSPECIFIED) 
As Boolean
```

#### Parameters 

inputdata 

The input stream of bytes with the data of the received packet. 

outputvalue 

The value read will be returned here. 

numofbytes 

The required number of bytes to read. If _LENGTH_UNSPECIFIED, then the declared length of the *outputvalue* parameter will be read. 

#### Return value 

True if success, false otherwise. If true, the output value *outputvalue* contains the result and the bytes read are removed from the input stream *inputdata*. If false, then bytes are not removed from the input stream.

The function <u>[GetLastError](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[185](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#185)</u>, <u>[18](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#187)</u><u>7</u>, <u>[18](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#188)</u><u>8</u>.

# PopBinDelimitedData

The function reads bytes from the input stream until the delimiter found. The delimiter will be removed from the input stream, but it will not be pushed into the output value. 

#### Syntax

```visualbasic
Function PopBinDelimitedData(
  ByRef inputdata As ByteString, 
  ByRef outputvalue As ByteString, 
  delimiter As ByteString) 
As Boolean
```

#### Parameters 

inputdata 

The input stream of bytes with the data of the received packet. 

outputvalue 

The value read will be returned here. 

delimiter 

The delimiter on the right side of the data. 

#### Return value* *

True if success, false otherwise. If true, the output value *outputvalue* contains the result and the bytes read are removed from the input stream *inputdata*. The delimiter found will be removed too. If false, then bytes are not removed from the input stream.

The function <u>[GetLastError](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[185](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#185)</u>, <u>[188](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#188)</u><u>,</u> <u>[189](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#189)</u>.

# PopBinSyncFrame

The function looks for the syncframe pattern (for example heading of the frame) in the inputdata stream. If the suncframe is found, then it will be removed from the inputdata stream. The data preceding the syncframe will be removed too. If  the syncframe is not found, nothing will be removed. 

#### Syntax

```visualbasic
Function PopBinSyncFrame(
  ByRef inputdata As ByteString, 
  syncframe As ByteString) 
As Boolean
```

#### Parameters 

inputdata 

The input stream of bytes with the data of the received packet. 

syncframe 

The pattern to look for in the inputdata stream. 

#### Return value 

True if success, false otherwise. If true, the bytes read are removed from the input stream *inputdata*. If false, then bytes are not removed from the input stream.

The function <u>[GetLastError](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[185](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#185)</u>, <u>[189](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#189)</u>.

# PopBinPattern

The function reads the required pattern from the begining of the inputdata stream. If the pattern is found on the begining of the stream, the pattern will be removed and the function returns true. If the pattern is not found, nothing will be removed and the function returns false. 

#### Syntax

```visualbasic
Function PopBinPattern(
  ByRef inputdata As ByteString, 
  pattern As ByteString) 
As Boolean
```

#### Parameters 

inputdata 

The input stream of bytes with the data of the received packet. 

pattern 

The pattern to look for on the start of the inputdata stream. 

#### Return value 

True if success, false otherwise. If true, the bytes read are removed from the input stream *inputdata. *If false, then bytes are not removed from the input stream.

The function <u>[GetLastError](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[185](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#185)</u>, <u>[189](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#189)</u>.

# **Push - transmit functions**

# PushBinDouble

The function is the mirror function to PopBinDouble. It converts the *inputvalue* parameter to its binary format (according the required encoding format) and appends the result to the end of the *outputdata* stream. The byte order is controlled by the parameter lsbfirst. 

#### Syntax

```visualbasic
Function PushBinDouble(
  ByRef outputdata As ByteString, 
  inputvalue As Double, 
  Optional encodingformat As Long := _IEE754_64BITS, 
  Optional lsbfirst As Boolean := False) 
As Boolean
```

#### Parameters 

outputdata 

The output stream of bytes with the data of the packet to be transmitted. 

inputvalue 

The value to be converted to its binary format. 

encodingformat 

The format controls the conversion. It can be _IEE754_64BITS or _IEE754_32BITS. 

lsbfirst 

If true, data will be appended LSB first. If false, the MSB will be the first byte to append. 

#### Return value 

True if success, false otherwise. If true, the conversion result will be appended to the end of the outputdata. If false, nothing will be appended.

The function <u>[GetLastError](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[186](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#186)</u>, <u>[188](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#188)</u>.

# PushBinInteger

The function is the mirror function to PopBinInteger. It converts the *inputvalue* parameter to its binary format (according the required encoding format) and appends the result to the end of the *outputdata* stream. The byte order is controlled by the parameter lsbfirst. 

#### Syntax

```visualbasic
Function PushBinInteger(
  ByRef outputdata As ByteString, 
  inputvalue As Long, 
  Optional encodingformat As Long := _SIGNED_INT_32BITS, 
  Optional lsbfirst As Boolean := False) 
As Boolean
```

#### Parameters 

outputdata 

The output stream of bytes with the data of the packet to be transmitted. 

inputvalue 

The value to be converted to its binary format. 

encodingformat 

The format controls the conversion. It can be _SIGNED_INT_8BITS, _UNSIGNED_INT_8BITS, _SIGNED_INT_16BITS, _UNSIGNED_INT_16BITS, _SIGNED_INT_32BITS, _UNSIGNED_INT_32BITS. 

lsbfirst 

If true, data will be appended LSB first. If false, the MSB will be the first byte to append. 

#### Return value* *

True if success, false otherwise. If true, the conversion result will be appended to the end of the outputdata. If false, nothing will be appended.

The function <u>[GetLastError](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[186](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#186)</u>, <u>[188](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#188)</u>.

# PushBinData

The function is the mirror function to PopBinData. It appends the *inputvalue* parameter to the end of the *outputdata* stream. 

#### Syntax

```visualbasic
Function PushBinData(
  ByRef outputdata As ByteString, 
  inputvalue As ByteString) 
As Boolean
```

#### Parameters 

outputdata 

The output stream of bytes with the data of the packet to be transmitted. 

inputvalue 

The value to be appended to the *outputdata* stream. 

#### Return value 

True if success, false otherwise. If true, the *inputvalue* will be appended to the end of the outputdata. If false, nothing will be appended.

The function <u>[GetLastError](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[188](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#188)</u>.