Script example

<< Click to Display Table of Contents >>

Navigation:  Program Windows > Python Script window >

Script example

# Sending DPA request Pulse LED red to the Coordinator or Node

 

import time

import iqrfpy.messages as messages

from iqrfpy.utils.dpa import ResponseCodes

from iqrfpy.transports.iqrfide_transport import IqrfIdeTransport

 

try:

    transport = IqrfIdeTransport()

    # Enable logging to the IQRF IDE Terminal Log

    transport.iqrfide_logging = True

except Exception as e:

    print('Connection error:', str(e))

    exit()

 

print('Connected')

# Enter NADR (0 - 239)

nadr = 0

 

# Pulse LED red using predefined request

try:

    # Send DPA request and try to receive the response

    response: messages.LedrPulseRsp = transport.send_and_receive(messages.LedrPulseReq(nadr))

    if response:

        print(f'Response code: {ResponseCodes.to_string(response.rcode)}')

except Exception as e:

    print(f'Error:', str(e))

 

time.sleep(1)

 

# Pulse LED red using generic request

try:

    # Send DPA request and try to receive the response

    pdata = []  # E.g. [0x00, 0x01, 0x02]

    response: messages.GenericResponse = transport.send_and_receive(messages.GenericRequest(nadr, pnum=0x06, pcmd=0x03, pdata=pdata))

    if response:

        print(f'Response code: {ResponseCodes.to_string(response.rcode)}')

        # Get possible PDATA

        #print(response.pdata)

except Exception as e:

    print(f'Error:', str(e))