forked from micro-manager/mmCoreAndDevices
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request micro-manager#359 from martinzak-zaber/zaber-zml
Adding ZML and Objective Changer
- Loading branch information
Showing
19 changed files
with
950 additions
and
689 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include "ConnectionManager.h" | ||
|
||
std::shared_ptr<zml::Connection> ConnectionManager::getConnection(std::string port) | ||
{ | ||
std::lock_guard<std::mutex> lockGuard(lock_); | ||
if (connections_.count(port) > 0) { | ||
if (auto connectionPtr = connections_.at(port).lock()) { | ||
return connectionPtr; | ||
} | ||
} | ||
|
||
auto connection = std::make_shared<zml::Connection>(zml::Connection::openSerialPort(port)); | ||
auto id = connection->getInterfaceId(); | ||
connection->getDisconnected().subscribe([=](std::shared_ptr<zmlbase::MotionLibException>) { | ||
removeConnection(port, id); | ||
}); | ||
connections_[port] = connection; | ||
|
||
return connection; | ||
} | ||
|
||
bool ConnectionManager::removeConnection(std::string port, int interfaceId) | ||
{ | ||
std::lock_guard<std::mutex> lockGuard(lock_); | ||
if (connections_.count(port) == 0) { | ||
return false; | ||
} | ||
|
||
if (interfaceId != -1) { | ||
if (auto connection = connections_.at(port).lock()) { | ||
if (connection->getInterfaceId() != interfaceId) { | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
connections_.erase(port); | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
|
||
#include <MMDevice.h> | ||
#include <zaber/motion/ascii/connection.h> | ||
#include <map> | ||
#include <string> | ||
#include <mutex> | ||
#include <memory> | ||
|
||
namespace zmlbase = zaber::motion; | ||
namespace zml = zaber::motion::ascii; | ||
|
||
class ConnectionManager | ||
{ | ||
public: | ||
std::shared_ptr<zml::Connection> getConnection(std::string port); | ||
bool removeConnection(std::string port, int interfaceId = -1); | ||
private: | ||
std::mutex lock_; | ||
std::map<std::string, std::weak_ptr<zml::Connection>> connections_; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.