int GenericSLM::OnGraphicsPort(MM::PropertyBase* pProp, MM::ActionType eAct) { if (eAct == MM::BeforeGet) { pProp->Set((const char *) graphicsPortDescription_.c_str()); } else if (eAct == MM::AfterSet) { long graphicsPortNum; pProp->Get(graphicsPortDescription_); GetCurrentPropertyData(g_Graphics_Port,graphicsPortNum); chosenDisplayIndex_ = graphicsPortNum; DetachDisplayDevice(&displays_[chosenDisplayIndex_]); } return HandleErrors(); }
int SerialPort::OnHandshaking(MM::PropertyBase* /*pProp*/, MM::ActionType eAct) { if (eAct == MM::BeforeGet) { // nothing to do } else if (eAct == MM::AfterSet) { if (initialized_) { long handshake; int ret; ret = GetCurrentPropertyData(MM::g_Keyword_Handshaking, handshake); if (ret != DEVICE_OK) return ret; pPort_->ChangeFlowControl(boost::asio::serial_port_base::flow_control::type(handshake)); } } return DEVICE_OK; }
int SerialPort::Initialize() { if (initialized_) return DEVICE_OK; // do not initialize if this port has been blacklisted std::vector<std::string>::iterator it = g_BlackListedPorts.begin(); while (it < g_BlackListedPorts.end()) { if( portName_ == (*it)) return ERR_PORT_BLACKLISTED; it++; } long sb; int ret = GetPropertyData(MM::g_Keyword_StopBits, stopBits_.c_str(), sb); assert(ret == DEVICE_OK); long parity; ret = GetPropertyData(MM::g_Keyword_Parity, parity_.c_str(), parity); long baud; ret = GetCurrentPropertyData(MM::g_Keyword_BaudRate, baud); assert(ret == DEVICE_OK); long handshake; ret = GetCurrentPropertyData(MM::g_Keyword_Handshaking, handshake); assert(ret == DEVICE_OK); pService_ = new boost::asio::io_service(); try { pPort_ = new AsioClient (*pService_, boost::lexical_cast<unsigned int>(baud), this->portName_, boost::asio::serial_port_base::flow_control::type(handshake), boost::asio::serial_port_base::parity::type(parity), boost::asio::serial_port_base::stop_bits::type(sb), this ); } catch( std::exception& what) { LogMessage(what.what(),false); return DEVICE_ERR; } try { pThread_ = new boost::thread(boost::bind(&boost::asio::io_service::run, pService_)); } catch(std::exception& what) { LogMessage(what.what(), false); return DEVICE_ERR; } ret = UpdateStatus(); if (ret != DEVICE_OK) return ret; initialized_ = true; return DEVICE_OK; }