# IOpcStateMachine Members

> Reference: Defines an interface which provides the state of a state machine and methods to change it (see OpcFiniteStateMachineNode).

<dl class="api-definition">
<dt>Type</dt>
<dd><a href="./">IOpcStateMachine</a></dd>
<dt>Namespace</dt>
<dd><a href="../namespaces/opc.uafx">Opc.UaFx</a></dd>
<dt>Assembly</dt>
<dd>Opc.UaFx.Advanced.dll</dd>
<dt>Package</dt>
<dd>Opc.UaFx.Advanced v2.59.0</dd>
</dl>

## Properties

### CurrentState

Gets or sets a human readable name for the current state of the state machine.

<div class="api-signature" data-lang="csharp">

```csharp
OpcText CurrentState { get; set; }
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Property CurrentState As OpcText
```

</div>

**Property value**

[OpcText](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opctext/)

A human readable name for the current state which may not be suitable for use in application control logic.

### LastTransition

Gets or sets a human readable name for the last transition which occurred in the state machine.

<div class="api-signature" data-lang="csharp">

```csharp
OpcText LastTransition { get; set; }
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Property LastTransition As OpcText
```

</div>

**Property value**

[OpcText](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opctext/)

A human readable name for the last transition which may not be suitable for use in application control logic.

### Name

Gets the name of the state machine.

<div class="api-signature" data-lang="csharp">

```csharp
OpcName Name { get; }
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
ReadOnly Property Name As OpcName
```

</div>

**Property value**

[OpcName](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcname/)

The [OpcName](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcname/) of the state machine node.

### SupportsCurrentState

Gets a value indicating whether the state machine supports changes of its current state.

<div class="api-signature" data-lang="csharp">

```csharp
bool SupportsCurrentState { get; }
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
ReadOnly Property SupportsCurrentState As Boolean
```

</div>

**Property value**

[Boolean](https://learn.microsoft.com/dotnet/api/system.boolean)

The value true if the state machine supports changes of its current state; otherwise the value false.

**Remarks**

If the value is false, [CanChangeStateTo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.iopcstatemachine/members#canchangestateto-opc-uafx-opccontext-system-object) returns false and [ChangeStateTo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.iopcstatemachine/members#changestateto) does not change the state.

## Methods

### CanChangeStateTo

<span class="api-meta">2 overloads</span>

| Overload | Description |
|---|---|
| [CanChangeStateTo(OpcContext, object)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.iopcstatemachine/members#canchangestateto-opc-uafx-opccontext-system-object) | Determines whether the current state can be changed to the `newState` specified. |
| [CanChangeStateTo(OpcContext, object, object)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.iopcstatemachine/members#canchangestateto-opc-uafx-opccontext-system-object-system-object) | Determines whether the `oldState` can be changed to the `newState` specified. |

#### CanChangeStateTo(OpcContext, object)

Determines whether the current state can be changed to the `newState` specified.

<div class="api-signature" data-lang="csharp">

```csharp
bool CanChangeStateTo(OpcContext context, object newState)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Function CanChangeStateTo(context As OpcContext, newState As Object) As Boolean
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `context` | [OpcContext](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opccontext/) | The [OpcContext](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opccontext/) to use to determine. |
| `newState` | [Object](https://learn.microsoft.com/dotnet/api/system.object) | The state number or the enumeration member of the state to change to. |

**Returns**

[Boolean](https://learn.microsoft.com/dotnet/api/system.boolean)

The value true if the `newState` is a known state other than the current state and a transition leads from the current state to it, or if neither a current state nor a last transition is set; otherwise the value false.

**Exceptions**

| Exception | Condition |
|---|---|
| [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception) | The `context` or `newState` is a null reference (Nothing in Visual Basic). |

#### CanChangeStateTo(OpcContext, object, object)

Determines whether the `oldState` can be changed to the `newState` specified.

<div class="api-signature" data-lang="csharp">

```csharp
bool CanChangeStateTo(OpcContext context, object oldState, object newState)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Function CanChangeStateTo(
    context As OpcContext,
    oldState As Object,
    newState As Object) As Boolean
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `context` | [OpcContext](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opccontext/) | The [OpcContext](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opccontext/) to use to determine. |
| `oldState` | [Object](https://learn.microsoft.com/dotnet/api/system.object) | The state number or the enumeration member of the state to change from. |
| `newState` | [Object](https://learn.microsoft.com/dotnet/api/system.object) | The state number or the enumeration member of the state to change to. |

**Returns**

[Boolean](https://learn.microsoft.com/dotnet/api/system.boolean)

The value true if both states are known and different and a transition leads from the `oldState` to the `newState`; otherwise the value false.

**Exceptions**

| Exception | Condition |
|---|---|
| [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception) | The `context`, `oldState` or `newState` is a null reference (Nothing in Visual Basic). |

### ChangeStateTo

Changes the current state of the state machine to the `newState` specified.

<div class="api-signature" data-lang="csharp">

```csharp
void ChangeStateTo(OpcContext context, object newState)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Sub ChangeStateTo(context As OpcContext, newState As Object)
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `context` | [OpcContext](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opccontext/) | The [OpcContext](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opccontext/) to use to change. |
| `newState` | [Object](https://learn.microsoft.com/dotnet/api/system.object) | The state number or the enumeration member of the state to change to. |

**Exceptions**

| Exception | Condition |
|---|---|
| [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception) | The `newState` is not a known state. |
| [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception) | The `context` or `newState` is a null reference (Nothing in Visual Basic). |
| [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception) | No transition leads from the current state to the `newState`. |
| [OpcException](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcexception/) | The change operation failed (see exception details for more information). |

**Remarks**

The method does not change the state if [SupportsCurrentState](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.iopcstatemachine/members#supportscurrentstate) is false or the `newState` is the current state. If neither a current state nor a last transition is set, the state can be changed to any known state.

### GetSubStatesMachine

<span class="api-meta">2 overloads</span>

| Overload | Description |
|---|---|
| [GetSubStatesMachine()](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.iopcstatemachine/members#getsubstatesmachine-noparams) | Gets the state machine of the sub-states of the current state. |
| [GetSubStatesMachine(object)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.iopcstatemachine/members#getsubstatesmachine-system-object) | Gets the state machine of the sub-states of the `state` specified. |

#### GetSubStatesMachine()

Gets the state machine of the sub-states of the current state.

<div class="api-signature" data-lang="csharp">

```csharp
IOpcStateMachine GetSubStatesMachine()
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Function GetSubStatesMachine() As IOpcStateMachine
```

</div>

**Returns**

[IOpcStateMachine](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.iopcstatemachine/)

The state machine of the sub-states of the current state, or a null reference (Nothing in Visual Basic) if the current state has none.

#### GetSubStatesMachine(object)

Gets the state machine of the sub-states of the `state` specified.

<div class="api-signature" data-lang="csharp">

```csharp
IOpcStateMachine GetSubStatesMachine(object state)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Function GetSubStatesMachine(state As Object) As IOpcStateMachine
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `state` | [Object](https://learn.microsoft.com/dotnet/api/system.object) | The state number or the enumeration member of the state, or a null reference (Nothing in Visual Basic) for the current state. |

**Returns**

[IOpcStateMachine](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.iopcstatemachine/)

The state machine of the sub-states of the `state`, or a null reference (Nothing in Visual Basic) if the state has none.
