https://github.com/yudaikitamura/mcpx
McpX is a library for communicating with Mitsubishi Electric PLCs using the MC protocol. It features a simple and easy-to-use API, allowing you to communicate without worrying about MC protocol details. It runs on various platforms, including Linux, Windows, and macOS.
https://github.com/yudaikitamura/mcpx
csharp dotnet mcprotocol melsec melsec-communication-protocol mitsubishi mxcomponent plc slmp visualbasic
Last synced: 4 months ago
JSON representation
McpX is a library for communicating with Mitsubishi Electric PLCs using the MC protocol. It features a simple and easy-to-use API, allowing you to communicate without worrying about MC protocol details. It runs on various platforms, including Linux, Windows, and macOS.
- Host: GitHub
- URL: https://github.com/yudaikitamura/mcpx
- Owner: YudaiKitamura
- License: mit
- Created: 2025-03-18T12:48:12.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-12-20T04:25:16.000Z (6 months ago)
- Last Synced: 2025-12-22T12:49:02.685Z (6 months ago)
- Topics: csharp, dotnet, mcprotocol, melsec, melsec-communication-protocol, mitsubishi, mxcomponent, plc, slmp, visualbasic
- Language: C#
- Homepage: https://yudaikitamura.github.io/McpX/
- Size: 6.41 MB
- Stars: 34
- Watchers: 2
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
**McpX is a library for communicating with Mitsubishi Electric PLCs using the MC protocol.**
It features a simple and easy-to-use API, allowing you to communicate without worrying about MC protocol details.
It runs on various platforms, including Linux, Windows, and macOS.
## Installation
### .NET CLI
```sh
dotnet add package McpX
```
### Package Manager(Visual Studio)
```sh
PM> NuGet\Install-Package McpX
```
## Example Usage
```csharp
using McpXLib;
using McpXLib.Enums;
// Connect to PLC by specifying IP and port
using (var mcpx = new McpX("192.168.12.88", 10000))
{
// Read 7000 points starting from M0
bool[] mArr = mcpx.BatchRead(Prefix.M, "0", 7000);
// Read 7000 words starting from D1000
short[] dArr = mcpx.BatchRead(Prefix.D, "1000", 7000);
// Write 1234 to D0 and 5678 to D1 as signed 32-bit integers
mcpx.BatchWrite(Prefix.D, "0", [1234, 5678]);
}
```
[C# and Visual Basic samples are available here.](https://github.com/YudaiKitamura/McpX/tree/main/Example)
## Supported Commands
| Name | Description | Synchronous Method | Asynchronous Method |
|------------------------------|------------------------------------------------------------------------|---------------------------------------------------------|------------------------------------------------------------------|
| **Single Read** | Reads a single value from the specified device. | `Read(Prefix prefix, string address)` | `ReadAsync(Prefix prefix, string address)` |
| **Single Write** | Writes a single value to the specified device. | `Write(Prefix prefix, string address, T value)` | `WriteAsync(Prefix prefix, string address, T value)` |
| **Batch Read** | Reads multiple consecutive values starting from the specified address. | `BatchRead(Prefix prefix, string address, ushort length)` | `BatchReadAsync(Prefix prefix, string address, ushort length)` |
| **Batch Write** | Writes an array of values to consecutive device addresses. | `BatchWrite(Prefix prefix, string address, T[] values)` | `BatchWriteAsync(Prefix prefix, string address, T[] values)` |
| **Random Read** | Reads values from non-consecutive word and double-word addresses. | `RandomRead((Prefix, string)[] wordAddresses, (Prefix, string)[] doubleWordAddresses)` | `RandomReadAsync((Prefix, string)[] wordAddresses, (Prefix, string)[] doubleWordAddresses)` |
| **Random Write** | Writes values to non-consecutive word and double-word addresses. | `RandomWrite(...)` | `RandomWriteAsync(...)` |
| **Monitor Registration** | Registers devices to monitor. | `MonitorRegist((Prefix, string)[] wordAddresses, (Prefix, string)[] doubleWordAddresses)` | `MonitorRegistAsync((Prefix, string)[] wordAddresses, (Prefix, string)[] doubleWordAddresses)` |
| **Monitor Read** | Reads the latest values from registered monitoring devices. | `Monitor(...)` | `MonitorAsync(...)` |
| **Remote Password Lock/Unlock** | Automatically locks the PLC with the specified remote password when the instance is created and unlocks it when disposed. | `McpX(string ip, int port, string? password = null)` | – |
## Supported Protocols
- TCP
- UDP
- 3E frame (binary code)
- 3E frame (ASCII code)
- 4E frame (binary code)
- 4E frame (ASCII code)
## Roadmap
- [x] ~~3E frame (ASCII code) support~~
- [x] ~~4E frame (binary code) support~~
- [x] ~~4E frame (ASCII code) support~~
- [x] ~~UDP support~~
## Changelog
- [CHANGELOG.md](./CHANGELOG.md)
## Related
- [mcpx-mcp-server](https://github.com/YudaiKitamura/mcpx-mcp-server) An MCP(Model Context Protocol) server that enables real-time access to Mitsubishi Electric PLC devices from generative AI.