Subversion Repositories Code-Repo

Rev

Rev 353 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 353 Rev 354
Line 28... Line 28...
28
 
28
 
29
void SerialHelper::Serial_Connect(QString port, QString speed, QString dataBits,
29
void SerialHelper::Serial_Connect(QString port, QString speed, QString dataBits,
30
                            QString stopBits, QString parity, QString flowControl)
30
                            QString stopBits, QString parity, QString flowControl)
31
{
31
{
32
    if (!connected) {
32
    if (!connected) {
33
        emit UpdateStatus("Serial: Connecting to " + port);
33
        emit UpdateStatus("Connecting to " + port);
34
        serialPort = new QSerialPort();
34
        serialPort = new QSerialPort();
35
        connect(serialPort, SIGNAL(readyRead()), this, SLOT(Serial_ProcessIncomingData()));
35
        connect(serialPort, SIGNAL(readyRead()), this, SLOT(Serial_ProcessIncomingData()));
36
        connect(serialPort, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(Serial_ProcessError(QSerialPort::SerialPortError)));
36
        connect(serialPort, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(Serial_ProcessError(QSerialPort::SerialPortError)));
37
        serialPort->setPortName(port);
37
        serialPort->setPortName(port);
38
        if (serialPort->open(QIODevice::ReadWrite)) {
38
        if (serialPort->open(QIODevice::ReadWrite)) {
Line 78... Line 78...
78
 
78
 
79
            // See http://umforum.ultimaker.com/index.php?/topic/5886-um2-controller-resetreboot-when-opening-usb-port-on-linux/
79
            // See http://umforum.ultimaker.com/index.php?/topic/5886-um2-controller-resetreboot-when-opening-usb-port-on-linux/
80
            serialPort->setDataTerminalReady(1);
80
            serialPort->setDataTerminalReady(1);
81
 
81
 
82
            if (ok) {
82
            if (ok) {
83
                QString status = "Serial: Connected (%1 @ %2 D: %3 S: %4 P: %5 FC: %6)";
83
                QString status = "Connected (%1 @ %2 D: %3 S: %4 P: %5 FC: %6)";
84
                emit UpdateStatus(status.arg(port).arg(speed).arg(dataBits).arg(stopBits).arg(parity).arg(flowControl));
84
                emit UpdateStatus(status.arg(port).arg(speed).arg(dataBits).arg(stopBits).arg(parity).arg(flowControl));
85
                emit Serial_Connected();
85
                emit Serial_Connected();
86
            } else
86
            } else
87
                Serial_Disconnect();
87
                Serial_Disconnect();
88
        }
88
        }
Line 94... Line 94...
94
    serialPort->disconnect();
94
    serialPort->disconnect();
95
    serialPort->close();
95
    serialPort->close();
96
    delete serialPort;
96
    delete serialPort;
97
    connected = false;
97
    connected = false;
98
    if (!errored)
98
    if (!errored)
99
        emit UpdateStatus("Serial: Disconnected");
99
        emit UpdateStatus("Disconnected");
100
    emit Serial_Disconnected();
100
    emit Serial_Disconnected();
101
}
101
}
102
 
102
 
103
void SerialHelper::Serial_TransmitString(QString string)
103
void SerialHelper::Serial_TransmitString(QString string)
104
{
104
{
105
    serialPort->write(string.toStdString().c_str());
105
    serialPort->write(string.toStdString().c_str());
106
    serialPort->write(SERIAL_NEWLINE_CHAR);
106
    serialPort->write(SERIAL_NEWLINE_CHAR);
107
}
107
}
108
 
108
 
109
void SerialHelper::Serial_TransmitByteArray(QByteArray buffer)
109
void SerialHelper::Serial_TransmitByteArray(QByteArray data)
110
{
110
{
111
    serialPort->write(buffer);
111
    serialPort->write(data);
112
}
112
}
113
 
113
 
114
void SerialHelper::Serial_ProcessIncomingData()
114
void SerialHelper::Serial_ProcessIncomingData()
115
{
115
{
116
    char tmpBuffer[SERIAL_BUFFER_SIZE];
116
    char tmpBuffer[SERIAL_BUFFER_SIZE];
Line 128... Line 128...
128
{
128
{
129
    if (error == QSerialPort::NoError) return;
129
    if (error == QSerialPort::NoError) return;
130
 
130
 
131
    switch(error) {
131
    switch(error) {
132
        case QSerialPort::DeviceNotFoundError:
132
        case QSerialPort::DeviceNotFoundError:
133
            emit UpdateStatus("Serial: (Error) Device not found");
133
            emit UpdateStatus("(Error) Device not found");
134
            return;
134
            return;
135
        case QSerialPort::PermissionError:
135
        case QSerialPort::PermissionError:
136
            emit UpdateStatus("Serial: (Error) Device already opened or lacking permission");
136
            emit UpdateStatus("(Error) Device already opened or lacking permission");
137
            return;
137
            return;
138
        case QSerialPort::OpenError:
138
        case QSerialPort::OpenError:
139
            emit UpdateStatus("Serial: (Error) Device already opened");
139
            emit UpdateStatus("(Error) Device already opened");
140
            return;
140
            return;
141
        case QSerialPort::NotOpenError:
141
        case QSerialPort::NotOpenError:
142
            emit UpdateStatus("Serial: (Error) Device not opened");
142
            emit UpdateStatus("(Error) Device not opened");
143
            return;
143
            return;
144
        case QSerialPort::ParityError:
144
        case QSerialPort::ParityError:
145
            emit UpdateStatus("Serial: (Error) Parity error detected");
145
            emit UpdateStatus("(Error) Parity error detected");
146
            break;
146
            break;
147
        case QSerialPort::FramingError:
147
        case QSerialPort::FramingError:
148
            emit UpdateStatus("Serial: (Error) Framing error detected");
148
            emit UpdateStatus("(Error) Framing error detected");
149
            break;
149
            break;
150
        case QSerialPort::BreakConditionError:
150
        case QSerialPort::BreakConditionError:
151
            emit UpdateStatus("Serial: (Error) Break condition detected");
151
            emit UpdateStatus("(Error) Break condition detected");
152
            break;
152
            break;
153
        case QSerialPort::WriteError:
153
        case QSerialPort::WriteError:
154
            emit UpdateStatus("Serial: (Error) Unable to write to device");
154
            emit UpdateStatus("(Error) Unable to write to device");
155
            break;
155
            break;
156
        case QSerialPort::ReadError:
156
        case QSerialPort::ReadError:
157
            emit UpdateStatus("Serial: (Error) Unable to read from device");
157
            emit UpdateStatus("(Error) Unable to read from device");
158
            break;
158
            break;
159
        case QSerialPort::ResourceError:
159
        case QSerialPort::ResourceError:
160
            emit UpdateStatus("Serial: (Error) Device missing or disconnected");
160
            emit UpdateStatus("(Error) Device missing or disconnected");
161
            break;
161
            break;
162
        case QSerialPort::UnsupportedOperationError:
162
        case QSerialPort::UnsupportedOperationError:
163
            emit UpdateStatus("Serial: (Error) Operation not supported or prohibited");
163
            emit UpdateStatus("(Error) Operation not supported or prohibited");
164
            break;
164
            break;
165
        case QSerialPort::TimeoutError:
165
        case QSerialPort::TimeoutError:
166
            emit UpdateStatus("Serial: (Error) Connection timeout");
166
            emit UpdateStatus("(Error) Connection timeout");
167
            break;
167
            break;
168
        case QSerialPort::UnknownError:
168
        case QSerialPort::UnknownError:
169
            emit UpdateStatus("Serial: (Error) Unknown error");
169
            emit UpdateStatus("(Error) Unknown error");
170
            break;
170
            break;
171
        default:
171
        default:
172
            break;
172
            break;
173
    }
173
    }
174
 
174