---
title: "BidirectionalDCMotor device"
canonical: "https://docs.cuesystem.com/space/CVCDD/446464008/BidirectionalDCMotor%20device"
format: markdown
---
## Overview

This device is intended for control of bidirectional DC motor by two relays. The device driver provides the correct order of the switching of the relay contacts. The driver also provides the timeout for maximum motor runtime.

# BidirectionalDCMotor device properties

|  |  |  |  |  |
| --- | --- | --- | --- | --- |
| Property Name | Data Type | Allowed Values | Default Value | Description |
| ForwardTime | Time Interval | Any | :20.0 | Maximum motor runtime in a forward direction. See Note 1 below. |
| ReverseTime | Time Interval | Any | :20.0 | Maximum motor runtime in reverse direction. See Note 1 below. |
| ReverseDirection | Boolean | True   
False | False | If the motor runs in the opposite direction than you expect, you can use this property to change direction without having to swap wires. |

> 📝 Note 1: This time should be about one or two seconds longer than the maximum real time needed for running the motor from the start position to the end position in the required direction.

## Global Functions

#### RunForward ()

This function switches the relays, so that the motor runs forward. The motor is stopped automatically after

*ForwardTime *is passed. The function does not wait, until the motor reaches the end, it ends immediately.

#### RunReverse ()

This function switches the relays, so that the motor runs reverse. The motor is stopped automatically after

*ReverseTime *is passed. The function does not wait, until the motor reaches the end, it ends immediately.

#### Stop ()

This function switches the relays, so that the motor stops.

#### SetState (newstate As Long) As Boolean

This function switches the relays, so that the motor is set to state given by parameter *newstate*. This parameter can have following values given by named constants build-in the driver:

- STOPPED := 0

- RUNNING_FORWARD := 1

- RUNNING_REVERSE := 2

The motor is stopped automatically after *ForwardTime *or *ReverseTime *is passed, if this is applicable. The function does not wait, until the motor reaches the end, it ends immediately. The function returns *True *on success or *False *if an error occurs (parameter *newstate *is out of range).

Example:

*Motor_Control1.SetState(Motor_Control1.RUNNING_FORWARD)*

#### GetState () As Long

This function returns the current state of the motor. The same values are used as the parameter *newstate *in function *SetState *uses.

#### SetForwardTime(newforwardtime As Time) As Boolean

This function sets the *ForwardTime *to *newforwardtime *value. If the motor is running forward at the time this function is called, the *newforwardtime *is used the next time. The function returns *True *on success or *False *if an error occurs (*newforwardtime *<= :0.0).

#### GetForwardTime() As Time

The function returns current *ForwardTime*.

#### SetReverseTime(newreversetime As Time) As Boolean

This function sets the *ReverseTime *to *newreversetime *value. If the motor is running reverse at the time this function is called, the *newreversetime *is used the next time. The function returns *True *on success or *False *if an error occurs ( *newreversetime *<= :0.0).

#### GetReverseTime() As Time

The function returns current *ReverseTime*.

# Global Events

#### OnStateChanged As Process (newstate As Long)

This event is generated by the driver each time the state of motor is changed. You can use parameter *newstate *to display current motor state on the touch panel. This parameter has the same values as *SetState *function uses.

Example:

*Private Process Motor_Control1_OnStateChanged( newstate As Long ) Link Motor_Control1.OnStateChanged*

*Select newstate*

*Case MyLink.STOPPED*

*Page1.ButtonMotorStop.SetStateDown() *

*Case MyLink.RUNNING_FORWARD*

*Page1.ButtonMotorRunForward.SetStateDown() *

*Case MyLink.RUNNING_REVERSE*

*Page1.ButtonMotorRunReverse.SetStateDown() *

*End Select*

*End Process*

In this example buttons *ButtonMotorStop, ButtonMotorRunForward *and *ButtonMotorRunReverse *are radio type buttons joined together.