Commit 2549a6da authored by Cristina Cocho's avatar Cristina Cocho

move tray to front position if stop is executed

parent 247dd117
......@@ -46,17 +46,8 @@ void RealAliasDriver::init() {
owner()->write(message, size);
owner()->read(buf, ack);
// Move also the tray to front position
// (1) Set program option "move tray" to front
// code STX | 6 1 | 0 1 | 0 8 3 0 | SP SP SP SP SP X | ETX -> x = 0 home, x = 1 front
unsigned char trayMoveMess[SIZE] = { STX, '6', '1', '0', '1', '0', '8', '3', '0', SP, SP, SP, SP, SP, '1', ETX };
owner()->write(trayMoveMess, SIZE);
owner()->read(buf, ack);
// (2) Start/stop user program value previously loaded
unsigned char startProgramMess[SIZE] = { STX, '6', '1', '0', '1', '5', '1', '0', '0', '1', '0', '0', '0', '0', '0', ETX };
owner()->write(startProgramMess, SIZE);
owner()->read(buf, ack);
//Move tray to front position
moveTrayToFrontPosition();
}
......@@ -83,14 +74,16 @@ void RealAliasDriver::stop() {
std::cout << "in stop" << endl;
// Stop sparkLink method: STX | 6 1 | 0 1 | 5 1 0 0 | 0 0 0 0 0 0 | ETX
// (1) Stop sparkLink method: STX | 6 1 | 0 1 | 5 1 0 0 | 0 0 0 0 0 0 | ETX
int size = 16;
string buf;
string ack(1, ACK);
unsigned char message[16] = { STX, '6', '1', '0', '1', '5', '1', '0', '0', '0', '0', '0', '0', '0', '0', ETX };
owner()->write(message, size);
// sleep(1);
owner()->read(buf, ack);
// (2) Move tray to front position
moveTrayToFrontPosition();
}
void RealAliasDriver::status() {
......@@ -119,8 +112,7 @@ void RealAliasDriver::status() {
if (error == "1") {
//Get error if needed
unsigned char message[16] = { STX, '6', '1', '0', '1', '1', '0',
'0', '1', SP, SP, '0', '1', '5', '5', ETX };
unsigned char message[16] = { STX, '6', '1', '0', '1', '1', '0', '0', '1', SP, SP, '0', '1', '5', '5', ETX };
owner()->write(message, size);
owner()->read(buf, etx);
answer = buf.substr(12, 3);
......@@ -408,4 +400,55 @@ void RealAliasDriver::moveTray() {
}
/*
* Move tray to the specific front position
*/
void RealAliasDriver::moveTrayToFrontPosition() {
string buf;
string ack(1, ACK);
// (1) Set program option "move tray" to front
// code STX | 6 1 | 0 1 | 0 8 3 0 | SP SP SP SP SP X | ETX -> x = 0 home, x = 1 front
unsigned char trayMoveMess[SIZE] = { STX, '6', '1', '0', '1', '0', '8', '3', '0', SP, SP, SP, SP, SP, '1', ETX };
owner()->write(trayMoveMess, SIZE);
owner()->read(buf, ack);
// (2) Start/stop user program value previously loaded
unsigned char startProgramMess[SIZE] = { STX, '6', '1', '0', '1', '5', '1', '0', '0', '1', '0', '0', '0', '0', '0', ETX };
owner()->write(startProgramMess, SIZE);
owner()->read(buf, ack);
}
/*
* Read the answer given by the machine when setting parameters
*/
void RealAliasDriver::readAnswer() {
/*
int32 bufferSize = 10;
uint8 buffer[bufferSize];
m_owner->read(buffer, bufferSize);
ostringstream version;
version << (int32)buffer[4] << "." << (int32)buffer[5];
*/
int32 bufferSize = 1;
uint8 buffer[bufferSize];
owner()->read(buffer, bufferSize);
// Convert answer into a string and check its value
ostringstream answerss;
answerss << buffer;
std::string answer = answerss.str();
if (answer == ACK) {
std::cout << "answer is ACK" << endl;
} else if (answer == NACK) {
std::cout << "answer is NACK" << endl;
} else if (answer == NACK0) {
std::cout << "answer is NACK0" << endl;
} else {
// error
std::cout << "error!" << endl;
}
}
}
......@@ -40,6 +40,10 @@ public:
virtual void setMode();
virtual void moveTray();
private:
void readAnswer();
void moveTrayToFrontPosition();
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment