Example #1
0
def setupCommunication():

    try:
        config = pyprofibus.PbConf.fromFile(
            "/home/david/robot_ws/src/vr_driver/config/panaprofi.conf")

        phy = config.makePhy()

        master = pyprofibus.DPM1(phy=phy,
                                 masterAddr=config.dpMasterAddr,
                                 debug=False)

        # slaveConf = config.slaveConfs[0]
        # slaveConf = config.slaveConfs.__next__()
        for slaveConf in config.slaveConfs:
            gsd = slaveConf.gsd

            slaveDesc = pyprofibus.DpSlaveDesc(
                identNumber=gsd.getIdentNumber(), slaveAddr=slaveConf.addr)
            slaveDesc.setCfgDataElements(gsd.getCfgDataElements())
            slaveDesc.setSyncMode(slaveConf.syncMode)
            slaveDesc.setFreezeMode(slaveConf.freezeMode)
            slaveDesc.setGroupMask(slaveConf.groupMask)
            slaveDesc.setWatchdog(slaveConf.watchdogMs)

        master.addSlave(slaveDesc)

        master.initialize()
        return master, slaveDesc

    except pyprofibus.ProfibusError as e:
        print("Terminating: %s" % str(e))

        return None, None
Example #2
0
    def test_dummy_phy(self):
        phy = pyprofibus.phy_dummy.CpPhyDummySlave(debug=True)
        phy.setConfig(baudrate=19200)

        master = pyprofibus.DPM1(phy=phy, masterAddr=42, debug=True)

        slaveDesc = pyprofibus.DpSlaveDesc(gsd=None, slaveAddr=84)

        slaveDesc.setCfgDataElements([
            pyprofibus.DpCfgDataElement(
                pyprofibus.DpCfgDataElement.ID_TYPE_OUT),
            pyprofibus.DpCfgDataElement(
                pyprofibus.DpCfgDataElement.ID_TYPE_IN),
        ])

        slaveDesc.setUserPrmData(bytearray([
            1,
            2,
            3,
            4,
        ]))

        slaveDesc.setSyncMode(True)
        slaveDesc.setFreezeMode(True)
        slaveDesc.setGroupMask(1)
        slaveDesc.setWatchdog(300)

        master.addSlave(slaveDesc)
        master.initialize()

        # Run slave initialization state machine.
        for i in range(25):
            slaveDesc.setOutData(bytearray([
                1,
            ]))
            master.run()
        # Check dummy-slave response to Data_Exchange.
        for i in range(100):
            print("testing %d" % i)
            j = 0
            while True:
                j += 1
                self.assertTrue(j < 10)
                slaveDesc.setOutData(bytearray([
                    i,
                ]))
                master.run()
                ret = slaveDesc.getInData()
                if j >= 5 and ret is not None:
                    break
            self.assertEqual(bytearray(ret), bytearray([
                i ^ 0xFF,
            ]))
	# Create a PHY (layer 1) interface object
	phy = config.makePhy()
	print "file: example_dummy.py lines:20"
	# Create a DP class 1 master with DP address 1
	master = pyprofibus.DPM1(phy = phy,
				 masterAddr = config.dpMasterAddr,
				 debug = True)
	print "file: example_dummy.py lines:25"
	exit(-1)
	# Create a slave descriptions.
	for slaveConf in config.slaveConfs:
		gsd = slaveConf.gsd

		slaveDesc = pyprofibus.DpSlaveDesc(
				identNumber = gsd.getIdentNumber(),
				slaveAddr = slaveConf.addr)

		# Create Chk_Cfg telegram elements
		slaveDesc.setCfgDataElements(gsd.getCfgDataElements())

		# Set User_Prm_Data
		dp1PrmMask = bytearray((DpTelegram_SetPrm_Req.DPV1PRM0_FAILSAFE,
					DpTelegram_SetPrm_Req.DPV1PRM1_REDCFG,
					0x00))
		dp1PrmSet  = bytearray((DpTelegram_SetPrm_Req.DPV1PRM0_FAILSAFE,
					DpTelegram_SetPrm_Req.DPV1PRM1_REDCFG,
					0x00))
		slaveDesc.setUserPrmData(gsd.getUserPrmData(dp1PrmMask = dp1PrmMask,
							    dp1PrmSet = dp1PrmSet))
Example #4
0
# Enable verbose debug messages?
debug = True

# Create a PHY (layer 1) interface object
phy = pyprofibus.CpPhy(debug=False)

# Create a DP class 1 master with DP address 1
master = pyprofibus.DPM1(phy = phy,
			 masterAddr = 1,
			 debug = debug)

# Create a slave description for an ET-200S.
# The ET-200S has got the DP address 8 set via DIP-switches.
et200s = pyprofibus.DpSlaveDesc(identNumber = 0x817A,
				slaveAddr = 3,
				inputAddressRangeSize = 22,
				outputAddressRangeSize = 6)

# Create Chk_Cfg telegram elements
for elem in (\
				pyprofibus.DpCfgDataElement(0xC1),		# 1 In-Byte & 1 Out-Byte follows
				pyprofibus.DpCfgDataElement(0x06-1),	# DI 22 Bytes
				pyprofibus.DpCfgDataElement(0x16-1),	# DO  6 Bytes
				pyprofibus.DpCfgDataElement(0x00)):		# 
			et200s.chkCfgTelegram.addCfgDataElement(elem)

# Set User_Prm_Data
et200s.setPrmTelegram.addUserPrmData([0x03,0x02,0x07,0x00,0x00])

# Set various standard parameters
et200s.setSyncMode(False)		# Sync-mode not supported
Example #5
0
import pyprofibus

# Enable verbose debug messages?
debug = True

# Create a PHY (layer 1) interface object
phy = pyprofibus.CpPhy(debug=debug)

# Create a DP class 1 master with DP address 1
master = pyprofibus.DPM1(phy=phy, masterAddr=1, debug=debug)

# Create a slave description for an ET-200S.
# The ET-200S has got the DP address 8 set via DIP-switches.
et200s = pyprofibus.DpSlaveDesc(identNumber=0x806A,
                                slaveAddr=8,
                                inputAddressRangeSize=1,
                                outputAddressRangeSize=2)

# Create Chk_Cfg telegram elements
for elem in (
        pyprofibus.DpCfgDataElement(0),  # PM-E module
        pyprofibus.DpCfgDataElement(0x20),  # 2-DO module
        pyprofibus.DpCfgDataElement(0x20),  # 2-DO module
        pyprofibus.DpCfgDataElement(0x10)):  # 4-DI module
    et200s.chkCfgTelegram.addCfgDataElement(elem)

# Set User_Prm_Data
et200s.setPrmTelegram.addUserPrmData([0x11 | 0x40])

# Set various standard parameters
et200s.setSyncMode(True)  # Sync-mode supported