From 4e08ff5ed53d447181726576b6d02c9fc2415338 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Mon, 24 Jun 2024 20:46:01 +0800 Subject: [PATCH] update --- a8000_protocol | 2 +- src/basic/widgetplot2d.cpp | 7 ++-- src/basic/widgetplot2d.h | 2 +- src/tab/plate_code_scaner_tab.cpp | 74 ++++++++++++++++++++++++--------------- 4 files changed, 51 insertions(+), 34 deletions(-) diff --git a/a8000_protocol b/a8000_protocol index 6388097..4f4db27 160000 --- a/a8000_protocol +++ b/a8000_protocol @@ -1 +1 @@ -Subproject commit 6388097349469105159878e482b826fb21c68734 +Subproject commit 4f4db2708e7503d5369c7b5f9bdc7781fcca1be9 diff --git a/src/basic/widgetplot2d.cpp b/src/basic/widgetplot2d.cpp index 5eef8ca..f585d5b 100644 --- a/src/basic/widgetplot2d.cpp +++ b/src/basic/widgetplot2d.cpp @@ -35,9 +35,8 @@ void WidgetPlot2D::addRefLine(double pos) { refLine->setLayer("refLineLayer"); // 将直线添加到我们创建的图层 refLine->setPen(QPen(Qt::red)); // 设置直线颜色 - double xPosition = 5.0; // 参考线的x轴位置 - refLine->point1->setCoords(xPosition, ui->customPlot->yAxis->range().lower); // 设置直线起点坐标 - refLine->point2->setCoords(xPosition, ui->customPlot->yAxis->range().upper); // 设置直线终点坐标 + refLine->point1->setCoords(pos, ui->customPlot->yAxis->range().lower); // 设置直线起点坐标 + refLine->point2->setCoords(pos, ui->customPlot->yAxis->range().upper); // 设置直线终点坐标 } WidgetPlot2D::~WidgetPlot2D() { delete ui; } @@ -467,7 +466,7 @@ void WidgetPlot2D::MyMouseMoveEvent(QMouseEvent* event) { if (dy <= y_tolerate && dx <= x_tolerate) { y_posval = ui->customPlot->graph(graphIndex)->data()->at(index)->value; - QString strToolTip = QString("CH%1 \nx=%2\ny=%3").arg(graphIndex + 1).arg(y_posval).arg(y_posval); + QString strToolTip = QString("CH%1 \nx=%2\ny=%3").arg(graphIndex + 1).arg(x_posval).arg(y_posval); QToolTip::showText(cursor().pos(), strToolTip, ui->customPlot); } diff --git a/src/basic/widgetplot2d.h b/src/basic/widgetplot2d.h index 6bab2bc..c42ab8a 100644 --- a/src/basic/widgetplot2d.h +++ b/src/basic/widgetplot2d.h @@ -24,6 +24,7 @@ class WidgetPlot2D : public QWidget { ~WidgetPlot2D(); void initGraphName(QStringList name); + void addRefLine(double pos); private: Ui::WidgetPlot2D *ui; @@ -42,7 +43,6 @@ class WidgetPlot2D : public QWidget { bool isDirExist(QString fullPath); void savePlotPng(); - void addRefLine(double pos); private slots: void changeGraphVisible(); diff --git a/src/tab/plate_code_scaner_tab.cpp b/src/tab/plate_code_scaner_tab.cpp index f705dee..b0fbe4b 100644 --- a/src/tab/plate_code_scaner_tab.cpp +++ b/src/tab/plate_code_scaner_tab.cpp @@ -26,6 +26,11 @@ PlateCodeScanerTab *PlateCodeScanerTab::inst() { return ins; } +typedef struct { + uint8_t buf[500]; + int16_t len; +} plate_code_cache_t; + void PlateCodeScanerTab::construct(QTabWidget *fathertab) { /*********************************************************************************************************************** * 模块操作 * @@ -47,58 +52,62 @@ void PlateCodeScanerTab::construct(QTabWidget *fathertab) { { ZQFunctionListBox *box = new ZQFunctionListBox(tab, "板夹仓扫描操作", 4); - box->newFunc("开始扫描", {"startpos"}, [this](int argn, const char **args) { ICM->callcmd1(getDeviceId(), kplate_code_scaner_start_scan, atoi(args[0])); }); + box->newFunc("开始扫描", {"stoppos"}, [this](int argn, const char **args) { ICM->callcmd1(getDeviceId(), kplate_code_scaner_push_card_and_scan, atoi(args[0])); }); box->newFunc("停止扫描", {}, [this](int argn, const char **args) { ICM->callcmd0(getDeviceId(), kplate_code_scaner_stop_scan); }); box->newFunc("读取结果", {}, [this](int argn, const char **args) { // int numResult = 0; // ICM->callcmd0(getDeviceId(), kplate_code_scaner_read_result_packet_num); // numResult = ICM->getAck(0); - // uint8_t buf[1024] = {0}; - // uint8_t len = 0; - // while (true) { - // ICM->callcmd0(getDeviceId(), kplate_code_scaner_read_result); - // if (ICM->getAckBufLen() == 0) break; + plate_code_cache_t rawcode = {0}; + int32_t packetIndex = 0; + while (true) { + ICM->callcmd1(getDeviceId(), kplate_code_scaner_read_result, packetIndex); + if (ICM->getAckBufLen() == 0) break; + + memcpy(rawcode.buf + rawcode.len, ICM->getAckBuf(), ICM->getAckBufLen()); + rawcode.len += ICM->getAckBufLen(); - // memcpy(buf + len, ICM->getAckBuf(), ICM->getAckBufLen()); - // len += ICM->getAckBufLen(); - // } + ZQUI::ins()->ishow("read(%d),%d", packetIndex, ICM->getAckBufLen()); + packetIndex++; + } - // int16_t *data = (int16_t *)buf; - // for (int i = 0; i < len / 2; i++) { - // ZQUI::ins()->ishow("%d", data[i]); - // } + ZQUI::ins()->ishow("pointNum:%d", rawcode.len / 2); - DoInUi([this]() { + DoInUi([this, rawcode]() { WidgetPlot2D *plot2d = new WidgetPlot2D(); QStringList lines; lines.push_back("line1"); plot2d->initGraphName(lines); - for (size_t i = 0; i < 10; i++) { - plot2d->addData("line1", i); + + int16_t *point_table = (int16_t *)rawcode.buf; + + for (int i = 0; i < rawcode.len / 2; i++) { + plot2d->addData("line1", point_table[i]); + } + + for (int i = 0; i < 15; i++) { + plot2d->addRefLine(i * 12 + 6); } + plot2d->show(); }); }); box->newFunc("读取条码", {}, [this](int argn, const char **args) { - int code0 = 0; - int code1 = 0; + // int32_t* rawcode, int32_t* legal, int32_t* item, int32_t* lot ICM->callcmd0(getDeviceId(), kplate_code_scaner_read_code); - code0 = ICM->getAck(0); - code1 = ICM->getAck(1); - - ZQUI::ins()->ishow("code0=%d, code1=%d", code0, code1); + int32_t rawcode = ICM->getAck(0); + int32_t legal = ICM->getAck(1); + int32_t item = ICM->getAck(2); + int32_t lot = ICM->getAck(3); + ZQUI::ins()->ishow("rawcode:0x%08x,legal:%d,item-lot: %d-%d", rawcode, legal, item, lot); }); } { ZQFunctionListBox *box = new ZQFunctionListBox(tab, "板夹仓扫码器-硬件调试", 4); - // kplate_code_scaner_adc_readraw = CMDID(0x73, 6), // int32_t* val - // kplate_code_scaner_open_laser = CMDID(0x73, 7), // - // kplate_code_scaner_close_laser = CMDID(0x73, 8), // - box->newSubButton("读取ADC", [this](int argn, const char **args) { int val = 0; ICM->callcmd0(getDeviceId(), kplate_code_scaner_adc_readraw); @@ -129,8 +138,17 @@ void PlateCodeScanerTab::construct(QTabWidget *fathertab) { tableBox->addReg("laster_intensity", kreg_plate_code_scaner_laster_intensity, ZRegItem::krw | ZRegItem::kdec); tableBox->addReg("scan_gain", kreg_plate_code_scaner_scan_gain, ZRegItem::krw | ZRegItem::kdec); - tableBox->addReg("scan_step_interval", kreg_plate_code_scaner_scan_step_interval, ZRegItem::krw | ZRegItem::kdec); - tableBox->addReg("scan_point_num", kreg_plate_code_scaner_scan_point_num, ZRegItem::krw | ZRegItem::kdec); + + tableBox->addReg("laster_intensity", kreg_plate_code_scaner_laster_intensity, ZRegItem::krw | ZRegItem::kdec); + tableBox->addReg("scan_gain", kreg_plate_code_scaner_scan_gain, ZRegItem::krw | ZRegItem::kdec); + tableBox->addReg("scan_velocity", kreg_plate_code_scaner_scan_velocity, ZRegItem::krw | ZRegItem::kdec); + tableBox->addReg("scan_start_pos(0.1mm)", kreg_plate_code_scaner_scan_start_pos, ZRegItem::krw | ZRegItem::kdec); + tableBox->addReg("final_stop_pos(0.1mm)", kreg_plate_code_scaner_final_stop_pos, ZRegItem::krw | ZRegItem::kdec); + tableBox->addReg("code_judgment_threshold(0..4095)", kreg_plate_code_scaner_code_judgment_threshold, ZRegItem::krw | ZRegItem::kdec); + tableBox->addReg("code_legal(1:有效,0:无效,-1:采集中断)", kreg_plate_code_scaner_code_legal, ZRegItem::krw | ZRegItem::kdec); + tableBox->addReg("item", kreg_plate_code_scaner_item, ZRegItem::krw | ZRegItem::kdec); + tableBox->addReg("lot", kreg_plate_code_scaner_lot, ZRegItem::krw | ZRegItem::kdec); + tableBox->addReg("rawcode", kreg_plate_code_scaner_rawcode, ZRegItem::krw | ZRegItem::kbinary); tableBox->addSpacer(); tab->addSpacer();