├── .gitignore ├── Makefile ├── README.md ├── serialtool.pro ├── src ├── comtoolmain.cpp ├── myqcombobox.h ├── myqlineedit.h ├── serialtool.cpp └── serialtool.h └── ui ├── close.jpg ├── error.jpg ├── error.png ├── erroring.png ├── myresource.qrc ├── network.jpg ├── off.jpg ├── on.jpg ├── serialtool.ui ├── success.png └── thank.png /.gitignore: -------------------------------------------------------------------------------- 1 | out/ 2 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ############################################################################# 2 | # Makefile for building: out/serialtool 3 | # Generated by qmake (2.01a) (Qt 4.7.2) on: Fri Jun 17 22:12:22 2011 4 | # Project: serialtool.pro 5 | # Template: app 6 | # Command: /usr/bin/qmake-qt4 -o Makefile serialtool.pro 7 | ############################################################################# 8 | 9 | ####### Compiler, tools and options 10 | 11 | CC = gcc 12 | CXX = g++ 13 | DEFINES = -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB 14 | CFLAGS = -pipe -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i686 -mtune=atom -fasynchronous-unwind-tables -Wall -W -D_REENTRANT $(DEFINES) 15 | CXXFLAGS = -pipe -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i686 -mtune=atom -fasynchronous-unwind-tables -Wall -W -D_REENTRANT $(DEFINES) 16 | INCPATH = -I/usr/lib/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include -I. -Isrc -Iout -Iout 17 | LINK = g++ 18 | LFLAGS = -Wl,-O1 19 | LIBS = $(SUBLIBS) -lQtGui -lQtCore -lpthread 20 | AR = ar cqs 21 | RANLIB = 22 | QMAKE = /usr/bin/qmake-qt4 23 | TAR = tar -cf 24 | COMPRESS = gzip -9f 25 | COPY = cp -f 26 | SED = sed 27 | COPY_FILE = $(COPY) 28 | COPY_DIR = $(COPY) -r 29 | STRIP = 30 | INSTALL_FILE = install -m 644 -p 31 | INSTALL_DIR = $(COPY_DIR) 32 | INSTALL_PROGRAM = install -m 755 -p 33 | DEL_FILE = rm -f 34 | SYMLINK = ln -f -s 35 | DEL_DIR = rmdir 36 | MOVE = mv -f 37 | CHK_DIR_EXISTS= test -d 38 | MKDIR = mkdir -p 39 | 40 | ####### Output directory 41 | 42 | OBJECTS_DIR = out/ 43 | 44 | ####### Files 45 | 46 | SOURCES = src/comtoolmain.cpp \ 47 | src/serialtool.cpp out/moc_myqcombobox.cpp \ 48 | out/moc_myqlineedit.cpp \ 49 | out/moc_serialtool.cpp \ 50 | out/qrc_myresource.cpp 51 | OBJECTS = out/comtoolmain.o \ 52 | out/serialtool.o \ 53 | out/moc_myqcombobox.o \ 54 | out/moc_myqlineedit.o \ 55 | out/moc_serialtool.o \ 56 | out/qrc_myresource.o 57 | DIST = /usr/lib/qt4/mkspecs/common/g++-multilib.conf \ 58 | /usr/lib/qt4/mkspecs/common/unix.conf \ 59 | /usr/lib/qt4/mkspecs/common/linux.conf \ 60 | /usr/lib/qt4/mkspecs/qconfig.pri \ 61 | /usr/lib/qt4/mkspecs/modules/qt_webkit_version.pri \ 62 | /usr/lib/qt4/mkspecs/features/qt_functions.prf \ 63 | /usr/lib/qt4/mkspecs/features/qt_config.prf \ 64 | /usr/lib/qt4/mkspecs/features/exclusive_builds.prf \ 65 | /usr/lib/qt4/mkspecs/features/default_pre.prf \ 66 | /usr/lib/qt4/mkspecs/features/release.prf \ 67 | /usr/lib/qt4/mkspecs/features/default_post.prf \ 68 | /usr/lib/qt4/mkspecs/features/warn_on.prf \ 69 | /usr/lib/qt4/mkspecs/features/qt.prf \ 70 | /usr/lib/qt4/mkspecs/features/unix/thread.prf \ 71 | /usr/lib/qt4/mkspecs/features/moc.prf \ 72 | /usr/lib/qt4/mkspecs/features/resources.prf \ 73 | /usr/lib/qt4/mkspecs/features/uic.prf \ 74 | /usr/lib/qt4/mkspecs/features/yacc.prf \ 75 | /usr/lib/qt4/mkspecs/features/lex.prf \ 76 | serialtool.pro 77 | QMAKE_TARGET = serialtool 78 | DESTDIR = out/ 79 | TARGET = out/serialtool 80 | 81 | first: all 82 | ####### Implicit rules 83 | 84 | .SUFFIXES: .o .c .cpp .cc .cxx .C 85 | 86 | .cpp.o: 87 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" 88 | 89 | .cc.o: 90 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" 91 | 92 | .cxx.o: 93 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" 94 | 95 | .C.o: 96 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" 97 | 98 | .c.o: 99 | $(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<" 100 | 101 | ####### Build rules 102 | 103 | all: Makefile $(TARGET) 104 | 105 | $(TARGET): out/ui_serialtool.h $(OBJECTS) 106 | @$(CHK_DIR_EXISTS) out/ || $(MKDIR) out/ 107 | $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS) 108 | 109 | Makefile: serialtool.pro /usr/lib/qt4/mkspecs/linux-g++/qmake.conf /usr/lib/qt4/mkspecs/common/g++-multilib.conf \ 110 | /usr/lib/qt4/mkspecs/common/unix.conf \ 111 | /usr/lib/qt4/mkspecs/common/linux.conf \ 112 | /usr/lib/qt4/mkspecs/qconfig.pri \ 113 | /usr/lib/qt4/mkspecs/modules/qt_webkit_version.pri \ 114 | /usr/lib/qt4/mkspecs/features/qt_functions.prf \ 115 | /usr/lib/qt4/mkspecs/features/qt_config.prf \ 116 | /usr/lib/qt4/mkspecs/features/exclusive_builds.prf \ 117 | /usr/lib/qt4/mkspecs/features/default_pre.prf \ 118 | /usr/lib/qt4/mkspecs/features/release.prf \ 119 | /usr/lib/qt4/mkspecs/features/default_post.prf \ 120 | /usr/lib/qt4/mkspecs/features/warn_on.prf \ 121 | /usr/lib/qt4/mkspecs/features/qt.prf \ 122 | /usr/lib/qt4/mkspecs/features/unix/thread.prf \ 123 | /usr/lib/qt4/mkspecs/features/moc.prf \ 124 | /usr/lib/qt4/mkspecs/features/resources.prf \ 125 | /usr/lib/qt4/mkspecs/features/uic.prf \ 126 | /usr/lib/qt4/mkspecs/features/yacc.prf \ 127 | /usr/lib/qt4/mkspecs/features/lex.prf 128 | $(QMAKE) -o Makefile serialtool.pro 129 | /usr/lib/qt4/mkspecs/common/g++-multilib.conf: 130 | /usr/lib/qt4/mkspecs/common/unix.conf: 131 | /usr/lib/qt4/mkspecs/common/linux.conf: 132 | /usr/lib/qt4/mkspecs/qconfig.pri: 133 | /usr/lib/qt4/mkspecs/modules/qt_webkit_version.pri: 134 | /usr/lib/qt4/mkspecs/features/qt_functions.prf: 135 | /usr/lib/qt4/mkspecs/features/qt_config.prf: 136 | /usr/lib/qt4/mkspecs/features/exclusive_builds.prf: 137 | /usr/lib/qt4/mkspecs/features/default_pre.prf: 138 | /usr/lib/qt4/mkspecs/features/release.prf: 139 | /usr/lib/qt4/mkspecs/features/default_post.prf: 140 | /usr/lib/qt4/mkspecs/features/warn_on.prf: 141 | /usr/lib/qt4/mkspecs/features/qt.prf: 142 | /usr/lib/qt4/mkspecs/features/unix/thread.prf: 143 | /usr/lib/qt4/mkspecs/features/moc.prf: 144 | /usr/lib/qt4/mkspecs/features/resources.prf: 145 | /usr/lib/qt4/mkspecs/features/uic.prf: 146 | /usr/lib/qt4/mkspecs/features/yacc.prf: 147 | /usr/lib/qt4/mkspecs/features/lex.prf: 148 | qmake: FORCE 149 | @$(QMAKE) -o Makefile serialtool.pro 150 | 151 | dist: 152 | @$(CHK_DIR_EXISTS) out/serialtool1.0.0 || $(MKDIR) out/serialtool1.0.0 153 | $(COPY_FILE) --parents $(SOURCES) $(DIST) out/serialtool1.0.0/ && $(COPY_FILE) --parents src/myqcombobox.h src/myqlineedit.h src/serialtool.h out/serialtool1.0.0/ && $(COPY_FILE) --parents ui/myresource.qrc out/serialtool1.0.0/ && $(COPY_FILE) --parents src/comtoolmain.cpp src/serialtool.cpp out/serialtool1.0.0/ && $(COPY_FILE) --parents ui/serialtool.ui out/serialtool1.0.0/ && (cd `dirname out/serialtool1.0.0` && $(TAR) serialtool1.0.0.tar serialtool1.0.0 && $(COMPRESS) serialtool1.0.0.tar) && $(MOVE) `dirname out/serialtool1.0.0`/serialtool1.0.0.tar.gz . && $(DEL_FILE) -r out/serialtool1.0.0 154 | 155 | 156 | clean:compiler_clean 157 | -$(DEL_FILE) $(OBJECTS) 158 | -$(DEL_FILE) *~ core *.core 159 | 160 | 161 | ####### Sub-libraries 162 | 163 | distclean: clean 164 | -$(DEL_FILE) $(TARGET) 165 | -$(DEL_FILE) Makefile 166 | 167 | 168 | check: first 169 | 170 | mocclean: compiler_moc_header_clean compiler_moc_source_clean 171 | 172 | mocables: compiler_moc_header_make_all compiler_moc_source_make_all 173 | 174 | compiler_moc_header_make_all: out/moc_myqcombobox.cpp out/moc_myqlineedit.cpp out/moc_serialtool.cpp 175 | compiler_moc_header_clean: 176 | -$(DEL_FILE) out/moc_myqcombobox.cpp out/moc_myqlineedit.cpp out/moc_serialtool.cpp 177 | out/moc_myqcombobox.cpp: src/myqcombobox.h 178 | /usr/lib/qt4/bin/moc $(DEFINES) $(INCPATH) src/myqcombobox.h -o out/moc_myqcombobox.cpp 179 | 180 | out/moc_myqlineedit.cpp: src/myqlineedit.h 181 | /usr/lib/qt4/bin/moc $(DEFINES) $(INCPATH) src/myqlineedit.h -o out/moc_myqlineedit.cpp 182 | 183 | out/moc_serialtool.cpp: out/ui_serialtool.h \ 184 | src/serialtool.h 185 | /usr/lib/qt4/bin/moc $(DEFINES) $(INCPATH) src/serialtool.h -o out/moc_serialtool.cpp 186 | 187 | compiler_rcc_make_all: out/qrc_myresource.cpp 188 | compiler_rcc_clean: 189 | -$(DEL_FILE) out/qrc_myresource.cpp 190 | out/qrc_myresource.cpp: ui/myresource.qrc \ 191 | ui/thank.png \ 192 | ui/close.jpg \ 193 | ui/erroring.png \ 194 | ui/error.jpg \ 195 | ui/success.png \ 196 | ui/off.jpg \ 197 | ui/network.jpg \ 198 | ui/on.jpg 199 | /usr/lib/qt4/bin/rcc -name myresource ui/myresource.qrc -o out/qrc_myresource.cpp 200 | 201 | compiler_image_collection_make_all: out/qmake_image_collection.cpp 202 | compiler_image_collection_clean: 203 | -$(DEL_FILE) out/qmake_image_collection.cpp 204 | compiler_moc_source_make_all: 205 | compiler_moc_source_clean: 206 | compiler_uic_make_all: out/ui_serialtool.h 207 | compiler_uic_clean: 208 | -$(DEL_FILE) out/ui_serialtool.h 209 | out/ui_serialtool.h: ui/serialtool.ui \ 210 | src/myqcombobox.h \ 211 | src/myqlineedit.h 212 | /usr/lib/qt4/bin/uic ui/serialtool.ui -o out/ui_serialtool.h 213 | 214 | compiler_yacc_decl_make_all: 215 | compiler_yacc_decl_clean: 216 | compiler_yacc_impl_make_all: 217 | compiler_yacc_impl_clean: 218 | compiler_lex_make_all: 219 | compiler_lex_clean: 220 | compiler_clean: compiler_moc_header_clean compiler_rcc_clean compiler_uic_clean 221 | 222 | ####### Compile 223 | 224 | out/comtoolmain.o: src/comtoolmain.cpp src/serialtool.h \ 225 | out/ui_serialtool.h 226 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o out/comtoolmain.o src/comtoolmain.cpp 227 | 228 | out/serialtool.o: src/serialtool.cpp src/serialtool.h \ 229 | out/ui_serialtool.h 230 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o out/serialtool.o src/serialtool.cpp 231 | 232 | out/moc_myqcombobox.o: out/moc_myqcombobox.cpp 233 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o out/moc_myqcombobox.o out/moc_myqcombobox.cpp 234 | 235 | out/moc_myqlineedit.o: out/moc_myqlineedit.cpp 236 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o out/moc_myqlineedit.o out/moc_myqlineedit.cpp 237 | 238 | out/moc_serialtool.o: out/moc_serialtool.cpp 239 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o out/moc_serialtool.o out/moc_serialtool.cpp 240 | 241 | out/qrc_myresource.o: out/qrc_myresource.cpp 242 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o out/qrc_myresource.o out/qrc_myresource.cpp 243 | 244 | ####### Install 245 | 246 | install: FORCE 247 | 248 | uninstall: FORCE 249 | 250 | FORCE: 251 | 252 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | serialtool -- 基于QT的串口调试助手 2 | ============================== 3 | 4 | 项目介绍 5 | ====== 6 | 本程序的编写者为 @zhuhehz,见[Ubuntu中文论坛](http://forum.ubuntu.org.cn/viewtopic.php?f=162&t=285625) 7 | 8 | 我对其进行了一些修改,包括: 9 | 10 | * 增加发送CRLF行结尾符功能 11 | * [todo]探测系统内的可用串口 12 | 13 | 等。 14 | 15 | 编译使用 16 | ====== 17 | 需要满足qt-dev依赖,然后`make`,用root权限运行`out/serialtool`即可。 18 | 19 | 如果不想使用root权限,需要将串口设备,比如`/dev/ttyUSB0`权限设666。 20 | 21 | 界面中COM1~4 对应`/dev/ttyS0~3`, COM5~6 对应 `/dev/ttyUSB0~1`。 22 | 23 | -------------------------------------------------------------------------------- /serialtool.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = serialtool 3 | DEPENDPATH += . src ui 4 | INCLUDEPATH += . src 5 | 6 | # Input 7 | HEADERS += src/myqcombobox.h src/myqlineedit.h src/serialtool.h 8 | FORMS += ui/serialtool.ui 9 | SOURCES += src/comtoolmain.cpp src/serialtool.cpp 10 | RESOURCES += ui/myresource.qrc 11 | 12 | # Output 13 | UI_DIR = out 14 | RCC_DIR = out 15 | MOC_DIR = out 16 | OBJECTS_DIR = out 17 | DESTDIR = out 18 | -------------------------------------------------------------------------------- /src/comtoolmain.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "serialtool.h" 5 | 6 | int main(int argc, char* argv[]) 7 | { 8 | QApplication app(argc, argv); 9 | QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); 10 | Q_INIT_RESOURCE(myresource); 11 | 12 | MyComTool tool; 13 | tool.show(); 14 | 15 | return app.exec(); 16 | } 17 | -------------------------------------------------------------------------------- /src/myqcombobox.h: -------------------------------------------------------------------------------- 1 | #ifndef MYQCOMBOBOX_H 2 | #define MYQCOMBOBOX_H 3 | 4 | 5 | #include 6 | #include 7 | class myQComboBox : public QComboBox 8 | { 9 | Q_OBJECT 10 | public: 11 | myQComboBox ( QWidget * parent ) : QComboBox(parent) {} 12 | 13 | 14 | virtual void keyPressEvent ( QKeyEvent * event ) 15 | { 16 | QString key_code; 17 | int key_val; 18 | key_val = event->key() ; 19 | key_code = event->text() ; 20 | if( (key_code != QString("1")) && (key_code != QString("2")) && (key_code != QString("3")) && (key_code != QString("4")) && (key_code != QString("5")) && (key_code != QString("6")) && (key_code != QString("7")) && (key_code != QString("8")) && (key_code != QString("9")) && (key_code != QString("0")) && (key_val != 16777219)) 21 | event->ignore(); 22 | else 23 | QComboBox::keyPressEvent ( event ); 24 | } 25 | }; 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /src/myqlineedit.h: -------------------------------------------------------------------------------- 1 | #ifndef MYQLINEEDIT_H 2 | #define MYQLINEEDIT_H 3 | 4 | 5 | #include 6 | #include 7 | class myQLineEdit : public QLineEdit 8 | { 9 | Q_OBJECT 10 | public: 11 | myQLineEdit ( QWidget * parent ) : QLineEdit(parent) {} 12 | 13 | 14 | virtual void keyPressEvent ( QKeyEvent * event ) 15 | { 16 | QString key_code; 17 | int key_val; 18 | key_val = event->key() ; 19 | key_code = event->text() ; 20 | if( (key_code != QString("1")) && (key_code != QString("2")) && (key_code != QString("3")) && (key_code != QString("4")) && (key_code != QString("5")) && (key_code != QString("6")) && (key_code != QString("7")) && (key_code != QString("8")) && (key_code != QString("9")) && (key_code != QString("0")) && (key_val != 16777219)) 21 | event->ignore(); 22 | else 23 | QLineEdit::keyPressEvent ( event ); 24 | } 25 | }; 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /src/serialtool.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "serialtool.h" 3 | 4 | MyComTool::MyComTool(QWidget* parent) 5 | : QWidget(parent), 6 | fd_com(-1), 7 | sty_num(0), 8 | auto_sent_count(0), 9 | receive_byte_counter(0), 10 | sent_byte_counter(0), 11 | already_sent_times(0), 12 | com_status(false), 13 | cease_receive_dispaly(false), 14 | auto_sent(false), 15 | sent_hex_model(false), 16 | saveFileName(QDir::currentPath () + "/comdata.txt"), 17 | com_all_status(""), 18 | com_Num("COM1"), 19 | saved("/tmp/savedata") 20 | 21 | { 22 | setupUi(this); 23 | myComThread = new ComReadThread(this); 24 | qApp->setStyle("GTK"); 25 | displayPathLabel->setText(saveFileName); 26 | autoSentpushButton->setEnabled (false); 27 | manualSentPushButton->setEnabled (false); 28 | saveDataPushButton->setEnabled (false); 29 | connect(openCloseSerialPushButton, SIGNAL(clicked()), this, SLOT(comStrat_Stop_Con())); 30 | connect(closeSelflPushButton, SIGNAL(clicked()), this, SLOT(close())); 31 | connect(clearDisplayPushButton, SIGNAL(clicked()), this, SLOT(clearCom_Receive())); 32 | connect(ceaseDisplayPushButton, SIGNAL(clicked()), this, SLOT(ceaseCom_Receive())); 33 | connect(autoSentpushButton, SIGNAL(clicked()), this, SLOT(set_autoCom_Sent())); 34 | connect(helpPushButton, SIGNAL(clicked()), this, SLOT(dis_Help_txt())); 35 | connect(clearSentPushButton, SIGNAL(clicked()), this, SLOT(clearCom_Sent())); 36 | connect(manualSentPushButton, SIGNAL(clicked()), this, SLOT(manualCom_Sent())); 37 | connect(colorPushButton, SIGNAL(clicked()), this, SLOT(set_widget_style() )); 38 | connect(hexDisplaycheckBox, SIGNAL(stateChanged(int)), this, SLOT(set_Receive_Hex(int))); 39 | connect(hexSentcheckBox, SIGNAL(stateChanged(int)), this, SLOT(set_sent_Hex(int))); 40 | connect(eolCheckBox, SIGNAL(stateChanged(int)), this, SLOT(set_eol(int))); 41 | connect(selectPathPushButton, SIGNAL(clicked()), this, SLOT(set_Save_Path())); 42 | connect(clearCountPushButton, SIGNAL(clicked()), this, SLOT(clear_Rs_counter())); 43 | connect(sentTimesPushButton, SIGNAL(clicked()), this, SLOT(clear_Sent_times())); 44 | connect(selectFilePushButton, SIGNAL(clicked()), this, SLOT(open_Sent_File())); 45 | connect(saveDataPushButton, SIGNAL(clicked()), this, SLOT(to_Save_File())); 46 | connect(&auto_sent_interval, SIGNAL(timeout ()), this, SLOT(to_autoCom_Sent())); 47 | connect(myComThread, SIGNAL(Log(QString)),this, SLOT(Log(QString))); 48 | connect(myComThread, SIGNAL(Name(QString)),this, SLOT(Name(QString))); 49 | connect(this, SIGNAL(ClearTmpFile()),myComThread,SLOT(ClearTmpFile())); 50 | 51 | } 52 | 53 | void MyComTool::comStrat_Stop_Con() 54 | { 55 | QString com_Buad, com_Testbit, com_Databit, com_Stopbit; 56 | QString path; 57 | if(com_status == false) 58 | { 59 | com_Num = selectserialComboBox->currentText(); 60 | com_Buad = selectBuadComboBox->currentText(); 61 | com_Testbit = selsetTestbitComboBox->currentText(); 62 | com_Databit = selectDatabitComboBox->currentText(); 63 | com_Stopbit = selectStopbitComboBox->currentText(); 64 | com_all_status = com_Num + " " + com_Buad + " " + com_Testbit + " " + com_Databit + " " + com_Stopbit; 65 | if(com_Num == "COM1") 66 | fd_com = open(COM1, O_RDWR); 67 | else if(com_Num == "COM2") 68 | fd_com = open(COM2, O_RDWR); 69 | else if(com_Num == "COM3") 70 | fd_com = open(COM3, O_RDWR); 71 | else if(com_Num == "COM4") 72 | fd_com = open(COM4, O_RDWR); 73 | else if(com_Num == "COM5") 74 | fd_com = open(COM5, O_RDWR); 75 | else if(com_Num == "COM6") 76 | fd_com = open(COM6, O_RDWR); 77 | else 78 | fd_com = open(COM1, O_RDWR); 79 | if(fd_com != -1) 80 | { 81 | path = ":/on.jpg"; 82 | serialstatusLabel->setPixmap(path); 83 | openCloseSerialPushButton->setText(tr("关闭串口")); 84 | com_all_status.replace(5, 8, "Used "); 85 | com_status = true; 86 | selectserialComboBox->setEnabled (false); 87 | selectBuadComboBox->setEnabled (false); 88 | selsetTestbitComboBox->setEnabled (false); 89 | selectDatabitComboBox->setEnabled (false); 90 | selectStopbitComboBox->setEnabled (false); 91 | autoSentpushButton->setEnabled (true); 92 | manualSentPushButton->setEnabled (true); 93 | saveDataPushButton->setEnabled (true); 94 | tcgetattr(fd_com,&oldtio); 95 | bzero(&newtio,sizeof(newtio)); 96 | if(com_Buad == "50") 97 | newtio.c_cflag = B50 | CLOCAL; 98 | else if(com_Buad == "75") 99 | newtio.c_cflag = B75 | CLOCAL; 100 | else if(com_Buad == "110") 101 | newtio.c_cflag = B110 | CLOCAL; 102 | else if(com_Buad == "134") 103 | newtio.c_cflag = B134 | CLOCAL; 104 | else if(com_Buad == "150") 105 | newtio.c_cflag = B150 | CLOCAL; 106 | else if(com_Buad == "200") 107 | newtio.c_cflag = B200 | CLOCAL; 108 | else if(com_Buad == "300") 109 | newtio.c_cflag = B300 | CLOCAL; 110 | else if(com_Buad == "600") 111 | newtio.c_cflag = B600 | CLOCAL; 112 | else if(com_Buad == "1200") 113 | newtio.c_cflag = B1200 | CLOCAL; 114 | else if(com_Buad == "1800") 115 | newtio.c_cflag = B1800 | CLOCAL; 116 | else if(com_Buad == "2400") 117 | newtio.c_cflag = B2400 | CLOCAL; 118 | else if(com_Buad == "4800") 119 | newtio.c_cflag = B4800 | CLOCAL; 120 | else if(com_Buad == "9600") 121 | newtio.c_cflag = B9600 | CLOCAL; 122 | else if(com_Buad == "19200") 123 | newtio.c_cflag = B19200 | CLOCAL; 124 | else if(com_Buad == "38400") 125 | newtio.c_cflag = B38400 | CLOCAL; 126 | else if(com_Buad == "57600") 127 | newtio.c_cflag = B57600 | CLOCAL; 128 | else if(com_Buad == "115200") 129 | newtio.c_cflag = B115200 | CLOCAL; 130 | else if(com_Buad == "230400") 131 | newtio.c_cflag = B230400| CLOCAL; 132 | else 133 | newtio.c_cflag = B9600; 134 | 135 | if(com_Testbit == "无校验(NONE)") 136 | { 137 | newtio.c_cflag &= ~PARENB; 138 | newtio.c_iflag &= ~INPCK; 139 | newtio.c_iflag |= IGNBRK; 140 | } 141 | else if(com_Testbit == "偶校验(EVEN)") 142 | { 143 | newtio.c_cflag |= PARENB; 144 | newtio.c_cflag &= ~PARODD; 145 | newtio.c_iflag |= INPCK; 146 | newtio.c_iflag |= IGNBRK; 147 | } 148 | else if(com_Testbit == "奇校验(ODD)") 149 | { 150 | newtio.c_cflag |= (PARODD | PARENB); 151 | newtio.c_iflag |= INPCK; 152 | newtio.c_iflag |= IGNBRK; 153 | } 154 | else if(com_Testbit == "空校验(SPACE)") 155 | { 156 | newtio.c_cflag &= ~PARENB; 157 | newtio.c_iflag &= ~INPCK; 158 | newtio.c_cflag &= ~CSTOPB; 159 | newtio.c_iflag |= IGNBRK; 160 | } 161 | else 162 | { 163 | newtio.c_cflag &= ~PARENB; 164 | newtio.c_iflag &= ~INPCK; 165 | newtio.c_iflag |= IGNBRK; 166 | } 167 | 168 | if(com_Databit == "5") 169 | { 170 | newtio.c_cflag&=~CSIZE; 171 | newtio.c_cflag |=CS5; 172 | } 173 | else if(com_Databit == "6") 174 | { 175 | newtio.c_cflag&=~CSIZE; 176 | newtio.c_cflag |=CS6; 177 | } 178 | else if(com_Databit == "7") 179 | { 180 | newtio.c_cflag&=~CSIZE; 181 | newtio.c_cflag |=CS7; 182 | } 183 | else if(com_Databit == "8") 184 | { 185 | newtio.c_cflag&=~CSIZE; 186 | newtio.c_cflag |=CS8; 187 | } 188 | else 189 | { 190 | newtio.c_cflag&=~CSIZE; 191 | newtio.c_cflag |=CS8; 192 | } 193 | 194 | if(com_Stopbit == "1") 195 | newtio.c_cflag &= ~CSTOPB; 196 | else if(com_Stopbit == "2") 197 | newtio.c_cflag |= CSTOPB; 198 | if(com_Stopbit == "1.5") 199 | newtio.c_cflag &= ~CSTOPB; 200 | else 201 | newtio.c_cflag &= ~CSTOPB; 202 | newtio.c_oflag &= ~OPOST ; 203 | newtio.c_lflag &= ~ICANON; 204 | newtio.c_lflag &= ~ECHO; 205 | newtio.c_cflag |= CREAD; 206 | newtio.c_cc[VTIME] = 0; 207 | newtio.c_cc[VMIN] = 1; 208 | tcflush(fd_com, TCIFLUSH); 209 | tcsetattr(fd_com, TCSANOW, &newtio); 210 | ::close(fd_com); 211 | 212 | if(com_Num == "COM1") 213 | { 214 | fds = open(COM1, O_WRONLY); 215 | fdr = open(COM1, O_RDONLY); 216 | } 217 | else if(com_Num == "COM2") 218 | { 219 | fds = open(COM2, O_WRONLY); 220 | fdr = open(COM2, O_RDONLY); 221 | } 222 | else if(com_Num == "COM3") 223 | { 224 | fds = open(COM3, O_WRONLY); 225 | fdr = open(COM3, O_RDONLY); 226 | } 227 | else if(com_Num == "COM4") 228 | { 229 | fds = open(COM4, O_WRONLY); 230 | fdr = open(COM4, O_RDONLY); 231 | } 232 | else if(com_Num == "COM5") 233 | { 234 | fds = open(COM5, O_WRONLY); 235 | fdr = open(COM5, O_RDONLY); 236 | } 237 | else if(com_Num == "COM6") 238 | { 239 | fds = open(COM6, O_WRONLY); 240 | fdr = open(COM6, O_RDONLY); 241 | } 242 | else 243 | { 244 | fds = open(COM1, O_WRONLY); 245 | fdr = open(COM1, O_RDONLY); 246 | } 247 | myComThread->start(); 248 | } 249 | else 250 | { 251 | path = ":/error.jpg"; 252 | serialstatusLabel->setPixmap(path); 253 | com_all_status.clear(); 254 | com_all_status = com_Num + " Error " ; 255 | } 256 | } 257 | else 258 | { 259 | ::close(fdr); 260 | ::close(fds); 261 | path = ":/off.jpg"; 262 | serialstatusLabel->setPixmap(path); 263 | com_all_status.replace(5, 8, "Closed "); 264 | openCloseSerialPushButton->setText(tr("打开串口")); 265 | com_status = false; 266 | selectserialComboBox->setEnabled (true); 267 | selectBuadComboBox->setEnabled (true); 268 | selsetTestbitComboBox->setEnabled (true); 269 | selectDatabitComboBox->setEnabled (true); 270 | selectStopbitComboBox->setEnabled (true); 271 | autoSentpushButton->setEnabled (false); 272 | manualSentPushButton->setEnabled (false); 273 | saveDataPushButton->setEnabled (false); 274 | } 275 | comStatusLabel->setText(com_all_status ); 276 | } 277 | 278 | 279 | 280 | void MyComTool::closeEvent ( QCloseEvent * event ) 281 | { 282 | if(com_status) 283 | { 284 | ::close(fdr); 285 | ::close(fds); 286 | if(com_Num == "COM1") 287 | fd_com = open(COM1, O_RDWR); 288 | else if(com_Num == "COM2") 289 | fd_com = open(COM2, O_RDWR); 290 | else if(com_Num == "COM3") 291 | fd_com = open(COM3, O_RDWR); 292 | else if(com_Num == "COM4") 293 | fd_com = open(COM4, O_RDWR); 294 | else if(com_Num == "COM5") 295 | fd_com = open(COM5, O_RDWR); 296 | else if(com_Num == "COM6") 297 | fd_com = open(COM6, O_RDWR); 298 | else 299 | fd_com = open(COM1, O_RDWR); 300 | tcsetattr(fd_com,TCSANOW,&oldtio); 301 | ::close(fd_com); 302 | myComThread->terminate (); 303 | myComThread->wait(); 304 | myComThread->tmpSaveFile.remove(); 305 | event->accept(); 306 | } 307 | } 308 | 309 | void MyComTool::clearCom_Receive() 310 | { 311 | comReceivePlainTextEdit->clear(); 312 | } 313 | 314 | void MyComTool::ceaseCom_Receive() 315 | { 316 | bool dis_able; 317 | cease_receive_dispaly = !cease_receive_dispaly; 318 | if(cease_receive_dispaly) 319 | { 320 | dis_able = !isEnabled(); 321 | comReceivePlainTextEdit->setEnabled (dis_able); 322 | ceaseDisplayPushButton->setText(tr("开始接收")); 323 | newtio.c_cflag &= ~CREAD; 324 | tcflush(fd_com, TCIFLUSH); 325 | tcsetattr(fd_com, TCSANOW, &newtio); 326 | 327 | } 328 | else 329 | { 330 | dis_able = isEnabled() ; 331 | comReceivePlainTextEdit->setEnabled (dis_able); 332 | ceaseDisplayPushButton->setText(tr("停止接收")); 333 | newtio.c_cflag |= CREAD; 334 | tcflush(fd_com, TCIFLUSH); 335 | tcsetattr(fd_com, TCSANOW, &newtio); 336 | } 337 | 338 | } 339 | 340 | void MyComTool::set_autoCom_Sent() 341 | { 342 | bool disable_autosent_setup; 343 | auto_sent = !auto_sent; 344 | if( auto_sent) 345 | { 346 | comSentTextEdit->setReadOnly(true); 347 | QString times = tr("无限"); 348 | if(times ==autoSentTimesComboBox->currentText()) 349 | sent_nolimited = true; 350 | else 351 | { 352 | sent_nolimited = false; 353 | auto_sent_count = atoi(autoSentTimesComboBox->currentText().toAscii()); 354 | } 355 | auto_sent_time = atoi(sentTimeLineEdit->text().toAscii()); 356 | manualCom_Sent(); 357 | auto_sent_interval.start (auto_sent_time); 358 | autoSentpushButton->setText(tr("停止发送")); 359 | disable_autosent_setup = !isEnabled(); 360 | sentTimeLineEdit->setEnabled (disable_autosent_setup); 361 | autoSentTimesComboBox->setEnabled (disable_autosent_setup); 362 | manualSentPushButton->setEnabled (disable_autosent_setup); 363 | } 364 | else 365 | { 366 | comSentTextEdit->setReadOnly(false); 367 | auto_sent_interval.stop(); 368 | autoSentpushButton->setText(tr("自动发送")); 369 | disable_autosent_setup = isEnabled(); 370 | sentTimeLineEdit->setEnabled (disable_autosent_setup); 371 | autoSentTimesComboBox->setEnabled (disable_autosent_setup);; 372 | manualSentPushButton->setEnabled (disable_autosent_setup); 373 | } 374 | } 375 | 376 | void MyComTool::to_autoCom_Sent() 377 | { 378 | auto_sent_interval.stop(); 379 | if(sent_nolimited) 380 | { 381 | manualCom_Sent(); 382 | auto_sent_interval.start (auto_sent_time); 383 | } 384 | else 385 | { 386 | if((--auto_sent_count) > 0) 387 | { 388 | manualCom_Sent(); 389 | auto_sent_interval.start (auto_sent_time); 390 | } 391 | else 392 | { 393 | auto_sent = !auto_sent; 394 | autoSentpushButton->setText(tr("自动发送")); 395 | comSentTextEdit->setReadOnly(false); 396 | sentTimeLineEdit->setEnabled (true); 397 | autoSentTimesComboBox->setEnabled (true); 398 | manualSentPushButton->setEnabled (true); 399 | } 400 | } 401 | 402 | } 403 | 404 | void MyComTool::dis_Help_txt() 405 | { 406 | QMessageBox msgBox(this); 407 | QString mymes = tr("串口调试工具 1.00.00 \n基于QT4.6&Linux 2.6的串口调试工具\nzhuhe\n"); 408 | QString pix; 409 | pix = ":/thank.png"; 410 | msgBox.setIconPixmap(pix); 411 | msgBox.setWindowTitle(tr("关于")); 412 | msgBox.setText(tr("\n\n\n感谢使用本串口调试工具!")); 413 | msgBox.setDetailedText (mymes); 414 | msgBox.exec(); 415 | } 416 | 417 | void MyComTool::clearCom_Sent() 418 | { 419 | comSentTextEdit->clear(); 420 | } 421 | 422 | 423 | void MyComTool::set_widget_style() 424 | { 425 | sty_num++; 426 | QPalette palette = qApp->palette(); 427 | switch(sty_num) 428 | { 429 | case 1: 430 | qApp->setStyle("plastique"); 431 | palette.setColor(QPalette::Window,QColor(255, 234, 254, 255)); 432 | palette.setColor(QPalette::WindowText, Qt::darkGreen); 433 | palette.setColor(QPalette::Text, Qt::darkGreen); 434 | palette.setColor(QPalette::ButtonText, Qt::darkGreen); 435 | qApp->setPalette(palette); 436 | break; 437 | case 2: 438 | qApp->setStyle("cde"); 439 | palette.setColor(QPalette::Window,QColor(223, 235, 220, 255)); 440 | palette.setColor(QPalette::WindowText, Qt::darkMagenta); 441 | palette.setColor(QPalette::Text, Qt::darkMagenta); 442 | palette.setColor(QPalette::ButtonText, Qt::darkMagenta); 443 | qApp->setPalette(palette); 444 | break; 445 | case 3: 446 | qApp->setStyle("motif"); 447 | palette.setColor(QPalette::Window,QColor(215, 252, 255, 255)); 448 | palette.setColor(QPalette::WindowText, Qt::darkYellow); 449 | palette.setColor(QPalette::Text, Qt::darkYellow); 450 | palette.setColor(QPalette::ButtonText, Qt::darkYellow); 451 | qApp->setPalette(palette); 452 | break; 453 | case 4: 454 | qApp->setStyle("cleanlooks"); 455 | palette.setColor(QPalette::Window,QColor(255, 241, 226, 255)); 456 | palette.setColor(QPalette::WindowText, Qt::darkBlue); 457 | palette.setColor(QPalette::Text, Qt::darkBlue); 458 | palette.setColor(QPalette::ButtonText, Qt::darkBlue); 459 | qApp->setPalette(palette); 460 | break; 461 | default: 462 | qApp->setStyle("GTK"); 463 | palette.setColor(QPalette::Window,QColor(238, 238, 238, 255)); 464 | palette.setColor(QPalette::WindowText, Qt::black); 465 | palette.setColor(QPalette::Text, Qt::black); 466 | qApp->setPalette(palette); 467 | sty_num = 0; 468 | } 469 | } 470 | 471 | void MyComTool::set_Save_Path() 472 | { 473 | saveFileName = QFileDialog::getSaveFileName ( 474 | this, 475 | tr("保存文件"), 476 | "~/comdata.txt", 477 | tr("文本文件(*.txt)")); 478 | 479 | if(saveFileName.isNull()) 480 | saveFileName = QDir::currentPath () + "/comdata.txt"; 481 | displayPathLabel->setText(saveFileName); 482 | } 483 | 484 | void MyComTool::open_Sent_File() 485 | { 486 | openFileName = QFileDialog::getOpenFileName ( 487 | this, 488 | tr("打开文件"), 489 | "/home", 490 | tr("文本文件(*.txt)")); 491 | if(openFileName.isNull()) 492 | fileNameLabel->setText(tr("没有选择文件")); 493 | else 494 | { 495 | 496 | QFile sentFile(openFileName); 497 | if (!sentFile.open(QIODevice::ReadOnly | QIODevice::Text)) 498 | { 499 | fileNameLabel->setText(tr("没有选择文件")); 500 | QMessageBox fileMesBox(this); 501 | QString my_pix; 502 | my_pix = ":/erroring.png"; 503 | QPixmap img(my_pix); 504 | fileMesBox.setIconPixmap(my_pix); 505 | fileMesBox.setWindowTitle(tr("错误")); 506 | fileMesBox.setText(tr("文件无效!")); 507 | fileMesBox.exec(); 508 | return; 509 | } 510 | fileNameLabel->setText(openFileName); 511 | QTextStream inOutDisplay(&sentFile); 512 | while (!inOutDisplay.atEnd()) 513 | { 514 | QString myLine = inOutDisplay.readLine(); 515 | comSentTextEdit->insertPlainText(myLine); 516 | } 517 | } 518 | } 519 | 520 | void MyComTool::set_Receive_Hex(int) 521 | { 522 | if( hexDisplaycheckBox->isChecked ()) 523 | myComThread ->hex_displaymodel = true; 524 | else 525 | myComThread->hex_displaymodel = false; 526 | } 527 | void MyComTool::set_sent_Hex(int) 528 | { 529 | if( hexSentcheckBox->isChecked ()) 530 | sent_hex_model = true; 531 | else 532 | sent_hex_model = false; 533 | } 534 | 535 | void MyComTool::set_eol(int) 536 | { 537 | if (eolCheckBox->isChecked()) 538 | eol_status = true; 539 | else 540 | eol_status = false; 541 | } 542 | 543 | void MyComTool::clear_Rs_counter() 544 | { 545 | receive_byte_counter = 0; 546 | sent_byte_counter = 0; 547 | comSentLabel->setNum(sent_byte_counter); 548 | comReceiveLabel->setNum(receive_byte_counter); 549 | } 550 | 551 | void MyComTool::clear_Sent_times() 552 | { 553 | already_sent_times = 0; 554 | sentTimesClearLabel->setNum(already_sent_times); 555 | } 556 | 557 | void MyComTool::to_Save_File() 558 | { 559 | bool save_sucessed; 560 | QMessageBox saveMesBox(this); 561 | QString mypix; 562 | if(QFile::exists(saveFileName)) 563 | { 564 | QMessageBox replaceBox(this); 565 | replaceBox.setWindowTitle(tr("提示")); 566 | replaceBox.setText(tr(" 该文件已经存在!")); 567 | replaceBox.setInformativeText(tr(" 确定替换码?")); 568 | replaceBox.setStandardButtons(QMessageBox::Yes| QMessageBox::No); 569 | replaceBox.setDefaultButton(QMessageBox::Yes); 570 | int ret = replaceBox.exec(); 571 | switch (ret) 572 | { 573 | case QMessageBox::Yes: 574 | QFile::remove(saveFileName); 575 | break; 576 | case QMessageBox::No: 577 | break; 578 | 579 | default: 580 | break; 581 | } 582 | } 583 | save_sucessed = saved.copy (tmp_file_name , saveFileName); 584 | emit ClearTmpFile(); 585 | if(save_sucessed) 586 | { 587 | 588 | mypix = ":/success.png"; 589 | QPixmap img(mypix); 590 | saveMesBox.setIconPixmap(mypix); 591 | saveMesBox.setWindowTitle(tr("信息")); 592 | saveMesBox.setText(tr("保存成功!")); 593 | saveMesBox.exec(); 594 | } 595 | else 596 | { 597 | mypix = ":/erroring.png"; 598 | QPixmap img(mypix); 599 | saveMesBox.setIconPixmap(mypix); 600 | saveMesBox.setWindowTitle(tr("信息")); 601 | saveMesBox.setText(tr("保存失败!")); 602 | saveMesBox.exec(); 603 | } 604 | 605 | } 606 | 607 | 608 | void MyComTool::manualCom_Sent() 609 | { 610 | QString user_input; 611 | char *to_sent; 612 | char sent_buf[2]; 613 | QChar *to_sent_tmp; 614 | int b; 615 | size_t char_count; 616 | user_input = comSentTextEdit->toPlainText (); 617 | if(eol_status){ 618 | // append \r\n 619 | QString eol; 620 | eol.sprintf("%c%c", 0x0d, 0x0a); 621 | user_input.append(eol); 622 | } 623 | to_sent = user_input.toAscii().data(); 624 | to_sent_tmp = user_input.data(); 625 | char_count = 0; 626 | already_sent_times++; 627 | if(!sent_hex_model) 628 | { 629 | while (!to_sent_tmp->isNull()) 630 | { 631 | ++to_sent_tmp; 632 | ++char_count; 633 | } 634 | sent_byte_counter += write(fds, to_sent, char_count); 635 | comReceiveLabel->setNum (sent_byte_counter); 636 | } 637 | else 638 | { 639 | while (!to_sent_tmp->isNull()) 640 | { 641 | b= (int)*to_sent; 642 | sprintf(sent_buf, "%x", b); 643 | hex_to_sent[char_count] = sent_buf[0]; 644 | hex_to_sent[char_count + 1] = sent_buf[1]; 645 | ++to_sent_tmp; 646 | ++to_sent; 647 | ++char_count; 648 | ++char_count; 649 | if(char_count >= 10240) 650 | { 651 | char_count = 0; 652 | QMessageBox warningBox(this); 653 | QString mypix; 654 | mypix = ":/erroring.png"; 655 | QPixmap img(mypix); 656 | warningBox.setIconPixmap(mypix); 657 | warningBox.setWindowTitle(tr("错误")); 658 | warningBox.setText(tr("发送数据过长!")); 659 | warningBox.exec(); 660 | break; 661 | } 662 | } 663 | sent_byte_counter += write(fds, hex_to_sent, char_count); 664 | comReceiveLabel->setNum (sent_byte_counter); 665 | } 666 | sentTimesClearLabel->setNum(already_sent_times); 667 | } 668 | 669 | void ComReadThread ::run() 670 | { 671 | QString com_read_buf = "Now Begin!"; 672 | QString temp_name; 673 | char to_receivebuf[2]; 674 | size_t n; 675 | mutex.lock(); 676 | int a; 677 | bool wrop = false; 678 | to_receivebuf[0] = NULL; 679 | to_receivebuf[1] = NULL; 680 | tmpSaveFile.open(); 681 | temp_name = tmpSaveFile.fileName(); 682 | emit Name(temp_name); 683 | while(1) 684 | { 685 | while(!(my->cease_receive_dispaly)) 686 | { 687 | n = read(my->fdr, to_receivebuf , 1); 688 | if (n == 1) 689 | { 690 | if(to_receivebuf[0] == 0x0a) 691 | wrop = true; 692 | else 693 | wrop = false; 694 | if(hex_displaymodel) 695 | { 696 | a= (int)to_receivebuf[0]; 697 | sprintf(to_receivebuf, "%2x", a); 698 | } 699 | QTextStream out(&tmpSaveFile); 700 | out << to_receivebuf[0]; 701 | if(wrop) 702 | out << endl; 703 | com_read_buf = QString(QLatin1String(to_receivebuf)); 704 | to_receivebuf[1] = NULL; 705 | emit Log(com_read_buf ); 706 | } 707 | } 708 | } 709 | mutex.unlock(); 710 | } 711 | -------------------------------------------------------------------------------- /src/serialtool.h: -------------------------------------------------------------------------------- 1 | #ifndef _SERIALTOOL_H_ 2 | #define _SERIALTOOL_H_ 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include "ui_serialtool.h" 20 | 21 | #define COM1 "/dev/ttyS0" 22 | #define COM2 "/dev/ttyS1" 23 | #define COM3 "/dev/ttyS2" 24 | #define COM4 "/dev/ttyS3" 25 | #define COM5 "/dev/ttyUSB0" 26 | #define COM6 "/dev/ttyUSB1" 27 | 28 | class ComReadThread; 29 | class MyComTool : public QWidget, public Ui_serailToolForm 30 | { 31 | Q_OBJECT 32 | public: 33 | MyComTool(QWidget* = 0); 34 | friend class ComReadThread ; 35 | virtual void closeEvent ( QCloseEvent * event ) ; 36 | 37 | private: 38 | ComReadThread* myComThread; 39 | int fd_com, fdr, fds,sty_num; 40 | unsigned int auto_sent_count; 41 | unsigned int auto_sent_time; 42 | int receive_byte_counter; 43 | int sent_byte_counter; 44 | int already_sent_times; 45 | bool com_status, cease_receive_dispaly, auto_sent, sent_nolimited,sent_hex_model; 46 | bool eol_status; 47 | QString saveFileName,openFileName; 48 | QString com_all_status; 49 | QString com_Num; 50 | QTimer auto_sent_interval; 51 | struct termios oldtio, newtio; 52 | char hex_to_sent[10240]; 53 | QFile saved; 54 | QString tmp_file_name; 55 | 56 | private slots: 57 | void comStrat_Stop_Con(); 58 | void clearCom_Receive(); 59 | void ceaseCom_Receive(); 60 | void set_autoCom_Sent(); 61 | void to_autoCom_Sent(); 62 | void manualCom_Sent(); 63 | void dis_Help_txt(); 64 | void clearCom_Sent(); 65 | void set_widget_style(); 66 | void set_Save_Path(); 67 | void set_Receive_Hex(int) ; 68 | void set_sent_Hex(int) ; 69 | void set_eol(int); 70 | void clear_Rs_counter(); 71 | void clear_Sent_times(); 72 | void open_Sent_File(); 73 | void to_Save_File(); 74 | public slots: 75 | void Log(QString sMessage) 76 | { 77 | if(!(cease_receive_dispaly)) 78 | { 79 | comReceivePlainTextEdit->insertPlainText(sMessage); 80 | ++receive_byte_counter; 81 | comSentLabel->setNum (receive_byte_counter); 82 | } 83 | } 84 | void Name(QString temp_name) 85 | { 86 | tmp_file_name = temp_name; 87 | } 88 | signals: 89 | void ClearTmpFile(); 90 | }; 91 | 92 | class ComReadThread : public QThread 93 | { 94 | Q_OBJECT 95 | 96 | public: 97 | 98 | ComReadThread (MyComTool* parent) : my(parent), haved_data(false) , hex_displaymodel(false), tmpSaveFile("/tmp/comdata"){} 99 | MyComTool * my; 100 | bool haved_data; 101 | bool hex_displaymodel; 102 | QTemporaryFile tmpSaveFile; 103 | public slots: 104 | void ClearTmpFile() 105 | { 106 | tmpSaveFile.resize(0); 107 | tmpSaveFile.close(); 108 | tmpSaveFile.open(); 109 | } 110 | protected: 111 | QMutex mutex; 112 | virtual void run(); 113 | signals: 114 | void Log(QString sMessage); 115 | void Name(QString temp_name); 116 | }; 117 | 118 | 119 | #endif 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /ui/close.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ninehills/serialtool/16fce32f436333d2ff9a44808383bbbf7e7ca103/ui/close.jpg -------------------------------------------------------------------------------- /ui/error.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ninehills/serialtool/16fce32f436333d2ff9a44808383bbbf7e7ca103/ui/error.jpg -------------------------------------------------------------------------------- /ui/error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ninehills/serialtool/16fce32f436333d2ff9a44808383bbbf7e7ca103/ui/error.png -------------------------------------------------------------------------------- /ui/erroring.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ninehills/serialtool/16fce32f436333d2ff9a44808383bbbf7e7ca103/ui/erroring.png -------------------------------------------------------------------------------- /ui/myresource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | success.png 4 | erroring.png 5 | thank.png 6 | error.jpg 7 | close.jpg 8 | on.jpg 9 | network.jpg 10 | off.jpg 11 | 12 | 13 | -------------------------------------------------------------------------------- /ui/network.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ninehills/serialtool/16fce32f436333d2ff9a44808383bbbf7e7ca103/ui/network.jpg -------------------------------------------------------------------------------- /ui/off.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ninehills/serialtool/16fce32f436333d2ff9a44808383bbbf7e7ca103/ui/off.jpg -------------------------------------------------------------------------------- /ui/on.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ninehills/serialtool/16fce32f436333d2ff9a44808383bbbf7e7ca103/ui/on.jpg -------------------------------------------------------------------------------- /ui/serialtool.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | serailToolForm 4 | 5 | 6 | true 7 | 8 | 9 | 10 | 0 11 | 0 12 | 873 13 | 600 14 | 15 | 16 | 17 | 18 | 0 19 | 0 20 | 21 | 22 | 23 | 串口调试工具 24 | 25 | 26 | 27 | :/network.jpg:/network.jpg 28 | 29 | 30 | 31 | 32 | 33 | 34 | 0 35 | 0 36 | 37 | 38 | 39 | QFrame::StyledPanel 40 | 41 | 42 | QFrame::Raised 43 | 44 | 45 | 46 | 47 | 48 | true 49 | 50 | 51 | 选择串口 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | Times New Roman 60 | 61 | 62 | 63 | Qt::DefaultContextMenu 64 | 65 | 66 | false 67 | 68 | 69 | 0 70 | 71 | 72 | false 73 | 74 | 75 | true 76 | 77 | 78 | 79 | COM1 80 | 81 | 82 | 83 | 84 | COM2 85 | 86 | 87 | 88 | 89 | COM3 90 | 91 | 92 | 93 | 94 | COM4 95 | 96 | 97 | 98 | 99 | COM5 100 | 101 | 102 | 103 | 104 | COM6 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | Qt::Horizontal 113 | 114 | 115 | 116 | 40 117 | 20 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | true 126 | 127 | 128 | 波特率 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | Times New Roman 137 | false 138 | 139 | 140 | 141 | Qt::DefaultContextMenu 142 | 143 | 144 | false 145 | 146 | 147 | 11 148 | 149 | 150 | false 151 | 152 | 153 | true 154 | 155 | 156 | 157 | 50 158 | 159 | 160 | 161 | 162 | 75 163 | 164 | 165 | 166 | 167 | 110 168 | 169 | 170 | 171 | 172 | 134 173 | 174 | 175 | 176 | 177 | 150 178 | 179 | 180 | 181 | 182 | 200 183 | 184 | 185 | 186 | 187 | 300 188 | 189 | 190 | 191 | 192 | 600 193 | 194 | 195 | 196 | 197 | 1200 198 | 199 | 200 | 201 | 202 | 2400 203 | 204 | 205 | 206 | 207 | 4800 208 | 209 | 210 | 211 | 212 | 9600 213 | 214 | 215 | 216 | 217 | 19200 218 | 219 | 220 | 221 | 222 | 38400 223 | 224 | 225 | 226 | 227 | 57600 228 | 229 | 230 | 231 | 232 | 115200 233 | 234 | 235 | 236 | 237 | 230400 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | Qt::Horizontal 246 | 247 | 248 | 249 | 40 250 | 20 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | true 259 | 260 | 261 | 校验位 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | Times New Roman 270 | 271 | 272 | 273 | Qt::DefaultContextMenu 274 | 275 | 276 | false 277 | 278 | 279 | 0 280 | 281 | 282 | false 283 | 284 | 285 | true 286 | 287 | 288 | 289 | 无校验(NONE) 290 | 291 | 292 | 293 | 294 | 偶校验(EVEN) 295 | 296 | 297 | 298 | 299 | 奇校验(ODD) 300 | 301 | 302 | 303 | 304 | 空校验(SPACE) 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | Qt::Horizontal 313 | 314 | 315 | 316 | 40 317 | 20 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | true 326 | 327 | 328 | 数据位 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | Times New Roman 337 | 338 | 339 | 340 | Qt::DefaultContextMenu 341 | 342 | 343 | false 344 | 345 | 346 | 3 347 | 348 | 349 | false 350 | 351 | 352 | true 353 | 354 | 355 | 356 | 5 357 | 358 | 359 | 360 | 361 | 6 362 | 363 | 364 | 365 | 366 | 7 367 | 368 | 369 | 370 | 371 | 8 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | Qt::Horizontal 380 | 381 | 382 | 383 | 40 384 | 20 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | true 393 | 394 | 395 | 停止位 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | Times New Roman 404 | 405 | 406 | 407 | Qt::DefaultContextMenu 408 | 409 | 410 | false 411 | 412 | 413 | 0 414 | 415 | 416 | false 417 | 418 | 419 | true 420 | 421 | 422 | 423 | 1 424 | 425 | 426 | 427 | 428 | 1.5 429 | 430 | 431 | 432 | 433 | 2 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | Qt::Horizontal 442 | 443 | 444 | 445 | 40 446 | 20 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 0 456 | 0 457 | 458 | 459 | 460 | QFrame::WinPanel 461 | 462 | 463 | QFrame::Sunken 464 | 465 | 466 | 467 | 468 | 469 | :/off.jpg 470 | 471 | 472 | 473 | 474 | 475 | 476 | true 477 | 478 | 479 | 480 | 0 481 | 0 482 | 483 | 484 | 485 | Qt::ActionsContextMenu 486 | 487 | 488 | 打开串口 489 | 490 | 491 | false 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 0 503 | 0 504 | 505 | 506 | 507 | QFrame::StyledPanel 508 | 509 | 510 | QFrame::Raised 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | true 519 | 520 | 521 | 522 | 0 523 | 0 524 | 525 | 526 | 527 | Qt::ActionsContextMenu 528 | 529 | 530 | 保存数据 531 | 532 | 533 | false 534 | 535 | 536 | 537 | 538 | 539 | 540 | true 541 | 542 | 543 | 544 | 0 545 | 0 546 | 547 | 548 | 549 | Qt::ActionsContextMenu 550 | 551 | 552 | 清除显示 553 | 554 | 555 | false 556 | 557 | 558 | 559 | 560 | 561 | 562 | true 563 | 564 | 565 | 566 | 0 567 | 0 568 | 569 | 570 | 571 | Qt::ActionsContextMenu 572 | 573 | 574 | 停止接收 575 | 576 | 577 | false 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 0 586 | 0 587 | 588 | 589 | 590 | 十六进制显示 591 | 592 | 593 | false 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 0 602 | 0 603 | 604 | 605 | 606 | 更改外观 607 | 608 | 609 | 610 | 611 | 612 | 613 | true 614 | 615 | 616 | 617 | 0 618 | 0 619 | 620 | 621 | 622 | Qt::ActionsContextMenu 623 | 624 | 625 | 存储路径 626 | 627 | 628 | false 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 0 637 | 0 638 | 639 | 640 | 641 | QFrame::WinPanel 642 | 643 | 644 | QFrame::Sunken 645 | 646 | 647 | ~/comdata.txt 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 接 659 | 收 660 | 显 661 | 示 662 | 区 663 | 664 | 665 | 666 | 667 | 668 | 669 | ArrowCursor 670 | 671 | 672 | true 673 | 674 | 675 | Qt::ClickFocus 676 | 677 | 678 | Qt::DefaultContextMenu 679 | 680 | 681 | false 682 | 683 | 684 | true 685 | 686 | 687 | QFrame::WinPanel 688 | 689 | 690 | Qt::ScrollBarAsNeeded 691 | 692 | 693 | Qt::ScrollBarAlwaysOff 694 | 695 | 696 | false 697 | 698 | 699 | false 700 | 701 | 702 | true 703 | 704 | 705 | Qt::TextSelectableByKeyboard 706 | 707 | 708 | true 709 | 710 | 711 | false 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | Qt::LeftToRight 724 | 725 | 726 | QFrame::StyledPanel 727 | 728 | 729 | QFrame::Raised 730 | 731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 0 739 | 0 740 | 741 | 742 | 743 | 自动发送 744 | 745 | 746 | 747 | 748 | 749 | 750 | 751 | 752 | true 753 | 754 | 755 | 自动发送间隔 756 | 757 | 758 | 759 | 760 | 761 | 762 | 763 | 0 764 | 0 765 | 766 | 767 | 768 | Qt::RightToLeft 769 | 770 | 771 | 1000 772 | 773 | 774 | 775 | 776 | 777 | 778 | true 779 | 780 | 781 | 毫秒 782 | 783 | 784 | 785 | 786 | 787 | 788 | 789 | 790 | 791 | 792 | true 793 | 794 | 795 | 自动发送次数 796 | 797 | 798 | 799 | 800 | 801 | 802 | 803 | Times New Roman 804 | false 805 | 806 | 807 | 808 | true 809 | 810 | 811 | Qt::StrongFocus 812 | 813 | 814 | Qt::DefaultContextMenu 815 | 816 | 817 | Qt::LeftToRight 818 | 819 | 820 | true 821 | 822 | 823 | true 824 | 825 | 826 | 0 827 | 828 | 829 | 17 830 | 831 | 832 | QComboBox::InsertAtCurrent 833 | 834 | 835 | QComboBox::AdjustToContents 836 | 837 | 838 | false 839 | 840 | 841 | true 842 | 843 | 844 | 845 | 1 846 | 847 | 848 | 849 | 850 | 2 851 | 852 | 853 | 854 | 855 | 3 856 | 857 | 858 | 859 | 860 | 4 861 | 862 | 863 | 864 | 865 | 5 866 | 867 | 868 | 869 | 870 | 6 871 | 872 | 873 | 874 | 875 | 7 876 | 877 | 878 | 879 | 880 | 8 881 | 882 | 883 | 884 | 885 | 9 886 | 887 | 888 | 889 | 890 | 10 891 | 892 | 893 | 894 | 895 | 50 896 | 897 | 898 | 899 | 900 | 100 901 | 902 | 903 | 904 | 905 | 500 906 | 907 | 908 | 909 | 910 | 1000 911 | 912 | 913 | 914 | 915 | 5000 916 | 917 | 918 | 919 | 920 | 10000 921 | 922 | 923 | 924 | 925 | 无限 926 | 927 | 928 | 929 | 930 | 931 | 932 | 933 | 934 | 935 | 936 | 937 | 938 | 939 | 940 | QLayout::SetMinAndMaxSize 941 | 942 | 943 | 944 | 945 | true 946 | 947 | 948 | 949 | 0 950 | 0 951 | 952 | 953 | 954 | 已发送次数 955 | 956 | 957 | 958 | 959 | 960 | 961 | 962 | 0 963 | 0 964 | 965 | 966 | 967 | true 968 | 969 | 970 | QFrame::WinPanel 971 | 972 | 973 | QFrame::Sunken 974 | 975 | 976 | 0 977 | 978 | 979 | true 980 | 981 | 982 | 983 | 984 | 985 | 986 | 987 | 988 | 989 | 0 990 | 0 991 | 992 | 993 | 994 | 次数清零 995 | 996 | 997 | 998 | 999 | 1000 | 1001 | true 1002 | 1003 | 1004 | 1005 | 0 1006 | 0 1007 | 1008 | 1009 | 1010 | Qt::ActionsContextMenu 1011 | 1012 | 1013 | 手动发送 1014 | 1015 | 1016 | false 1017 | 1018 | 1019 | 1020 | 1021 | 1022 | 1023 | 1024 | 1025 | 1026 | 1027 | 1028 | 0 1029 | 0 1030 | 1031 | 1032 | 1033 | 十六进制发送 1034 | 1035 | 1036 | 1037 | 1038 | 1039 | 1040 | 1041 | 1042 | true 1043 | 1044 | 1045 | 1046 | 0 1047 | 0 1048 | 1049 | 1050 | 1051 | Qt::ActionsContextMenu 1052 | 1053 | 1054 | 选择发送文件 1055 | 1056 | 1057 | false 1058 | 1059 | 1060 | 1061 | 1062 | 1063 | 1064 | 1065 | 0 1066 | 0 1067 | 1068 | 1069 | 1070 | QFrame::WinPanel 1071 | 1072 | 1073 | QFrame::Sunken 1074 | 1075 | 1076 | 没有选择文件 1077 | 1078 | 1079 | 1080 | 1081 | 1082 | 1083 | 1084 | 1085 | true 1086 | 1087 | 1088 | 1089 | 0 1090 | 0 1091 | 1092 | 1093 | 1094 | Qt::ActionsContextMenu 1095 | 1096 | 1097 | 清空重填 1098 | 1099 | 1100 | false 1101 | 1102 | 1103 | 1104 | 1105 | 1106 | 1107 | true 1108 | 1109 | 1110 | 1111 | 0 1112 | 0 1113 | 1114 | 1115 | 1116 | Qt::ActionsContextMenu 1117 | 1118 | 1119 | 关于 1120 | 1121 | 1122 | false 1123 | 1124 | 1125 | 1126 | 1127 | 1128 | 1129 | CRLF 1130 | 1131 | 1132 | 1133 | 1134 | 1135 | 1136 | 1137 | 1138 | 1139 | 1140 | 发 1141 | 送 1142 | 显 1143 | 示 1144 | 区 1145 | 1146 | 1147 | 1148 | 1149 | 1150 | 1151 | 1152 | 0 1153 | 0 1154 | 1155 | 1156 | 1157 | QTextEdit::AutoAll 1158 | 1159 | 1160 | false 1161 | 1162 | 1163 | 1164 | 1165 | 1166 | 1167 | 1168 | 1169 | 1170 | 1171 | 1172 | QFrame::StyledPanel 1173 | 1174 | 1175 | QFrame::Raised 1176 | 1177 | 1178 | 1179 | 1180 | 1181 | 1182 | 1183 | 状态: 1184 | 1185 | 1186 | 1187 | 1188 | 1189 | 1190 | 1191 | 0 1192 | 0 1193 | 1194 | 1195 | 1196 | QFrame::WinPanel 1197 | 1198 | 1199 | QFrame::Sunken 1200 | 1201 | 1202 | 1203 | 1204 | 1205 | 1206 | 1207 | 1208 | 1209 | 1210 | 1211 | 发送(TX): 1212 | 1213 | 1214 | 1215 | 1216 | 1217 | 1218 | 1219 | 0 1220 | 0 1221 | 1222 | 1223 | 1224 | QFrame::WinPanel 1225 | 1226 | 1227 | QFrame::Sunken 1228 | 1229 | 1230 | 0 1231 | 1232 | 1233 | 1234 | 1235 | 1236 | 1237 | 接收(RX): 1238 | 1239 | 1240 | 1241 | 1242 | 1243 | 1244 | 1245 | 0 1246 | 0 1247 | 1248 | 1249 | 1250 | QFrame::WinPanel 1251 | 1252 | 1253 | QFrame::Sunken 1254 | 1255 | 1256 | 0 1257 | 1258 | 1259 | 1260 | 1261 | 1262 | 1263 | 1264 | 1265 | true 1266 | 1267 | 1268 | 1269 | 0 1270 | 0 1271 | 1272 | 1273 | 1274 | Qt::ActionsContextMenu 1275 | 1276 | 1277 | 清除计数 1278 | 1279 | 1280 | false 1281 | 1282 | 1283 | 1284 | 1285 | 1286 | 1287 | 1288 | 1289 | true 1290 | 1291 | 1292 | 1293 | 0 1294 | 0 1295 | 1296 | 1297 | 1298 | Qt::ActionsContextMenu 1299 | 1300 | 1301 | false 1302 | 1303 | 1304 | 关闭程序 1305 | 1306 | 1307 | 1308 | :/close.jpg 1309 | 1310 | 1311 | 1312 | false 1313 | 1314 | 1315 | 1316 | 1317 | 1318 | 1319 | 1320 | 1321 | 1322 | 1323 | myQComboBox 1324 | QComboBox 1325 |
myqcombobox.h
1326 |
1327 | 1328 | myQLineEdit 1329 | QLineEdit 1330 |
myqlineedit.h
1331 |
1332 |
1333 | 1334 | 1335 | 1336 | 1337 |
1338 | -------------------------------------------------------------------------------- /ui/success.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ninehills/serialtool/16fce32f436333d2ff9a44808383bbbf7e7ca103/ui/success.png -------------------------------------------------------------------------------- /ui/thank.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ninehills/serialtool/16fce32f436333d2ff9a44808383bbbf7e7ca103/ui/thank.png --------------------------------------------------------------------------------