本文整理汇总了C++中mm::Core::GetSerialAnswer方法的典型用法代码示例。如果您正苦于以下问题:C++ Core::GetSerialAnswer方法的具体用法?C++ Core::GetSerialAnswer怎么用?C++ Core::GetSerialAnswer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mm::Core
的用法示例。
在下文中一共展示了Core::GetSerialAnswer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
示例4: 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
{
unsigned char c[2];
c[0]=0x01;
c[1]=0x02;
ret = core.WriteToSerial(&device, port_.c_str(), c, 2);
//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;
// printf("c:%x i:%u j:%ld\n", answer[i], i, j);
read++;
}
} else // TODO: check that we have a USB port
{
// 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;
std::ostringstream os;
os << "LMM5 answered: ";
for (unsigned int i=0; i < read; i++)
os << std::hex << answer[i];
os << std::endl;
core.LogMessage(&device, os.str().c_str(), true);
}
return DEVICE_OK;
}
示例5: 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();
}
示例6: ClearAllRcvBuf
/*
* Queries CSU for current NIR Shutter
*/
int CSUW1Hub::GetNIRShutterPosition(MM::Device& device, MM::Core& core, bool& open)
{
ClearAllRcvBuf(device, core);
int ret = ExecuteCommand(device, core, "SH2, ?");
// analyze what comes back:
ret = core.GetSerialAnswer(&device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\r");
if (ret != DEVICE_OK)
return ret;
open = (strstr(rcvBuf_, "OPEN") != 0);
return DEVICE_OK;
}
示例7: GetPrismSliderPosition
int CARVIIHub::GetPrismSliderPosition(MM::Device& device, MM::Core& core, int pos) {
ClearAllRcvBuf(device, core);
int ret = ExecuteCommand(device, core, "rP");
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
pos = rcvBuf_[2];
return DEVICE_OK;
}
示例8: GetShutterPosition
int CARVIIHub::GetShutterPosition(MM::Device& device, MM::Core& core, int pos) {
ClearAllRcvBuf(device, core);
int ret = ExecuteCommand(device, core, "rS");
// analyze what comes back:
ret = core.GetSerialAnswer(&device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\r");
if (ret != DEVICE_OK)
return ret;
//CARVII echoes command, shutter position is in bit 3
pos = rcvBuf_[2];
return DEVICE_OK;
}
示例9: 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;
}
示例10: 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;
}
示例11:
/*
* An 'A' acknowledges receipt of a command, ('N' means it is not understood)
* Function is not really appropriately named
*/
int CSU22Hub::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;
if (rcvBuf_[1]=='N')
return 1;
if (rcvBuf_[1]!='A')
return DEVICE_SERIAL_INVALID_RESPONSE;
return DEVICE_OK;
}
示例12: GetDichroicPosition
int CSUXHub::GetDichroicPosition(MM::Device& device, MM::Core& core, long &dichroic)
{
ClearAllRcvBuf(device, core);
int ret = ExecuteCommand(device, core, "DM_POS, ?");
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;
dichroic = atol(rcvBuf_);
return DEVICE_OK;
}
示例13: GetShutterPosition
/*
* 1 = closed
* 0 = open
*/
int CSUXHub::GetShutterPosition(MM::Device& device, MM::Core& core, int& pos)
{
ClearAllRcvBuf(device, core);
int ret = ExecuteCommand(device, core, "SH, ?");
// analyze what comes back:
ret = core.GetSerialAnswer(&device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\r");
if (ret != DEVICE_OK)
return ret;
if (strstr(rcvBuf_, "CLOSE") != 0)
pos = 1;
pos = 0;
return DEVICE_OK;
}
示例14: GetMaxDriveSpeed
/*
* Reports the maximum drive speed available from this model
*/
int CSUXHub::GetMaxDriveSpeed(MM::Device& device, MM::Core& core, long& maxSpeed)
{
ClearAllRcvBuf(device, core);
int ret = ExecuteCommand(device, core, "MS_MAX, ?");
// analyze what comes back:
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;
maxSpeed = atol(rcvBuf_);
return DEVICE_OK;
}
示例15: GetFilterWheelSpeed
/*
* Gets speed of filter wheel (0-3)
*/
int CSUXHub::GetFilterWheelSpeed(MM::Device& device, MM::Core& core, long wheelNr, long& speed)
{
ClearAllRcvBuf(device, core);
ostringstream os;
os << "FW_SPEED, " << wheelNr << ", ?";
int ret = ExecuteCommand(device, core, os.str().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;
speed = atol(rcvBuf_);
return DEVICE_OK;
}