Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/normandy72/modbus-rtu-for-unity
Modbus RTU protocol for Unity.
https://github.com/normandy72/modbus-rtu-for-unity
android modbus modbusrtu odroid unity
Last synced: about 1 month ago
JSON representation
Modbus RTU protocol for Unity.
- Host: GitHub
- URL: https://github.com/normandy72/modbus-rtu-for-unity
- Owner: Normandy72
- License: mit
- Created: 2024-06-09T18:28:31.000Z (7 months ago)
- Default Branch: master
- Last Pushed: 2024-06-09T20:01:33.000Z (7 months ago)
- Last Synced: 2024-06-10T21:40:00.957Z (7 months ago)
- Topics: android, modbus, modbusrtu, odroid, unity
- Language: ShaderLab
- Homepage:
- Size: 1.24 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# MODBUS RTU for UNITY
ModbusRTU is a library for working with the Modbus RTU protocol in C#. The library provides simple methods for reading and writing registers, coils, and other Modbus RTU elements via a serial port.
### INSTALLATION
You can copy the source code from the ModbusRTU.cs file directly into your project, or add the ModbusRTU.cs file as a reference to your project.### USAGE
ATTENTION! It works only with .NET Framework (Project Settings -> Player -> Other Settings -> Api Compatibility Level -> .NET Framework).1. Create an instance of the ModbusRTU class, specifying the serial port name and baud rate.
2. Call the `Connect()` method to establish a connection with the device.
3. Perform the necessary read or write operations on registers, coils, etc., using the appropriate methods of the ModbusRTU class.
4. After completing work with the device, call the `Disconnect()` method to close the connection.```
using UnityEngine;
using System;public class Example : MonoBehaviour
{
private ModbusRTU _modbus;void Start()
{
_modbus = new ModbusRTU("COM1", 9600);if(_modbus.Connect())
{
// DO SOMETHING IF CONNECTED
}
else
{
// DO SOMETHING IF CONNECTION FAILED
}
}
}
```### METHODS
#### Connect()
Establishes a connection with the device. Returns true if the connection is established successfully, and false otherwise.#### Disconnect()
Closes the connection with the device.### Reading and writing registers
#### ReadSingleRegister(byte deviceId, ushort startAddress)
Reads the value of a single register.#### ReadSingleRegisterAsync(byte deviceId, ushort startAddress)
Asynchronously reads the value of a single register.#### WriteSingleRegister(byte deviceId, ushort registerAddress, ushort value)
Writes a value to a single register.#### WriteSingleRegisterAsync(byte deviceId, ushort registerAddress, ushort value)
Asynchronously writes a value to a single register.#### WriteMultipleRegisters(byte deviceId, ushort startAddress, ushort[] values)
Writes values to multiple consecutive registers.#### WriteMultipleRegistersAsync(byte deviceId, ushort startAddress, ushort[] values)
Asynchronously writes values to multiple consecutive registers.### Reading and writing coils
#### ReadCoils(byte deviceId, ushort startAddress, ushort coilCount)
Reads the values of coils.#### ReadCoilsAsync(byte deviceId, ushort startAddress, ushort coilCount)
Asynchronously reads the values of coils.#### WriteSingleCoil(byte deviceId, ushort coilAddress, bool value)
Writes a value to a single coil.#### WriteSingleCoilAsync(byte deviceId, ushort coilAddress, bool value)
Asynchronously writes a value to a single coil.#### WriteMultipleCoils(byte deviceId, ushort startAddress, bool[] values)
Writes values to multiple coils.#### WriteMultipleCoilsAsync(byte deviceId, ushort startAddress, bool[] values)
Asynchronously writes values to multiple coils.### Other functions
#### ReadExceptionStatus(byte deviceId)
Reads the exception status (only for Modbus RTU).#### ReadExceptionStatusAsync(byte deviceId)
Asynchronously reads the exception status (only for Modbus RTU).#### DiagnosticsEcho(byte deviceId, byte[] data)
Performs a diagnostic echo request.#### DiagnosticsEchoAsync(byte deviceId, byte[] data)
Asynchronously performs a diagnostic echo request.#
### License
This library is distributed under the MIT license. See the LICENSE file for more details.