|
| 1 | +from nisystemlink.clients.core import HttpConfiguration |
| 2 | +from nisystemlink.clients.spec import SpecClient |
| 3 | +from nisystemlink.clients.spec.models import ( |
| 4 | + Condition, |
| 5 | + ConditionRange, |
| 6 | + ConditionType, |
| 7 | + CreateSpecificationsRequest, |
| 8 | + NumericConditionValue, |
| 9 | + QuerySpecificationsRequest, |
| 10 | + SpecificationDefinition, |
| 11 | + SpecificationLimit, |
| 12 | + SpecificationType, |
| 13 | +) |
| 14 | + |
| 15 | +# Setup the server configuration to point to your instance of SystemLink Enterprise |
| 16 | +server_configuration = HttpConfiguration( |
| 17 | + server_uri="https://yourserver.yourcompany.com", |
| 18 | + api_key="YourAPIKeyGeneratedFromSystemLink", |
| 19 | +) |
| 20 | +client = SpecClient(configuration=server_configuration) |
| 21 | + |
| 22 | +# Create the spec requests |
| 23 | +product = "Amplifier" |
| 24 | +spec_requests = [ |
| 25 | + SpecificationDefinition( |
| 26 | + product_id=product, |
| 27 | + spec_id="spec1", |
| 28 | + type=SpecificationType.PARAMETRIC, |
| 29 | + category="Parametric Specs", |
| 30 | + name="output voltage", |
| 31 | + limit=SpecificationLimit(min=1.2, max=1.5), |
| 32 | + unit="mV", |
| 33 | + ), |
| 34 | + SpecificationDefinition( |
| 35 | + product_id=product, |
| 36 | + spec_id="spec2", |
| 37 | + type=SpecificationType.PARAMETRIC, |
| 38 | + category="Parametric Specs", |
| 39 | + name="input voltage", |
| 40 | + limit=SpecificationLimit(min=0.02, max=0.15), |
| 41 | + unit="mV", |
| 42 | + conditions=[ |
| 43 | + Condition( |
| 44 | + name="Temperature", |
| 45 | + value=NumericConditionValue( |
| 46 | + condition_type=ConditionType.NUMERIC, |
| 47 | + range=[ConditionRange(min=-25, step=20, max=85)], |
| 48 | + unit="C", |
| 49 | + ), |
| 50 | + ), |
| 51 | + Condition( |
| 52 | + name="Supply Voltage", |
| 53 | + value=NumericConditionValue( |
| 54 | + condition_type=ConditionType.NUMERIC, |
| 55 | + discrete=[1.3, 1.5, 1.7], |
| 56 | + unit="mV", |
| 57 | + ), |
| 58 | + ), |
| 59 | + ], |
| 60 | + ), |
| 61 | + SpecificationDefinition( |
| 62 | + product_id=product, |
| 63 | + spec_id="spec3", |
| 64 | + type=SpecificationType.FUNCTIONAL, |
| 65 | + category="Noise Thresholds", |
| 66 | + name="noise", |
| 67 | + ), |
| 68 | +] |
| 69 | + |
| 70 | +# Create the specs on the server |
| 71 | +client.create_specs(CreateSpecificationsRequest(specs=spec_requests)) |
| 72 | + |
| 73 | +# You can query specs based on any field using DynamicLinq syntax. |
| 74 | +# These are just some representative examples. |
| 75 | + |
| 76 | +response = client.query_specs(QuerySpecificationsRequest(productIds=[product])) |
| 77 | +all_product_specs = response.specs |
| 78 | + |
| 79 | +# Query based on spec id |
| 80 | +response = client.query_specs( |
| 81 | + QuerySpecificationsRequest(product_ids=[product], filter='specId == "spec2"') |
| 82 | +) |
| 83 | +if response.specs: |
| 84 | + spec2 = response.specs[0] |
| 85 | + |
| 86 | +# Query based on name |
| 87 | +response = client.query_specs( |
| 88 | + QuerySpecificationsRequest(product_ids=[product], filter='name.Contains("voltage")') |
| 89 | +) |
| 90 | +voltage_specs = response.specs |
| 91 | + |
| 92 | +# Query based on Category |
| 93 | +response = client.query_specs( |
| 94 | + QuerySpecificationsRequest( |
| 95 | + product_ids=[product], filter='category == "Noise Thresholds"' |
| 96 | + ) |
| 97 | +) |
| 98 | +noise_category = response.specs |
| 99 | +print(noise_category) |
0 commit comments