Skip to content

Commit 2a9d4c6

Browse files
committed
[Modbus] Code style and markup fixes
***NO_CI***
1 parent 92599d4 commit 2a9d4c6

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

devices/Modbus/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ To initialize and use a Modbus client, you can do the following:
2626
```csharp
2727
// Modbus Client
2828
var client = new ModbusClient("COM3");
29-
client.ReadTimeout = client.WriteTimeout = 2000;
29+
client.ReadTimeout = client.WriteTimeout =2000;
3030

31-
client.WriteMultipleRegisters(2, 0x5, new ushort[] { 3, 5, 2, 3 });
32-
client.Raw(2, FunctionCode.Diagnostics, new byte[] { 0x01, 0x01, 0x01, 0x01 });
31+
client.WriteMultipleRegisters(2,0x5, new ushort[] {3,5,2,3 });
32+
client.Raw(2, FunctionCode.Diagnostics, new byte[] {0x01,0x01,0x01,0x01 });
3333

34-
var data1 = client.ReadHoldingRegisters(2, 0x7, 4);
35-
var data2 = client.ReadCoils(2, 0x23, 2);
34+
var data1 = client.ReadHoldingRegisters(2,0x7,4);
35+
var data2 = client.ReadCoils(2,0x23,2);
3636
```
3737

3838
As shown in the sample, you have the possibility to write multiple registers, use raw function and also ready multiple registers.
@@ -44,7 +44,7 @@ A server implementation is also available:
4444
```csharp
4545
// Modbus Server
4646
var server = new ModbusServer(new Device(1), "COM2");
47-
server.ReadTimeout = server.WriteTimeout = 2000;
47+
server.ReadTimeout = server.WriteTimeout =2000;
4848
server.StartListening();
4949
```
5050

@@ -58,7 +58,7 @@ When using Modbus with an RS485, you can for example use a MAX485 to make the in
5858

5959
## RS232 support
6060

61-
You can change the ```mode``` parameter in constructor to 0 (SerialMode.Normal) if you're using Modbus over RS232
61+
You can change the ```mode``` parameter in constructor to0 (SerialMode.Normal) if you're using Modbus over RS232
6262
```csharp
6363
// Modbus Client
6464
var client = new ModbusClient("COM3",SerialMode.Normal);

devices/Modbus/samples/Program.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Iot.Device.Modbus.Client;
5+
using Iot.Device.Modbus.Server;
6+
using Microsoft.Extensions.Logging;
7+
using nanoFramework.Hardware.Esp32;
8+
using nanoFramework.Logging.Debug;
19
using System;
210
using System.Diagnostics;
311
using System.Threading;
@@ -13,7 +21,7 @@ public class Program
1321
{
1422
public static void Main()
1523
{
16-
Debug.WriteLine("Hello from nanoFramework!");
24+
Debug.WriteLine("Hello from nanoFramework!");
1725

1826
// SerialPort COM2
1927
Configuration.SetPinFunction(16, DeviceFunction.COM2_RX);
@@ -26,16 +34,16 @@ public static void Main()
2634
Configuration.SetPinFunction(27, DeviceFunction.COM3_RTS);
2735

2836
// Modbus Server (RS485 mode)
29-
var server = new ModbusServer(new Device(1), "COM2");
37+
//var server = new ModbusServer(new Device(1), "COM2");
3038

3139
// Modbus Server (RS232 mode)
3240
// var server= new ModbusServer(new Device(1),"COM2",mode:SerialMode.Normal);
3341

34-
server.ReadTimeout = server.WriteTimeout = 2000;
35-
server.StartListening();
42+
//server.ReadTimeout = server.WriteTimeout = 2000;
43+
//server.StartListening();
3644

3745
// Modbus Client (RS485 mode)
38-
var client = new ModbusClient("COM3");
46+
var client = new ModbusClient("COM2");
3947

4048
// Modbus Client (RS232 mode)
4149
// var client = new ModbusClient("COM3",mode:SerialMode.Normal);
@@ -55,7 +63,7 @@ public static void Main()
5563
class Device : ModbusDevice
5664
{
5765
public Device(byte id = 1) : base(id)
58-
{
66+
{
5967
}
6068

6169
/// <summary>

0 commit comments

Comments
 (0)