fixed device discovery
This commit is contained in:
parent
4403be8d76
commit
ac6318a10d
@ -112,53 +112,49 @@ DeviceManager::DeviceError DevicePluginSerialPortCommander::discoverDevices(cons
|
|||||||
QList<DeviceDescriptor> deviceDescriptors;
|
QList<DeviceDescriptor> deviceDescriptors;
|
||||||
|
|
||||||
Q_FOREACH(QSerialPortInfo port, QSerialPortInfo::availablePorts()) {
|
Q_FOREACH(QSerialPortInfo port, QSerialPortInfo::availablePorts()) {
|
||||||
qCDebug(dcSerialPortCommander()) << "Found Serial interface:" << port.systemLocation() << port.portName();
|
if (m_serialPortCommanders.contains(port.portName())){
|
||||||
QString description = port.manufacturer() + " | " + port.description();
|
SerialPortCommander *serialPortCommander = m_serialPortCommanders.value(port.portName());
|
||||||
DeviceDescriptor descriptor(deviceClassId, port.systemLocation(), description);
|
QSerialPort *serialPort = serialPortCommander->serialPort();
|
||||||
ParamList parameters;
|
QString description = "Note, this serial port is also used by another device";
|
||||||
|
DeviceDescriptor descriptor(deviceClassId, serialPort->portName(), description);
|
||||||
|
ParamList parameters;
|
||||||
|
|
||||||
if (deviceClassId == serialPortInputDeviceClassId) {
|
if (deviceClassId == serialPortInputDeviceClassId) {
|
||||||
//TODO add all currenly used devices
|
parameters.append(Param(serialPortInputSerialPortParamTypeId, serialPort->portName()));
|
||||||
parameters.append(Param(serialPortInputSerialPortParamTypeId, port.systemLocation()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (deviceClassId == serialPortOutputDeviceClassId) {
|
|
||||||
//TODO add currently only as input used devices
|
|
||||||
parameters.append(Param(serialPortOutputSerialPortParamTypeId, port.systemLocation()));
|
|
||||||
}
|
|
||||||
descriptor.setParams(parameters);
|
|
||||||
deviceDescriptors.append(descriptor);
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_FOREACH(SerialPortCommander *serialPortCommander, m_serialPortCommanders.values()) {
|
|
||||||
|
|
||||||
QSerialPort *serialPort = serialPortCommander->serialPort();
|
|
||||||
QString description = "also used by another device";
|
|
||||||
DeviceDescriptor descriptor(deviceClassId, serialPort->portName(), description);
|
|
||||||
ParamList parameters;
|
|
||||||
|
|
||||||
if (deviceClassId == serialPortInputDeviceClassId) {
|
|
||||||
parameters.append(Param(serialPortInputSerialPortParamTypeId, serialPort->portName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (deviceClassId == serialPortOutputDeviceClassId) {
|
|
||||||
if (serialPortCommander->hasOutputDevice()){
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parameters.append(Param(serialPortOutputSerialPortParamTypeId, serialPort->portName()));
|
if (deviceClassId == serialPortOutputDeviceClassId) {
|
||||||
parameters.append(Param(serialPortOutputBaudRateParamTypeId, serialPort->baudRate()));
|
if (serialPortCommander->hasOutputDevice()){
|
||||||
parameters.append(Param(serialPortOutputDataBitsParamTypeId, serialPort->dataBits()));
|
continue;
|
||||||
parameters.append(Param(serialPortOutputFlowControlParamTypeId, serialPort->flowControl()));
|
}
|
||||||
parameters.append(Param(serialPortOutputStopBitsParamTypeId, serialPort->stopBits()));
|
}
|
||||||
parameters.append(Param(serialPortOutputParityParamTypeId, serialPort->parity()));
|
parameters.append(Param(serialPortOutputSerialPortParamTypeId, serialPort->portName()));
|
||||||
|
parameters.append(Param(serialPortOutputBaudRateParamTypeId, serialPort->baudRate()));
|
||||||
|
parameters.append(Param(serialPortOutputDataBitsParamTypeId, serialPort->dataBits()));
|
||||||
|
parameters.append(Param(serialPortOutputFlowControlParamTypeId, serialPort->flowControl()));
|
||||||
|
parameters.append(Param(serialPortOutputStopBitsParamTypeId, serialPort->stopBits()));
|
||||||
|
parameters.append(Param(serialPortOutputParityParamTypeId, serialPort->parity()));
|
||||||
|
descriptor.setParams(parameters);
|
||||||
|
deviceDescriptors.append(descriptor);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
qCDebug(dcSerialPortCommander()) << "Found Serial interface:" << port.portName();
|
||||||
|
QString description = port.manufacturer() + " | " + port.description();
|
||||||
|
DeviceDescriptor descriptor(deviceClassId, port.portName(), description);
|
||||||
|
ParamList parameters;
|
||||||
|
|
||||||
|
if (deviceClassId == serialPortInputDeviceClassId) {
|
||||||
|
parameters.append(Param(serialPortInputSerialPortParamTypeId, port.portName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (deviceClassId == serialPortOutputDeviceClassId) {
|
||||||
|
parameters.append(Param(serialPortOutputSerialPortParamTypeId, port.portName()));
|
||||||
|
}
|
||||||
|
descriptor.setParams(parameters);
|
||||||
|
deviceDescriptors.append(descriptor);
|
||||||
}
|
}
|
||||||
descriptor.setParams(parameters);
|
|
||||||
deviceDescriptors.append(descriptor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
emit devicesDiscovered(deviceClassId, deviceDescriptors);
|
emit devicesDiscovered(deviceClassId, deviceDescriptors);
|
||||||
return DeviceManager::DeviceErrorAsync;
|
return DeviceManager::DeviceErrorAsync;
|
||||||
}
|
}
|
||||||
@ -192,16 +188,21 @@ void DevicePluginSerialPortCommander::deviceRemoved(Device *device)
|
|||||||
interface = device->paramValue(serialPortInputSerialPortParamTypeId).toString();
|
interface = device->paramValue(serialPortInputSerialPortParamTypeId).toString();
|
||||||
serialPortCommander = m_serialPortCommanders.value(interface);
|
serialPortCommander = m_serialPortCommanders.value(interface);
|
||||||
serialPortCommander->removeInputDevice(device);
|
serialPortCommander->removeInputDevice(device);
|
||||||
|
if (serialPortCommander->isEmpty()) {
|
||||||
|
m_serialPortCommanders.remove(interface);
|
||||||
|
serialPortCommander->deleteLater();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device->deviceClassId() == serialPortOutputDeviceClassId) {
|
if (device->deviceClassId() == serialPortOutputDeviceClassId) {
|
||||||
interface = device->paramValue(serialPortOutputSerialPortParamTypeId).toString();
|
interface = device->paramValue(serialPortOutputSerialPortParamTypeId).toString();
|
||||||
serialPortCommander = m_serialPortCommanders.value(interface);
|
serialPortCommander = m_serialPortCommanders.value(interface);
|
||||||
serialPortCommander->removeOutputDevice();
|
serialPortCommander->removeOutputDevice();
|
||||||
|
if (serialPortCommander->isEmpty()) {
|
||||||
|
m_serialPortCommanders.remove(interface);
|
||||||
|
serialPortCommander->deleteLater();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (serialPortCommander->isEmpty())
|
|
||||||
m_serialPortCommanders.remove(interface);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user