Results 1 to 8 of 8

Thread: Moving stage using udp command in qt gui

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Moving stage using udp command in qt gui

    Quote Originally Posted by ankit.1g@gmail.com View Post
    the command is as:
    Header = 07 (two bytes)
    FL1000
    <cr> (ASCII carriage return) = 13.
    This is different to your first post. Fewer zeroes.
    They only have C# example in the manual which forms the send bytes as:
    Qt Code:
    1. sendBytes[0] = 0;
    2. sendBytes[1] = 7;
    3. Byte[] SCLstring = Encoding.ASCII.GetBytes(“RV”); // for sendin RV command///
    4. // copy string to the byte array
    5. System.Array.Copy(SCLstring, 0, sendBytes, 2, SCLstring.Length);
    6. // insert terminator
    7. sendBytes[sendBytes.Length - 1] = 13; // CR
    8. // send it to the drive
    9. udpClient.Send(sendBytes, sendBytes.Length);
    To copy to clipboard, switch view to plain text mode 
    I am no C# guru, but this looks like it overwrites the 'V' with the <CR> Unless the array is a fixed length prefilled with spaces or GetBytes() returns a trailing terminator byte and that is counted in the length. Have you tried mimicking this command?
    should i create array of specific length then?
    No, you should create a QByteArray of the correct length for a correct command. We have no way to know whether what you are sending is correct. That will be somewhere in the documentation for the device. I have given you a list of generic ways it may be wrong.
    How can I do that...? creating in main window? can you please give me an example.
    thank you
    You create a QUdpSocket member variable in the main window class, exactly as d_stranz wrote. Then you use that member variable instead of creating a new local object everytime you need one. No magic involved, just C++ 101.
    Qt Code:
    1. class MainWindow: public QMainWindow
    2. {
    3. Q_OBJECT
    4. public:
    5. MainWindow(QWidget *p = 0);
    6. private:
    7. QUdpSocket *m_socket;
    8. }
    9.  
    10.  
    11.  
    12. MainWindow::MainWindow(QWidget *p = 0):
    13. {
    14. ...
    15. m_socket = new QUdpSocket(this);
    16. }
    17.  
    18. // elsewhere
    19. m_socket->writeDatagram(datagram, ...);
    To copy to clipboard, switch view to plain text mode 

  2. The following user says thank you to ChrisW67 for this useful post:

    ankit.1g@gmail.com (1st February 2016)

Similar Threads

  1. Replies: 3
    Last Post: 2nd December 2012, 15:10
  2. Stage active event from QML file
    By AbinaThomas in forum Qt Programming
    Replies: 1
    Last Post: 8th September 2012, 06:05
  3. How to make fewer errors at the stage of code writing. Part N3. QT.
    By Andrey_Karpov in forum General Discussion
    Replies: 0
    Last Post: 13th July 2011, 08:39
  4. Replies: 1
    Last Post: 12th April 2010, 13:00

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.