This is not another site. Its only pdf document location.
Printable View
This is not another site. Its only pdf document location.
Sorry, I see .ru in the URL. That is another site.Quote:
not another site
Can you post here the parts of the doc that answers my questions?
Here is format,
Message Format
From the Host
STX
(02)
Length
(08H)
Msg type
and Ack#
Data
Byte 0
Data
Byte 1
Data
Byte 2
ETX
(03)
Check
Sum
From the
Format is changes thats why am asking you to check with url.
Is the PC considered the host?Quote:
From the Host
Does the contents of the list you posed consist of Strings?
Does a String have a terminating character like \n or \r?
Is there a response for each String the PC sends to the device?
For example, if the PC sends: "STX\n" is the device expected to send a response?
What would the response be?
What does (02) mean?
What is that the format of?Quote:
Here is format,
Thats why am posting the EBDS document. I dont have knowledge of this.
It should be discussed in the document.Quote:
I dont have knowledge of this.
Have you read the document and considered my questions?
If you have any specific questions about text in the document, post the text from the document with your questions.
My experience with devices (GPS receivers) connected to a PC via a serial connection used protocols where the PC sent a request to the device and the device sent a response. Is that the way the device you are working with is supposed to work?
The data sent/received is in the form of messages which have a defined format . There are 2 formats - from the PC (the host) to the device (the Acceptor) and one from the device to the PC.
From the PC each message is 8 bytes
1 byte STX (binary 2)
1 byte binary 8 (length)
1 byte message type
3 bytes of data
1 byte ETX (binary 3)
1 byte checksum - XOR of the 5 bytes between the ATX and the ETX bytes
From the device:
1 byte STX (binary 2)
1 byte binary for 11 (length)
1 byte message type
6 bytes of data
1 byte ETX (binary 3)
1 byte checksum - XOR of the 8 bytes between the ATX and the ETX bytes
Sorry, but I can't help you with Java as I only use c/c++. :eek:
The From the device message contents shows 10 bytes but the length is supposed to be 11?
Is ATX same as STX? Is there a byte missing?Quote:
8 bytes between the ATX and the ETX bytes
Hi 2Kaud,
Could you please send me the communication code in c/c++. so that i can translate into java or test the device.
Thanks for that.
From previous post, the java code for read was
I suggest in c++ something like this (NOT tried)Code:{
int len = 0;
while ( ( data = in.read()) > -1 )
{
if ( data == '\n' ) {
break;
}
buffer[len++] = (byte) data;
}
System.out.print(new String(buffer,0,len));
}
The code for sending would be something similar, but writing bytes rather than reading them.Code:if (in.read() != 2) // STX
cout << "No start STX\n";
else
if (in.read() != 8) // Length
cout << "Bad length\n";
else {
int check = 8; // Length
byte mess = in.read(); // Message code
check ^= mess;
for (int l = 0; l < 3; ++l) {
buffer[l] = in.read(); // Read the data bytes
check ^= buffer[l];// Computer check sum
}
if (in.read() != 3) // ETX
cout << "No end ETX\n";
else
if (in.read() != check) // Checksum
cout << "Invalid checksum\n";
else {
// Process mess/buffer as needed
}
}
Another approach rather than indicting an error if first byte is not STX, is to read the input until a STX byte is received.
Code:while (in.read() != 2); // Loop until STX received
I write the code to do aread as a method that reads the message and returns an instance of a class that contains the message type and the 3 bytes of data. It would throw an InvalidMessageException if any of the checks failed.
For the write there would be a method that would take the message type and the data to be written, build the message to send and write it.
Thanks 2krod
But here am not seen the message format to be write on port.
Output is somewhat easier. Consider (NOT tried)
This assumes that mess is the message and data1...data6 are the 6 data bytes.Code:byte arr[11] = {2, 11};
arr[2] = mess; // Set message byte
arr[3] = data1;
arr[4] = data2;
arr[5] = data3;
arr[6] = data4;
arr[7] = data5;
arr[8] = data6;
arr[9] = 3;
for (int i = 1; i < 9; ++i)
arr[10] ^= arr[i];
for (int i = 0; i < 11; ++i)
out.write(arr[i]);