Kaynağa Gözat

建立初始的工程

DESKTOP-1PBHPQR\admin 2 yıl önce
işleme
bbfc82afe3
13 değiştirilmiş dosya ile 3194 ekleme ve 0 silme
  1. 188 0
      CGH_ProjectView.cpp
  2. 428 0
      CGH_ProjectView.ui
  3. 375 0
      CGH_Relays.cpp
  4. 80 0
      CGH_Shutter.cpp
  5. 1 0
      CGH_State.cpp
  6. 1 0
      CGH_TabBar.cpp
  7. 1 0
      CGH_TabWidget.cpp
  8. BIN
      CH375DLL.DLL
  9. BIN
      PI_GCS2_DLL.dll
  10. 182 0
      PrintThread.cpp
  11. 60 0
      main.cpp
  12. 14 0
      resource.h
  13. 1864 0
      ui_CGH_Printer.h

+ 188 - 0
CGH_ProjectView.cpp

@@ -0,0 +1,188 @@
+#include "CGH_ProjectView.h"
+#include "ui_CGH_ProjectView.h"
+#include <QFileDialog>
+#include <QMessageBox>
+#include <QString>
+#include <string>
+#pragma execution_character_set("utf-8")
+
+CGH_ProjectView::CGH_ProjectView(QWidget *parent)
+	: QDialog(parent)
+{
+	ui = new Ui::CGH_ProjectView();
+	ui->setupUi(this);
+    initSlots();
+}
+
+CGH_ProjectView::~CGH_ProjectView()
+{
+	delete ui;
+}
+
+void CGH_ProjectView::initSlots()
+{
+	connect(ui->ButtonViewResource, SIGNAL(clicked()), this, SLOT(ChooseResourcePath()));
+	connect(ui->ButtonViewOk, SIGNAL(clicked()), this, SLOT(OkNewProject()));
+	connect(ui->ButtonViewCancel, SIGNAL(clicked()), this, SLOT(CancelNewProject()));
+}
+
+// 资源路径
+void CGH_ProjectView::ChooseResourcePath()
+{
+    QFileDialog* file_dialog = new QFileDialog(this);
+    file_dialog->setOption(QFileDialog::ShowDirsOnly);//设置显示选项
+    file_dialog->setFileMode(QFileDialog::Directory);//设置文件模式
+    file_dialog->setViewMode(QFileDialog::List);//设置显示模式
+    //点击确定按钮
+    if (file_dialog->exec() == QFileDialog::Accepted)
+    {
+        //获取新建项目路径
+        QString path = file_dialog->selectedFiles().at(0);
+        ui->ViewResource->setText(path);//设置路径栏
+    }
+    //点取消则返回
+    else
+    {
+        return;
+    }
+    delete file_dialog;
+    file_dialog = NULL;
+}
+
+// 确认
+void CGH_ProjectView::OkNewProject()
+{
+    //判断名字与路径是否为空
+    if (ui->ViewName->text().isEmpty())
+    {
+        QMessageBox::information(this, tr("提示"), tr("表格未填写完整,新建项目失败:\n文件名不可为空!"), QMessageBox::Yes);
+        return;
+    }
+
+    if (ui->ViewLSpacing->text().isEmpty() || ui->ViewCSpacing->text().isEmpty() || ui->ViewLine->text().isEmpty() || ui->ViewColumn->text().isEmpty())
+    {
+        QMessageBox::information(this, tr("提示"), tr("表格未填写完整,新建项目失败:\n控制设置不可为空!"), QMessageBox::Yes);
+        return;
+    }
+
+    if (ui->ViewPrefix->text().isEmpty() || ui->ViewExpose->text().isEmpty() || ui->ViewQuiet->text().isEmpty())
+    {
+        QMessageBox::information(this, tr("提示"), tr("表格未填写完整,新建项目失败:\n曝光设置不可为空!"), QMessageBox::Yes);
+        return;
+    }
+
+    if (ui->ViewSave->text().isEmpty() || ui->ViewResource->text().isEmpty())
+    {
+        QMessageBox::information(this, tr("提示"), tr("表格未填写完整,新建项目失败:\n路径设置不可为空!"), QMessageBox::Yes);
+        return;
+    }
+    QDialog::accept();
+}
+
+// 取消
+void CGH_ProjectView::CancelNewProject()
+{
+    if (QMessageBox::warning(this, tr("提示"), tr("确定取消创建工程?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
+    {
+        QDialog::reject();
+    }
+    return;
+}
+
+string CGH_ProjectView::getViewName()
+{
+	return ui->ViewName->text().toStdString();
+}
+
+string CGH_ProjectView::getViewLSpacing()
+{
+	return ui->ViewLSpacing->text().toStdString();
+}
+
+string CGH_ProjectView::getViewCSpacing()
+{
+	return ui->ViewCSpacing->text().toStdString();
+}
+
+string CGH_ProjectView::getViewLine()
+{
+	return ui->ViewLine->text().toStdString();
+}
+
+string CGH_ProjectView::getViewColumn()
+{
+	return ui->ViewColumn->text().toStdString();
+}
+
+string CGH_ProjectView::getViewPrefix()
+{
+	return ui->ViewPrefix->text().toStdString();
+}
+
+string CGH_ProjectView::getViewExpose()
+{
+	return ui->ViewExpose->text().toStdString();
+}
+
+string CGH_ProjectView::getViewQuiet()
+{
+	return ui->ViewQuiet->text().toStdString();
+}
+
+string CGH_ProjectView::getViewResource()
+{
+	return ui->ViewResource->text().toStdString();
+}
+
+void CGH_ProjectView::setViewName(const string& str)
+{
+    ui->ViewName->setText(QString::fromStdString(str));
+}
+
+void CGH_ProjectView::setViewLSpacing(const string& str)
+{
+    ui->ViewLSpacing->setText(QString::fromStdString(str));
+}
+
+void CGH_ProjectView::setViewCSpacing(const string& str)
+{
+    ui->ViewCSpacing->setText(QString::fromStdString(str));
+}
+
+void CGH_ProjectView::setViewLine(const string& str)
+{
+    ui->ViewLine->setText(QString::fromStdString(str));
+}
+
+void CGH_ProjectView::setViewColumn(const string& str)
+{
+    ui->ViewColumn->setText(QString::fromStdString(str));
+}
+
+void CGH_ProjectView::setViewPrefix(const string& str)
+{
+    ui->ViewPrefix->setText(QString::fromStdString(str));
+}
+
+void CGH_ProjectView::setViewExpose(const string& str)
+{
+    ui->ViewExpose->setText(QString::fromStdString(str));
+}
+
+void CGH_ProjectView::setViewQuiet(const string& str)
+{
+    ui->ViewQuiet->setText(QString::fromStdString(str));
+}
+
+void CGH_ProjectView::setViewResource(const string& str)
+{
+    ui->ViewResource->setText(QString::fromStdString(str));
+}
+
+void CGH_ProjectView::initWindow()
+{
+    relproPath = "../Project";
+    curabsPath = (QCoreApplication::applicationDirPath()).toStdString();
+    absproPath = curabsPath + "/" + relproPath;
+	ui->ViewSave->setText(QString::fromStdString(absproPath));
+}

+ 428 - 0
CGH_ProjectView.ui

@@ -0,0 +1,428 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>CGH_ProjectView</class>
+ <widget class="QDialog" name="CGH_ProjectView">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>600</height>
+   </rect>
+  </property>
+  <property name="minimumSize">
+   <size>
+    <width>400</width>
+    <height>600</height>
+   </size>
+  </property>
+  <property name="maximumSize">
+   <size>
+    <width>400</width>
+    <height>600</height>
+   </size>
+  </property>
+  <property name="windowTitle">
+   <string>创建工程</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <widget class="QGroupBox" name="groupBox_6">
+     <property name="title">
+      <string/>
+     </property>
+     <layout class="QHBoxLayout" name="horizontalLayout">
+      <item>
+       <widget class="QLabel" name="label_14">
+        <property name="text">
+         <string>文件名</string>
+        </property>
+        <property name="alignment">
+         <set>Qt::AlignCenter</set>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QLineEdit" name="ViewName">
+        <property name="alignment">
+         <set>Qt::AlignCenter</set>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
+    <widget class="QGroupBox" name="groupBox">
+     <property name="font">
+      <font>
+       <pointsize>12</pointsize>
+      </font>
+     </property>
+     <property name="title">
+      <string>控制设置</string>
+     </property>
+     <layout class="QGridLayout" name="gridLayout_3">
+      <item row="0" column="0">
+       <widget class="QGroupBox" name="groupBox_2">
+        <property name="font">
+         <font>
+          <pointsize>9</pointsize>
+         </font>
+        </property>
+        <property name="title">
+         <string>步进位移</string>
+        </property>
+        <layout class="QGridLayout" name="gridLayout">
+         <item row="0" column="0">
+          <widget class="QLabel" name="label">
+           <property name="text">
+            <string>行距</string>
+           </property>
+           <property name="alignment">
+            <set>Qt::AlignCenter</set>
+           </property>
+          </widget>
+         </item>
+         <item row="0" column="1">
+          <widget class="QLineEdit" name="ViewLSpacing">
+           <property name="alignment">
+            <set>Qt::AlignCenter</set>
+           </property>
+          </widget>
+         </item>
+         <item row="0" column="2">
+          <widget class="QLabel" name="label_2">
+           <property name="text">
+            <string>mm</string>
+           </property>
+           <property name="alignment">
+            <set>Qt::AlignCenter</set>
+           </property>
+          </widget>
+         </item>
+         <item row="1" column="0">
+          <widget class="QLabel" name="label_3">
+           <property name="text">
+            <string>列距</string>
+           </property>
+           <property name="alignment">
+            <set>Qt::AlignCenter</set>
+           </property>
+          </widget>
+         </item>
+         <item row="1" column="1">
+          <widget class="QLineEdit" name="ViewCSpacing">
+           <property name="alignment">
+            <set>Qt::AlignCenter</set>
+           </property>
+          </widget>
+         </item>
+         <item row="1" column="2">
+          <widget class="QLabel" name="label_4">
+           <property name="text">
+            <string>mm</string>
+           </property>
+           <property name="alignment">
+            <set>Qt::AlignCenter</set>
+           </property>
+          </widget>
+         </item>
+        </layout>
+       </widget>
+      </item>
+      <item row="0" column="1">
+       <widget class="QGroupBox" name="groupBox_3">
+        <property name="font">
+         <font>
+          <pointsize>9</pointsize>
+         </font>
+        </property>
+        <property name="title">
+         <string>图片设置</string>
+        </property>
+        <layout class="QGridLayout" name="gridLayout_2">
+         <item row="0" column="0">
+          <widget class="QLabel" name="label_5">
+           <property name="text">
+            <string>行数</string>
+           </property>
+           <property name="alignment">
+            <set>Qt::AlignCenter</set>
+           </property>
+          </widget>
+         </item>
+         <item row="0" column="1">
+          <widget class="QLineEdit" name="ViewLine">
+           <property name="alignment">
+            <set>Qt::AlignCenter</set>
+           </property>
+          </widget>
+         </item>
+         <item row="1" column="0">
+          <widget class="QLabel" name="label_6">
+           <property name="text">
+            <string>列数</string>
+           </property>
+           <property name="alignment">
+            <set>Qt::AlignCenter</set>
+           </property>
+          </widget>
+         </item>
+         <item row="1" column="1">
+          <widget class="QLineEdit" name="ViewColumn">
+           <property name="alignment">
+            <set>Qt::AlignCenter</set>
+           </property>
+          </widget>
+         </item>
+        </layout>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
+    <widget class="QGroupBox" name="groupBox_4">
+     <property name="font">
+      <font>
+       <pointsize>12</pointsize>
+      </font>
+     </property>
+     <property name="title">
+      <string>曝光设置</string>
+     </property>
+     <layout class="QGridLayout" name="gridLayout_4">
+      <item row="0" column="0">
+       <widget class="QLabel" name="label_7">
+        <property name="font">
+         <font>
+          <pointsize>9</pointsize>
+         </font>
+        </property>
+        <property name="text">
+         <string>前缀</string>
+        </property>
+        <property name="alignment">
+         <set>Qt::AlignCenter</set>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="1">
+       <widget class="QLineEdit" name="ViewPrefix">
+        <property name="font">
+         <font>
+          <pointsize>9</pointsize>
+         </font>
+        </property>
+        <property name="alignment">
+         <set>Qt::AlignCenter</set>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="0">
+       <widget class="QLabel" name="label_8">
+        <property name="font">
+         <font>
+          <pointsize>9</pointsize>
+         </font>
+        </property>
+        <property name="text">
+         <string>曝光时间</string>
+        </property>
+        <property name="alignment">
+         <set>Qt::AlignCenter</set>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="1">
+       <widget class="QLineEdit" name="ViewExpose">
+        <property name="font">
+         <font>
+          <pointsize>9</pointsize>
+         </font>
+        </property>
+        <property name="alignment">
+         <set>Qt::AlignCenter</set>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="2">
+       <widget class="QLabel" name="label_10">
+        <property name="font">
+         <font>
+          <pointsize>9</pointsize>
+         </font>
+        </property>
+        <property name="text">
+         <string>ms</string>
+        </property>
+        <property name="alignment">
+         <set>Qt::AlignCenter</set>
+        </property>
+       </widget>
+      </item>
+      <item row="2" column="0">
+       <widget class="QLabel" name="label_9">
+        <property name="font">
+         <font>
+          <pointsize>9</pointsize>
+         </font>
+        </property>
+        <property name="text">
+         <string>静台时间</string>
+        </property>
+        <property name="alignment">
+         <set>Qt::AlignCenter</set>
+        </property>
+       </widget>
+      </item>
+      <item row="2" column="1">
+       <widget class="QLineEdit" name="ViewQuiet">
+        <property name="font">
+         <font>
+          <pointsize>9</pointsize>
+         </font>
+        </property>
+        <property name="alignment">
+         <set>Qt::AlignCenter</set>
+        </property>
+       </widget>
+      </item>
+      <item row="2" column="2">
+       <widget class="QLabel" name="label_11">
+        <property name="font">
+         <font>
+          <pointsize>9</pointsize>
+         </font>
+        </property>
+        <property name="text">
+         <string>ms</string>
+        </property>
+        <property name="alignment">
+         <set>Qt::AlignCenter</set>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
+    <widget class="QGroupBox" name="groupBox_5">
+     <property name="font">
+      <font>
+       <pointsize>12</pointsize>
+      </font>
+     </property>
+     <property name="title">
+      <string>路径设置</string>
+     </property>
+     <layout class="QGridLayout" name="gridLayout_5">
+      <item row="0" column="0">
+       <widget class="QLabel" name="label_12">
+        <property name="font">
+         <font>
+          <pointsize>9</pointsize>
+         </font>
+        </property>
+        <property name="text">
+         <string>存储路径</string>
+        </property>
+        <property name="alignment">
+         <set>Qt::AlignCenter</set>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="0">
+       <widget class="QLabel" name="label_13">
+        <property name="font">
+         <font>
+          <pointsize>9</pointsize>
+         </font>
+        </property>
+        <property name="text">
+         <string>资源路径</string>
+        </property>
+        <property name="alignment">
+         <set>Qt::AlignCenter</set>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="1">
+       <widget class="QLineEdit" name="ViewResource">
+        <property name="font">
+         <font>
+          <pointsize>9</pointsize>
+         </font>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="2">
+       <widget class="QPushButton" name="ButtonViewResource">
+        <property name="font">
+         <font>
+          <pointsize>9</pointsize>
+         </font>
+        </property>
+        <property name="text">
+         <string>选择</string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="1" colspan="2">
+       <widget class="QLineEdit" name="ViewSave">
+        <property name="font">
+         <font>
+          <pointsize>9</pointsize>
+         </font>
+        </property>
+        <property name="readOnly">
+         <bool>true</bool>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
+    <widget class="QGroupBox" name="groupBox_7">
+     <property name="title">
+      <string/>
+     </property>
+     <layout class="QHBoxLayout" name="horizontalLayout_2">
+      <item>
+       <spacer name="horizontalSpacer">
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>40</width>
+          <height>20</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+      <item>
+       <widget class="QPushButton" name="ButtonViewOk">
+        <property name="text">
+         <string>确定</string>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QPushButton" name="ButtonViewCancel">
+        <property name="text">
+         <string>取消</string>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <resources/>
+ <connections/>
+</ui>

+ 375 - 0
CGH_Relays.cpp

@@ -0,0 +1,375 @@
+#include "CGH_Relays.h"
+
+/*******************************************************************
+* 名称: openSyn
+* 功能: 同步方式打开串口,并配置默认信息
+* 参数:
+    serial_name:串口名称
+    baud_rate  :波特率,取值如下
+        ......
+        CBR_9600    9600bps
+        CBR_14400   14400bps
+        ......
+    parity     :校验方式
+        EVENPARITY  偶校验
+        MARKPARITY  标号校验
+        NOPARITY    无校验
+        ODDPARITY   奇校验
+        SPACEPARITY 空格校验
+    byte_size  :数据位大小
+        4,5,6,7,8
+    stop_bits  :停止位
+        ONESTOPBIT      1个停止位
+        ONE5STOPBITS    1.5个停止位
+        TWOSTOPBITS     2个停止位
+* 返回: 正确返回为ture,错误返回为false
+*******************************************************************/
+bool CGH_Relays::openSyn(string serial_name, unsigned char baud_rate, unsigned char parity, unsigned char byte_size, unsigned char stop_bits)
+{
+    if (!openSyn(serial_name))
+        return false;
+    DCB dcb;
+
+    if (false == GetCommState(hCom, &dcb))//获得当前串口的配置信息
+    {
+        setSerialLastError("SerialInterface::open() : GetCommState Error");
+        return false;
+    }
+
+    dcb.DCBlength = sizeof(DCB);
+    dcb.BaudRate = baud_rate;
+    dcb.Parity = parity;
+    dcb.ByteSize = byte_size;
+    dcb.StopBits = stop_bits;
+
+    if (false == SetCommState(hCom, &dcb))//用DCB结构重新配置串行端口信息
+    {
+        setSerialLastError("SerialInterface::open() : SetCommState Error");
+        return false;
+    }
+
+    //超时处理
+    COMMTIMEOUTS timeouts;
+    timeouts.ReadIntervalTimeout = MAXDWORD; //读间隔超时
+    // 把间隔超时设为最大,把总超时设为0将导致ReadFile立即返回并完成操作 
+
+    timeouts.ReadTotalTimeoutMultiplier = 0; //读时间系数
+    timeouts.ReadTotalTimeoutConstant = 0; //读时间常量
+    timeouts.WriteTotalTimeoutMultiplier = 50; // 写时间系数
+    timeouts.WriteTotalTimeoutConstant = 2000; //写时间常量
+    //总的读/写超时时间 = Read(Write)TotalTimeoutMultiplier x 要读/写的字节数 + Read(Write)TotalTimeoutConstant. 
+    if (false==SetCommTimeouts(hCom, &timeouts))
+    {
+        setSerialLastError("SerialInterface::open() : SetCommTimeouts Error");
+        return false;
+    }
+
+
+
+    //清空缓冲区,为读写串口做准备
+    if (false == PurgeComm(hCom, PURGE_TXCLEAR | PURGE_RXCLEAR | PURGE_TXABORT | PURGE_RXABORT))
+    {
+        setSerialLastError("SerialInterface::open() : PurgeComm Error");
+        return false;
+    }
+    return true;
+}
+
+/*******************************************************************
+* 名称: openSyn
+* 功能: 同步方式打开串口(需自己配置串口参数)
+* 参数:
+    serial_name:串口名称
+* 返回: 正确返回为ture,错误返回为false
+*******************************************************************/
+bool CGH_Relays::openSyn(string serial_name)
+{
+	hCom = CreateFileA(
+		serial_name.data(),//普通文件名或者设备文件名,这里是串口名
+		GENERIC_READ | GENERIC_WRITE,//访问模式,读和写
+		0,//共享模式,独占模式
+		NULL,//指向安全属性的指针,不使用,传NULL
+		OPEN_EXISTING,//如何创建,在串口中必须设置为OPEN_EXISTING。表示不能创建新端口只能打开已有的端口。
+		FILE_ATTRIBUTE_NORMAL,//文件属性,使用默认属性FILE_ATTRIBUTE_NORMAL。
+		NULL//用于复制文件句柄,通常这个参数设置为NULL,为空表示不使用模板
+	);
+
+
+	if (INVALID_HANDLE_VALUE == hCom)//出错判断
+	{
+		hCom = NULL;
+        setSerialLastError("open():CreateFileA Error!");
+		return false;
+	}
+	return true;
+}
+
+/*******************************************************************
+* 名称: closeComm
+* 功能: 关闭串口
+* 参数: 无
+* 返回: 正确返回为ture,错误返回为false
+*******************************************************************/
+void CGH_Relays::closeComm()
+{
+    if(NULL==hCom)
+        return;
+    CloseHandle(hCom);
+    hCom=NULL;
+}
+
+/*******************************************************************
+* 名称: closeComm
+* 功能: 判断串口是否打开
+* 参数: 无
+* 返回: 正确返回为ture,错误返回为false
+*******************************************************************/
+bool CGH_Relays::isOpened()
+{
+    return NULL == hCom ? false : true;
+}
+
+DWORD CGH_Relays::readData(char *buffer,int length)
+{
+    DWORD writeSize=0;
+
+    bool ret=false;
+
+    ret=ReadFile(hCom,buffer,length,&writeSize,NULL);
+
+    if(false==ret)
+        return 0;
+
+    return writeSize;
+}
+
+DWORD CGH_Relays::writeData(char *buffer,int length)
+{
+    DWORD writeSize=0;
+
+    bool ret=false;
+
+    ret=WriteFile(hCom,buffer,length,&writeSize,NULL);
+
+    if(false==ret)
+        return 0;
+
+    return writeSize;
+
+}
+
+DWORD CGH_Relays::writeStr(string str)
+{
+	bool ret = false;
+
+	DWORD writeSize = 0;
+
+
+	ret = WriteFile(hCom, str.data(), str.length(), &writeSize, NULL);
+
+    if (0 == ret)
+    {
+        last_error = "Error By writeStr(string str)";
+        return 0;
+    }
+		
+
+    last_error = "";
+	return writeSize;
+
+}
+
+/*******************************************************************
+* 名称: setTimeouts
+* 功能: 设置超时
+* 参数:
+    timeouts:超时配置的COMMTIMEOUTS结构体
+* 返回: 正确返回为ture,错误返回为false
+*******************************************************************/
+bool CGH_Relays::setTimeouts(COMMTIMEOUTS &timeouts)
+{
+
+    if (false == SetCommTimeouts(hCom, &timeouts))
+    {
+        setSerialLastError("SerialInterface::setTimeouts() : SetCommTimeouts Error");
+        return false;
+    }
+    return true;
+}
+
+/*******************************************************************
+* 名称: setDCB
+* 功能: 设置串口信息
+* 参数:
+    dcb:串口信息配置的DCB结构体
+* 返回: 正确返回为ture,错误返回为false
+*******************************************************************/
+bool CGH_Relays::setDCB(DCB& dcb)
+{
+    if (false == SetCommState(hCom, &dcb))
+    {
+        setSerialLastError("SerialInterface::setDCB() : SetCommState Error");
+        return false;
+    }
+    return true;
+}
+
+/*******************************************************************
+* 名称: purgeBuff
+* 功能: 刷新缓冲区
+* 参数: 
+    flags:需要完成的操作,取值如下
+        PURGE_RXABORT 终止所有未完成的重叠读取操作并立即返回,即使读取操作尚未完成。
+        PURGE_RXCLEAR 清除输入缓冲区(如果设备驱动程序有一个)。
+        PURGE_TXABORT 终止所有未完成的重叠写操作并立即返回,即使写操作尚未完成。
+        PURGE_TXCLEAR 清除输出缓冲区(如果设备驱动程序有一个)。
+* 返回: 正确返回为ture,错误返回为false
+* 提示:PurgeComm()函数可以在读写操作的同时,清空缓冲区。当应用程序在读写操作时
+调用PurgeComm()函数,不能保证缓冲区内的所有字符都被发送。
+*******************************************************************/
+bool CGH_Relays::purgeBuff(DWORD flags)
+{
+
+    if (false == PurgeComm(hCom, flags))
+    {
+        setSerialLastError("SerialInterface::purgeBuff() : PurgeComm Error");
+        return false;
+    }
+    return true;
+}
+
+/*******************************************************************
+* 名称:flushBuff
+* 功能:刷新缓冲区
+* 参数:无
+* 返回:正确返回为ture,错误返回为false
+* 提示:该函数只受流量控制的支配,不受超时控制的支配,它在所有的写操作完成后才返回。
+*******************************************************************/
+bool CGH_Relays::flushBuff()
+{
+    if(FlushFileBuffers(hCom))
+    {
+        setSerialLastError("SerialInterface::flushBuff() : FlushFileBuffers Error");
+        return false;
+    }
+    return true;
+}
+
+/*******************************************************************
+* 名称: setBufferSize
+* 功能: 设置推荐的缓冲大小
+* 参数:
+    inputBuff:输入缓冲大小
+    outBuffer:输出缓冲大小
+* 返回: 正确返回为ture,错误返回为false
+*******************************************************************/
+bool CGH_Relays::setBufferSize(DWORD inputBuff,DWORD outBuffer)
+{
+    if(inputBuff<=0||outBuffer<=0)
+        return false;
+    
+    return SetupComm(hCom,inputBuff,outBuffer);
+}
+
+/*******************************************************************
+* 名称: getSerialLastError
+* 功能: 得到最后一次失败的错误信息
+* 参数: 无
+* 返回: 数据类型:string,错误信息
+*******************************************************************/
+string CGH_Relays::getSerialLastError()
+{
+    return last_error;
+}
+
+bool CGH_Relays::OpenUSB1()
+{
+    char OpenUSB1DataBuf[4];
+    OpenUSB1DataBuf[0] = 0xA0;
+    OpenUSB1DataBuf[1] = 0x01;
+    OpenUSB1DataBuf[2] = 0x01;
+    OpenUSB1DataBuf[3] = 0xA2;
+
+    if (writeData(OpenUSB1DataBuf, 4))
+    {
+        return true;
+    }
+    else
+    {
+        return false;
+    }
+}
+
+bool CGH_Relays::CloseUSB1()
+{
+	char CloseUSB1DataBuf[4];
+    CloseUSB1DataBuf[0] = 0xA0;
+    CloseUSB1DataBuf[1] = 0x01;
+    CloseUSB1DataBuf[2] = 0x00;
+    CloseUSB1DataBuf[3] = 0xA1;
+
+	if (writeData(CloseUSB1DataBuf, 4))
+	{
+		return true;
+	}
+	else
+	{
+		return false;
+	}
+}
+
+bool CGH_Relays::OpenUSB2()
+{
+	char OpenUSB2DataBuf[4];
+	OpenUSB2DataBuf[0] = 0xA0;
+	OpenUSB2DataBuf[1] = 0x02;
+	OpenUSB2DataBuf[2] = 0x01;
+	OpenUSB2DataBuf[3] = 0xA3;
+
+	if (writeData(OpenUSB2DataBuf, 4))
+	{
+		return true;
+	}
+	else
+	{
+		return false;
+	}
+}
+
+bool CGH_Relays::CloseUSB2()
+{
+	char CloseUSB2DataBuf[4];
+	CloseUSB2DataBuf[0] = 0xA0;
+	CloseUSB2DataBuf[1] = 0x02;
+	CloseUSB2DataBuf[2] = 0x00;
+	CloseUSB2DataBuf[3] = 0xA2;
+
+	if (writeData(CloseUSB2DataBuf, 4))
+	{
+		return true;
+	}
+	else
+	{
+		return false;
+	}
+}
+
+void CGH_Relays::setSerialLastError(string error_msg)
+{
+    last_error = error_msg;
+}
+
+void CGH_Relays::clearSerialLastError()
+{
+    last_error = "";
+}
+
+CGH_Relays::CGH_Relays()
+{
+    hCom=NULL;
+}
+
+CGH_Relays::~CGH_Relays()
+{
+
+}

+ 80 - 0
CGH_Shutter.cpp

@@ -0,0 +1,80 @@
+#include "CGH_Shutter.h"
+//#include "CH375DLL.H"
+//#pragma comment(lib, "CH375DLL.LIB")
+//#pragma comment(lib, "CH375DLLd.LIB")
+
+CGH_Shutter::CGH_Shutter()
+{
+    mIndex = 0;
+    m_open = false;
+    if (!m_open)
+    {
+        if (CH375OpenDevice(mIndex) == INVALID_HANDLE_VALUE)   // 打开CH375设备
+        {
+            return;
+        }
+        m_open = TRUE;
+    }
+    CH375OpenDevice(mIndex);
+    m_open = TRUE;
+}
+
+int CGH_Shutter::open()
+{
+    if (!m_open)
+    {
+        return -1;
+    }
+    ULONG dlen = 2;
+    unsigned char* mBuf;
+    unsigned char  srcmBuf[3];
+    srcmBuf[0] = '8'; srcmBuf[1] = 'a'; srcmBuf[2] = '\0';
+    mBuf = mStrtoVal(srcmBuf, 4);
+    CH375WriteData(mIndex, &mBuf[0], &dlen);
+    return 0;
+
+}
+
+int CGH_Shutter::close() {
+    if (!m_open)
+    {
+        return -1;
+    }
+    ULONG dlen = 2;
+    unsigned char* mBuf;
+    unsigned char  srcmBuf[3];
+    srcmBuf[0] = '0'; srcmBuf[1] = 'a'; srcmBuf[2] = '\0';
+    mBuf = mStrtoVal(srcmBuf, 4);
+    CH375WriteData(mIndex, &mBuf[0], &dlen);
+    return 0;
+}
+
+CGH_Shutter::~CGH_Shutter() 
+{
+}
+
+bool CGH_Shutter::isconnected()
+{
+    return m_open;
+}
+
+void CGH_Shutter::disconnected()
+{
+    close();
+    if (m_open)
+        CH375CloseDevice(mIndex);
+}
+
+//void CGH_Shutter::connect()
+//{
+//    mIndex = 0;
+//    m_open = false;
+//    if (!m_open)
+//    {
+//        if (CH375OpenDevice(mIndex) == INVALID_HANDLE_VALUE)   // 打开CH375设备
+//        {
+//            return;
+//        }
+//        m_open = TRUE;
+//    }
+//}

+ 1 - 0
CGH_State.cpp

@@ -0,0 +1 @@
+#include "CGH_State.h"

+ 1 - 0
CGH_TabBar.cpp

@@ -0,0 +1 @@
+#include "CGH_TabBar.h"

+ 1 - 0
CGH_TabWidget.cpp

@@ -0,0 +1 @@
+#include "CGH_TabWidget.h"

BIN
CH375DLL.DLL


BIN
PI_GCS2_DLL.dll


+ 182 - 0
PrintThread.cpp

@@ -0,0 +1,182 @@
+#include "PrintThread.h"
+
+PrintThread::PrintThread(QObject* parent) : m_Printer(dynamic_cast<CGH_Printer*>(parent))
+{
+	connect(this, SIGNAL(TransCGH(const QString&)), m_Printer, SLOT(SLMUpdate(const QString&)));
+	connect(this, SIGNAL(TransPrintProgress(int, int)), m_Printer, SLOT(PrintUpdate(int, int)));
+	connect(this, SIGNAL(PrintOK()), m_Printer, SLOT(PrintOKUpdate()));
+	connect(this, SIGNAL(PrintCancel()), m_Printer, SLOT(PrintCancelUpdate()));
+
+
+	// 初始化变量
+	MyShutter = new CGH_Shutter();
+	HoloLine = 0;
+	HoloColumn = 0;
+	OffsetX = 0;
+	PrintColumn = 0;
+	PrintExpose = 0;
+	PrintLine = 0;
+	PrintQuiet = 0;
+	PrintLSpacing = 0;
+	PrintCSpacing = 0;
+	initPrintX = 0;
+	initPrintY = 0;
+	PRINTSTOP = FALSE;
+}
+
+PrintThread::~PrintThread()
+{
+
+}
+
+
+
+std::string PrintThread::numberToString(int n, int l /*= 3*/)
+{
+	string res = to_string(n);
+	int length = res.size();
+	while (length++ < l) {
+		res = "0" + res;
+	}
+	return res;
+}
+
+void PrintThread::run()
+{
+	Print();
+	if (!PRINTSTOP)
+	{
+		emit PrintOK();
+	}
+	else
+	{
+		emit PrintCancel();
+	}
+}
+
+
+void PrintThread::Print()
+{
+	PRINTSTOP = FALSE;
+
+	// 主线程参数传递到子线程
+	Devices = m_Printer->Get_Devices();
+	sAxis = m_Printer->Get_sAxis();
+	PrintLSpacing = m_Printer->Get_PrintLSpacing();
+	PrintCSpacing = m_Printer->Get_PrintCSpacing();
+	PrintLine = m_Printer->Get_PrintLine();
+	PrintColumn = m_Printer->Get_PrintColumn();
+	PrintPrefix = m_Printer->Get_PrintPrefix();
+	PrintExpose = m_Printer->Get_PrintExpose();
+	PrintQuiet = m_Printer->Get_PrintQuiet();
+	PrintResource = m_Printer->Get_PrintResource();
+
+	// 平移台
+	HoloLine = PrintLSpacing * PrintLine;
+	HoloColumn = PrintCSpacing * PrintColumn;
+	initPrintX = -(HoloColumn + PrintCSpacing) / 2;
+	initPrintY = -(HoloLine - PrintLSpacing) / 2;
+	PI_MOV(Devices[0], sAxis.c_str(), &initPrintX);
+	PI_MOV(Devices[1], sAxis.c_str(), &initPrintY);
+
+	BOOL isMoving_sAxisX = TRUE;
+	BOOL isMoving_sAxisY = TRUE;
+	while (isMoving_sAxisX || isMoving_sAxisY)
+	{
+		PI_IsMoving(Devices[0], sAxis.c_str(), &isMoving_sAxisX);
+		PI_IsMoving(Devices[1], sAxis.c_str(), &isMoving_sAxisY);
+
+		QCoreApplication::processEvents();
+	}
+
+	 // 开始打印任务
+	int LL, CC, KK;
+	string Format = ".bmp";
+	string sep = "/";
+	string Filename, PrintFullname;
+	string midl, midr;
+	OffsetY = PrintLSpacing;
+	for (LL = 1; LL <= PrintLine; LL++)
+	{
+		midl = numberToString(LL);
+
+		for (CC = 1; CC <= PrintColumn; CC++)
+		{
+			if (LL % 2 == 1)
+			{
+				KK = CC;
+				midr = numberToString(KK);
+			}
+			else
+			{
+				KK = PrintColumn - CC + 1;
+				midr = numberToString(KK);
+			}
+
+			Filename = PrintPrefix + midl + midr + Format;
+			PrintFullname = PrintResource + sep + Filename;
+
+			if (LL % 2 == 1)
+			{
+				OffsetX = PrintCSpacing;
+				PI_MVR(Devices[0], sAxis.c_str(), &OffsetX);
+			}
+			else
+			{
+				OffsetX = -1 * PrintCSpacing;
+				PI_MVR(Devices[0], sAxis.c_str(), &OffsetX);
+			}
+
+			isMoving_sAxisX = TRUE;
+			isMoving_sAxisY = TRUE;
+			while (isMoving_sAxisX || isMoving_sAxisY)
+			{
+				PI_IsMoving(Devices[0], sAxis.c_str(), &isMoving_sAxisX);
+				PI_IsMoving(Devices[1], sAxis.c_str(), &isMoving_sAxisY);
+
+				QCoreApplication::processEvents();
+			}
+
+			emit TransCGH(QString::fromStdString(PrintFullname));
+
+			Sleep(PrintQuiet);// 静台
+
+			MyShutter->open();
+			Sleep(PrintExpose);
+			MyShutter->close();
+
+			emit TransPrintProgress(LL, CC);
+
+			PRINTSTOP = m_Printer->Get_PRINTSTOP();
+			if (PRINTSTOP)
+			{
+				break;
+			}
+		}
+		if (LL % 2 == 1)
+		{
+			OffsetX = PrintCSpacing;
+			PI_MVR(Devices[0], sAxis.c_str(), &OffsetX);
+		}
+		else
+		{
+			OffsetX = -1 * PrintCSpacing;
+			PI_MVR(Devices[0], sAxis.c_str(), &OffsetX);
+		}
+		PI_MVR(Devices[1], sAxis.c_str(), &OffsetY);
+
+		isMoving_sAxisX = TRUE;
+		isMoving_sAxisY = TRUE;
+		while (isMoving_sAxisX || isMoving_sAxisY)
+		{
+			PI_IsMoving(Devices[0], sAxis.c_str(), &isMoving_sAxisX);
+			PI_IsMoving(Devices[1], sAxis.c_str(), &isMoving_sAxisY);
+
+			QCoreApplication::processEvents();
+		}
+		if (PRINTSTOP)
+		{
+			break;
+		}
+	}
+}

+ 60 - 0
main.cpp

@@ -0,0 +1,60 @@
+#include "CGH_Printer.h"
+#include <QApplication>
+#include <QFile>
+
+int main(int argc, char *argv[])
+{
+//     添加一个槽函数,页面切换打开相机 第210行---------------------------------
+// 	   视频预览稍有修改,添加了一个判定条件 第1169-------------------------------
+// 	   修改tabwidget的背景颜色实现了部分 第 35 行-------------------------------
+	// 
+	//实现全屏显示
+
+
+	QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+	QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
+
+	//DEVMODE NewDevMode;
+	////获取屏幕设置中的分辨率
+	//EnumDisplaySettings(0, ENUM_CURRENT_SETTINGS, &NewDevMode);
+	//qreal  cx = NewDevMode.dmPelsWidth;			//当前设置的屏幕宽度
+
+	////qreal  cx = GetSystemMetrics(SM_CXSCREEN);
+	//qreal scale = cx / 960;				// 960 = 1920 / 2
+	//qputenv("QT_SCALE_FACTOR", QString::number(scale).toLatin1());
+
+
+	 //实现全屏显示
+	qputenv("QT_SCALE_FACTOR", "2.0");
+
+	//QT设计师的预览界面和运行界面不一致解决办法
+	//if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
+	//	QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+	if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
+		QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+    QApplication a(argc, argv);
+	//QWidget* widget = new QWidget();
+
+	//师兄留下的几行注释代码
+	//QFile qss(":/QSS/IMG/QSS/MacOS.qss");
+	//qss.open(QFile::ReadOnly);
+	//qApp->setStyleSheet(qss.readAll());
+	//qss.close();
+
+
+    CGH_Printer w;
+	//修改窗口背景色
+	QPalette palette;
+	palette.setBrush(QPalette::Background, QBrush(Qt::darkCyan));
+	w.setPalette(palette);
+	
+	// 
+	// 
+    //w.show();
+	//w.showFullScreen();
+	//w.setWindowState(w.windowState() ^ Qt::WindowFullScreen);
+	w.show();
+	
+
+    return a.exec();
+}

+ 14 - 0
resource.h

@@ -0,0 +1,14 @@
+//{{NO_DEPENDENCIES}}
+// Microsoft Visual C++ generated include file.
+// Used by CGH_Printer.rc
+
+// жÔÏóµÄÏÂÒ»×éĬÈÏÖµ
+// 
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NEXT_RESOURCE_VALUE        101
+#define _APS_NEXT_COMMAND_VALUE         40001
+#define _APS_NEXT_CONTROL_VALUE         1001
+#define _APS_NEXT_SYMED_VALUE           101
+#endif
+#endif

Dosya farkı çok büyük olduğundan ihmal edildi
+ 1864 - 0
ui_CGH_Printer.h