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

Method open

Software/src/LedDeviceAdalight.cpp:190–247  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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