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. UDP between Simulink and Qt
Forum Updated to NodeBB v4.3 + New Features

UDP between Simulink and Qt

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 4 Posters 3.3k Views 3 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.
  • S Offline
    S Offline
    Surizer
    wrote on 19 May 2016, 11:52 last edited by A Former User
    #1

    Hey guys!! I am trying to send or/ stream variables from simulink to Qt . I tried setting up and UDP connection between simulink and Qt following few forums but nothing worked. Could anyone help to set up an UDP conncection between Simulink and Qt or if there is anyother way to stream the varaibles please enlighten me.

    Thank you

    ? 1 Reply Last reply 19 May 2016, 16:33
    0
    • S Surizer
      19 May 2016, 11:52

      Hey guys!! I am trying to send or/ stream variables from simulink to Qt . I tried setting up and UDP connection between simulink and Qt following few forums but nothing worked. Could anyone help to set up an UDP conncection between Simulink and Qt or if there is anyother way to stream the varaibles please enlighten me.

      Thank you

      ? Offline
      ? Offline
      A Former User
      wrote on 19 May 2016, 16:33 last edited by
      #2

      @Surizer Hi! There is nothing such as a "UDP connection". What did you try so far (please show us some code)?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Surizer
        wrote on 20 May 2016, 09:59 last edited by
        #3

        I tried the following in QT and used "UDP SEND" block in simulink .I dono if i edited this code in QT in the best way .

        Source: http://www.bogotobogo.com/Qt/Qt5_QUdpSocket.php .

        I want to modify this is code in such a way it has to receive data from simulink.

        Modified Code:

        • #include "myudp.h"
          MyUDP::MyUDP(QObject *parent) :
          QObject(parent)
          {
          // create a QUDP socket
          socket = new QUdpSocket(this);
          // The most common way to use QUdpSocket class is
          // to bind to an address and port using bind()
          // bool QAbstractSocket::bind(const QHostAddress & address,
          // quint16 port = 0, BindMode mode = DefaultForPlatform)
          socket->bind(QHostAddress::LocalHost, 1234);
          connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead()));
          }
          /*void MyUDP::HelloUDP()
          {
          QByteArray Data;
          Data.append("Hello from UDP");
          // Sends the datagram datagram
          // to the host address and at port.
          // qint64 QUdpSocket::writeDatagram(const QByteArray & datagram,
          // const QHostAddress & host, quint16 port)
          socket->writeDatagram(Data, QHostAddress::LocalHost, 1234);
          }
          */
          void MyUDP::readyRead()
          {
          // when data comes in
          QByteArray buffer;
          buffer.resize(socket->pendingDatagramSize());
          QHostAddress sender;
          quint16 senderPort;
          // qint64 QUdpSocket::readDatagram(char * data, qint64 maxSize,
          // QHostAddress * address = 0, quint16 * port = 0)
          // Receives a datagram no larger than maxSize bytes and stores it in data.
          // The sender's host address and port is stored in *address and *port
          // (unless the pointers are 0).
          socket->readDatagram(buffer.data(), buffer.size(),
          &sender, &senderPort);
          qDebug() << "Message from: " << sender.toString();
          qDebug() << "Message port: " << senderPort;
          qDebug() << "Message: " << buffer;
          }

        In the worst case if this code is of no use to send variables from simulink to QT for a real time application ,Could you let me know if there is anyother way?

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on 20 May 2016, 10:22 last edited by A Former User
          #4

          The code looks good to me. What exactly doesn't work? Does bind() work? Maybe the bind() is blocked by your OS's mandatory access control system (SELinux, AppArmor, Tomoyo, ...) Did you turn off your firewall?

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Surizer
            wrote on 20 May 2016, 10:56 last edited by
            #5

            I have shared a screenshot . The problem is i dono if i set up the configurations properly to receive the data from the simulink.
            Simulink,QT,serial monitor

            ? 1 Reply Last reply 20 May 2016, 11:05
            0
            • S Surizer
              20 May 2016, 10:56

              I have shared a screenshot . The problem is i dono if i set up the configurations properly to receive the data from the simulink.
              Simulink,QT,serial monitor

              ? Offline
              ? Offline
              A Former User
              wrote on 20 May 2016, 11:05 last edited by
              #6

              @Surizer That looks ok. There are always two ports: In your own application you set the receiving port (25000). The sender (Simulink) uses a different port number for sending. The number of the receiving port is fixed because the sender must know where to send the packets to. But the sending port number doesn't matter to the receiver, so it's usually selected by random according to which port is currently unused on the system.

              1 Reply Last reply
              0
              • Q Offline
                Q Offline
                Q139
                wrote on 20 May 2016, 12:25 last edited by
                #7

                Is simulink outside connection , maybe you have router port blocked

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  Surizer
                  wrote on 20 May 2016, 13:02 last edited by
                  #8

                  What you said was right and then the problem was in sending the proper type of the variables. We sent uint8 70in simulink and received "F" in our application.

                  T 1 Reply Last reply 20 May 2016, 13:33
                  0
                  • S Surizer
                    20 May 2016, 13:02

                    What you said was right and then the problem was in sending the proper type of the variables. We sent uint8 70in simulink and received "F" in our application.

                    T Offline
                    T Offline
                    the_
                    wrote on 20 May 2016, 13:33 last edited by
                    #9

                    @Surizer

                    We sent uint8 70in simulink and received "F" in our application.

                    Thats a correct value if you translate uint8 to char, as the character 'F' has a decimal value of 70 according to ASCII ;)

                    -- No support in PM --

                    1 Reply Last reply
                    1

                    3/9

                    20 May 2016, 09:59

                    6 unread
                    • Login

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