LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Python code with no argumants

Hi, ran the attached python code to read a NRF Sniffer and it works well. I am now trying to use the Python node in LabVIEW to read the returned value. I can't seem to figure out a way to read it without getting the following error "Python returned the following error: <class 'TypeError'> bad argument type for built-in operation"

 

Aashish_M_0-1708494140468.png

Any help would be golden.

 

Aashish M
CEO
TransferFi
www.transferfi.com
0 Kudos
Message 1 of 6
(672 Views)

Your main() function doesn't return anything, so just remove the string contant from your Python node.

Message 2 of 6
(628 Views)

Thank you for the response. Yes it runs without errors when I do that, but I am trying to get a the data returned into LabVIEW, just like when I run it in Python and see the data being printed. What do I need to add in the Python script to get the data in LabVIEW?

Aashish M
CEO
TransferFi
www.transferfi.com
0 Kudos
Message 3 of 6
(607 Views)

You need to have your data formatted as string....if you are trying to return an object you need to define it or return it as a string using... https://www.digitalocean.com/community/tutorials/python-str-repr-functions

 

How do you need to return data?

 

CLA, CTA
Message 4 of 6
(603 Views)

Hey thank you for the reply. Looking to get the Data string in bold.

 

def main():
mySniffer = setup_sniffer()
if mySniffer:
if scan_and_follow(mySniffer):
packets = mySniffer.getPackets()
if packets:
data = packets[0].payload
hex_string = ''.join(format(x, '02x') for x in data)
print(hex_string)
print(f"Received {len(packets)} packets")
# ignore everything till the 17th byte
index_626 = hex_string.find('6261636b790104cc13b4e559b1')
if index_626 != -1:
desired_hex_string = hex_string[index_626:]
print(desired_hex_string)
print("Data after '9b1':", desired_hex_string[26:]) # Print the data after '9b1'
dataString = desired_hex_string[26:]
print(dataString[0:24])
hex_string2 = dataString[0:24]
last_two_bytes = dataString[24:26]
decimal_list = [int(hex_string2[i:i+4], 16) for i in range(0, len(hex_string2), 4)]
decimal_string = ', '.join(map(str, decimal_list))
print(decimal_string)


if __name__ == "__main__":
main()

Aashish M
CEO
TransferFi
www.transferfi.com
0 Kudos
Message 5 of 6
(594 Views)

@Aashish_M  ha scritto:

Hey thank you for the reply. Looking to get the Data string in bold.

 

def main():
print(decimal_string)


Add  'return decimal_string' to your function in Python and in LabVIEW wire the return type with a string.

0 Kudos
Message 6 of 6
(581 Views)