MCPcopy Create free account
hub / github.com/Atarity/Lightpack / open

Method open

Software/src/LedDeviceArdulight.cpp:197–254  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

195}
196
197void LedDeviceArdulight::open()
198{
199 DEBUG_LOW_LEVEL << Q_FUNC_INFO;
200
201// m_gamma = Settings::getDeviceGamma();
202// m_brightness = Settings::getDeviceBrightness();
203
204 if (m_ArdulightDevice != NULL)
205 m_ArdulightDevice->close();
206 else
207 m_ArdulightDevice = new QSerialPort();
208
209 m_ArdulightDevice->setPortName(m_portName);
210
211 m_ArdulightDevice->open(QIODevice::WriteOnly);
212 bool ok = m_ArdulightDevice->isOpen();
213
214 // Ubuntu 10.04: on every second attempt to open the device leads to failure
215 if (ok == false)
216 {
217 // Try one more time
218 m_ArdulightDevice->open(QIODevice::WriteOnly);
219 ok = m_ArdulightDevice->isOpen();
220 }
221
222 if (ok)
223 {
224 DEBUG_LOW_LEVEL << Q_FUNC_INFO << "Serial device" << m_ArdulightDevice->portName() << "open";
225
226 ok = m_ArdulightDevice->setBaudRate(m_baudRate);
227 if (ok)
228 {
229 ok = m_ArdulightDevice->setDataBits(QSerialPort::Data8);
230 if (ok)
231 {
232 DEBUG_LOW_LEVEL << Q_FUNC_INFO << "Baud rate :" << m_ArdulightDevice->baudRate();
233 DEBUG_LOW_LEVEL << Q_FUNC_INFO << "Data bits :" << m_ArdulightDevice->dataBits();
234 DEBUG_LOW_LEVEL << Q_FUNC_INFO << "Parity :" << m_ArdulightDevice->parity();
235 DEBUG_LOW_LEVEL << Q_FUNC_INFO << "Stop bits :" << m_ArdulightDevice->stopBits();
236 DEBUG_LOW_LEVEL << Q_FUNC_INFO << "Flow :" << m_ArdulightDevice->flowControl();
237 } else {
238 qWarning() << Q_FUNC_INFO << "Set data bits 8 fail";
239 }
240 } else {
241 qWarning() << Q_FUNC_INFO << "Set baud rate" << m_baudRate << "fail";
242 }
243
244 } else {
245 qWarning() << Q_FUNC_INFO << "Serial device" << m_ArdulightDevice->portName() << "open fail. " << m_ArdulightDevice->errorString();
246 DEBUG_OUT << Q_FUNC_INFO << "Available ports:";
247 QList<QSerialPortInfo> availPorts = QSerialPortInfo::availablePorts();
248 for(int i=0; i < availPorts.size(); i++) {
249 DEBUG_OUT << Q_FUNC_INFO << availPorts[i].portName();
250 }
251 }
252
253 emit openDeviceSuccess(ok);
254}

Callers

nothing calls this directly

Calls 10

setPortNameMethod · 0.80
baudRateMethod · 0.80
dataBitsMethod · 0.80
parityMethod · 0.80
stopBitsMethod · 0.80
flowControlMethod · 0.80
closeMethod · 0.45
portNameMethod · 0.45
setBaudRateMethod · 0.45
setDataBitsMethod · 0.45

Tested by

no test coverage detected