Files
Automotive-Power-Simulator-App/test.py

39 lines
1.4 KiB
Python
Raw Normal View History

2026-01-07 11:47:54 +00:00
def parse_idn_response(idn_string):
"""
Parses the SCPI *IDN? response string into individual components.
Args:
idn_string: The raw string received from the instrument.
Example: "Agilent Technologies,DSO80204B,MY46002160,05.30.0005"
Returns:
A dictionary containing the manufacturer, model, serial number,
and firmware version.
"""
# Split the string by the comma delimiter
components = idn_string.strip().split(',')
if len(components) == 4:
# Assign the components to meaningful keys in a dictionary
parsed_data = {
"manufacturer": components[0],
"model": components[1],
"serial_number": components[2],
"firmware_version": components[3]
}
return parsed_data
else:
# Handle cases where the string format is unexpected
print(f"Warning: Unexpected IDN string format. Expected 4 parts, got {len(components)}.")
return {"raw_response": idn_string, "components": components}
# Example Usage:
response_string = "Agilent Technologies,DSO80204B,MY46002160,05.30.0005"
data = parse_idn_response(response_string)
# Print the resulting dictionary
print(data)
# You can access individual elements like this:
print(f"Manufacturer: {data.get('manufacturer')}")
print(f"Model: {data.get('model')}")