Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Serial port
Forum Updated to NodeBB v4.3 + New Features

Serial port

Scheduled Pinned Locked Moved General and Desktop
37 Posts 6 Posters 17.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KushalAusula
    wrote on last edited by
    #22

    use this

    @QString a="a";
    QByteArray BA1=a.toUtf8();
    QByteArray BA2=BA1.toHex();
    const char* chArr1=BA2.constData();
    qDebug()<<QString::fromUtf8(chArr1);@

    1 Reply Last reply
    0
    • McLionM Offline
      McLionM Offline
      McLion
      wrote on last edited by
      #23

      Is your fd the serialport?
      Again, as asked before, why are you not using QSerialPort?
      What is your target, the task you need to get done?

      1 Reply Last reply
      0
      • K Offline
        K Offline
        KushalAusula
        wrote on last edited by
        #24

        Basic serial port usage as I have worked on is

        @ serial=new QSerialPort(this);

        serial->setPortName("/dev/ttyS0");
        serial->setBaudRate(9600);
        serial->setDataBits(QSerialPort::Data8);
        serial->setParity(QSerialPort::NoParity);
        serial->setFlowControl(QSerialPort::NoFlowControl);
        
        
        serial->open(QIODevice::ReadWrite);
        
        serial->write("Hello World");
        
        connect(serial,SIGNAL(readyRead()),this,SLOT(readSerialData()));@
        
        1 Reply Last reply
        0
        • McLionM Offline
          McLionM Offline
          McLion
          wrote on last edited by
          #25

          .. and the readSerialData() ... (pseudo code)
          @
          void QTGUI_MainWindow::readSerialData()
          {
          while((iBytesAvailable = serial->bytesAvailable()))
          {
          QByteArray RawPortData = serial->read(iBytesAvailable);
          ...

          @

          1 Reply Last reply
          0
          • S Offline
            S Offline
            shirisha
            wrote on last edited by
            #26

            int main(int argc, char *argv[])
            {

            QCoreApplication a(argc, argv);
            fd = open(MODEMDEVICE,O_RDWR|O_NOCTTY);

            While(true)

            {
            Buffer.clear();
            nreturn = read(fd,&chBuf,1);
            if(nreturn > 0)
            {
            for(i=0;i<nreturn;i++)
            {
            Buffer.append(chBuf[i]);

            if(chBuf[0] == 0xc9) nReadIndex = 0;

            pData[nReadIndex++] = chBuf[i];

            qDebug() << "data" << Buffer.toHex();
            }
            if(chBuf[0] == 0xcf)
            {

            if(nReadIndex >= 10)

            //Display of Gui opreration //

            nReadIndex = 0;

            }

            For this how can i use timers instead of while loop, where should i start timer , i tried but am geting segmentation problem.Please help me

            1 Reply Last reply
            0
            • McLionM Offline
              McLionM Offline
              McLion
              wrote on last edited by
              #27

              Your issue seems not to be about the serial port. Please open a new thread for a new topic.

              btw: You seem to be very reluctant in using QSerialPort.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                shirisha
                wrote on last edited by
                #28

                k .

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  shirisha
                  wrote on last edited by
                  #29

                  Hi sir,

                  How to flush the data in serial port without using qextserialport

                  Please help me sir...

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    shirisha
                    wrote on last edited by
                    #30

                    hi sir...,
                    When i use Baud rate B115200...am getting segmentation fault ..in qt...How would i solve the problem..Please help me...

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      shirisha
                      wrote on last edited by
                      #31

                      hi sir...,
                      When i use Baud rate B115200...am getting segmentation fault ..in qt...How would i solve the problem..Please help me...

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #32

                        Without any proper code, I can't.

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #33

                          Without any proper code, I can't.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            shirisha
                            wrote on last edited by
                            #34

                            #define BAUDRATE B9600

                            1 Reply Last reply
                            0
                            • S Offline
                              S Offline
                              shirisha
                              wrote on last edited by
                              #35

                              #define BAUDRATE B9600

                              1 Reply Last reply
                              0
                              • SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on last edited by
                                #36

                                That won't really help debugging but from the looks of it, you are using the linux platform API, so please ask this on a linux dedicated forum.

                                There's also this "how to":http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/x115.html that should give you some hints and this "stack overflow post":http://stackoverflow.com/questions/6947413/how-to-open-read-and-write-from-serial-port-in-c

                                Interested in AI ? www.idiap.ch
                                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                1 Reply Last reply
                                0
                                • SGaistS Offline
                                  SGaistS Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #37

                                  That won't really help debugging but from the looks of it, you are using the linux platform API, so please ask this on a linux dedicated forum.

                                  There's also this "how to":http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/x115.html that should give you some hints and this "stack overflow post":http://stackoverflow.com/questions/6947413/how-to-open-read-and-write-from-serial-port-in-c

                                  Interested in AI ? www.idiap.ch
                                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  1 Reply Last reply
                                  0

                                  • Login

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • Users
                                  • Groups
                                  • Search
                                  • Get Qt Extensions
                                  • Unsolved