Skip to content

Commit 3143c67

Browse files
bparks13anjaldoshi
authored andcommitted
Gracefully disconnect socket when acquisition stops
- If the server was disconnected during acquisition, and the plugin is trying to automatically reconnect, it will now disconnect if acquisition stops to prevent it going into an unrecoverable state - Update the Python script so it waits to initialize the server until after the user provides keyboard input. This prevents the client from connecting, deciding it can't read any data, and disconnecting - Bump version to 0.5.1
1 parent e8fcd4b commit 3143c67

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ if(MSVC)
6565
target_compile_options(${PLUGIN_NAME} PRIVATE /sdl- /W0)
6666

6767
install(TARGETS ${PLUGIN_NAME} RUNTIME DESTINATION ${GUI_BIN_DIR}/plugins CONFIGURATIONS ${CMAKE_CONFIGURATION_TYPES})
68+
install(FILES $<TARGET_PDB_FILE:${PLUGIN_NAME}> DESTINATION ${GUI_BIN_DIR}/plugins OPTIONAL)
6869

6970
set(CMAKE_PREFIX_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../libs)
7071
elseif(LINUX)

Resources/python-example-tcp.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@
3838
oneCycle = np.concatenate((intList_1, intList_2))
3939
allData = np.tile(oneCycle, (numChannels, totalDuration)).T
4040

41+
# ---- WAIT FOR USER INPUT ---- #
42+
value = input("Press enter key to start...")
43+
4144
# ---- CREATE THE SOCKET SERVER ---- #
4245
tcpServer = socket.socket(family=socket.AF_INET, type=socket.SOCK_STREAM)
4346
tcpServer.bind(('localhost', 9001))
4447
tcpServer.listen(1)
4548

46-
# ---- WAIT FOR USER INPUT ---- #
47-
value = input("Press enter key to start...")
48-
4949
print("Waiting for external connection to start...")
5050
(tcpClient, address) = tcpServer.accept()
5151
print("Connected.")
@@ -75,3 +75,9 @@ def currentTime():
7575
print("Done")
7676
except BrokenPipeError:
7777
print("Connection closed by the server. Unable to send data. Exiting...")
78+
79+
except ConnectionAbortedError:
80+
print("Connection was aborted, unable to send data. Try disconnecting and reconnecting the remote client. Exiting...")
81+
82+
except ConnectionResetError:
83+
print("Connection was aborted, unable to send data. Try disconnecting and reconnecting the remote client. Exiting...")

Source/EphysSocket.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ void EphysSocket::registerParameters()
4646

4747
void EphysSocket::disconnectSocket()
4848
{
49+
socket.signalThreadShouldExit();
50+
socket.waitForThreadToExit(1000);
4951
socket.disconnectSocket();
5052

5153
getParameter ("port")->setEnabled (true);

Source/OpenEphysLib.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ extern "C" EXPORT void getLibInfo (Plugin::LibraryInfo* info)
3838
{
3939
info->apiVersion = PLUGIN_API_VER;
4040
info->name = "Ephys Socket";
41-
info->libVersion = "0.5.0";
41+
info->libVersion = "0.5.1";
4242
info->numPlugins = NUM_PLUGINS;
4343
}
4444

Source/SocketThread.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ void SocketThread::startAcquisition()
4747
void SocketThread::stopAcquisition()
4848
{
4949
acquiring = false;
50+
51+
if (shouldReconnect)
52+
{
53+
processor->disconnectSocket();
54+
}
5055
}
5156

5257
bool SocketThread::connectSocket (int port, bool printOutput)

0 commit comments

Comments
 (0)