1 #include "IselLinearControl.hh"
2 #include <Base/Common/W32Compat.hh>
3 #include <Base/Common/BIASpragma.hh>
4 #include <Base/Debug/Error.hh>
11 IselLinearControl::IselLinearControl()
17 IselLinearControl::~IselLinearControl() {}
20 int IselLinearControl::Reset()
22 SendRawCommand(
"@0R1\r");
26 int IselLinearControl::Init(
int nCOMportNumber)
28 char COMportPrefix[10] =
"/dev/ttyS";
30 sprintf(COMportName,
"%s%d", COMportPrefix, nCOMportNumber);
31 return Init(COMportName);
34 int IselLinearControl::Init(
const char *COMportName)
36 cout <<
"YoYoYo" << endl;
37 cout <<
"Opening port " << COMportName <<
" for Isel Linear."<<endl;
38 COMstream_ = open_host_port((
char*)COMportName);
39 if (COMstream_ == PORT_NOT_OPENED) {
42 SendRawCommand(
"@01\r");
46 void IselLinearControl::Close()
48 close_host_port(COMstream_);
52 int IselLinearControl::SetSpeed(
int speed)
54 if (speed > 0 && speed <= 40000) {
58 BIASERR(
"speed out of bounds, use value 0..40000");
63 void IselLinearControl::GetSpeed(
int &speed)
68 int IselLinearControl::SetAcceleration(
int accel)
76 BIASERR(
"implement me");
80 void IselLinearControl::GetAcceleration(
int &accel)
83 BIASERR(
"implement me");
86 int IselLinearControl::MoveLeft(
float millimeters)
88 float steps = millimeters * steps_per_mm_;
89 int nValue = (int)steps;
90 if (steps - (
float)nValue > 0.0f) {
91 BIASWARN(
"\nwant to move " << steps <<
" steps. flooring to " << nValue <<
" steps, loosing precision.\n"
92 <<
"Isel control does 1/"<<steps_per_mm_<<
" steps.");
95 s <<
"@0A" << nValue <<
"," << speed_ <<
"\r";
96 SendRawCommand(s.str());
100 int IselLinearControl::MoveRight(
float millimeters)
102 float steps = millimeters * steps_per_mm_;
103 int nValue = (int)steps;
104 if (steps - (
float)nValue > 0.0f) {
105 BIASWARN(
"\nwant to move " << steps <<
" steps. flooring to " << nValue <<
" steps, loosing precision.\n"
106 <<
"Isel control does 1/"<<steps_per_mm_<<
" steps.");
110 s <<
"@0A" << nValue <<
"," << speed_ <<
"\r";
111 SendRawCommand(s.str());
112 return CheckStatus();
115 void IselLinearControl::GetCurrentPosition(
int &pos)
118 BIASERR(
"implement me");
121 int IselLinearControl::SetPosition(
int pos,
bool bWaitComplete)
124 s <<
"@0M" << pos <<
"," << speed_ <<
"\r";
125 SendRawCommand(s.str());
127 return CheckStatus();
132 void IselLinearControl::SendRawCommand(
string cmd) {
133 SerialStringOut(COMstream_, (
unsigned char*) cmd.c_str());
136 int IselLinearControl::ReadRawLine(
string &cmd) {
139 ReadSerialLine(COMstream_, (
unsigned char*)result,1,&len);
140 cmd = string(result,len);
144 int IselLinearControl::CheckStatus() {
146 while (ReadRawLine(test) == 0) {}
147 if (test.length() == 1) {
148 unsigned char c = test.c_str()[0];
154 BIASERR(
"reached limit, need to move free");
155 SendRawCommand(
"@0F1\r");
156 return CheckStatus();
158 BIASERR(
"Got Errorcode: " << test);
162 BIASERR(
"unknown response: " << test);