Home        Store        Learn        Blog

Ping360 code giving error, where device_data is None

The code I am running to collect sonar data works for my colleague, who was using a serial connection to test the sonar. I am using a UDP connection on the actual AUV, and am trying to run her code, using the UDP option instead. (She has the argparse and connection setup in the right way, like you do in the examples) I am getting the error, seen in the above image.

Here is a snippet of the main loop of the program, the header of the log file has already been written, and p is the ping device.

while True:
        direction=direction*(-1)
        for x in range(61)[::direction]:
            device_data = p.transmitAngle(x)
            print(x)
            print(p.set_number_of_samples(200))
            print(p.get_device_data())
            print(device_data.gain_setting)
            print(device_data.data)

            orginal_string1 = str(datetime.datetime.now().time())[:-3]
            encoded__byte_string1 = orginal_string1.encode('utf-16-be')
            version_format = '>1i'
            a1=struct.Struct(version_format).pack(len(encoded__byte_string1.decode()))
            file.write(a1)
            file.write(encoded__byte_string1)


The code did not copy over well, so here is the main snippet!

Hi,

Please share a minimal version of your script that can replicate the issue,
the error message does not match with the snippet that you shared.
You can share the script via pastebin, paste.rs or any paste website, you can also use a git server as github or gitlab.

Hi, thanks, the problem was resolved after. I added an if statement to catch if the message returned from transmitAngle(angle) was a None type, and made some other changes since then. Am not sure what fixed it in the end, but it is working now. Also I realized this snippet that I posted was missing the part where I actually log the sensor data, though this also works in my current version.
Thanks again!