-
Notifications
You must be signed in to change notification settings - Fork 14
/
sample_network_configuration.py
66 lines (51 loc) · 1.95 KB
/
sample_network_configuration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""Sample demonstrating network configuration of a Zivid camera."""
import zivid
def _confirm(message):
while True:
input_value = input(f"{message} [Y/n] ")
if input_value.lower() in ["y", "yes"]:
return True
if input_value.lower() in ["n", "no"]:
return False
def _main():
app = zivid.Application()
camera = app.cameras()[0]
original_config = camera.network_configuration
print(f"Current network configuration of camera {camera.info.serial_number}:")
print(original_config)
print()
mode = zivid.NetworkConfiguration.IPV4.Mode.manual
address = original_config.ipv4.address
subnet_mask = original_config.ipv4.subnet_mask
if _confirm("Do you want to use DHCP?"):
mode = zivid.NetworkConfiguration.IPV4.Mode.dhcp
else:
input_address = input(f"Enter IPv4 Address [{original_config.ipv4.address}]: ")
address = input_address if input_address else original_config.ipv4.address
input_subnet_mask = input(
f"Enter new Subnet mask [{original_config.ipv4.subnet_mask}]: "
)
subnet_mask = (
input_subnet_mask if input_subnet_mask else original_config.ipv4.subnet_mask
)
new_config = zivid.NetworkConfiguration(
ipv4=zivid.NetworkConfiguration.IPV4(
mode=mode,
address=address,
subnet_mask=subnet_mask,
)
)
print()
print("New network configuration:")
print(new_config)
if _confirm(
f"Do you want to apply the new network configuration to camera {camera.info.serial_number}?"
):
print("Applying network configuration...")
camera.apply_network_configuration(new_config)
print(f"Updated network configuration of camera {camera.info.serial_number}:")
print(camera.network_configuration)
print()
print(f"Camera status is '{camera.state.status}'")
if __name__ == "__main__":
_main()