本文整理汇总了C++中mm::Core类的典型用法代码示例。如果您正苦于以下问题:C++ Core类的具体用法?C++ Core怎么用?C++ Core使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Core类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ClearAllRcvBuf
int ASIFW1000Hub::FilterWheelBusy(MM::Device& device, MM::Core& core, bool& busy)
{
ClearAllRcvBuf(device, core);
int ret = core.SetSerialCommand(&device, port_.c_str(), "?", "");
if (ret != DEVICE_OK)
return ret;
unsigned long read = 0;
MM::MMTime startTime = core.GetCurrentMMTime();
while (read == 0 && ( (core.GetCurrentMMTime() - startTime) < 10000))
ret = core.ReadFromSerial(&device, port_.c_str(), (unsigned char*)rcvBuf_, 1, read);
if (ret != DEVICE_OK)
return ret;
if (read != 1) {
printf (" FilterWheel received no answer!\n");
return ERR_NO_ANSWER;
}
if (rcvBuf_[0] == '0' || rcvBuf_[0] == '1' || rcvBuf_[0] =='2')
busy = false;
else
if (rcvBuf_[0] == '3')
busy = true;
return DEVICE_OK;
}
示例2: ExecuteCommand
/*
* 1 = open
* 0 = close
*/
int ASIFW1000Hub::GetShutterPosition(MM::Device& device, MM::Core& core, int shutterNr, bool& pos)
{
//ClearAllRcvBuf(device, core);
ostringstream os;
os << "SQ " << shutterNr;
int ret = ExecuteCommand(device, core, os.str().c_str());
// analyze answer
ret = core.GetSerialAnswer(&device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\n\r");
if (ret != DEVICE_OK)
return ret;
string response = rcvBuf_;
// If the answer is too short, there is likely no shutter card (we could do a better check)
if (response.length() < 2)
{
return ERR_SHUTTER_NOT_FOUND;
}
int x = atoi(response.substr(response.length() - 2).c_str());
// sometimes, the controller does not answer, but sends 0. ask once more
if (x < 16)
{
ret = ExecuteCommand(device, core, os.str().c_str());
ret = core.GetSerialAnswer(&device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\n\r");
response = rcvBuf_;
x = atoi(response.substr(response.length() - 2).c_str());
}
if (shutterNr==1)
x = x >> 1;
pos = x & 1;
return DEVICE_OK;
}
示例3: ClearPort
//
// General utility function
//
int ClearPort(MM::Device& device, MM::Core& core, const char* sPort)
{
// Clear contents of serial port
const int nBufSize = 255;
unsigned char sClear[nBufSize];
unsigned long lRead = nBufSize;
int ret;
// reset the communication port buffer
while ((int) lRead == nBufSize)
{
// reading from the serial port
ret = core.ReadFromSerial(&device, sPort, sClear, nBufSize, lRead);
std::ostringstream sMessage;
sMessage << "<nPC400::ClearPort> port = (" << sPort << ") :: clearBuffer(" << lRead << ") = (" << sClear << ")";
core.LogMessage(&device, sMessage.str().c_str(), false);
// verify the read operation
if (ret != DEVICE_OK) return ret;
}
// upon successful restting the port
return DEVICE_OK;
}
示例4: StopCameraAcquisition
/**
* Stop Seq sequence acquisition
* This is the function for internal use and can/should be called from the thread
*/
int DVCCamera::StopCameraAcquisition() {
{
DriverGuard dg(this);
HANDLE hCam = camMap_[m_camId];
if (!sequenceRunning_)
return DEVICE_OK;
LogMessage("Stopped sequence acquisition");
dvcStopSequence(hCam);
int state;
unsigned long remaining;
dvcGetStreamState(hCam, &state, &remaining);
while (state != DVC_IDLE) {
CDeviceUtils::SleepMs(100);
dvcGetStreamState(hCam, &state, &remaining);
}
sequenceRunning_ = false;
}
MM::Core* cb = GetCoreCallback();
if (cb)
return cb->AcqFinished(this, 0);
else
return DEVICE_OK;
}
示例5: sprintf
/*
* The Spectral LMM5 has a silly difference between USB and serial communication:
* Commands can be sent straight to USB. Commands to the serial port need to converted in some kind of weird ASCI: The command "0x1A0xFF0x000x12<CR>" becomes "1AFF0012<CR>". Presumably, the same weird conversion takes place on the way back. We handle this translation in this function
*/
int SpectralLMM5Interface::ExecuteCommand(MM::Device& device, MM::Core& core, unsigned char* buf, unsigned long bufLen, unsigned char* answer, unsigned long answerLen, unsigned long& read)
{
int ret;
if (portType_ == MM::SerialPort)
{
std::string serialCommand;
char tmp[3];
tmp[2] = 0;
for (unsigned long i=0; i<bufLen; i++) {
sprintf(tmp, "%.2x", buf[i]);
serialCommand += tmp;
}
ret = core.SetSerialCommand(&device, port_.c_str(), serialCommand.c_str(), "\r");
} else // check for USB port
{
ret = core.WriteToSerial(&device, port_.c_str(), buf, bufLen);
}
if (ret != DEVICE_OK)
return ret;
if (portType_ == MM::SerialPort)
{
char strAnswer[128];
read = 0;
ret = core.GetSerialAnswer(&device, port_.c_str(), 128, strAnswer, "\r");
if (ret != DEVICE_OK)
return ret;
std::ostringstream os;
os << "LMM5 answered: " << strAnswer << " Port status: " << ret;
core.LogMessage(&device, os.str().c_str(), true);
// 'translate' back into numbers:
std::string tmp = strAnswer;
for (unsigned int i=0; i < tmp.length()/2; i++) {
char * end;
long j = strtol(tmp.substr(i*2,2).c_str(), &end, 16);
answer[i] = (unsigned char) j;
read++;
}
} else if (portType_ == MM::HIDPort)
{
// The USB port will attempt to read up to answerLen characters
ret = core.ReadFromSerial(&device, port_.c_str(), answer, answerLen, read);
if (ret != DEVICE_OK)
return ret;
/*
// Uncomment for debugging (although port should give the same info)
std::ostringstream os;
os << "LMM5 answered: " << std::hex << std::setfill('0');
for (unsigned int i=0; i < read; i++)
os << std::setw(2) << (unsigned int) answer[i] << " ";
core.LogMessage(&device, os.str().c_str(), true);
*/
}
return DEVICE_OK;
}
示例6: SetCurrentWheel
int ASIFW1000Hub::SetFilterWheelPosition(MM::Device& device, MM::Core& core, int wheelNr, int pos)
{
if (wheelNr != activeWheel_)
// TODO: error checking
SetCurrentWheel(device, core, wheelNr);
const char* command = "MP ";
ostringstream os;
os << command << pos;
// send command
int ret = ExecuteCommand(device, core, os.str().c_str());
if (ret != DEVICE_OK)
return ret;
// devices echos command and returns position
ret = core.GetSerialAnswer(&device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\n\r");
if (ret != DEVICE_OK)
return ret;
int posread = rcvBuf_[strlen(rcvBuf_)-1] - '0';
if ( pos != posread)
return ERR_SETTING_WHEEL;
return DEVICE_OK;
}
示例7: ClearAllRcvBuf
/**
* Clears the serial receive buffer.
*/
void CARVIIHub::ClearAllRcvBuf(MM::Device& device, MM::Core& core) {
// Read whatever has been received so far:
unsigned long read;
core.ReadFromSerial(&device, port_.c_str(), (unsigned char*) rcvBuf_, RCV_BUF_LENGTH, read);
// Delete it all:
memset(rcvBuf_, 0, RCV_BUF_LENGTH);
}
示例8: GetAcknowledgment
/*
* An 'A' acknowledges receipt of a command, ('N' means it is not understood)
* Function is not really appropriately named
*/
int CSUXHub::GetAcknowledgment(MM::Device& device, MM::Core& core)
{
// block until we get a response
int ret = core.GetSerialAnswer(&device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\r");
if (ret != DEVICE_OK)
return ret;
return Acknowledge();
}
示例9: sprintf
/*
* The LMM5 USB HID commands are a sequence of binary bytes with no terminator.
* The serial commands are the same bytes formatted as an ASCII hex string, two
* characters per byte, and terminated with a CR; e.g.:
* USB: "\x1a\xff\x00\x12" (4 bytes)
* RS-232: "1AFF0012\r" (9 bytes)
* The opposite transformation takes place for the reply.
*
* This function abstracts these differences. Note that the exact answerLen is
* important for USB HID: reading excess bytes can result in garbage being
* appended to the reply (at least on Windows).
*/
int SpectralLMM5Interface::ExecuteCommand(MM::Device& device, MM::Core& core, unsigned char* buf, unsigned long bufLen, unsigned char* answer, unsigned long answerLen, unsigned long& read)
{
int ret;
if (portType_ == MM::SerialPort)
{
std::string serialCommand;
char tmp[3];
tmp[2] = 0;
for (unsigned long i=0; i<bufLen; i++) {
sprintf(tmp, "%.2x", buf[i]);
serialCommand += tmp;
}
ret = core.SetSerialCommand(&device, port_.c_str(), serialCommand.c_str(), "\r");
} else // check for USB port
{
ret = core.WriteToSerial(&device, port_.c_str(), buf, bufLen);
}
if (ret != DEVICE_OK)
return ret;
if (portType_ == MM::SerialPort)
{
char strAnswer[128];
read = 0;
ret = core.GetSerialAnswer(&device, port_.c_str(), 128, strAnswer, "\r");
if (ret != DEVICE_OK)
return ret;
// 'translate' back into numbers:
std::string tmp = strAnswer;
for (unsigned int i=0; i < tmp.length()/2; i++) {
char * end;
long j = strtol(tmp.substr(i*2,2).c_str(), &end, 16);
answer[i] = (unsigned char) j;
read++;
}
} else if (portType_ == MM::HIDPort)
{
// The USB port will attempt to read up to answerLen characters
ret = core.ReadFromSerial(&device, port_.c_str(), answer, answerLen, read);
if (ret != DEVICE_OK)
return ret;
}
return DEVICE_OK;
}
示例10: ClearAllRcvBuf
/*
* Queries CSU for current Aperture position
* 0 = Position 1
* 1 = Position 2
* ***
* 9 = Position 10
*/
int CSUW1Hub::GetAperturePosition(MM::Device& device, MM::Core& core, int& pos)
{
ClearAllRcvBuf(device, core);
std::string cmd;
cmd = "AP_WIDTH,1,?";
int ret = ExecuteCommand(device, core, cmd.c_str());
ret = core.GetSerialAnswer(&device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\r");
if (ret != DEVICE_OK)
return ret;
ret = Acknowledge();
if (ret != DEVICE_OK)
return ret;
std::ostringstream os;
os << "Get Aperture answer is: " << rcvBuf_;
core.LogMessage(&device, os.str().c_str(), false);
pos = atoi(rcvBuf_) - 1;
return DEVICE_OK;
}
示例11: ExecuteCommand
/**
* Sends serial command to the MMCore virtual serial port.
*/
int CARVIIHub::ExecuteCommand(MM::Device& device, MM::Core& core, const char* command) {
// empty the Rx serial buffer before sending command
//FetchSerialData(device, core);
ClearAllRcvBuf(device, core);
// send command
return core.SetSerialCommand(&device, port_.c_str(), command, "\r");
}
示例12: while
/**
* Clears the serial receive buffer.
*/
void ASIFW1000Hub::ClearAllRcvBuf(MM::Device& device, MM::Core& core)
{
// Read whatever has been received so far:
unsigned long read = RCV_BUF_LENGTH;
while (read == (unsigned long) RCV_BUF_LENGTH)
{
core.ReadFromSerial(&device, port_.c_str(), (unsigned char*)rcvBuf_, RCV_BUF_LENGTH, read);
}
// Delete it all:
memset(rcvBuf_, 0, RCV_BUF_LENGTH);
}
示例13: ClearAllRcvBuf
/**
* Sends serial command to the MMCore virtual serial port.
*/
int ASIFW1000Hub::ExecuteCommand(MM::Device& device, MM::Core& core, const char* command)
{
std::string base_command = "";
ClearAllRcvBuf(device, core);
if (oldProtocol_)
base_command += "3F"; // prefix to all commands for old devices
base_command += command;
// send command
return core.SetSerialCommand(&device, port_.c_str(), base_command.c_str(), "\r");
}
示例14: ClearAllRcvBuf
/*
* TODO: improve error reporting
*/
int CSU22Hub::GetDriveSpeedPosition(MM::Device& device, MM::Core& core, int& pos)
{
ClearAllRcvBuf(device, core);
int ret = ExecuteCommand(device, core, "rsm");
// analyze what comes back:
ret = core.GetSerialAnswer(&device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\r");
if (ret != DEVICE_OK)
return ret;
int speed = atoi(rcvBuf_);
pos = speed;
return DEVICE_OK;
}
示例15: GetTouchScreenState
int CARVIIHub::GetTouchScreenState(MM::Device& device, MM::Core& core, int state) {
ClearAllRcvBuf(device, core);
int ret = ExecuteCommand(device, core, "rM");
ret = core.GetSerialAnswer(&device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\r");
if (ret != DEVICE_OK)
return ret;
// CARVII echoes command, motor state is in bit 3
state = rcvBuf_[2];
return DEVICE_OK;
}