genicam / harvesters

Image Acquisition Library for GenICam-based Machine Vision System
Apache License 2.0
501 stars 86 forks source link

detect camera on different subnet or be able to change subnet #333

Closed BaileyHelfer closed 2 years ago

BaileyHelfer commented 2 years ago

What is the goal that you want to achieve by the request? Please describe a clear and concise description of what the motivation is. For example:

I'm not sure if there already is a way that I don't know about but being able to detect cameras on different subnets or being able to change the subnet through harvesters would be very useful. I've been able to get the subnet mask with GevInterfaceSubnetMask but if I go to change the value I get and error saying the node is not writable or something along those lines.

Additional context This would be nice for mass setting camera ip address's even if they are not on the same subnet because they can be detected and configured through the GenTL Producer if they are on different subnet so I figured you could do the same within harvesters.

olofsjo1SICKAG commented 2 years ago

The support for doing GevDeviceForceIP has recently been added to Harvester by mr Kazunari by exposing the required node map without connecting to the device. If your device supports this or not is another question since it is an optional feature in the standard.

The following code snippet is sample on how the functionality can be achived:

node_map = h.device_info_list[index].parent.node_map
node_map.GevDeviceProposeIP.execute()
node_map.GevDeviceForceIP.execute()
while not node_map.GevDeviceForceIP.is_done():
  time.sleep(0.1)
h.update()

After doing this you can connect to the camera and change the IP-settings permanently.

Which camera and cti-file are you using in your application? This is sometimes/often useful information.

BaileyHelfer commented 2 years ago

Thank you for your response. I am using Matrix Vision CTI file. I will have to try your solution and see if that is what I want accomplished. When I use GevInterfaceSubnetMask.set(4294967040) I get this error. NotImplementedError: Wrong number or type of arguments for overloaded function 'IInteger_set'. Possible C/C++ prototypes are: GENAPI_NAMESPACE::IInteger::Set(uint8_t const ,int64_t,bool) GENAPI_NAMESPACE::IInteger::Set(uint8_t const ,int64_t) But by the looks of it this has to do with the geniapi and not harvesters itself.

kazunarikudo commented 2 years ago

Hi, maybe you want to code as follows:

GevInterfaceSubnetMask.value = 4294967040  # you can assign 0xFFFFFF00 instead, of course!

I'd recommend checking this if you have time. Regards, Kazunari. (Jonas, thanks for your help!)

BaileyHelfer commented 2 years ago

Hello, when I try and set the value as such I get an error saying that the node is not writeable with this traceback... Traceback (most recent call last): File ".\temp.py", line 58, in main() File ".\temp.py", line 27, in main temp2.node_map.GevInterfaceSubnetMask.value = 4294967040 File "C:\Users\bhelf\source\repos\VISIONPRO_PYTHONCALL\myenv\lib\site-packages\genicam\genapi.py", line 2259, in setattr = lambda self, name, value: _swig_setattr(self, IInteger, name, value) File "C:\Users\bhelf\source\repos\VISIONPRO_PYTHONCALL\myenv\lib\site-packages\genicam\genapi.py", line 101, in _swig_setattr return _swig_setattr_nondynamic(self, class_type, name, value, 0) File "C:\Users\bhelf\source\repos\VISIONPRO_PYTHONCALL\myenv\lib\site-packages\genicam\genapi.py", line 93, in _swig_setattr_nondynamic object.setattr(self, name, value) File "C:\Users\bhelf\source\repos\VISIONPRO_PYTHONCALL\myenv\lib\site-packages\genicam\genapi.py", line 2351, in _set_value self._primal_set_value(value) File "C:\Users\bhelf\source\repos\VISIONPRO_PYTHONCALL\myenv\lib\site-packages\genicam\genapi.py", line 2270, in _primal_set_value return _genapi.IInteger__primal_set_value(self, Value, Verify) _genapi.AccessException: Node is not writable. : AccessException thrown in node 'GevInterfaceSubnetMask' while calling 'GevInterfaceSubnetMask.SetValue()' (file 'IntegerT.h', line 77)

Here is the code snippet that I am running:

gentl_file = r"C:\Program Files\MATRIX VISION\mvIMPACT Acquire\bin\x64\mvGenTLProducer.cti"
h.add_file(gentl_file)
h.update()
temp2 = h._ifaces[0]      # Connect through interface because device can not be seen with h.device_info_list
temp2.node_map.GevInterfaceSubnetMask.value = 4294967040
kazunarikudo commented 2 years ago

Quick question: How did you notice that the GevInterfaceSubnetMask is the feature node that you want to work with?

BaileyHelfer commented 2 years ago

Sure, I am not for certain that it is the feature node that I want to work with but I figured that it would be. I figured it would be because if I changed the subnet mask on for my Network Interface Card (NIC) to the same as camera then I can detect it. And when I print out the value of this feature node it is indeed the subnet mask of my NIC so I figured that it would be feature node to work with.

kazunarikudo commented 2 years ago

Ah, please excuse me: I had been mixed up this with another topic. However, the GevInterfaceSubnetMask is defined as a read-only node; see this standard document. Isn't it possible to set the subnet on the interface in advance without involving Harvester or other tools? You can change the IP address-related properties on the device side but as far as I check you can't on the other entities.

BaileyHelfer commented 2 years ago

Thank you for the information and the useful link. Yes it is possible to set it before hand but it could be useful to have a script to automate to check all or certain subnets for cameras and set their IP's to proper configuration but I believe this might be achievable by some other tools/libraries maybe? I just thought maybe it was possible in Harvesters.

BaileyHelfer commented 2 years ago

Is it possible to change the IP of a camera with access status as "No Access"? If the camera is on the same subnet I can see it but can't connect because it has different ip address. If I could change the IP without connection that would be useful so I can connect to it without having to change it manually.

olofsjo1SICKAG commented 2 years ago

If you are looking to change the IP-address of the camera prior to connecting to it my code snippet might be useful, we use it to change the camera IP settings when we detect a camera that we cannot connect to due to different subnets. If you want to change your local computers settings, that can also be done using Python but I assume not with Harvesters so then you need to look into using another library.

BaileyHelfer commented 2 years ago

I finally found what I was looking for..... I had to use GevDeviceForceIPAddress.set_value(some ip) & GevDeviceForceSubnetMask.set_value(some ip) and then use GevDeviceForceIP.execute() after. Thank you guys for all the help.

kazunarikudo commented 2 years ago

Thank you guys, keep happy coding.