@@ -43,6 +43,9 @@ public enum RegisterOrder { LowHigh = 0, HighLow = 1 };
43
43
private StopBits stopBits = StopBits . One ;
44
44
private bool connected = false ;
45
45
string mqttRootTopic = "easymodbusclient" ;
46
+ public string MqttUserName { get ; set ; }
47
+ public string MqttPassword { get ; set ; }
48
+ public int MqttBrokerPort = 1883 ;
46
49
47
50
public delegate void ReceiveDataChanged ( object sender ) ;
48
51
public event ReceiveDataChanged receiveDataChanged ;
@@ -771,11 +774,13 @@ public static bool DetectValidModbusFrame(byte[] readBuffer, int length)
771
774
/// Read Discrete Inputs from Server device (FC2) and publishes the values to a MQTT-Broker.
772
775
/// The Topic will be easymodbusclient/discreteinputs/'address' e.g. easymodbusclient/discreteinputs/0 for address "0".
773
776
/// Note that the Address that will be publishes is "0"-Based. The Root topic can be changed using the Parameter
777
+ /// By default we are using the Standard-Port 1883. This Port can be changed using the Property "MqttBrokerPort"
778
+ /// A Username and Passowrd can be provided using the Properties "MqttUserName" and "MqttPassword"
774
779
/// 'MqttRootTopic' Default is 'easymodbusclient'
775
780
/// </summary>
776
781
/// <param name="startingAddress">First discrete input to read</param>
777
782
/// <param name="quantity">Number of discrete Inputs to read</param>
778
- /// <param name="mqttBrokerAddress">Broker address 8the values will be published to</param>
783
+ /// <param name="mqttBrokerAddress">Broker address the values will be published to</param>
779
784
/// <returns>Boolean Array which contains the discrete Inputs</returns>
780
785
public bool [ ] ReadDiscreteInputs ( int startingAddress , int quantity , string mqttBrokerAddress )
781
786
{
@@ -788,6 +793,9 @@ public bool[] ReadDiscreteInputs(int startingAddress, int quantity, string mqttB
788
793
payload [ i ] = returnValue [ i ] . ToString ( ) ;
789
794
}
790
795
EasyModbus2Mqtt easyModbus2Mqtt = new EasyModbus2Mqtt ( ) ;
796
+ easyModbus2Mqtt . MqttBrokerPort = this . MqttBrokerPort ;
797
+ easyModbus2Mqtt . MqttUserName = this . MqttUserName ;
798
+ easyModbus2Mqtt . MqttPassword = this . MqttPassword ;
791
799
easyModbus2Mqtt . publish ( topic , payload , mqttBrokerAddress ) ;
792
800
793
801
return returnValue ;
@@ -968,6 +976,8 @@ public bool[] ReadDiscreteInputs(int startingAddress, int quantity)
968
976
/// The Topic will be easymodbusclient/coils/'address' e.g. easymodbusclient/coils/0 for address "0".
969
977
/// Note that the Address that will be publishes is "0"-Based. The Root topic can be changed using the Parameter
970
978
/// 'MqttRootTopic' Default is 'easymodbusclient'
979
+ /// By default we are using the Standard-Port 1883. This Port can be changed using the Property "MqttBrokerPort"
980
+ /// A Username and Passowrd can be provided using the Properties "MqttUserName" and "MqttPassword"
971
981
/// </summary>
972
982
/// <param name="startingAddress">First coil to read</param>
973
983
/// <param name="quantity">Number of coils to read</param>
@@ -984,6 +994,9 @@ public bool[] ReadCoils(int startingAddress, int quantity, string mqttBrokerAddr
984
994
payload [ i ] = returnValue [ i ] . ToString ( ) ;
985
995
}
986
996
EasyModbus2Mqtt easyModbus2Mqtt = new EasyModbus2Mqtt ( ) ;
997
+ easyModbus2Mqtt . MqttBrokerPort = this . MqttBrokerPort ;
998
+ easyModbus2Mqtt . MqttUserName = this . MqttUserName ;
999
+ easyModbus2Mqtt . MqttPassword = this . MqttPassword ;
987
1000
easyModbus2Mqtt . publish ( topic , payload , mqttBrokerAddress ) ;
988
1001
989
1002
@@ -1164,6 +1177,8 @@ public bool[] ReadCoils(int startingAddress, int quantity)
1164
1177
/// The Topic will be easymodbusclient/holdingregisters/'address' e.g. easymodbusclient/holdingregisters/0 for address "0".
1165
1178
/// Note that the Address that will be publishes is "0"-Based. The Root topic can be changed using the Parameter
1166
1179
/// 'MqttRootTopic' Default is 'easymodbusclient'
1180
+ /// By default we are using the Standard-Port 1883. This Port can be changed using the Property "MqttBrokerPort"
1181
+ /// A Username and Passowrd can be provided using the Properties "MqttUserName" and "MqttPassword"
1167
1182
/// </summary>
1168
1183
/// <param name="startingAddress">First Holding Register to read</param>
1169
1184
/// <param name="quantity">Number of Holding Registers to read</param>
@@ -1180,6 +1195,9 @@ public int[] ReadHoldingRegisters(int startingAddress, int quantity, string mqtt
1180
1195
payload [ i ] = returnValue [ i ] . ToString ( ) ;
1181
1196
}
1182
1197
EasyModbus2Mqtt easyModbus2Mqtt = new EasyModbus2Mqtt ( ) ;
1198
+ easyModbus2Mqtt . MqttBrokerPort = this . MqttBrokerPort ;
1199
+ easyModbus2Mqtt . MqttUserName = this . MqttUserName ;
1200
+ easyModbus2Mqtt . MqttPassword = this . MqttPassword ;
1183
1201
easyModbus2Mqtt . publish ( topic , payload , mqttBrokerAddress ) ;
1184
1202
return returnValue ;
1185
1203
}
@@ -1359,6 +1377,8 @@ public int[] ReadHoldingRegisters(int startingAddress, int quantity)
1359
1377
/// The Topic will be easymodbusclient/inputregisters/'address' e.g. easymodbusclient/inputregisters/0 for address "0".
1360
1378
/// Note that the Address that will be publishes is "0"-Based. The Root topic can be changed using the Parameter
1361
1379
/// 'MqttRootTopic' Default is 'easymodbusclient'
1380
+ /// By default we are using the Standard-Port 1883. This Port can be changed using the Property "MqttBrokerPort"
1381
+ /// A Username and Passowrd can be provided using the Properties "MqttUserName" and "MqttPassword"
1362
1382
/// </summary>
1363
1383
/// <param name="startingAddress">First Input Register to read</param>
1364
1384
/// <param name="quantity">Number of Input Registers to read</param>
@@ -1375,6 +1395,9 @@ public int[] ReadInputRegisters(int startingAddress, int quantity, string mqttBr
1375
1395
payload [ i ] = returnValue [ i ] . ToString ( ) ;
1376
1396
}
1377
1397
EasyModbus2Mqtt easyModbus2Mqtt = new EasyModbus2Mqtt ( ) ;
1398
+ easyModbus2Mqtt . MqttBrokerPort = this . MqttBrokerPort ;
1399
+ easyModbus2Mqtt . MqttUserName = this . MqttUserName ;
1400
+ easyModbus2Mqtt . MqttPassword = this . MqttPassword ;
1378
1401
easyModbus2Mqtt . publish ( topic , payload , mqttBrokerAddress ) ;
1379
1402
1380
1403
0 commit comments