3 Commits 75b9589ed5 ... 7746a90cdb

Author SHA1 Message Date
  Michael Buesch 7746a90cdb examples: Add flow control to all configs 5 years ago
  Michael Buesch 8780996369 conf: Add missing field defaults 5 years ago
  Ewald Weinhandl 84ebaf5525 Add enable/disable hardware flow control (RTS/CTS) and (DSR/DTR) in config file. 5 years ago
5 changed files with 24 additions and 4 deletions
  1. 4 0
      example_dummy.conf
  2. 4 0
      example_et200s.conf
  3. 4 0
      example_s7-315-2dp.conf
  4. 7 1
      pyprofibus/conf.py
  5. 5 3
      pyprofibus/phy_serial.py

+ 4 - 0
example_dummy.conf

@@ -28,6 +28,10 @@ type=dummy_slave
 ; The Profibus on-wire baud rate.
 baud=19200
 
+; Serial line flow control and handshaking
+rtscts=False
+dsrdtr=False
+
 
 ; FDL protocol layer configuration
 [FDL]

+ 4 - 0
example_et200s.conf

@@ -28,6 +28,10 @@ dev=/dev/ttyS0
 ; The Profibus on-wire baud rate.
 baud=19200
 
+; Serial line flow control and handshaking
+rtscts=False
+dsrdtr=False
+
 
 ; FDL protocol layer configuration
 [FDL]

+ 4 - 0
example_s7-315-2dp.conf

@@ -28,6 +28,10 @@ dev=/dev/ttyS0
 ; The Profibus on-wire baud rate.
 baud=19200
 
+; Serial line flow control and handshaking
+rtscts=False
+dsrdtr=False
+
 
 ; FDL protocol layer configuration
 [FDL]

+ 7 - 1
pyprofibus/conf.py

@@ -51,6 +51,8 @@ class PbConf(object):
 	phyType		= None
 	phyDev		= None
 	phyBaud		= None
+	phyRtsCts	= None
+	phyDsrDtr	= None
 	# [DP] section
 	dpMasterClass	= None
 	dpMasterAddr	= None
@@ -111,6 +113,10 @@ class PbConf(object):
 					  fallback = "/dev/ttyS0")
 			self.phyBaud = getint("PHY", "baud",
 					      fallback = 9600)
+			self.phyRtsCts = getboolean("PHY", "rtscts",
+					      fallback = False)
+			self.phyDsrDtr = getboolean("PHY", "dsrdtr",
+					      fallback = False)
 
 			# [DP]
 			self.dpMasterClass = getint("DP", "master_class",
@@ -180,5 +186,5 @@ class PbConf(object):
 		else:
 			raise PbConfError("Invalid phyType parameter value: "
 					  "%s" % self.phyType)
-		phy.setConfig(baudrate = self.phyBaud)
+		phy.setConfig(baudrate = self.phyBaud, rtscts = self.phyRtsCts, dsrdtr = self.phyDsrDtr)
 		return phy

+ 5 - 3
pyprofibus/phy_serial.py

@@ -64,7 +64,7 @@ class CpPhySerial(CpPhy):
 			self.__serial.timeout = 0
 			self.__serial.xonxoff = False
 			self.__serial.rtscts = False
-			self.__serial.dsrdtr = True
+			self.__serial.dsrdtr = False
 			if useRS485Class:
 				self.__serial.rs485_mode = serial.rs485.RS485Settings(
 					rts_level_for_tx = True,
@@ -165,7 +165,7 @@ class CpPhySerial(CpPhy):
 			raise PhyError("PHY-serial: Failed to transmit "
 				"telegram:\n" + str(e))
 
-	def setConfig(self, baudrate = CpPhy.BAUD_9600):
+	def setConfig(self, baudrate = CpPhy.BAUD_9600, rtscts = False, dsrdtr = False):
 		wellSuppBaud = (9600, 19200)
 		if baudrate not in wellSuppBaud:
 			# The hw/driver might silently ignore the baudrate
@@ -179,9 +179,11 @@ class CpPhySerial(CpPhy):
 			      baudrate,
 			      ", ".join(str(b) for b in wellSuppBaud)))
 		try:
-			if baudrate != self.__serial.baudrate:
+			if baudrate != self.__serial.baudrate or rtscts != self.__serial.rtscts or dsrdtr != self.__serial.dsrdtr:
 				self.__serial.close()
 				self.__serial.baudrate = baudrate
+				self.__serial.rtscts = rtscts
+				self.__serial.dsrdtr = dsrdtr
 				self.__serial.open()
 				self.__rxBuf = bytearray()
 		except (serial.SerialException, ValueError) as e: