From b4333373f577e2353900264d54541214523634d7 Mon Sep 17 00:00:00 2001 From: Christopher Stawarz Date: Wed, 22 Apr 2015 13:21:59 -0400 Subject: [PATCH 1/2] Make network node on by default in MacOSX build --- Builds/MacOSX/open-ephys.xcodeproj/project.pbxproj | 6 ++++-- open-ephys.jucer | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Builds/MacOSX/open-ephys.xcodeproj/project.pbxproj b/Builds/MacOSX/open-ephys.xcodeproj/project.pbxproj index 6de513dd9..a896d19b9 100644 --- a/Builds/MacOSX/open-ephys.xcodeproj/project.pbxproj +++ b/Builds/MacOSX/open-ephys.xcodeproj/project.pbxproj @@ -2879,6 +2879,7 @@ GCC_PREPROCESSOR_DEFINITIONS = ( "_DEBUG=1", "DEBUG=1", + "ZEROMQ", "JUCER_XCODE_MAC_F6D2F4CF=1", "JUCE_APP_VERSION=0.3.5", "JUCE_APP_VERSION_HEX=0x305", ); @@ -2888,7 +2889,7 @@ INSTALL_PATH = "$(HOME)/Applications"; LIBRARY_SEARCH_PATHS = ("$(inherited)", "\"/opt/local/lib\"", "\"/usr/local/lib\""); MACOSX_DEPLOYMENT_TARGET_ppc = 10.4; - OTHER_LDFLAGS = "-lhdf5 -lhdf5_cpp"; + OTHER_LDFLAGS = "-lhdf5 -lhdf5_cpp -lzmq"; SDKROOT_ppc = macosx10.5; }; name = Debug; }; 7A6F9B742B69F66DC3E29FA8 = {isa = XCBuildConfiguration; buildSettings = { CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; @@ -2901,6 +2902,7 @@ GCC_PREPROCESSOR_DEFINITIONS = ( "_NDEBUG=1", "NDEBUG=1", + "ZEROMQ", "JUCER_XCODE_MAC_F6D2F4CF=1", "JUCE_APP_VERSION=0.3.5", "JUCE_APP_VERSION_HEX=0x305", ); @@ -2911,7 +2913,7 @@ INSTALL_PATH = "$(HOME)/Applications"; LIBRARY_SEARCH_PATHS = ("$(inherited)", "\"/opt/local/lib\"", "\"/usr/local/lib\""); MACOSX_DEPLOYMENT_TARGET_ppc = 10.4; - OTHER_LDFLAGS = "-lhdf5 -lhdf5_cpp"; + OTHER_LDFLAGS = "-lhdf5 -lhdf5_cpp -lzmq"; SDKROOT_ppc = macosx10.5; }; name = Release; }; C8018C9A4DA633CA60663294 = {isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; diff --git a/open-ephys.jucer b/open-ephys.jucer index 6ec5539a1..49c313a5e 100644 --- a/open-ephys.jucer +++ b/open-ephys.jucer @@ -12,7 +12,8 @@ includeBinaryInAppConfig="1"> + extraLinkerFlags="-lhdf5 -lhdf5_cpp -lzmq" objCExtraSuffix="fea2mT" + extraDefs="ZEROMQ"> Date: Thu, 21 May 2015 14:47:25 -0400 Subject: [PATCH 2/2] Fixed bug in NetworkEvents::createZmqContext. Added Python example script for sending network events. --- Resources/Python/network_events_console.py | 28 +++++++++++++++++++ .../NetworkEvents/NetworkEvents.cpp | 4 +-- 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 Resources/Python/network_events_console.py diff --git a/Resources/Python/network_events_console.py b/Resources/Python/network_events_console.py new file mode 100644 index 000000000..8459862f5 --- /dev/null +++ b/Resources/Python/network_events_console.py @@ -0,0 +1,28 @@ +from __future__ import print_function, unicode_literals + +import zmq + +try: + raw_input +except NameError: + # Python 3 + raw_input = input + + +def run(hostname='localhost', port=5556): + with zmq.Context() as ctx: + with ctx.socket(zmq.REQ) as sock: + sock.connect('tcp://%s:%d' % (hostname, port)) + while True: + try: + req = raw_input('> ') + sock.send_string(req) + rep = sock.recv_string() + print(rep) + except EOFError: + print() # Add final newline + break + + +if __name__ == '__main__': + run() diff --git a/Source/Processors/NetworkEvents/NetworkEvents.cpp b/Source/Processors/NetworkEvents/NetworkEvents.cpp index b2f978bc8..3b8fefc97 100644 --- a/Source/Processors/NetworkEvents/NetworkEvents.cpp +++ b/Source/Processors/NetworkEvents/NetworkEvents.cpp @@ -449,7 +449,7 @@ void NetworkEvents::run() if (rc != 0) { // failed to open socket? - std::cout << "Failed to open socket." << std::endl; + std::cout << "Failed to open socket: " << zmq_strerror(zmq_errno()) << std::endl; return; } @@ -562,7 +562,7 @@ void NetworkEvents::loadCustomParametersFromXml() void NetworkEvents::createZmqContext() { #ifdef ZEROMQ - if (zmqcontext != nullptr) + if (zmqcontext == nullptr) zmqcontext = zmq_ctx_new(); //<-- this is only available in version 3+ #endif } \ No newline at end of file