def setRoute(self): #ONLY ON LINUX! SENDER_AMS = '1.2.3.4.1.1' PLC_IP = '192.168.0.100' USERNAME = '******' PASSWORD = '******' ROUTE_NAME = 'RouteToMyPC' HOSTNAME = 'MyPC' PLC_AMS_ID = '11.22.33.44.1.1' pyads.add_route_to_plc(SENDER_AMS, HOSTNAME, PLC_IP, USERNAME, PASSWORD, route_name=ROUTE_NAME)
def test_incorrect_route(self): if platform_is_linux(): # Start receiving listener route_thread = threading.Thread(target=self.plc_route_reciever) route_thread.setDaemon(True) route_thread.start() # Try to set up a route with ourselves using all the optionals AND an incorrect password try: result = add_route_to_plc(self.SENDER_AMS, self.HOSTNAME, self.PLC_IP, self.USERNAME, 'Incorrect Password', route_name=self.ROUTE_NAME, added_net_id=self.ADDING_AMS_ID) except: result = None self.assertFalse(result)
def test_correct_route(self): if platform_is_linux(): # Start receiving listener route_thread = threading.Thread(target=self.plc_route_receiver) route_thread.setDaemon(True) route_thread.start() time.sleep(1) # Try to set up a route with ourselves using all the optionals try: result = add_route_to_plc( self.SENDER_AMS, self.HOSTNAME, self.PLC_IP, self.USERNAME, self.PASSWORD, route_name=self.ROUTE_NAME, added_net_id=self.ADDING_AMS_ID, ) except: result = None self.assertTrue(result)
__date__ = "1/24/20" import pyads if __name__ == "__main__": SENDER_AMS = '141.33.59.7.1.1' PLC_IP = '141.33.59.208' USERNAME = '******' PASSWORD = '******' ROUTE_NAME = '141.33.59.7' HOSTNAME = '141.33.59.7' PLC_AMS_ID = '5.34.116.124.1.1' pyads.add_route_to_plc(SENDER_AMS, HOSTNAME, PLC_IP, USERNAME, PASSWORD, route_name=ROUTE_NAME) adsport = pyads.PORT_TC3PLC1 print('using port {}'.format(adsport)) plc = pyads.Connection(PLC_AMS_ID, adsport, PLC_IP) plc.set_timeout(3000) print('Connecting ...') plc.open() print('Connected') print(plc.read_device_info()) print(plc.read_state()) q = plc.read_by_name('MAIN.Dust5.Q', pyads.PLCTYPE_BOOL) print(q) plc.write_by_name('MAIN.Dust5.PV', 8192, pyads.PLCTYPE_WORD)