Skip to content

Commit e6c83b6

Browse files
Added ics.enable_network_com() method.
Signed-off-by: David Rebbe <drebbe@intrepidcs.com> # Conflicts: # include/methods.h
1 parent ba95612 commit e6c83b6

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

include/methods.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ PyObject* meth_set_fd_bit_rate(PyObject* self, PyObject* args);
7979
PyObject* meth_set_bit_rate_ex(PyObject* self, PyObject* args);
8080
PyObject* meth_get_timestamp_for_msg(PyObject* self, PyObject* args);
8181
PyObject* meth_get_device_status(PyObject* self, PyObject* args);
82+
PyObject* meth_enable_network_com(PyObject* self, PyObject* args);
8283

8384
#ifdef _cplusplus
8485
}
@@ -1190,6 +1191,30 @@ PyObject* meth_get_device_status(PyObject* self, PyObject* args);
11901191
"\t>>> status.fire2Status.ethernetActivationLineEnabled\n" \
11911192
"\t0\n" \
11921193

1194+
#define _DOC_ENABLE_NETWORK_COM \
1195+
MODULE_NAME".enable_network_com(device, enable, net_id)\n" \
1196+
"\n" \
1197+
"Enable or disable network communication.\n" \
1198+
"\n" \
1199+
"Args:\n" \
1200+
"\tdevice (:class:`"MODULE_NAME"."NEO_DEVICE_OBJECT_NAME"`): :class:`"MODULE_NAME"."NEO_DEVICE_OBJECT_NAME"`\n\n" \
1201+
"\n" \
1202+
"\tenable (:class:`bool`): :class:`bool`\n\n" \
1203+
"\n" \
1204+
"\tnet_id (:class:`int`): :class:`int`: Optional. If left blank, disables/enables all networks.\n\n" \
1205+
"\n" \
1206+
"Raises:\n" \
1207+
"\t:class:`"MODULE_NAME".RuntimeError`\n" \
1208+
"\n" \
1209+
"Returns:\n" \
1210+
"\tNone.\n" \
1211+
"\n" \
1212+
"\t>>> import ics\n" \
1213+
"\t>>> d = ics.open_device()\n" \
1214+
"\t>>> status = ics.enable_network_com(d, True)\n" \
1215+
"\t>>> \n"
1216+
1217+
11931218
static PyMethodDef IcsMethods[] = {
11941219
_EZ_ICS_STRUCT_METHOD("find_devices", "FindNeoDevices", (PyCFunction)meth_find_devices, METH_VARARGS | METH_KEYWORDS, _DOC_FIND_DEVICES),
11951220
_EZ_ICS_STRUCT_METHOD("open_device", "OpenNeoDevice", (PyCFunction)meth_open_device, METH_VARARGS | METH_KEYWORDS, _DOC_OPEN_DEVICES),
@@ -1258,6 +1283,7 @@ static PyMethodDef IcsMethods[] = {
12581283
_EZ_ICS_STRUCT_METHOD("get_timestamp_for_msg", "icsneoGetTimeStampForMsg", meth_get_timestamp_for_msg, METH_VARARGS, _DOC_GET_TIMESTAMP_FOR_MSG),
12591284
_EZ_ICS_STRUCT_METHOD("get_device_status", "icsneoGetDeviceStatus", meth_get_device_status, METH_VARARGS, _DOC_GET_DEVICE_STATUS),
12601285

1286+
_EZ_ICS_STRUCT_METHOD("enable_network_com", "icsneoEnableNetworkCom", meth_enable_network_com, METH_VARARGS, _DOC_ENABLE_NETWORK_COM),
12611287
{"override_library_name", (PyCFunction)meth_override_library_name, METH_VARARGS, _DOC_OVERRIDE_LIBRARY_NAME},
12621288
{"get_library_path", (PyCFunction)meth_get_library_path, METH_NOARGS, ""},
12631289

src/methods.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4040,6 +4040,51 @@ PyObject* meth_get_device_status(PyObject* self, PyObject* args)
40404040
return set_ics_exception(exception_runtime_error(), "This is a bug!");
40414041
}
40424042

4043+
PyObject* meth_enable_network_com(PyObject* self, PyObject* args)
4044+
{
4045+
PyObject* obj = NULL;
4046+
bool enable = true;
4047+
long net_id = -1;
4048+
if (!PyArg_ParseTuple(args, arg_parse("O|bk:", __FUNCTION__), &obj, &enable, &net_id)) {
4049+
return NULL;
4050+
}
4051+
if (!PyNeoDevice_CheckExact(obj)) {
4052+
return set_ics_exception(exception_runtime_error(), "Argument must be of type " MODULE_NAME "." NEO_DEVICE_OBJECT_NAME);
4053+
}
4054+
ICS_HANDLE handle = PyNeoDevice_GetHandle(obj);
4055+
try
4056+
{
4057+
ice::Library* lib = dll_get_library();
4058+
if (!lib) {
4059+
char buffer[512];
4060+
return set_ics_exception(exception_runtime_error(), dll_get_error(buffer));
4061+
}
4062+
// int _stdcall icsneoEnableNetworkCom(void* hObject, int iEnable)
4063+
// int _stdcall icsneoEnableNetworkComEx(void* hObject, int iEnable, int iNetId)
4064+
ice::Function<int __stdcall (ICS_HANDLE, int)> icsneoEnableNetworkCom(lib, "icsneoEnableNetworkCom");
4065+
ice::Function<int __stdcall (ICS_HANDLE, int, int)> icsneoEnableNetworkComEx(lib, "icsneoEnableNetworkComEx");
4066+
Py_BEGIN_ALLOW_THREADS
4067+
if (net_id == -1) {
4068+
if (!icsneoEnableNetworkCom(handle, enable)) {
4069+
Py_BLOCK_THREADS
4070+
return set_ics_exception(exception_runtime_error(), "icsneoEnableNetworkCom() Failed");
4071+
}
4072+
} else {
4073+
if (!icsneoEnableNetworkComEx(handle, enable, net_id)) {
4074+
Py_BLOCK_THREADS
4075+
return set_ics_exception(exception_runtime_error(), "icsneoEnableNetworkComEx() Failed");
4076+
}
4077+
}
4078+
Py_END_ALLOW_THREADS
4079+
Py_RETURN_NONE;
4080+
}
4081+
catch (ice::Exception& ex)
4082+
{
4083+
return set_ics_exception(exception_runtime_error(), (char*)ex.what());
4084+
}
4085+
return set_ics_exception(exception_runtime_error(), "This is a bug!");
4086+
}
4087+
40434088
PyObject* meth_override_library_name(PyObject* self, PyObject* args)
40444089
{
40454090
const char* name = NULL;

0 commit comments

Comments
 (0)