Digital weigher not responding

I am a novice at Serial communication and have a problem getting response from weigher ( Applied Weighing TASK 120) . I am asking it to send the weight displayed, which is COMMAND 2 in their manual below. My code must be wrong! I am pretty confused by all this MS bit and byte stuff. I would be very grateful if someone could post up some code that would enable COMMAND 2 and send back data. I guess this simple stuff, but I am not progressing at the moment!

Below is an extract from their manual.

General
Incoming data is continually monitored by the TASK 120 on its serial input line.
Each byte of data is formatted as an eight bit word without parity, preceded by one start bit
and followed by one stop bit.
Mantrabus - selected when CP is 128
To signify commencement of a new ‘block’ of data, the HEX number FFH is used as a ‘frame’
character, followed by the station number of the unit under interrogation.
The TASK 120 acts upon incoming data only if its own station number immediately follows the
FFH character.
New data must be received as a string of four nibbles (bits 7-4 set to zero) which are
assembled into two bytes and written into the variables store within the TASK 120. The most
significant nibble must be received first and the last nibble must have the most significant bit
(bit 7) set to indicate the end of data. This is followed by the checksum. The data transmitted
from the TASK 120 is always sent as complete bytes. The station number precedes the data
and the checksum follows the data. The data format used is signed 15 Bit. The most
significant Bit of the most significant Byte is set for negative numbers.

Updating
The required mode or variable to be updated is determined by the station number followed by
the command byte. An EXOR checksum consisting of the station number command byte and
any following data must be appended to the received data. It is most important that the byte
proceding the checksum must have its most significant bit set to signify the end of data.
The TASK 120 works out its own checksum and, if it disagrees with the received one, a not
acknowledge (NAK) message is returned
Communications Commands

COMMAND 2 REQUEST DISPLAY DATA
DATA transmitted to TASK 120 for Command 2.
0FFH, Station number, 082H, Chksum
Where Chksum = Station number EXOR with 082H
Example: To obtain the display reading of an TASK 120 whose station number is 47 send the
following Data:
0FFH, 02FH, 082H, 0ADH
|
Note MS Bit Set
RESPONSE TO COMMAND 2 from TASK 120
BYTE
1
2
3
4
Station No.
Display reading M.S. Byte.
Display reading L.S. Byte.
EXOR checksum of above data and Station No.
If, when using commands 1 or 2, an error is detected by the TASK 120 then the Not

Acknowledgement string is transmitted by the TASK 120.

My code must be wrong!

Your code to ask for data may be wrong, or your code to get and process the reply might be wrong. But, as you didn't post it, it's hard to help you.

What is your station number?

Do you know the baudrate of the serial port of the device? I don't see it in the "documentation". Do you have some code written? could you share it? Do you have an URL for the datasheet of the device?

If you are not familiar with serial ports please read Arduino Tutorial - Lesson 4 - Serial communication and playing with data

Thanks for for your speedy response!
This is the code I have tried (with various alternatives)
The STATION No is 01 rather than the 47 in the manual example.

byte incomingByte = 0; // for incoming serial data

[code]void setup(){
  Serial.begin(9600);
  Serial1.begin(9600);
  
}

void loop() {
  Serial1.print(0,HEX);
  Serial1.print(255,HEX);
  Serial1.print(0,HEX);
  Serial1.print(1,HEX);
  Serial1.print(130,HEX);
  Serial1.print(131,HEX);
  
  Serial.print(0,BIN);
  Serial.print(255,BIN);
  Serial.print(0,BIN);
  Serial.print(1,BIN);
  Serial.print(130,BIN);
  Serial.print(131,BIN);
  Serial.println();
  
  delay(500);
//if (Serial1.available() >0) {
  Serial.print("Reading: ");
  incomingByte = Serial1.read();
  Serial.println(incomingByte,BIN);
//}

delay(500);
}

[/code]

Think you sent too many bytes, try this and please let us know the result.

void loop()
{
  Serial1.print(0xFF);
  Serial1.print(0x01);
  Serial1.print(0x82);
  Serial1.print(0x83);

 delay(500);
 while (Serial1.available() >0)
 {
    incomingByte = Serial1.read();
    Serial.println(incomingByte,BIN);
  }
}

You should be sending 4 bytes, using write(). The bytes should be 0xFF, 0x01, 0x82, and 0x82^0x01.

byte staNum = 0x01;
Serial.write(0xFF);
Serial.write(staNum );
Serial.write(0x82);
Serial.write(0x82^staNum);

Then, you should be using a while loop to read the data.

while(Serial.available() > 0)
{
   byte val = Serial.read();
   Serial1.print("Byte: ");
   Serial1.println(val, DEC);
}

It appears that you should get 4 bytes back.

If I were you, add a pushbutton switch, debounced, and send the data to the scale every time the button was pushed. The rest of the time would be spent reading and printing serial data.

Once you get any response, we can help decipher it (maybe :)).

Thank you for your suggestions Gentlemen! I will give them a go and report back in the next day or two.

Good news, PaulS's code did the trick! Thanks robtillaart for your input, I have not got this code going yet - is this to do with using Serialprint() rather than write() ?
My problem was compounded by having Tx & Rx wires inverted before going into Max232.

Any cunning ways of extracting the 3rd byte out of the 4 bytes sent?

The project involves controlling a concrete batching system which I am trying to automate. The weight coming back from the weigher tells the cement auger relay when to stop and then ( I hope) will send data to printer to record how much cement went into mix. My next task is to communicate with printer ABLE SYSTEMS 892 - may be back for more help!

I am very grateful to you both for your help.

Any cunning ways of extracting the 3rd byte out of the 4 bytes sent?

Change this:

while(Serial.available() > 0)
{
   byte val = Serial.read();
   Serial1.print("Byte: ");
   Serial1.println(val, DEC);
}

to this:

byte scaleData[10]; // In case you get more than 4 bytes
byte scaleIndex = 0;

void loop()
{
   while(Serial.available() > 0)
   {
      byte val = Serial.read();
      if(scaleIndex < 10)
        scaleData[scaleIndex++] = val;
      Serial1.print("Byte: ");
      Serial1.println(val, DEC);
   }

   // Now, as long as scaleIndex > 2, you can access the 3rd byte as scaleData[2]
}

The difference between Serial.print() and Serial.write() is that Serial.print(), in the absence of contrary direction, converts the value to a string and sends the string to the serial port, while Serial.write() expects data in byte size chunks that it writes to the serial port directly.

Thanks PaulS , really useful.

Weigher now working fine. Got the Able printer going BUT cannot wake it up!
Need to send a String of 50 NUL characters - Not certain of code - any ideas?

any ideas?

byte wakeywakey = 0x00;
for(int i = 0; i <50; i++) Serial.write(wakeywakey);

Thread is continued in the software section here http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1291246988/0