--- /dev/null
+This is a very stupid QT4 based program that is able to read pictures
+from Tektronix oscilloscope through serial line. Currently, there are
+no configuration options. The configuration is hardcoded in sources
+and is:
+
+Serial line: /dev/ttyS0
+Speed: 19200
+No handshake
+Image format: TIFF
+
+The osciloscope must be setup to the same format.
+
+If you want the program to display images and copy them to clipboard
+automatically, TIFF image plugin for QT must be installed. There is
+one available at http://artis.imag.fr/Software/TiffIO/.
+
+
+Author: Michal Sojka <sojkam1@fel.cvut.cz>
--- /dev/null
+<ui version="4.0" >
+ <class>MainWin</class>
+ <widget class="QDialog" name="MainWin" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>430</width>
+ <height>352</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>TekPic</string>
+ </property>
+ <layout class="QHBoxLayout" >
+ <property name="margin" >
+ <number>9</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <layout class="QVBoxLayout" >
+ <property name="margin" >
+ <number>0</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QScrollArea" name="scrollArea" >
+ <property name="sizePolicy" >
+ <sizepolicy>
+ <hsizetype>5</hsizetype>
+ <vsizetype>5</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="frameShape" >
+ <enum>QFrame::StyledPanel</enum>
+ </property>
+ <property name="frameShadow" >
+ <enum>QFrame::Sunken</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QProgressBar" name="progressBar" >
+ <property name="value" >
+ <number>24</number>
+ </property>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QVBoxLayout" >
+ <property name="margin" >
+ <number>0</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QLabel" name="label_2" >
+ <property name="text" >
+ <string>&File name prefix:</string>
+ </property>
+ <property name="buddy" >
+ <cstring>prefixLine</cstring>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="prefixLine" >
+ <property name="sizePolicy" >
+ <sizepolicy>
+ <hsizetype>1</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text" >
+ <string>osc-</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_3" >
+ <property name="text" >
+ <string>Full file &name:</string>
+ </property>
+ <property name="buddy" >
+ <cstring>fileLine</cstring>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="fileLine" />
+ </item>
+ <item>
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>201</width>
+ <height>71</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="saveButton" >
+ <property name="text" >
+ <string>&Save</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="quitButton" >
+ <property name="text" >
+ <string>&Quit</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>QScrollArea</class>
+ <extends>QFrame</extends>
+ <header>QScrollArea</header>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2006 by Michal Sojka *
+ * sojkam1@fel.cvut.cz *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+#include "mainwindow.h"
+#include <QTextStream>
+#include <QDataStream>
+#include <QFile>
+#include <QClipboard>
+
+MainWindow::MainWindow(const string &tty)
+ : QDialog(), m_commThread(tty), m_fileNum(0), m_image()
+{
+ ui.setupUi(this);
+
+ imageLabel = new QLabel;
+ ui.scrollArea->setWidget(imageLabel);
+ ui.progressBar->setValue(0);
+ ui.progressBar->setMaximum(15000);
+ ui.saveButton->setDisabled(true);
+
+ connect(ui.quitButton, SIGNAL(clicked()), this, SLOT(close()));
+ connect(&m_commThread, SIGNAL(bytesReceived(int)), ui.progressBar, SLOT(setValue(int)));
+ connect(&m_commThread, SIGNAL(imageAvailable(OscImage*)), this, SLOT(processImage(OscImage*)));
+ connect(ui.prefixLine, SIGNAL(textChanged(const QString&)), this, SLOT(generateFileName(const QString&)));
+ connect(ui.saveButton, SIGNAL(clicked()), this, SLOT(saveImage()));
+
+ m_commThread.start();
+}
+
+
+MainWindow::~MainWindow()
+{
+}
+
+void MainWindow::processImage( OscImage * img )
+{
+ bool ret;
+ ui.saveButton->setEnabled(true);
+ ui.progressBar->setMaximum(img->size());
+ ui.progressBar->setValue(img->size());
+ ui.progressBar->update();
+
+ m_fileNum++;
+ generateFileName( ui.prefixLine->text());
+
+ if (m_image) delete m_image;
+ m_image = img;
+
+ QPixmap pixmap;
+ ret = pixmap.loadFromData(*m_image);
+ if (!ret) cerr << "Can't display image!"<<endl;
+ QApplication::clipboard()->setPixmap(pixmap);
+ imageLabel->setPixmap(pixmap);
+ imageLabel->adjustSize();
+}
+
+
+
+void MainWindow::resetFileCounter( )
+{
+ m_fileNum = 0;
+}
+
+void MainWindow::generateFileName( const QString & prefix )
+{
+ QString fname;
+ QTextStream ts(&fname);
+
+ ts.setFieldWidth(3);
+ ts.setPadChar('0') ;
+ ts << prefix << m_fileNum << ".tif";
+ ui.fileLine->setText(fname);
+}
+
+void MainWindow::saveImage()
+{
+ QFile file(ui.fileLine->text());
+ QDataStream ds(&file);
+
+ file.open(QIODevice::WriteOnly);
+ ds.writeRawData(m_image->data(), m_image->size());
+ file.close();
+}
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2006 by Michal Sojka *
+ * sojkam1@fel.cvut.cz *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <qdialog.h>
+#include "ui_main.h"
+#include "osccommthread.h"
+#include <string>
+#include "mainwindow.h"
+
+using namespace std;
+/**
+ @author Michal Sojka <sojkam1@fel.cvut.cz>
+*/
+class MainWindow : public QDialog
+{
+ Q_OBJECT
+public:
+ MainWindow(const string &tty);
+
+ ~MainWindow();
+private:
+ Ui::MainWin ui;
+ OscCommThread m_commThread;
+ int m_fileNum;
+ OscImage *m_image;
+ QLabel *imageLabel;
+private slots:
+ void processImage(OscImage *img);
+ void saveImage();
+ void resetFileCounter();
+ void generateFileName(const QString& prefix);
+
+};
+
+#endif
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2006 by Michal Sojka *
+ * sojkam1@fel.cvut.cz *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+#include "osccommthread.h"
+#include <termios.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <poll.h>
+#include <iomanip>
+#include <iostream>
+using namespace std;
+
+ostream& operator<<(ostream& s, OscImage& im)
+{
+ int i;
+ ios::fmtflags f;
+
+ s << "Size: " << im.size() << " Data " << (void *)im.data() << ": ";
+ f = s.flags();
+ s << hex;
+ for (i=0; i<(im.size() > 32 ? 32 : im.size()); i++)
+ s << setw(2) << setfill('0') << (unsigned int)(unsigned char)im.at(i) << ' ';
+ s.flags(f);
+ if (im.size() >= i) s << "...";
+ return s;
+}
+
+OscCommThread::OscCommThread( const string &tty)
+{
+ m_fd = open(tty.c_str(), O_RDWR);
+ if (m_fd<0) {
+ perror(tty.c_str());
+ exit(1);
+ }
+ m_img = new OscImage;
+
+ struct termios ts;
+
+ /* Flush input and output queues. */
+ if (tcflush(m_fd, TCIOFLUSH) != 0) {
+ cerr << "Error in tcflush" << endl;
+ exit(1);
+ }
+
+ /* Fetch the current terminal parameters. */
+ if (tcgetattr(m_fd, &ts) != 0) {
+ cerr << "Error in tcfgetattr" << endl;
+ exit(1);
+ }
+
+ /* Sets hardware control flags: */
+ /* 8 data bits */
+ /* Enable receiver */
+ /* Ignore CD (local connection) */
+ ts.c_cflag = CS8 | CREAD | CLOCAL;
+ //ts.c_cflag |= CRTSCTS; /* CCTS_OFLOW | CRTS_IFLOW */
+ ts.c_iflag = 0;
+ ts.c_oflag = NL0 | CR0 | TAB0 | BS0 | VT0 | FF0;
+ ts.c_lflag = 0;
+
+ cfsetispeed (&ts, B19200);
+ cfsetospeed (&ts, B19200);
+
+ /* Sets the new terminal parameters. */
+ if (tcsetattr(m_fd, TCSANOW, &ts) != 0) {
+ cerr << "Error in tcsetattr" << endl;
+ exit(1);
+ }
+}
+
+
+OscCommThread::~OscCommThread()
+{}
+
+/*!
+ \fn OscCommThread::run()
+ */
+void OscCommThread::run()
+{
+ char buf[100];
+ int n;
+ struct pollfd pfd;
+ int ret;
+
+ pfd.fd = m_fd;
+ pfd.events = POLLIN;
+
+ while (1) {
+ ret = poll(&pfd, 1, 1000/*ms*/);
+ if (ret>0) {
+ n = read(m_fd, buf, sizeof(buf)-1);
+ QByteArray ba = QByteArray::fromRawData(buf, n);
+ m_img->append(ba);
+ bytesReceived( m_img->size() );
+ } else if (ret==0) {
+ if (m_img->size()) {
+ processImage();
+ }
+ }
+ }
+}
+
+void OscCommThread::processImage()
+{
+ imageAvailable( m_img );
+ m_img = new OscImage;
+}
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2006 by Michal Sojka *
+ * sojkam1@fel.cvut.cz *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+#ifndef OSCCOMMTHREAD_H
+#define OSCCOMMTHREAD_H
+
+#include <QThread>
+#include <serial.h>
+#include <string>
+#include <iostream>
+#include <ext/stdio_filebuf.h>
+#include <vector>
+#include <QByteArray>
+using namespace std;
+
+class OscImage : public QByteArray
+{
+public:
+ OscImage()
+ {
+// cout << "Img created" << (void*)this->data() << endl;
+ reserve(1000);
+ }
+ virtual ~OscImage() {
+// cout << "Img destroyed" << this << endl;
+ }
+};
+
+ostream& operator<<(ostream& s, OscImage& im);
+
+
+/**
+ @author Michal Sojka <sojkam1@fel.cvut.cz>
+*/
+class OscCommThread : public QThread
+{
+ Q_OBJECT
+public:
+ OscCommThread(const string &tty);
+ ~OscCommThread();
+private:
+ int m_fd;
+ OscImage *m_img;
+
+ void run();
+ void processImage();
+signals:
+ void imageAvailable(OscImage *img);
+ void bytesReceived(int bytes);
+};
+
+#endif
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2006 by Michal Sojka *
+ * sojkam1@fel.cvut.cz *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+#include "serial.h"
+
+Serial::Serial(QObject *parent)
+ : QIODevice(parent)
+{
+}
+
+
+Serial::~Serial()
+{
+}
+
+
+
+
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2006 by Michal Sojka *
+ * sojkam1@fel.cvut.cz *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+#ifndef SERIAL_H
+#define SERIAL_H
+
+#include <QIODevice>
+
+/**
+ @author Michal Sojka <sojkam1@fel.cvut.cz>
+*/
+class Serial : public QIODevice
+{
+Q_OBJECT
+public:
+ Serial(QObject *parent = 0);
+
+ ~Serial();
+
+};
+
+#endif
--- /dev/null
+# File generated by kdevelop's qmake manager.
+# -------------------------------------------
+# Subdir relative project main directory: ./src
+# Target is an application: ../bin/tekpic
+
+TARGET = ../bin/tekpic
+CONFIG += debug \
+ warn_on
+TEMPLATE = app
+FORMS += main.ui
+HEADERS += mainwindow.h \
+ serial.h \
+ osccommthread.h
+SOURCES += tekpic.cpp \
+ mainwindow.cpp \
+ serial.cpp \
+ osccommthread.cpp
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2006 by Michal Sojka *
+ * sojkam1@fel.cvut.cz *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "mainwindow.h"
+#include <string>
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow *window = new MainWindow(string("/dev/ttyS0"));
+
+ window->show();
+ return app.exec();
+}
--- /dev/null
+TEMPLATE=subdirs
+SUBDIRS=src
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2006 by Michal Sojka *
+ * sojkam1@fel.cvut.cz *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2006 by Michal Sojka *
+ * sojkam1@fel.cvut.cz *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/