# Mitsubishi McpX (Pro)

{% hint style="warning" %}
**Beta Interface**: This interface is currently in beta. If you encounter any issues or need assistance, please contact realvirtual support or through our community forum.
{% endhint %}

The **Mitsubishi McpX** interface provides high-performance communication with Mitsubishi PLCs using the MC Protocol 3E/4E frames through the McpX library.

## Overview

The Mitsubishi McpX interface enables real-time bidirectional data exchange between Unity simulations and Mitsubishi Q, L, R, iQ-R, and iQ-F series PLCs. This Professional-only interface utilizes the MC Protocol (MELSEC Communication Protocol) with 3E/4E frame formats for robust industrial communication. A key feature is its intelligent batch read optimization that automatically groups signals into efficient read operations, reducing network traffic and improving throughput by up to 30x compared to individual signal reads.

The interface supports all major Mitsubishi device types including physical inputs/outputs (X/Y), internal relays (M), data registers (D), timers (T), counters (C), state relays (S), and special devices (SM/SD). Communication runs in a background thread using the FastInterface architecture, ensuring smooth Unity performance while maintaining reliable PLC connectivity.

{% hint style="info" %}
This interface requires **realvirtual Professional** and uses the McpX library (<https://github.com/YudaiKitamura/McpX>) for MC Protocol implementation.
{% endhint %}

## Installation

The Mitsubishi McpX interface is included in realvirtual Professional and can be added to your scene through:

1. **Menu Method**: Select **Tools > realvirtual > Add Interface > Mitsubishi McpX (Pro)**
2. **Manual Method**: Add the `MitsubishiMcpXInterface` script to an empty GameObject

The interface files are located at: `Assets/realvirtual/Interfaces/Mitsubishi/`

## Properties

<figure><img src="https://260262196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpYxFg97YnJX96UzNNTSd%2Fuploads%2Fgit-blob-f5065e729bee91cc9845d566c02cd5d79b4e3256%2Fmitsubishi-mcpx-inspector.png?alt=media" alt=""><figcaption><p>Mitsubishi McpX Interface Inspector</p></figcaption></figure>

### Connection Settings

* **IP Address** (string): IP address of the Mitsubishi PLC. Default: "192.168.3.39"
* **Port** (int): MC Protocol communication port. Default: 5001 (standard port for MC Protocol 3E/4E frames)
* **Connection Timeout** (int): Maximum connection establishment time in milliseconds. Default: 5000

{% hint style="info" %}
The interface uses MC Protocol **3E binary frame format** and **TCP** transport by default. These are optimized settings for Mitsubishi Q, L, R, iQ-R, and iQ-F series PLCs and cannot be changed.
{% endhint %}

### Batch Optimization

Dramatically improves communication efficiency by grouping multiple signal reads into single network operations, providing up to 30x performance improvement.

* **Optimize Batch Reads** (boolean): Enables automatic signal grouping for efficient reading. Default: true
* **Max Gap Size** (int): Maximum address gap between signals in the same batch. Default: 5
* **Min Batch Size** (int): Minimum signals required to justify batch reading. Default: 3
* **Max Batch Size Bits** (int): Maximum batch size for bit devices (X, Y, M, etc.). Default: 960 (MC Protocol limit)
* **Max Batch Size Words** (int): Maximum batch size for word devices (D, W, R, etc.). Default: 120 (MC Protocol limit)

### GX Works3 Import

Provides seamless integration with GX Works3 device comment exports for rapid signal configuration.

* **GX Works3 CSV File** (string): Path to device comment CSV export file. Use **Select CSV File** button to browse
* **Use Standard GX Format** (boolean): Uses standard GX Works3 CSV format (Device,Comment,Data Type,Initial Value). Default: true
* **Create Device Hierarchy** (boolean): Organizes imported signals by device type (Physical Inputs (X), Physical Outputs (Y), etc.). Default: true
* **Import Comments** (boolean): Uses device comments as signal names for meaningful identification. Default: true
* **Max Import Devices** (int): Safety limit for imported devices to prevent memory issues. Default: 1000
* **Validate Device Addresses** (boolean): Checks device addresses for validity before import. Default: true

### Device Type Filtering

Controls which device types are imported from CSV files.

* **Import Physical Inputs** (boolean): Import X devices (sensors, buttons, switches). Default: true
* **Import Physical Outputs** (boolean): Import Y devices (actuators, lights, valves). Default: true
* **Import Internal Relays** (boolean): Import M devices (internal memory bits). Default: true
* **Import Data Registers** (boolean): Import D devices (16-bit data storage). Default: true
* **Import Timers** (boolean): Import T devices (timer current values and contacts). Default: true
* **Import Counters** (boolean): Import C devices (counter current values and contacts). Default: true
* **Import State Relays** (boolean): Import S devices (state/step relays). Default: true
* **Import Special Devices** (boolean): Import SM/SD devices (system special relays and registers). Default: false

## PLC Configuration

### Enabling MC Protocol

Configure your Mitsubishi PLC to accept MC Protocol connections:

1. **GX Works3 Configuration**:
   * Open your project in GX Works3
   * Navigate to **Project > Parameter > Ethernet Configuration**
   * Enable MC Protocol on port 5001 (standard port for 3E frames)
   * Set communication data code to **Binary** (required for 3E frame format)
   * Configure allowed operations (Read/Write)
2. **Network Settings**:
   * Ensure PLC and Unity PC are on the same network
   * Configure IP address and subnet mask appropriately
   * Test connectivity with ping command
3. **Security Settings**:
   * MC Protocol typically doesn't require authentication
   * Ensure firewall allows communication on configured port
   * Some PLCs may require enabling external communication

### Device Comment Export

To export device comments from GX Works3 for import:

1. **Export Process**:
   * Open your GX Works3 project
   * Navigate to **Project > Export > Device Comment**
   * Select CSV format
   * Choose devices to export
   * Save with meaningful filename
2. **CSV Format**:

   ```csv
   Device,Comment,Data Type,Initial Value
   X0,Start Button,Bit,0
   Y0,Motor Output,Bit,0
   D100,Speed Setpoint,Word[Signed],0
   M100,System Ready,Bit,0
   ```

### Optional InputOutput Column

{% hint style="info" %}
This feature is available since realvirtual **6.3**.
{% endhint %}

The CSV import supports an optional **InputOutput** column that allows you to override the default signal direction for each device. This is useful when the standard device-type-based direction doesn't match your application requirements.

**Supported column headers**: `InputOutput`, `Input/Output`, or `IO` (case-insensitive)

**CSV Format with InputOutput column**:

```csv
Device,Comment,Data Type,Initial Value,InputOutput
D0,Rx000,Word[Signed],0,Input
D1,Rx001,Word[Signed],0,Output
D2,Rx002,Word[Signed],0,
M0,System Flag,Bit,0,Output
```

**Behavior**:

* **Column present with value**: The specified direction ("Input" or "Output") overrides the default
* **Column present but empty**: Uses the default direction based on device type
* **Column not present**: Uses the default direction based on device type

**Default directions by device type** (from PLC perspective):

| Device Type   | Default Direction | Description                                                  |
| ------------- | ----------------- | ------------------------------------------------------------ |
| X             | Input             | PLC inputs (sensors) - Unity simulates sensors, sends to PLC |
| Y             | Output            | PLC outputs (actuators) - PLC sends commands to Unity        |
| M, D, T, C, S | Output            | Most devices default to reading from PLC                     |
| SM, SD        | Output            | Special devices are read-only from PLC                       |

{% hint style="warning" %}
**Use with caution**: Setting the wrong direction for device types with strongly defined behavior may lead to unexpected results. For example, Y devices (PLC outputs) should not be set to "Input" as they represent actuator commands from the PLC. Similarly, SM/SD (special devices) are system read-only registers. Only override directions when you fully understand the implications for your specific application.
{% endhint %}

## Manual Signal Creation

For precise control over signal configuration, you can manually create individual PLC signals. The interface automatically parses device type and address from the signal name.

### Basic Setup Process

1. **Add Interface to Scene**:
   * Create an empty GameObject and name it "MitsubishiPLC"
   * Add the **MitsubishiMcpXInterface** component
   * Configure the connection settings (IP address and port)
2. **Create Signal GameObject**:
   * Right-click the interface GameObject in the hierarchy
   * Select **Create Empty** to add a child GameObject
   * **Name it descriptively** (e.g., "ConveyorStartButton", "MotorSpeedSetpoint", "SystemReady")
3. **Add Signal Component**:
   * Select the signal GameObject
   * Add the appropriate PLC signal component based on device type:
     * **PLCInputBool** - Send boolean values to PLC (for X devices - sensors)
     * **PLCOutputBool** - Read boolean values from PLC (for Y, M devices - actuators, flags)
     * **PLCInputFloat** - Send numeric values to PLC (for D devices used as setpoints)
     * **PLCOutputFloat** - Read numeric values from PLC (for D devices - status values)
4. **Configure Signal Properties**:
   * **Name**: Set to the Mitsubishi device format (e.g., "X100", "D200", "M5")
   * **Comment**: Add documentation describing the signal purpose

{% hint style="info" %}
**Device Parsing**: The interface automatically extracts the device type and address from the **Signal Name** property (not the GameObject name). For example:

* Signal Name "X100" → DeviceType: "X", Address: "100"
* Signal Name "D200" → DeviceType: "D", Address: "200"
* Signal Name "M5" → DeviceType: "M", Address: "5"
  {% endhint %}

### Signal Configuration Examples

| GameObject Name     | Signal Name | Signal Component | Direction | Comment               |
| ------------------- | ----------- | ---------------- | --------- | --------------------- |
| ConveyorStartButton | X0          | PLCInputBool     | Input     | Sensor → PLC          |
| MotorContactor      | Y0          | PLCOutputBool    | Output    | PLC → Actuator        |
| SystemReady         | M100        | PLCOutputBool    | Output    | Read flag from PLC    |
| SpeedSetpoint       | D200        | PLCInputFloat    | Input     | Send setpoint to PLC  |
| ActualSpeed         | D201        | PLCOutputFloat   | Output    | Read value from PLC   |
| DelayTimer          | T0          | PLCOutputBool    | Output    | Timer status from PLC |

### Configuration Summary

* **GameObject Name**: Descriptive name for easy identification in Unity hierarchy
* **Signal Name**: Mitsubishi device format (X100, D200, etc.) - used for PLC communication
* **Comment**: Additional documentation about the signal's purpose and usage

## CSV Import

The CSV import feature allows rapid signal creation from GX Works3 device comment exports, dramatically reducing setup time for large systems.

### Preparing CSV File in GX Works3

1. **Export Device Comments**:
   * Open your GX Works3 project
   * Navigate to **Project > Export > Device Comment**
   * Select **CSV format** from the export options
   * Choose the device ranges to export
   * Save to a location accessible from Unity
2. **Verify CSV Format**: The exported CSV should follow this structure:

   ```csv
   Device,Comment,Data Type,Initial Value
   X0,Start Button,Bit,0
   X1,Stop Button,Bit,0
   Y0,Motor Contactor,Bit,0
   Y1,Status Light,Bit,0
   D100,Speed Setpoint,Word[Signed],1500
   D101,Temperature Reading,Word[Signed],0
   M0,System Ready,Bit,0
   M1,Auto Mode Active,Bit,0
   ```

### Import Process in Unity

1. **Select CSV File**:
   * In the Mitsubishi McpX Interface Inspector
   * Click the **Select CSV File** button
   * Navigate to your exported CSV file
   * Click **Open** to load the file path
2. **Configure Import Settings**:
   * **Use Standard GX Format**: Keep enabled for GX Works3 exports
   * **Create Device Hierarchy**: Enable to organize signals by device type
   * **Import Comments**: Enable to use device comments as signal names
   * **Max Import Devices**: Set safety limit (default 1000)
   * **Validate Device Addresses**: Keep enabled to catch errors
3. **Filter Device Types**: Enable only the device types you need:
   * **Physical Inputs (X)**: Sensors, buttons, switches
   * **Physical Outputs (Y)**: Actuators, lights, valves
   * **Internal Relays (M)**: Logic flags and status bits
   * **Data Registers (D)**: Numeric values and parameters
   * **Timers (T)**: Timer current values and contacts
   * **Counters (C)**: Counter values and contacts
   * **State Relays (S)**: Step sequence control
   * **Special Devices (SM/SD)**: Usually disabled
4. **Execute Import**:
   * Click the **Import from CSV** button
   * Monitor the Unity Console for import progress and any warnings
   * Review created signals in the hierarchy

### Post-Import Organization

After successful import, you'll have:

* **Organized hierarchy**: Signals grouped by device type (if enabled)
* **Named signals**: Using device comments for meaningful names
* **Configured addresses**: All device types and addresses set correctly
* **Ready-to-use signals**: Immediately available for connection to simulation components

### Import Validation and Troubleshooting

**Common CSV Issues**:

* **Encoding problems**: Ensure CSV is saved as UTF-8
* **Format mismatches**: Verify column order matches GX Works3 standard
* **Invalid addresses**: Check for typos in device addresses
* **Large imports**: Consider splitting very large files into smaller segments

**Post-Import Verification**:

* Check Unity Console for any import warnings or errors
* Verify signal names match your expectations
* Test connectivity with a few sample signals before connecting all components
* Review batch optimization settings for optimal performance with your signal layout

## Troubleshooting

### Connection Issues

**Cannot connect to PLC**:

1. Verify PLC IP address is correct
2. Check MC Protocol is enabled on PLC
3. Test with ping command: `ping 192.168.3.39`
4. Verify firewall settings allow port 5001
5. Check network cable and switches

**Connection timeouts**:

* Increase Connection Timeout value
* Reduce batch sizes if using optimization
* Check network latency
* Verify PLC scan time isn't too long

### Import Issues

**CSV import fails**:

* Verify CSV format matches GX Works3 standard
* Check file encoding (UTF-8 recommended)
* Ensure device addresses are valid
* Review console log for specific errors

**Signals not updating**:

* Verify PLC is in RUN mode
* Check signal direction: X devices should be Input (Unity → PLC), Y devices should be Output (PLC → Unity)
* Ensure device addresses match PLC program
* Review batch optimization settings

### Performance Issues

**Slow update rates**:

* Enable batch optimization
* Adjust Max Gap Size for better grouping
* Increase Min Batch Size to reduce operations
* Check network bandwidth and latency

**Unity freezes during communication**:

* Interface runs in background thread
* Check for exceptions in console
* Verify reasonable number of signals (<5000)
* Consider splitting into multiple interfaces

## Supported Device Types

The interface supports all standard Mitsubishi device types:

| Device | Description              | Data Type | Address Range  |
| ------ | ------------------------ | --------- | -------------- |
| X      | Physical Inputs          | Bit       | X0-X7FF (hex)  |
| Y      | Physical Outputs         | Bit       | Y0-Y7FF (hex)  |
| M      | Internal Relays          | Bit       | M0-M8191       |
| L      | Latch Relays             | Bit       | L0-L8191       |
| F      | Annunciator              | Bit       | F0-F2047       |
| V      | Edge Relays              | Bit       | V0-V2047       |
| B      | Link Relays              | Bit       | B0-B1FFF (hex) |
| D      | Data Registers           | Word      | D0-D12287      |
| W      | Link Registers           | Word      | W0-W1FFF (hex) |
| T      | Timer Contacts/Current   | Bit/Word  | T0-T511        |
| C      | Counter Contacts/Current | Bit/Word  | C0-C255        |
| S      | State Relays             | Bit       | S0-S4095       |
| SM     | Special Relays           | Bit       | SM0-SM2047     |
| SD     | Special Registers        | Word      | SD0-SD2047     |
| R      | File Registers           | Word      | R0-R32767      |
| ZR     | File Registers           | Word      | ZR0-ZR65535    |

## See Also

* [Signal Manager](https://doc.realvirtual.io/components-and-scripts/interfaces/interface-tools/signal-manager) - Managing and organizing signals
* [Signal Importer Exporter](https://doc.realvirtual.io/components-and-scripts/interfaces/signal-importer-exporter) - Import and export signal configurations
* [Custom Interfaces](https://doc.realvirtual.io/components-and-scripts/interfaces/custom-interfaces) - Creating custom interfaces
* [S7 TCP](https://doc.realvirtual.io/components-and-scripts/interfaces/s7-tcp) - Similar interface for Siemens PLCs

## External Resources

* [McpX Library GitHub](https://github.com/YudaiKitamura/McpX) - MC Protocol implementation
* [Mitsubishi MC Protocol Manual](https://www.mitsubishielectric.com/fa/) - Official protocol documentation
* [GX Works3 Documentation](https://www.mitsubishielectric.com/fa/products/cnt/plceng/smerit/gx_works3/) - PLC programming software

© 2025 realvirtual GmbH [https://realvirtual.io](https://realvirtual.io/) - All rights reserved. No part of this publication may be reproduced, distributed, or transmitted in any form or by any means, including printing, saving, photocopying, recording, or other electronic or mechanical methods, without the prior written permission of the publisher.
