# IOpcStateMachine&lt;T&gt; Members

> Reference: Defines an interface which provides the state of a state machine whose states are identified by values of the type T and methods to change it (see OpcFiniteStateMachineNode<T>).

<dl class="api-definition">
<dt>Type</dt>
<dd><a href="./">IOpcStateMachine&lt;T&gt;</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>

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

## Methods

### CanChangeStateTo

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

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

#### CanChangeStateTo(OpcContext, T)

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

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

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

</div>

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

```vbnet
Function CanChangeStateTo(context As OpcContext, newState As T) 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` | T | 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, T, T)

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

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

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

</div>

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

```vbnet
Function CanChangeStateTo(
    context As OpcContext,
    oldState As T,
    newState As T) 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` | T | The state to change from. |
| `newState` | T | 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, T newState)
```

</div>

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

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

</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` | T | 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

Gets the state machine of the sub-states of the `state` specified whose states are identified by values of the type `TSubStates`.

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

```csharp
IOpcStateMachine<TSubStates> GetSubStatesMachine<TSubStates>(T state)
```

</div>

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

```vbnet
Function GetSubStatesMachine(Of TSubStates)(
    state As T) As IOpcStateMachine(Of TSubStates)
```

</div>

**Type parameters**

| Name | Description |
|---|---|
| `TSubStates` | The type which identifies the sub-states. |

**Parameters**

| Name | Type | Description |
|---|---|---|
| `state` | T | The state whose sub-states machine is to be retrieved. |

**Returns**

[IOpcStateMachine](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.iopcstatemachine-1/)&lt;TSubStates&gt;

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