@@ -43,6 +43,9 @@ public enum RegisterOrder { LowHigh = 0, HighLow = 1 };
4343 private StopBits stopBits = StopBits . One ;
4444 private bool connected = false ;
4545 string mqttRootTopic = "easymodbusclient" ;
46+ public string MqttUserName { get ; set ; }
47+ public string MqttPassword { get ; set ; }
48+ public int MqttBrokerPort = 1883 ;
4649
4750 public delegate void ReceiveDataChanged ( object sender ) ;
4851 public event ReceiveDataChanged receiveDataChanged ;
@@ -771,11 +774,13 @@ public static bool DetectValidModbusFrame(byte[] readBuffer, int length)
771774 /// Read Discrete Inputs from Server device (FC2) and publishes the values to a MQTT-Broker.
772775 /// The Topic will be easymodbusclient/discreteinputs/'address' e.g. easymodbusclient/discreteinputs/0 for address "0".
773776 /// 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"
774779 /// 'MqttRootTopic' Default is 'easymodbusclient'
775780 /// </summary>
776781 /// <param name="startingAddress">First discrete input to read</param>
777782 /// <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>
779784 /// <returns>Boolean Array which contains the discrete Inputs</returns>
780785 public bool [ ] ReadDiscreteInputs ( int startingAddress , int quantity , string mqttBrokerAddress )
781786 {
@@ -788,6 +793,9 @@ public bool[] ReadDiscreteInputs(int startingAddress, int quantity, string mqttB
788793 payload [ i ] = returnValue [ i ] . ToString ( ) ;
789794 }
790795 EasyModbus2Mqtt easyModbus2Mqtt = new EasyModbus2Mqtt ( ) ;
796+ easyModbus2Mqtt . MqttBrokerPort = this . MqttBrokerPort ;
797+ easyModbus2Mqtt . MqttUserName = this . MqttUserName ;
798+ easyModbus2Mqtt . MqttPassword = this . MqttPassword ;
791799 easyModbus2Mqtt . publish ( topic , payload , mqttBrokerAddress ) ;
792800
793801 return returnValue ;
@@ -968,6 +976,8 @@ public bool[] ReadDiscreteInputs(int startingAddress, int quantity)
968976 /// The Topic will be easymodbusclient/coils/'address' e.g. easymodbusclient/coils/0 for address "0".
969977 /// Note that the Address that will be publishes is "0"-Based. The Root topic can be changed using the Parameter
970978 /// '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"
971981 /// </summary>
972982 /// <param name="startingAddress">First coil to read</param>
973983 /// <param name="quantity">Number of coils to read</param>
@@ -984,6 +994,9 @@ public bool[] ReadCoils(int startingAddress, int quantity, string mqttBrokerAddr
984994 payload [ i ] = returnValue [ i ] . ToString ( ) ;
985995 }
986996 EasyModbus2Mqtt easyModbus2Mqtt = new EasyModbus2Mqtt ( ) ;
997+ easyModbus2Mqtt . MqttBrokerPort = this . MqttBrokerPort ;
998+ easyModbus2Mqtt . MqttUserName = this . MqttUserName ;
999+ easyModbus2Mqtt . MqttPassword = this . MqttPassword ;
9871000 easyModbus2Mqtt . publish ( topic , payload , mqttBrokerAddress ) ;
9881001
9891002
@@ -1164,6 +1177,8 @@ public bool[] ReadCoils(int startingAddress, int quantity)
11641177 /// The Topic will be easymodbusclient/holdingregisters/'address' e.g. easymodbusclient/holdingregisters/0 for address "0".
11651178 /// Note that the Address that will be publishes is "0"-Based. The Root topic can be changed using the Parameter
11661179 /// '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"
11671182 /// </summary>
11681183 /// <param name="startingAddress">First Holding Register to read</param>
11691184 /// <param name="quantity">Number of Holding Registers to read</param>
@@ -1180,6 +1195,9 @@ public int[] ReadHoldingRegisters(int startingAddress, int quantity, string mqtt
11801195 payload [ i ] = returnValue [ i ] . ToString ( ) ;
11811196 }
11821197 EasyModbus2Mqtt easyModbus2Mqtt = new EasyModbus2Mqtt ( ) ;
1198+ easyModbus2Mqtt . MqttBrokerPort = this . MqttBrokerPort ;
1199+ easyModbus2Mqtt . MqttUserName = this . MqttUserName ;
1200+ easyModbus2Mqtt . MqttPassword = this . MqttPassword ;
11831201 easyModbus2Mqtt . publish ( topic , payload , mqttBrokerAddress ) ;
11841202 return returnValue ;
11851203 }
@@ -1359,6 +1377,8 @@ public int[] ReadHoldingRegisters(int startingAddress, int quantity)
13591377 /// The Topic will be easymodbusclient/inputregisters/'address' e.g. easymodbusclient/inputregisters/0 for address "0".
13601378 /// Note that the Address that will be publishes is "0"-Based. The Root topic can be changed using the Parameter
13611379 /// '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"
13621382 /// </summary>
13631383 /// <param name="startingAddress">First Input Register to read</param>
13641384 /// <param name="quantity">Number of Input Registers to read</param>
@@ -1375,6 +1395,9 @@ public int[] ReadInputRegisters(int startingAddress, int quantity, string mqttBr
13751395 payload [ i ] = returnValue [ i ] . ToString ( ) ;
13761396 }
13771397 EasyModbus2Mqtt easyModbus2Mqtt = new EasyModbus2Mqtt ( ) ;
1398+ easyModbus2Mqtt . MqttBrokerPort = this . MqttBrokerPort ;
1399+ easyModbus2Mqtt . MqttUserName = this . MqttUserName ;
1400+ easyModbus2Mqtt . MqttPassword = this . MqttPassword ;
13781401 easyModbus2Mqtt . publish ( topic , payload , mqttBrokerAddress ) ;
13791402
13801403
0 commit comments