diff --git a/main.cpp b/main.cpp index b1cf781e..d511753e 100644 --- a/main.cpp +++ b/main.cpp @@ -9,7 +9,7 @@ int main() { CRC_16 crc = CRC_16(0x8005, 0xFFFF, 0xFFFF, false); piCout << PICoutManipulators::Hex << s; piCout << PICoutManipulators::Hex << crc.calculate(msg);*/ - PIIODevice * ser = PIIODevice::createFromFullPath("ser://COM3:9600:9:o:2 (wo,bwr)"); + PIIODevice * ser = PIIODevice::createFromFullPath("ser://COM3:9600:7:e:1 (wo,bwr)"); piCout << ser << ser->constructVariant() << ser->constructFullPath(); ser = PIIODevice::createFromVariant(ser->constructVariant()); piCout << ser << ser->constructVariant() << ser->constructFullPath(); diff --git a/src_main/io_devices/piserial.cpp b/src_main/io_devices/piserial.cpp index 76e316c5..23f99ebe 100755 --- a/src_main/io_devices/piserial.cpp +++ b/src_main/io_devices/piserial.cpp @@ -720,22 +720,45 @@ void PISerial::configureFromFullPathDevice(const PIString & full_path) { PIPropertyStorage PISerial::constructVariantDevice() const { PIPropertyStorage ret; ret.addProperty("path", path()); - ret.addProperty("speed", (int)inSpeed()); - ret.addProperty("bits", dataBitsCount()); - ret.addProperty("parity", parameters()[ParityControl]); - ret.addProperty("parityEven", !parameters()[ParityOdd]); - ret.addProperty("twoStopBits", parameters()[TwoStopBits]); + PIVariantTypes::Enum e; + + PIVector as = availableSpeeds(); + piForeachC (int s, as) {e << PIVariantTypes::Enumerator(s, PIString::fromNumber(s));} + e.selectValue((int)inSpeed()); + ret.addProperty("speed", e); + + e = PIVariantTypes::Enum(); + for (int i = 5; i <= 8; ++i) {e << PIVariantTypes::Enumerator(i, PIString::fromNumber(i));} + e.selectValue(dataBitsCount()); + ret.addProperty("dataBits", e); + + e = PIVariantTypes::Enum(); + e << "None" << "Odd" << "Even"; + if (parameters()[ParityControl]) { + if (parameters()[ParityOdd]) + e.selectValue(1); + else + e.selectValue(2); + } else + e.selectValue(0); + ret.addProperty("parity", e); + + e = PIVariantTypes::Enum(); + for (int i = 1; i <= 2; ++i) {e << PIVariantTypes::Enumerator(i, PIString::fromNumber(i));} + e.selectValue(parameters()[TwoStopBits] ? 2 : 1); + ret.addProperty("stopBits", e); return ret; } void PISerial::configureFromVariantDevice(const PIPropertyStorage & d) { setPath(d.propertyValueByName("path").toString()); - setSpeed((Speed)d.propertyValueByName("speed").toInt()); - setDataBitsCount(d.propertyValueByName("bits").toInt()); - setParameter(ParityControl, d.propertyValueByName("parity").toBool()); - setParameter(ParityOdd , !d.propertyValueByName("parityEven").toBool()); - setParameter(TwoStopBits , d.propertyValueByName("twoStopBits").toBool()); + setSpeed((Speed)d.propertyValueByName("speed").toEnum().selectedValue()); + setDataBitsCount(d.propertyValueByName("dataBits").toEnum().selectedValue()); + PIVariantTypes::Enum e = d.propertyValueByName("parity").toEnum(); + setParameter(ParityControl, e.selectedValue() > 0); + setParameter(ParityOdd , e.selectedValue() == 1); + setParameter(TwoStopBits , d.propertyValueByName("stopBits").toEnum().selectedValue() == 2); }