|
|
|
@ -484,59 +484,59 @@ void posctl_gui_update() {
|
|
|
|
gtk_widget_set_sensitive(e_posdevice, false);
|
|
|
|
gtk_widget_set_sensitive(e_posdevice, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
strfromd (txt, sizeof(txt-1), (const char *)"%f", posctl.calib_rot.a);
|
|
|
|
strfromd (txt, sizeof(txt-1), (char *)"%f", posctl.calib_rot.a);
|
|
|
|
gtk_entry_set_text (GTK_ENTRY(e_cal_rotangle), txt);
|
|
|
|
gtk_entry_set_text (GTK_ENTRY(e_cal_rotangle), txt);
|
|
|
|
strfromd (txt, sizeof(txt-1), (const char *)"%f", posctl.calib_rot.l);
|
|
|
|
strfromd (txt, sizeof(txt-1), (char *)"%f", posctl.calib_rot.l);
|
|
|
|
gtk_entry_set_text (GTK_ENTRY(e_cal_rotlen), txt);
|
|
|
|
gtk_entry_set_text (GTK_ENTRY(e_cal_rotlen), txt);
|
|
|
|
|
|
|
|
|
|
|
|
strfromd (txt, sizeof(txt-1), (const char *)"%f", posctl.calib_axis1.a);
|
|
|
|
strfromd (txt, sizeof(txt-1), (char *)"%f", posctl.calib_axis1.a);
|
|
|
|
gtk_entry_set_text (GTK_ENTRY(e_cal_a1angle), txt);
|
|
|
|
gtk_entry_set_text (GTK_ENTRY(e_cal_a1angle), txt);
|
|
|
|
strfromd (txt, sizeof(txt-1), (const char *)"%f", posctl.calib_axis1.l);
|
|
|
|
strfromd (txt, sizeof(txt-1), (char *)"%f", posctl.calib_axis1.l);
|
|
|
|
gtk_entry_set_text (GTK_ENTRY(e_cal_a1len), txt);
|
|
|
|
gtk_entry_set_text (GTK_ENTRY(e_cal_a1len), txt);
|
|
|
|
|
|
|
|
|
|
|
|
strfromd (txt, sizeof(txt-1), (const char *)"%f", posctl.calib_axis2.a);
|
|
|
|
strfromd (txt, sizeof(txt-1), (char *)"%f", posctl.calib_axis2.a);
|
|
|
|
gtk_entry_set_text (GTK_ENTRY(e_cal_a2angle), txt);
|
|
|
|
gtk_entry_set_text (GTK_ENTRY(e_cal_a2angle), txt);
|
|
|
|
strfromd (txt, sizeof(txt-1), (const char *)"%f", posctl.calib_axis2.l);
|
|
|
|
strfromd (txt, sizeof(txt-1), (char *)"%f", posctl.calib_axis2.l);
|
|
|
|
gtk_entry_set_text (GTK_ENTRY(e_cal_a2len), txt);
|
|
|
|
gtk_entry_set_text (GTK_ENTRY(e_cal_a2len), txt);
|
|
|
|
|
|
|
|
|
|
|
|
strfromd (txt, sizeof(txt-1), (const char *)"%f", posctl.calib_rot.a - posctl.calib_axis1.a);
|
|
|
|
strfromd (txt, sizeof(txt-1), (char *)"%f", posctl.calib_rot.a - posctl.calib_axis1.a);
|
|
|
|
gtk_label_set_text (GTK_LABEL(lb_earthaxis), txt);
|
|
|
|
gtk_label_set_text (GTK_LABEL(lb_earthaxis), txt);
|
|
|
|
strfromd (txt, sizeof(txt-1), (const char *)"%f", posctl.calib_axis1.a - posctl.calib_axis2.a);
|
|
|
|
strfromd (txt, sizeof(txt-1), (char *)"%f", posctl.calib_axis1.a - posctl.calib_axis2.a);
|
|
|
|
gtk_label_set_text (GTK_LABEL(lb_axisaxis), txt);
|
|
|
|
gtk_label_set_text (GTK_LABEL(lb_axisaxis), txt);
|
|
|
|
|
|
|
|
|
|
|
|
gtk_entry_set_text (GTK_ENTRY(e_posdevice), posctl.GetDevice().c_str());
|
|
|
|
gtk_entry_set_text (GTK_ENTRY(e_posdevice), posctl.GetDevice().c_str());
|
|
|
|
strfromd (txt, sizeof(txt-1), (const char *)"%f", posctl.axis_op[0]);
|
|
|
|
strfromd (txt, sizeof(txt-1), (char *)"%f", posctl.axis_op[0]);
|
|
|
|
gtk_label_set_text(GTK_LABEL(a1_out), txt);
|
|
|
|
gtk_label_set_text(GTK_LABEL(a1_out), txt);
|
|
|
|
strfromd (txt, sizeof(txt-1), (const char *)"%f", posctl.axis_op[1]);
|
|
|
|
strfromd (txt, sizeof(txt-1), (char *)"%f", posctl.axis_op[1]);
|
|
|
|
gtk_label_set_text(GTK_LABEL(a2_out), txt);
|
|
|
|
gtk_label_set_text(GTK_LABEL(a2_out), txt);
|
|
|
|
|
|
|
|
|
|
|
|
strfromd (txt, sizeof(txt-1), (const char *)"%f", posctl.axis_pv[0]);
|
|
|
|
strfromd (txt, sizeof(txt-1), (char *)"%f", posctl.axis_pv[0]);
|
|
|
|
gtk_label_set_text(GTK_LABEL(a1_pv), txt);
|
|
|
|
gtk_label_set_text(GTK_LABEL(a1_pv), txt);
|
|
|
|
strfromd (txt, sizeof(txt-1), (const char *)"%f", posctl.axis_pv[1]);
|
|
|
|
strfromd (txt, sizeof(txt-1), (char *)"%f", posctl.axis_pv[1]);
|
|
|
|
gtk_label_set_text(GTK_LABEL(a2_pv), txt);
|
|
|
|
gtk_label_set_text(GTK_LABEL(a2_pv), txt);
|
|
|
|
|
|
|
|
|
|
|
|
posctl.GetAxisParam(0, &mi, &ma, &kp, &ki, &kd);
|
|
|
|
posctl.GetAxisParam(0, &mi, &ma, &kp, &ki, &kd);
|
|
|
|
strfromd (txt, sizeof(txt-1), (const char *)"%f", mi);
|
|
|
|
strfromd (txt, sizeof(txt-1), (char *)"%f", mi);
|
|
|
|
gtk_entry_set_text_nofocus (a1_min, txt);
|
|
|
|
gtk_entry_set_text_nofocus (a1_min, txt);
|
|
|
|
strfromd (txt, sizeof(txt-1), (const char *)"%f", ma);
|
|
|
|
strfromd (txt, sizeof(txt-1), (char *)"%f", ma);
|
|
|
|
gtk_entry_set_text_nofocus (a1_max, txt);
|
|
|
|
gtk_entry_set_text_nofocus (a1_max, txt);
|
|
|
|
strfromd (txt, sizeof(txt-1), (const char *)"%f", kp);
|
|
|
|
strfromd (txt, sizeof(txt-1), (char *)"%f", kp);
|
|
|
|
gtk_entry_set_text_nofocus (a1_kp, txt);
|
|
|
|
gtk_entry_set_text_nofocus (a1_kp, txt);
|
|
|
|
strfromd (txt, sizeof(txt-1), (const char *)"%f", ki);
|
|
|
|
strfromd (txt, sizeof(txt-1), (char *)"%f", ki);
|
|
|
|
gtk_entry_set_text_nofocus (a1_ki, txt);
|
|
|
|
gtk_entry_set_text_nofocus (a1_ki, txt);
|
|
|
|
strfromd (txt, sizeof(txt-1), (const char *)"%f", kd);
|
|
|
|
strfromd (txt, sizeof(txt-1), (char *)"%f", kd);
|
|
|
|
gtk_entry_set_text_nofocus (a1_kd, txt);
|
|
|
|
gtk_entry_set_text_nofocus (a1_kd, txt);
|
|
|
|
|
|
|
|
|
|
|
|
posctl.GetAxisParam(1, &mi, &ma, &kp, &ki, &kd);
|
|
|
|
posctl.GetAxisParam(1, &mi, &ma, &kp, &ki, &kd);
|
|
|
|
strfromd (txt, sizeof(txt-1), (const char *)"%f", mi);
|
|
|
|
strfromd (txt, sizeof(txt-1), (char *)"%f", mi);
|
|
|
|
gtk_entry_set_text_nofocus (a2_min, txt);
|
|
|
|
gtk_entry_set_text_nofocus (a2_min, txt);
|
|
|
|
strfromd (txt, sizeof(txt-1), (const char *)"%f", ma);
|
|
|
|
strfromd (txt, sizeof(txt-1), (char *)"%f", ma);
|
|
|
|
gtk_entry_set_text_nofocus (a2_max, txt);
|
|
|
|
gtk_entry_set_text_nofocus (a2_max, txt);
|
|
|
|
strfromd (txt, sizeof(txt-1), (const char *)"%f", kp);
|
|
|
|
strfromd (txt, sizeof(txt-1), (char *)"%f", kp);
|
|
|
|
gtk_entry_set_text_nofocus (a2_kp, txt);
|
|
|
|
gtk_entry_set_text_nofocus (a2_kp, txt);
|
|
|
|
strfromd (txt, sizeof(txt-1), (const char *)"%f", ki);
|
|
|
|
strfromd (txt, sizeof(txt-1), (char *)"%f", ki);
|
|
|
|
gtk_entry_set_text_nofocus (a2_ki, txt);
|
|
|
|
gtk_entry_set_text_nofocus (a2_ki, txt);
|
|
|
|
strfromd (txt, sizeof(txt-1), (const char *)"%f", kd);
|
|
|
|
strfromd (txt, sizeof(txt-1), (char *)"%f", kd);
|
|
|
|
gtk_entry_set_text_nofocus (a2_kd, txt);
|
|
|
|
gtk_entry_set_text_nofocus (a2_kd, txt);
|
|
|
|
|
|
|
|
|
|
|
|
const gchar *txtptr = gtk_entry_get_text(GTK_ENTRY(e_posdevice));
|
|
|
|
const gchar *txtptr = gtk_entry_get_text(GTK_ENTRY(e_posdevice));
|
|
|
|
@ -575,7 +575,11 @@ PosCtl::PosCtl() {
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
calib_mode = POSCTL_CALIB_MODE_OFF;
|
|
|
|
calib_mode = POSCTL_CALIB_MODE_OFF;
|
|
|
|
|
|
|
|
#if BUILD_WINDOWS
|
|
|
|
|
|
|
|
device_fd = INVALID_HANDLE_VALUE;
|
|
|
|
|
|
|
|
#else
|
|
|
|
device_fd = -1;
|
|
|
|
device_fd = -1;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
device = "";
|
|
|
|
device = "";
|
|
|
|
device_type = POSCTL_DEVTYPE_TTY;
|
|
|
|
device_type = POSCTL_DEVTYPE_TTY;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
@ -835,17 +839,42 @@ void PosCtl::SetDevice (std::string d) {
|
|
|
|
|
|
|
|
|
|
|
|
int PosCtl::OutputClose() {
|
|
|
|
int PosCtl::OutputClose() {
|
|
|
|
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
|
|
|
|
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
|
|
|
|
|
|
|
|
#ifdef BUILD_WINDOWS
|
|
|
|
|
|
|
|
if (device_fd != INVALID_HANDLE_VALUE) CloseHandle(device_fd);
|
|
|
|
|
|
|
|
device_fd = INVALID_HANDLE_VALUE;
|
|
|
|
|
|
|
|
#else
|
|
|
|
if (device_fd > 0) close(device_fd);
|
|
|
|
if (device_fd > 0) close(device_fd);
|
|
|
|
device_fd = -1;
|
|
|
|
device_fd = -1;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int PosCtl::OutputOpen() {
|
|
|
|
int PosCtl::OutputOpen() {
|
|
|
|
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
|
|
|
|
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
|
|
|
|
|
|
|
|
#ifdef BUILD_WINDOWS
|
|
|
|
|
|
|
|
if (device_fd != INVALID_HANDLE_VALUE) return 0;
|
|
|
|
|
|
|
|
#else
|
|
|
|
if (device_fd > 0) return 0;
|
|
|
|
if (device_fd > 0) return 0;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef BUILD_WINDOWS
|
|
|
|
|
|
|
|
device_fd = CreateFile(device.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
|
|
|
|
|
|
|
|
if (device_fd == INVALID_HANDLE_VALUE) {
|
|
|
|
|
|
|
|
printf ("%s:%d could not open device:%s Error:%ld\n", __FILE__, __LINE__,
|
|
|
|
|
|
|
|
device.c_str(), GetLastError());
|
|
|
|
|
|
|
|
errormessage_display ((char *)"window-posctl", (char *)"OutputOpen",
|
|
|
|
|
|
|
|
(char*)"%s:%d could not open device:%s Error:%ld\n", __FILE__, __LINE__, device.c_str(), GetLastError());
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
COMMTIMEOUTS comTimeOut;
|
|
|
|
|
|
|
|
comTimeOut.ReadIntervalTimeout = 100;
|
|
|
|
|
|
|
|
comTimeOut.ReadTotalTimeoutMultiplier = 1;
|
|
|
|
|
|
|
|
comTimeOut.ReadTotalTimeoutConstant = 100;
|
|
|
|
|
|
|
|
comTimeOut.WriteTotalTimeoutMultiplier = 0;
|
|
|
|
|
|
|
|
comTimeOut.WriteTotalTimeoutConstant = 0;
|
|
|
|
|
|
|
|
SetCommTimeouts(device_fd, &comTimeOut);
|
|
|
|
|
|
|
|
#else
|
|
|
|
device_fd = open (device.c_str(), O_RDWR);
|
|
|
|
device_fd = open (device.c_str(), O_RDWR);
|
|
|
|
if (device_fd < 0) {
|
|
|
|
if (device_fd < 0) {
|
|
|
|
printf ("%s:%d could not open device:%s Error:%s\n", __FILE__, __LINE__,
|
|
|
|
printf ("%s:%d could not open device:%s Error:%s\n", __FILE__, __LINE__,
|
|
|
|
@ -854,14 +883,26 @@ int PosCtl::OutputOpen() {
|
|
|
|
(char*)"%s:%d could not open device:%s Error:%s\n", __FILE__, __LINE__, device.c_str(), strerror(errno));
|
|
|
|
(char*)"%s:%d could not open device:%s Error:%s\n", __FILE__, __LINE__, device.c_str(), strerror(errno));
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
int PosCtl::WriteTTY (char * outbuf) {
|
|
|
|
int PosCtl::WriteTTY (char * outbuf) {
|
|
|
|
ssize_t len;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf ("%s:%d %s send: '%s'\n", __FILE__, __LINE__, __FUNCTION__, outbuf);
|
|
|
|
printf ("%s:%d %s send: '%s'\n", __FILE__, __LINE__, __FUNCTION__, outbuf);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef BUILD_WINDOWS
|
|
|
|
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
int res;
|
|
|
|
|
|
|
|
res = WriteFile(device_fd, outbuf, strlen(outbuf), &len, NULL);
|
|
|
|
|
|
|
|
if (res == 0 || len != strlen(outbuf)) {
|
|
|
|
|
|
|
|
printf ("%s:%d could not write data to device:%s Error:%ld\n", __FILE__, __LINE__,
|
|
|
|
|
|
|
|
device.c_str(), GetLastError());
|
|
|
|
|
|
|
|
errormessage_display ((char *)"window-posctl", (char *)"WriteTTY",
|
|
|
|
|
|
|
|
(char *) "%s:%d could not write data to device:%s Error:%ld\n", __FILE__, __LINE__,
|
|
|
|
|
|
|
|
device.c_str(), GetLastError());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
ssize_t len;
|
|
|
|
len = write (device_fd, outbuf, strlen(outbuf));
|
|
|
|
len = write (device_fd, outbuf, strlen(outbuf));
|
|
|
|
if ((size_t) len != strlen(outbuf) || len < 0) {
|
|
|
|
if ((size_t) len != strlen(outbuf) || len < 0) {
|
|
|
|
printf ("%s:%d could not write data to device:%s Error:%s\n", __FILE__, __LINE__,
|
|
|
|
printf ("%s:%d could not write data to device:%s Error:%s\n", __FILE__, __LINE__,
|
|
|
|
@ -870,14 +911,30 @@ int PosCtl::WriteTTY (char * outbuf) {
|
|
|
|
(char *) "%s:%d could not write data to device:%s Error:%s\n", __FILE__, __LINE__,
|
|
|
|
(char *) "%s:%d could not write data to device:%s Error:%s\n", __FILE__, __LINE__,
|
|
|
|
device.c_str(), strerror(errno));
|
|
|
|
device.c_str(), strerror(errno));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PosCtl::ReadTTY (char * inbuf, int length) {
|
|
|
|
int PosCtl::ReadTTY (char * inbuf, int length) {
|
|
|
|
|
|
|
|
#ifdef BUILD_WINDOWS
|
|
|
|
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
int res;
|
|
|
|
|
|
|
|
res = ReadFile(device_fd, inbuf, length, &len, NULL);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (res == 0) {
|
|
|
|
|
|
|
|
printf ("%s:%d could not read data from device:%s Error:%ld\n", __FILE__, __LINE__,
|
|
|
|
|
|
|
|
device.c_str(), GetLastError());
|
|
|
|
|
|
|
|
errormessage_display ((char *)"window-posctl", (char *)"ReadTTY",
|
|
|
|
|
|
|
|
(char *) "%s:%d could not read data from device:%s Error:%ld\n", __FILE__, __LINE__,
|
|
|
|
|
|
|
|
device.c_str(), GetLastError());
|
|
|
|
|
|
|
|
inbuf[0] = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
inbuf[len] = 0;
|
|
|
|
|
|
|
|
printf ("%s:%d %s receive: '%s'\n", __FILE__, __LINE__, __FUNCTION__, inbuf);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
ssize_t len;
|
|
|
|
ssize_t len;
|
|
|
|
// FIXME: how to use the com/usb-com port on windows.
|
|
|
|
|
|
|
|
#ifndef BUILD_WINDOWS
|
|
|
|
|
|
|
|
// make device non-blocking
|
|
|
|
// make device non-blocking
|
|
|
|
fcntl(device_fd, F_SETFL, fcntl(device_fd, F_GETFL) | O_NONBLOCK);
|
|
|
|
fcntl(device_fd, F_SETFL, fcntl(device_fd, F_GETFL) | O_NONBLOCK);
|
|
|
|
|
|
|
|
|
|
|
|
@ -916,10 +973,12 @@ int PosCtl::OutputWriteValue (int axis, double value) {
|
|
|
|
simulation.AxisSetValue(axis, value);
|
|
|
|
simulation.AxisSetValue(axis, value);
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// FIXME: how to use the com/usb-com port on windows.
|
|
|
|
|
|
|
|
#ifndef BUILD_WINDOWS
|
|
|
|
|
|
|
|
if (device_fd <= 0) if (OutputOpen() != 0) return -1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef BUILD_WINDOWS
|
|
|
|
|
|
|
|
if (device_fd == INVALID_HANDLE_VALUE) if (OutputOpen() != 0) return -1;
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
if (device_fd <= 0) if (OutputOpen() != 0) return -1;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// save language setting and set to plain C
|
|
|
|
// save language setting and set to plain C
|
|
|
|
std::string s = setlocale(LC_ALL, NULL);
|
|
|
|
std::string s = setlocale(LC_ALL, NULL);
|
|
|
|
@ -933,7 +992,7 @@ int PosCtl::OutputWriteValue (int axis, double value) {
|
|
|
|
|
|
|
|
|
|
|
|
WriteTTY(outbuf);
|
|
|
|
WriteTTY(outbuf);
|
|
|
|
ReadTTY(outbuf, sizeof(outbuf) - 1);
|
|
|
|
ReadTTY(outbuf, sizeof(outbuf) - 1);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
@ -948,7 +1007,11 @@ int PosCtl::OutputWriteStop () {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
snprintf (outbuf, 255, ":Q#");
|
|
|
|
snprintf (outbuf, 255, ":Q#");
|
|
|
|
|
|
|
|
#ifdef BUILD_WINDOWS
|
|
|
|
|
|
|
|
if (device_fd == INVALID_HANDLE_VALUE) if (OutputOpen() != 0) return -1;
|
|
|
|
|
|
|
|
#else
|
|
|
|
if (device_fd <= 0) if (OutputOpen() != 0) return -1;
|
|
|
|
if (device_fd <= 0) if (OutputOpen() != 0) return -1;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
WriteTTY(outbuf);
|
|
|
|
WriteTTY(outbuf);
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
|