402 lines
12 KiB
C++
402 lines
12 KiB
C++
|
#include "RTC4Scanner.h"
|
||
|
#include "RTC4impl.h"
|
||
|
#include "../global.h"
|
||
|
#include "../Logger.h"
|
||
|
#include "../LanguageManager.h"
|
||
|
#include "../utils/MathHelper.h"
|
||
|
|
||
|
RTC4Scanner::RTC4Scanner(LaserCfg* cfg) :Scanner(cfg)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
|
||
|
RTC4Scanner::~RTC4Scanner()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
bool RTC4Scanner::Init()
|
||
|
{
|
||
|
#ifdef _DEBUG
|
||
|
return true;
|
||
|
#endif
|
||
|
m_output_vfactor = 1023.0 / 10.0;
|
||
|
m_list_memory = 4000;
|
||
|
m_kfactor = m_CorrectParamCfg->m_FactorK;
|
||
|
m_xfactor = m_kfactor*m_CorrectParamCfg->m_xcorrect;
|
||
|
m_yfactor = m_kfactor*m_CorrectParamCfg->m_ycorrect;
|
||
|
|
||
|
short errorCode = 0;
|
||
|
char buffer[512];
|
||
|
sprintf_s(buffer, sizeof(buffer), "%sSLM%d.ctb", g_AppPath.c_str(), m_LaserCfg->m_Cno);
|
||
|
string crtPath = string(buffer);
|
||
|
errorCode = n_load_correction_file((unsigned short)m_LaserCfg->m_Cno, crtPath.c_str(), 1, 1.0, 1.0, m_CorrectParamCfg->m_angle, 0.0, 0.0);
|
||
|
if (errorCode) {
|
||
|
g_log->TraceError(g_LngManager->Log_LoadCorrectFileError->ShowText());
|
||
|
m_InitErrorInfos.push_back(g_LngManager->Log_LoadCorrectFileError->ShowText());
|
||
|
return false;
|
||
|
}
|
||
|
string pfilePath = g_AppPath + "SLM.hex";
|
||
|
errorCode = n_load_program_file((unsigned short)m_LaserCfg->m_Cno, pfilePath.c_str());
|
||
|
if (errorCode) {
|
||
|
g_log->TraceError(g_LngManager->Log_LoadRTCFileError->ShowText());
|
||
|
m_InitErrorInfos.push_back(g_LngManager->Log_LoadRTCFileError->ShowText());
|
||
|
return false;
|
||
|
}
|
||
|
n_select_cor_table((unsigned short)m_LaserCfg->m_Cno, 1, 0);
|
||
|
n_set_laser_mode((unsigned short)m_LaserCfg->m_Cno, 4);
|
||
|
unsigned short power = 1023.0* m_PowerCompensateCfg->CalcPowerCompensate((float)m_ScanTestCfg->m_laser_power) / 100.0;
|
||
|
|
||
|
unsigned short jumpDelay = m_ScanParamCfg->m_jump_delay / 10;
|
||
|
unsigned short markDelay = m_ScanParamCfg->m_scan_delay / 10;
|
||
|
unsigned short polygonDelay = m_ScanParamCfg->m_polygon_delay / 10;
|
||
|
|
||
|
double markspeed = m_kfactor* m_ScanParamCfg->m_mark_speed / 1000.0;
|
||
|
double jumpspeed = m_kfactor* m_ScanParamCfg->m_jump_speed / 1000.0;
|
||
|
unsigned short edgeLevel = m_ScanParamCfg->m_edge_level / 10;
|
||
|
unsigned short minJumpDelay = m_ScanParamCfg->m_min_jump_delay / 10;
|
||
|
|
||
|
float xoffset = m_CorrectParamCfg->m_xposfix*cos(m_CorrectParamCfg->m_angle*MathHelper::m_PI / 180.0) - m_CorrectParamCfg->m_yoffset*sin(m_CorrectParamCfg->m_angle*MathHelper::m_PI / 180.0);
|
||
|
float yoffset = m_CorrectParamCfg->m_xposfix*sin(m_CorrectParamCfg->m_angle*MathHelper::m_PI / 180.0) + m_CorrectParamCfg->m_yoffset*cos(m_CorrectParamCfg->m_angle*MathHelper::m_PI / 180.0);
|
||
|
n_set_start_list((unsigned short)m_LaserCfg->m_Cno, 1);
|
||
|
n_set_scanner_delays((unsigned short)m_LaserCfg->m_Cno, jumpDelay, markDelay, polygonDelay);
|
||
|
n_set_laser_delays((unsigned short)m_LaserCfg->m_Cno, (short)m_ScanParamCfg->m_laseron_delay, (short)m_ScanParamCfg->m_laseroff_delay);
|
||
|
n_set_delay_mode((unsigned short)m_LaserCfg->m_Cno, 1, 0, edgeLevel, minJumpDelay, (unsigned int)(m_ScanParamCfg->m_jump_length_limit*m_kfactor));
|
||
|
n_set_jump_speed((unsigned short)m_LaserCfg->m_Cno, jumpspeed);
|
||
|
n_set_mark_speed((unsigned short)m_LaserCfg->m_Cno, markspeed);
|
||
|
n_write_da_1_list((unsigned short)m_LaserCfg->m_Cno, power);
|
||
|
n_set_offset_list((unsigned short)m_LaserCfg->m_Cno, (short)(xoffset*m_xfactor), (short)(yoffset*m_yfactor));
|
||
|
n_set_end_of_list((unsigned short)m_LaserCfg->m_Cno);
|
||
|
ListExecute(1, true);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
bool RTC4Scanner::PreInit(unsigned int &card_count)
|
||
|
{
|
||
|
card_count = rtc4_count_cards();
|
||
|
g_ScanSerial = get_serial_number();
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
int RTC4Scanner::GetSerialNo(unsigned int no)
|
||
|
{
|
||
|
return n_get_serial_number(no);
|
||
|
}
|
||
|
|
||
|
bool RTC4Scanner::StopWork()
|
||
|
{
|
||
|
n_stop_execution((unsigned short)m_LaserCfg->m_Cno);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
|
||
|
void RTC4Scanner::LoadList(unsigned int listid, bool wait)
|
||
|
{
|
||
|
if (wait) {
|
||
|
bool isbreak = false;
|
||
|
unsigned short busy, position;
|
||
|
while (true) {
|
||
|
n_get_status((unsigned short)m_LaserCfg->m_Cno, &busy, &position);
|
||
|
if (busy) {
|
||
|
if (listid == 2) {
|
||
|
if (position >= 4000) {
|
||
|
Sleep(10);
|
||
|
}
|
||
|
else {
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
if (position < 4000) {
|
||
|
Sleep(10);
|
||
|
}
|
||
|
else {
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
break;
|
||
|
}
|
||
|
if (m_print_state == BaseCtrl::STOP) {
|
||
|
isbreak = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if (!isbreak)
|
||
|
{
|
||
|
n_set_start_list((unsigned short)m_LaserCfg->m_Cno, listid);
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
n_set_start_list((unsigned short)m_LaserCfg->m_Cno, listid);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void RTC4Scanner::EndList()
|
||
|
{
|
||
|
n_set_end_of_list((unsigned short)m_LaserCfg->m_Cno);
|
||
|
}
|
||
|
|
||
|
|
||
|
void RTC4Scanner::ListExecute(unsigned int listid, bool wait)
|
||
|
{
|
||
|
n_execute_list((unsigned short)m_LaserCfg->m_Cno, (unsigned short)listid);
|
||
|
unsigned short Busy(0), Pos(0);
|
||
|
if (wait) {
|
||
|
do
|
||
|
{
|
||
|
Sleep(20);
|
||
|
n_get_status((unsigned short)m_LaserCfg->m_Cno, &Busy, &Pos);
|
||
|
if (m_print_state == BaseCtrl::STOP) {
|
||
|
break;
|
||
|
}
|
||
|
} while (Busy);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void RTC4Scanner::AutoChangeList()
|
||
|
{
|
||
|
n_auto_change((unsigned short)m_LaserCfg->m_Cno);
|
||
|
}
|
||
|
|
||
|
void RTC4Scanner::WaitListFree()
|
||
|
{
|
||
|
unsigned short Busy(0), Pos(0);
|
||
|
do
|
||
|
{
|
||
|
Sleep(10);
|
||
|
n_get_status((unsigned short)m_LaserCfg->m_Cno, &Busy, &Pos);
|
||
|
if (m_print_state == BaseCtrl::STOP) {
|
||
|
break;
|
||
|
}
|
||
|
} while (Busy);
|
||
|
}
|
||
|
|
||
|
void RTC4Scanner::SetScanSpeed(double fspeed)
|
||
|
{
|
||
|
double speed = fspeed / 1000.0*m_kfactor;
|
||
|
n_set_mark_speed((unsigned short)m_LaserCfg->m_Cno, speed);
|
||
|
}
|
||
|
|
||
|
void RTC4Scanner::SetPower(double watt)
|
||
|
{
|
||
|
unsigned short power = 1023.0*watt / 100.0;
|
||
|
if (power > 1023)power = 1023;
|
||
|
n_write_da_1_list((unsigned short)m_LaserCfg->m_Cno, power);
|
||
|
}
|
||
|
|
||
|
void RTC4Scanner::AddVector(double startx, double starty, double endx, double endy)
|
||
|
{
|
||
|
|
||
|
int lstartx = (int)round(startx*m_xfactor);
|
||
|
int lstarty = (int)round(starty*m_yfactor);
|
||
|
int lendx = (int)round(endx*m_xfactor);
|
||
|
int lendy = (int)round(endy*m_yfactor);
|
||
|
if (lstartx > SHRT_MAX) {
|
||
|
lstartx = SHRT_MAX;
|
||
|
}
|
||
|
if (lstartx < SHRT_MIN) {
|
||
|
lstartx = SHRT_MIN;
|
||
|
}
|
||
|
if (lstarty > SHRT_MAX) {
|
||
|
lstarty = SHRT_MAX;
|
||
|
}
|
||
|
if (lstarty < SHRT_MIN) {
|
||
|
lstarty = SHRT_MIN;
|
||
|
}
|
||
|
if (lendx > SHRT_MAX)
|
||
|
{
|
||
|
lendx = SHRT_MAX;
|
||
|
}
|
||
|
if (lendx < SHRT_MIN) {
|
||
|
lendx = SHRT_MIN;
|
||
|
}
|
||
|
if (lendy > SHRT_MAX)
|
||
|
{
|
||
|
lendy = SHRT_MAX;
|
||
|
}
|
||
|
if (lendy < SHRT_MIN) {
|
||
|
lendy = SHRT_MIN;
|
||
|
}
|
||
|
n_jump_abs((unsigned short)m_LaserCfg->m_Cno, lstartx, lstarty);
|
||
|
n_mark_abs((unsigned short)m_LaserCfg->m_Cno, lendx, lendy);
|
||
|
}
|
||
|
|
||
|
void RTC4Scanner::ListNop()
|
||
|
{
|
||
|
n_list_nop((unsigned short)m_LaserCfg->m_Cno);
|
||
|
}
|
||
|
|
||
|
void RTC4Scanner::JumpAbs(double x, double y)
|
||
|
{
|
||
|
int lx = (int)round(x*m_xfactor);
|
||
|
int ly = (int)round(y*m_yfactor);
|
||
|
if (lx > SHRT_MAX) {
|
||
|
lx = SHRT_MAX;
|
||
|
}
|
||
|
if (lx < SHRT_MIN)
|
||
|
{
|
||
|
lx = SHRT_MIN;
|
||
|
}
|
||
|
if (ly > SHRT_MAX) {
|
||
|
ly = SHRT_MAX;
|
||
|
}
|
||
|
if (ly < SHRT_MIN)
|
||
|
{
|
||
|
ly = SHRT_MIN;
|
||
|
}
|
||
|
n_jump_abs((unsigned short)m_LaserCfg->m_Cno, lx, ly);
|
||
|
}
|
||
|
|
||
|
void RTC4Scanner::MarkAbs(double x, double y)
|
||
|
{
|
||
|
int lx = (int)round(x*m_xfactor);
|
||
|
int ly = (int)round(y*m_yfactor);
|
||
|
if (lx > SHRT_MAX) {
|
||
|
lx = SHRT_MAX;
|
||
|
}
|
||
|
if (lx < SHRT_MIN) {
|
||
|
lx = SHRT_MIN;
|
||
|
}
|
||
|
if (ly > SHRT_MAX) {
|
||
|
ly = SHRT_MAX;
|
||
|
}
|
||
|
if (ly < SHRT_MIN) {
|
||
|
ly = SHRT_MIN;
|
||
|
}
|
||
|
n_mark_abs((unsigned short)m_LaserCfg->m_Cno, lx, ly);
|
||
|
}
|
||
|
|
||
|
void RTC4Scanner::ScanDebug()
|
||
|
{
|
||
|
unsigned short power = (unsigned short)(1023.0*m_PowerCompensateCfg->CalcPowerCompensate((float)m_ScanTestCfg->m_laser_power) / 100.0);
|
||
|
if (power > 1023)power = 1023;
|
||
|
double markspeed = m_kfactor*m_ScanParamCfg->m_mark_speed / 1000.0;
|
||
|
n_set_start_list((unsigned short)m_LaserCfg->m_Cno, 1);
|
||
|
n_write_da_1_list((unsigned short)m_LaserCfg->m_Cno, power);
|
||
|
n_set_mark_speed((unsigned short)m_LaserCfg->m_Cno, markspeed);
|
||
|
if (m_ScanParamCfg->m_IsDynamicFocus) {
|
||
|
short df = m_ScanTestCfg->m_defocus*m_zfactor;
|
||
|
n_set_defocus_list((unsigned short)m_LaserCfg->m_Cno, df);
|
||
|
}
|
||
|
else {
|
||
|
n_set_defocus_list((unsigned short)m_LaserCfg->m_Cno, 0);
|
||
|
}
|
||
|
n_set_end_of_list((unsigned short)m_LaserCfg->m_Cno);
|
||
|
ListExecute(1, true);
|
||
|
do {
|
||
|
ScanTestProc();
|
||
|
Sleep(20);
|
||
|
} while (m_ScanTestCfg->m_is_cycle && m_DebugFlag);
|
||
|
}
|
||
|
|
||
|
void RTC4Scanner::ScanTestProc()
|
||
|
{
|
||
|
int shapeSize = m_ScanTestCfg->m_shape_size;
|
||
|
switch (m_ScanTestCfg->m_debug_shape) {
|
||
|
case 0: {
|
||
|
double xoffset = m_ScanTestCfg->m_cross_x*cos(m_CorrectParamCfg->m_angle*MathHelper::m_PI / 180.0) - m_ScanTestCfg->m_cross_y*sin(m_CorrectParamCfg->m_angle*MathHelper::m_PI / 180.0);
|
||
|
double yoffset = m_ScanTestCfg->m_cross_x*sin(m_CorrectParamCfg->m_angle*MathHelper::m_PI / 180.0) + m_ScanTestCfg->m_cross_y*cos(m_CorrectParamCfg->m_angle*MathHelper::m_PI / 180.0);
|
||
|
double tempx = xoffset - shapeSize / 2;
|
||
|
double tempy = yoffset + shapeSize / 2;
|
||
|
n_set_start_list((unsigned short)m_LaserCfg->m_Cno, 1);
|
||
|
JumpAbs(tempx, yoffset);
|
||
|
MarkAbs(tempx + shapeSize, yoffset);
|
||
|
JumpAbs(xoffset, tempy);
|
||
|
MarkAbs(xoffset, tempy - shapeSize);
|
||
|
n_set_end_of_list((unsigned short)m_LaserCfg->m_Cno);
|
||
|
ListExecute(1, true);
|
||
|
}break;
|
||
|
case 1: {
|
||
|
float sqlength = (float)shapeSize / 2;
|
||
|
double xoffset = m_ScanTestCfg->m_cross_x*cos(m_CorrectParamCfg->m_angle*MathHelper::m_PI / 180.0) - m_ScanTestCfg->m_cross_y*sin(m_CorrectParamCfg->m_angle*MathHelper::m_PI / 180.0);
|
||
|
double yoffset = m_ScanTestCfg->m_cross_x*sin(m_CorrectParamCfg->m_angle*MathHelper::m_PI / 180.0) + m_ScanTestCfg->m_cross_y*cos(m_CorrectParamCfg->m_angle*MathHelper::m_PI / 180.0);
|
||
|
polygon square[] = {
|
||
|
-sqlength + xoffset, -sqlength + yoffset,
|
||
|
-sqlength + xoffset, sqlength + yoffset,
|
||
|
sqlength + xoffset, sqlength + yoffset,
|
||
|
sqlength + xoffset, -sqlength + yoffset,
|
||
|
-sqlength + xoffset, -sqlength + yoffset
|
||
|
};
|
||
|
int sqsize = (sizeof(square) / sizeof(polygon));
|
||
|
n_set_start_list((unsigned short)m_LaserCfg->m_Cno, 1);
|
||
|
JumpAbs(square[0].xval, square[0].yval);
|
||
|
for (int i = 1; i < sqsize; i++) {
|
||
|
MarkAbs(square[i].xval, square[i].yval);
|
||
|
}
|
||
|
n_set_end_of_list((unsigned short)m_LaserCfg->m_Cno);
|
||
|
ListExecute(1, true);
|
||
|
}break;
|
||
|
case 2: {
|
||
|
n_set_start_list(m_LaserCfg->m_Cno, 1);
|
||
|
n_set_defocus_list(m_LaserCfg->m_Cno, 0);
|
||
|
JumpAbs(m_ScanTestCfg->m_cross_x, m_ScanTestCfg->m_cross_y);
|
||
|
n_set_end_of_list(m_LaserCfg->m_Cno);
|
||
|
ListExecute(1, true);
|
||
|
Sleep(200);
|
||
|
n_laser_signal_on(m_LaserCfg->m_Cno);
|
||
|
DWORD tflag = GetTickCount();
|
||
|
while (m_DebugFlag) {
|
||
|
Sleep(20);
|
||
|
DWORD tnow = GetTickCount();
|
||
|
unsigned int dif = tnow - tflag;
|
||
|
if (dif >= m_ExtCfg->m_TestEmissionTime) {
|
||
|
m_DebugFlag = false;
|
||
|
if (m_ScanTestCfg->m_is_cycle) {
|
||
|
m_ScanTestCfg->m_is_cycle = false;
|
||
|
}
|
||
|
//StopWork();
|
||
|
}
|
||
|
}
|
||
|
n_laser_signal_off(m_LaserCfg->m_Cno);
|
||
|
}break;
|
||
|
case 3: {
|
||
|
n_set_defocus_list((unsigned short)m_LaserCfg->m_Cno, 0);
|
||
|
Sleep(10);
|
||
|
long zlength = n_get_z_distance((unsigned short)m_LaserCfg->m_Cno, m_ScanTestCfg->m_cross_x*m_xfactor, m_ScanTestCfg->m_cross_y*m_yfactor, 0);
|
||
|
if (m_zfactor != 0.0) {
|
||
|
m_ScanTestCfg->m_z_distance = (double)zlength / m_zfactor;
|
||
|
}
|
||
|
}break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void RTC4Scanner::UpdateSetting()
|
||
|
{
|
||
|
unsigned short power = 1023.0* m_PowerCompensateCfg->CalcPowerCompensate((float)m_ScanTestCfg->m_laser_power) / 100.0;
|
||
|
if (power > 1023)power = 1023;
|
||
|
unsigned short jumpDelay = m_ScanParamCfg->m_jump_delay / 10;
|
||
|
unsigned short markDelay = m_ScanParamCfg->m_scan_delay / 10;
|
||
|
unsigned short polygonDelay = m_ScanParamCfg->m_polygon_delay / 10;
|
||
|
|
||
|
double markspeed = m_kfactor* m_ScanParamCfg->m_mark_speed / 1000.0;
|
||
|
double jumpspeed = m_kfactor* m_ScanParamCfg->m_jump_speed / 1000.0;
|
||
|
unsigned short edgeLevel = m_ScanParamCfg->m_edge_level / 10;
|
||
|
unsigned short minJumpDelay = m_ScanParamCfg->m_min_jump_delay / 10;
|
||
|
n_set_start_list((unsigned short)m_LaserCfg->m_Cno, 1);
|
||
|
n_write_da_1_list((unsigned short)m_LaserCfg->m_Cno, power);
|
||
|
n_set_scanner_delays((unsigned short)m_LaserCfg->m_Cno, jumpDelay, markDelay, polygonDelay);
|
||
|
n_set_laser_delays((unsigned short)m_LaserCfg->m_Cno, (short)m_ScanParamCfg->m_laseron_delay, (short)m_ScanParamCfg->m_laseroff_delay);
|
||
|
n_set_delay_mode((unsigned short)m_LaserCfg->m_Cno, 1, 0, edgeLevel, minJumpDelay, (unsigned int)(m_ScanParamCfg->m_jump_length_limit*m_kfactor));
|
||
|
n_set_jump_speed((unsigned short)m_LaserCfg->m_Cno, jumpspeed);
|
||
|
n_set_mark_speed((unsigned short)m_LaserCfg->m_Cno, markspeed);
|
||
|
n_set_end_of_list((unsigned short)m_LaserCfg->m_Cno);
|
||
|
ListExecute(1, true);
|
||
|
}
|
||
|
|
||
|
void RTC4Scanner::SetXyOffset(float x, float y)
|
||
|
{
|
||
|
short bitx = x*m_xfactor*m_scaleX;
|
||
|
short bity = y*m_yfactor*m_scaleY;
|
||
|
n_set_offset((unsigned short)m_LaserCfg->m_Cno, bitx, bity);
|
||
|
}
|
||
|
|
||
|
|
||
|
void RTC4Scanner::SetAngle(double angle)
|
||
|
{
|
||
|
double m11 = cos(angle*MathHelper::m_PI / 180.0);
|
||
|
double m12 = -sin(angle*MathHelper::m_PI / 180.0);
|
||
|
double m21 = sin(angle*MathHelper::m_PI / 180.0);
|
||
|
double m22 = cos(angle*MathHelper::m_PI / 180.0);
|
||
|
n_set_matrix((unsigned short)m_LaserCfg->m_Cno, m11, m12, m21, m22);
|
||
|
}
|