
Originally Posted by
ankit.1g@gmail.com
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:
sendBytes[0] = 0;
sendBytes[1] = 7;
Byte[] SCLstring = Encoding.ASCII.GetBytes(“RVâ€); // for sendin RV command///
// copy string to the byte array
System.Array.Copy(SCLstring, 0, sendBytes, 2, SCLstring.Length);
// insert terminator
sendBytes[sendBytes.Length - 1] = 13; // CR
// send it to the drive
udpClient.Send(sendBytes, sendBytes.Length);
sendBytes[0] = 0;
sendBytes[1] = 7;
Byte[] SCLstring = Encoding.ASCII.GetBytes(“RVâ€); // for sendin RV command///
// copy string to the byte array
System.Array.Copy(SCLstring, 0, sendBytes, 2, SCLstring.Length);
// insert terminator
sendBytes[sendBytes.Length - 1] = 13; // CR
// send it to the drive
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.
{
Q_OBJECT
public:
private:
}
MainWindow
::MainWindow(QWidget *p
= 0): {
...
}
// elsewhere
m_socket->writeDatagram(datagram, ...);
class MainWindow: public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *p = 0);
private:
QUdpSocket *m_socket;
}
MainWindow::MainWindow(QWidget *p = 0):
QMainWindow(p)
{
...
m_socket = new QUdpSocket(this);
}
// elsewhere
m_socket->writeDatagram(datagram, ...);
To copy to clipboard, switch view to plain text mode
Bookmarks