Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to access IO port in QT?



  • Hello everyone
    does anyone know how to access I/O port in QT?
    ex: RTC CMOS have IO port 0x70,0x71
    serial port have IO 0x3F8,0x2F8....
    we have some device that need to access by this operation
    is there any function or lib could access I/O directly?


  • Lifetime Qt Champion

    Hi @HaCoMaTaTa,

    about which platform and operating system are you talking?

    Direct port access was done in MS-DOS times. All modern operating systems provides and API for that.

    To access serial ports you can use QSerialPort.

    Regards



  • Hi @aha_1980
    hi
    thanks for your reply
    i use QT in windows platform,
    i need direct port access in QT to control my hardware device,
    is there any direct port access method tutorial?
    or it need include extra library such as winio to done that?


  • Lifetime Qt Champion

    Hi @HaCoMaTaTa,

    There is no direct port access possible in all Windows NT related versions (Windows NT, XP, Vista, 7, 8, 10).

    It was possible in the MS-DOS based Windows versions (3.1, 95, 98, ME). You can google for that.

    Regards



  • hi @aha_1980

    if it don't have direct method to access, is there any indirect port access method on QT?
    or we only could use 3 party library such as WINIO library


  • Lifetime Qt Champion

    Hi @HaCoMaTaTa,

    there is no integrated support for accessing hardware ports in Qt. You will need external libraries (with appropriate Kernel driver).

    You didn't say what you want to do with the RS-232 ports. QSerialPort also provides functions to set some of the control pins. Maybe that's already enough for you.

    Regards



  • Hi @aha_1980

    thanks for your reply
    Serial port is not my purpose, i want create an UI interface to access hardware register , so it need to access many type of device such as SuperIO (use io port 0x2e 0x2f...), DIO through smbus (io port 0xf040..), or Embeded Controller (EC), even my custom io information in memory IO,



  • @aha_1980 u can read/write byte to I/O port using winio.lib in windows XP,7.
    using inpout32.lib in windows 10 both x86 and x64. For linux, u need to using the mmap function for mapping I/O address before read/write.
    However qt can not provide a class for that.
    I think this function is important for automation.


  • Lifetime Qt Champion

    Hi @aowoo,

    I think this function is important for automation.

    I don't think so. Nowadays, (hardware) serial and parallel ports are uncommon in the PC world. You can use USB interface boards like Bus Pirate as alternative.

    For industrial use, ruggedized, but more expensive interfaces - often optical isolated - are available.

    Regards



  • @aha_1980 I am agree with that parallel port is uncommon now, however the serial port is still widely used in the my industry (semiconductor) for different sensors.
    The most Important is that most industries board (ISA PCI...) usually provide only one driver for one or two old OS(windowXP,7).
    So if we want to update or changed the OS without a driver, We have to build a new lib which based on directly read and write to the I/O port.


  • Qt Champions 2020

    @aowoo said in How to access IO port in QT?:

    directly read and write to the I/O port

    AFAIK, It's impossible for Windows && Linux:

    • On Windows you need in a special driver (It is not enough to use just some DLL's, because you need in a driver. Most likelly, that inpout32.dll has a pre-compiled driver in own resources and loads this driver in runtime).

    • On Linux you need in a special permissions too.