hlp:桂林国际齿轮泵代码

This commit is contained in:
kite_lucs
2026-10-09 10:25:24 +08:00
commit fd606b3c81
2447 changed files with 999531 additions and 0 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

@@ -0,0 +1,290 @@
#include "modbustcp.h"
#include "InkJetPrinter.h"
#include <QDebug>
#include <QFile>
#include "../../LogInfo.h"
#include <iostream>
#include <string>
/* ----------------------- Modbus includes ----------------------------------*/
#include "mb.h"
#include "mbport.h"
/* ----------------------- Defines ------------------------------------------*/
#define REG_INPUT_START 1
#define REG_INPUT_NREGS 400
#define REG_HOLDING_START 1//40001 //40001
#define REG_HOLDING_NREGS 400
/* ----------------------- Static variables ---------------------------------*/
static USHORT usRegInputStart = REG_INPUT_START;
//static USHORT usRegInputBuf[REG_INPUT_NREGS];
static USHORT usRegHoldingStart = REG_HOLDING_START;
//static USHORT usRegHoldingBuf[REG_HOLDING_NREGS];
USHORT* usRegInputBuf;
USHORT* usRegHoldingBuf;
ModbusTcp::ModbusTcp(ModbusPrintParas *mPara, const ModbusPrintStatus* mStatus)
{
#ifdef MODBUS
modbus_status = 0;
modbus_up_QRCODE = 0;
if( eMBTCPInit( MB_TCP_PORT_USE_DEFAULT ) != MB_ENOERR )
{
qDebug()<< "can't initialize modbus stack!\r\n";
modbus_status = -1;
}
else
{
eSetPollingThreadState( STOPPED );
/* CLI interface. */
//bDoExit = FALSE;
}
input_registers = (uint16_t*) mStatus;
holding_registers = (uint16_t*) mPara;
moveToThread(&m_thread);
m_thread.start();
if (modbus_status != -1) {
connect(&m_thread, SIGNAL(started()), this, SLOT(pvPollingThread()));
modbus_status = 1;
}
#endif
}
ModbusTcp::~ModbusTcp(void)
{
#ifdef MODBUS
disconnect(&m_thread, SIGNAL(started()), this, SLOT(pvPollingThread()));
if (m_thread.isRunning()) {
m_thread.quit();
m_thread.wait();
}
( void )eMBClose( );
#endif
}
extern InkJetPrinter *pInkJectPrinter;
void ModbusTcp::pvPollingThread()
{
#ifdef MODBUS
eSetPollingThreadState( RUNNING );
if (modbus_status != 1) {
return;
}
if( eMBEnable( ) == MB_ENOERR )
{
do
{
if( eMBPoll( ) != MB_ENOERR ) {
qDebug()<<"modbus poll error";
break;
}
}
while( eGetPollingThreadState( ) != SHUTDOWN );
}
if( eMBEnable( ) == MB_ENOERR )
( void )eMBDisable( );
eSetPollingThreadState( STOPPED );
#endif
return;
}
enum ThreadState
ModbusTcp::eGetPollingThreadState( )
{
enum ThreadState eCurState;
modbusThreadMutex.lock();
eCurState = ePollThreadState;
modbusThreadMutex.unlock();
return eCurState;
}
void
ModbusTcp::eSetPollingThreadState( enum ThreadState eNewState )
{
modbusThreadMutex.lock();
ePollThreadState = eNewState;
modbusThreadMutex.unlock();
}
qint32 ModbusTcp::getModbusStatus()
{
return modbus_status;
}
qint32 ModbusTcp::processCommands(qint32 index)
{
qint32 rc = 0;
// 打印机指令
if(index == ((offsetof(ModbusPrintParas, printCommand) + sizeof(uint16_t))/2 - 1)) { // 打印控制
if(holding_registers[index] == PRINT_START_COMMAND) {
emit startPrint();
}
else if(holding_registers[index] == PRINT_PAUSE_COMMAND) {
emit pausePrint();
}
else if(holding_registers[index] == PRINT_STOP_COMMAND) {
emit stopPrint();
}
}
else if(index == ((offsetof(ModbusPrintParas, QRcode_buf) + 240)/2 - 1)) { // 传送DM码数据
qDebug() << "updateQRcode";
modbus_up_QRCODE = true;
emit updateQRcode();
}
else if(index == ((offsetof(ModbusPrintParas, selectFileName) + 100)/2 - 1)) { // 打开文件
char fileName[100];
int fileIndex = offsetof(ModbusPrintParas, selectFileName)/2;
memcpy(fileName, &holding_registers[fileIndex], 100);
//qDebug()<<"oopen file: "<<fileName;
if (strlen(fileName)) {
QFile mdOpenFile(QString("/home/plg/doc/%1").arg(fileName));
if (mdOpenFile.exists()) {
emit openFile(mdOpenFile.fileName(), false);
}
}
}
else if(index == ((offsetof(ModbusPrintParas, printContent) + sizeof(uint16_t))/2 - 1)){
int content = holding_registers[index];
#ifdef PROJECT_PLC1
emit receivedPrintContent(content);
#endif
}
else if(index == ((offsetof(ModbusPrintParas, faultRusume) + sizeof(uint16_t))/2 - 1)) { // 报警恢复
emit faultResume();
}
else if(index == 113) { // 设置计数器1当前值
qDebug()<<"writeCalendar1"<< endl;
emit writeCalendar1();
}
else if(index == 117) { // 设置计数器1结束值
qDebug()<<"writeCalendar1EndValue"<< endl;
emit writeCalendar1EndValue();
}
else if(index == 119) { // 设置计数器2结束值
qDebug()<<"writeCalendar2EndValue"<< endl;
emit writeCalendar2EndValue();
}
else if(index == 121) { // 设置计数器2重复值
qDebug()<<"writeCalendar2RepeatValue"<< endl;
emit writeCalendar2RepeatValue();
}
else if(index == 129) { // 设置计数器2起始值
qDebug()<<"writeCalendar2InitValue"<< endl;
emit writeCalendar2InitValue();
}
else if(index == 136) { // 立即重新计米
qDebug()<<"CNTResetNow"<< endl;
emit CNTResetNow();
}
else if(index == ((offsetof(ModbusPrintParas, setCalendar) + sizeof(calandar_and_dat_t))/2 - 1)) { // 设置计数器1,2
emit writeCalendar();
}
else if(index == ((offsetof(ModbusPrintParas, lineSpaceAndCharSpace) + sizeof(uint32_t))/2 - 1)) { // 设置字符间距和行间距
int lineSpace = holding_registers[index];
int charSpace = holding_registers[index-1];
emit mbLineAndCharSpace(lineSpace, charSpace);
}
return rc;
}
eMBErrorCode
eMBRegInputCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs )
{
eMBErrorCode eStatus = MB_ENOERR;
int iRegIndex;
if( ( usAddress >= REG_INPUT_START )
&& ( usAddress + usNRegs <= REG_INPUT_START + REG_INPUT_NREGS ) )
{
usRegInputBuf = (USHORT*) pInkJectPrinter->modbus->input_registers;
iRegIndex = ( int )( usAddress - usRegInputStart );
while( usNRegs > 0 )
{
*pucRegBuffer++ = ( unsigned char )(( usRegInputBuf[iRegIndex] >> 8 )& 0xFF);
*pucRegBuffer++ = ( unsigned char )( usRegInputBuf[iRegIndex] & 0xFF );
iRegIndex++;
usNRegs--;
}
}
else
{
eStatus = MB_ENOREG;
}
return eStatus;
}
eMBErrorCode
eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegisterMode eMode )
{
eMBErrorCode eStatus = MB_ENOERR;
int iRegIndex;
if( ( usAddress >= REG_HOLDING_START ) &&
( usAddress + usNRegs <= REG_HOLDING_START + REG_HOLDING_NREGS ) )
{
usRegHoldingBuf = (USHORT*) pInkJectPrinter->modbus->holding_registers;
iRegIndex = ( int )( usAddress - usRegHoldingStart );
switch ( eMode )
{
/* Pass current register values to the protocol stack. */
case MB_REG_READ:
while( usNRegs > 0 )
{
*pucRegBuffer++ = ( UCHAR ) ( usRegHoldingBuf[iRegIndex] >> 8 );
*pucRegBuffer++ = ( UCHAR ) ( usRegHoldingBuf[iRegIndex] & 0xFF );
iRegIndex++;
usNRegs--;
}
break;
/* Update current register values with new values from the
* protocol stack. */
case MB_REG_WRITE:
while( usNRegs > 0 )
{
usRegHoldingBuf[iRegIndex] = *pucRegBuffer++ << 8;
usRegHoldingBuf[iRegIndex] |= *pucRegBuffer++;
pInkJectPrinter->modbus->processCommands(iRegIndex);
iRegIndex++;
usNRegs--;
}
}
}
else
{
eStatus = MB_ENOREG;
}
return eStatus;
}
eMBErrorCode
eMBRegCoilsCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNCoils, eMBRegisterMode eMode )
{
Q_UNUSED(pucRegBuffer);
Q_UNUSED(usAddress);
Q_UNUSED(usNCoils);
Q_UNUSED(eMode);
return MB_ENOREG;
}
eMBErrorCode
eMBRegDiscreteCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNDiscrete )
{
Q_UNUSED(pucRegBuffer);
Q_UNUSED(usAddress);
Q_UNUSED(usNDiscrete);
return MB_ENOREG;
}
@@ -0,0 +1,138 @@
/*
*
*
* DIFF_SEPTAL_POSITION 隔膜位置由20改为50的主泵动作时间
*/
#ifndef INKJETPRINTER_H
#define INKJETPRINTER_H
#define SPEEDOVER //超速停止
#include <QTabWidget>
#include <QTimer>
#include <QTime>
#include "Tftp/filetranseceiver.h"
#include "ParaSettingUI.h"
#include "modbus/modbustcp.h"
#include <QCloseEvent>
#include "dlgshowmsg.h"
#include <QThread>
#include <QMessageBox>
namespace Ui {
class InkJetPrinter;
}
#define MAX_PRESSURE_RELEASE_DIFF 25
#define MAX_PRESSURE_DIFF 50
#define MAX_VISICOSITY_RATIO 110 //105%
#define DIFF_SEPTAL_POSITION 50
#define MAX_VISICOSITY_VALUE_OVERFLOW_NUM 3 //连续超过此值会进行粘度调整
#define MAX_ALLOW_VISICOSITY_OVERFLOW_NUM 120 //连续超那么多次,会被认为粘度故障
class PicScene;
class InkJetPrinter : public QTabWidget,public ParaSettingUI
{
Q_OBJECT
public:
explicit InkJetPrinter(QWidget *parent = 0);
~InkJetPrinter();
void pressureAdj(int);
FileTranseceiver* fileTransceiv;
FileTranseceiver* tcpTransceiv;
// void processCommands();
#ifdef MODBUS
// class ModbusSerial *modbus;
class ModbusTcp *modbus;
QThread m_thread;
#endif
public slots:
void onchangeEditMode(int);
void onChangeTab(QString);
//void onPrintErrorStatus(QString s);
void onPrintErrorStatus(QString s, unsigned int res);
void close_jd_timer();
void handlePushButtonStartPressed(bool);
void handleInitedPID();
void onModbusWriteCalendar();
void resetPressureCnt();
void pressureAdjustForsystemseeting();
private:
Ui::InkJetPrinter *ui;
DlgShowMsg *dlgShowMsg;
//MainWindow *mainWindow;
QTimer* viscosity_timer;
QTimer* timer;
QTimer* jd_timer;
QTime t1;
void autoControlHeater();
void autoControlValvePump();
void detectAndcontrolReclaimTank();
void refreshModbusStatus(void);
void checkPressureControl();
void showMessage(QString);
Q_SIGNALS:
// void updateQRcode();
// void startPrint();
// void pausePrint();
// void stopPrint();
void setReclaimTankCurrentPos(int);
void reclaimTankOpenDone();
void reclaimTankCloseDone();
void reclaimTankBlock(); //回收槽卡住
//void changeEditMode(int);
void SpeedOver(int mode);
void updateCnt1GroupDisp(bool);void updateCnt2GroupDisp(bool);
void updataPara2UI();
void sendPicScene(PicScene* pPicScene);
void openFile(QString filePath,bool insertFlag);
private slots:
void OnSpeedOver(int mode);
void jd_timerHandler();
void timerHandler();
void onInkJetPrinterCurrentChanged(int index);
void onReclaimTankBlock();
void onAuthChanged(int auth);
void onConfigChanged();
void OnFinished(int event);
void OnBoxFinished(int event);
void DacAdjustStore();
void fpgaDebugWriteByte();
void fpgaDebugReadByte();
void fpgaDebugWriteWord();
void fpgaDebugReadWord();
void fpgaDebugWriteDWord();
void fpgaDebugReadDWord();
void recievedFile2Save(QString fileName);
void viscosity_timerHandler();
void disableTabClick();
private:
QLabel *t_label;
QMessageBox *msgtest,*msgBox1;
void closeEvent(QCloseEvent *event);
void resizeEvent(QResizeEvent *);
void checkMixValveOpen();
void checkMixValveClose();
void cycleValveRunForSelfCheck();
void cnt1GroupCheck(void);void cnt2GroupCheck(void);
void loadVoltageValue();
char jd_res;
bool pushButtonStartFlag;
unsigned char rWarnViscoReady;
};
#endif // INKJETPRINTER_H
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

@@ -0,0 +1,24 @@
#ifndef DIALOGLINESPACE_H
#define DIALOGLINESPACE_H
#include <QDialog>
namespace Ui {
class DialogLineSpace;
}
class DialogLineSpace : public QDialog
{
Q_OBJECT
public:
explicit DialogLineSpace(QWidget *parent = 0);
~DialogLineSpace();
void getValue(int *lineSpace,int *charSpace);
void setValue(int lineSpace,int charSpace);
private:
Ui::DialogLineSpace *ui;
};
#endif // DIALOGLINESPACE_H
@@ -0,0 +1,24 @@
!greaterThan(QT_MAJOR_VERSION, 4): {
INCLUDEPATH += \
$$PWD
SOURCES += \
$$PWD/qjson.cpp \
$$PWD/qjsonarray.cpp \
$$PWD/qjsondocument.cpp \
$$PWD/qjsonobject.cpp \
$$PWD/qjsonparser.cpp \
$$PWD/qjsonvalue.cpp \
$$PWD/qjsonwriter.cpp
HEADERS += \
$$PWD/qjson_p.h \
$$PWD/qjsonarray.h \
$$PWD/qjsondocument.h \
$$PWD/qjsonobject.h \
$$PWD/qjsonparser_p.h \
$$PWD/qjsonvalue.h \
$$PWD/qjsonwriter_p.h
}
@@ -0,0 +1,64 @@
#ifndef DIALOGCYCLEPRINT_H
#define DIALOGCYCLEPRINT_H
#include <QDialog>
typedef struct {
int area_end1;
int area_end2;
int area_end3;
int area_end4;
int area_end5;
int area_end6;
int cycle_time1;
int cycle_time2;
int cycle_time3;
int cycle_time4;
int cycle_time5;
int cycle_time6;
}CycleprintArg;
namespace Ui {
class DialogCycleprint;
}
class DialogCycleprint : public QDialog
{
Q_OBJECT
public:
explicit DialogCycleprint(QWidget *parent = 0);
void getSpinboxValue(CycleprintArg &t_arg);
void SetSpinboxValue(CycleprintArg &t_arg);
void update_save();
~DialogCycleprint();
private slots:
void on_spinBoxarea3_editingFinished();
void on_spinBoxcycletime3_editingFinished();
void on_spinBoxarea4_editingFinished();
void on_spinBoxcycletime4_editingFinished();
void on_spinBoxarea5_editingFinished();
void on_spinBoxcycletime5_editingFinished();
void on_spinBoxarea6_editingFinished();
void on_spinBoxcycletime6_editingFinished();
private:
void set_spinBox_value(int area, int cycletime, int which_box);
CycleprintArg save_arg;
Ui::DialogCycleprint *ui;
};
#endif // DIALOGCYCLEPRINT_H