Serial command ask/answer

Hey
I'm trying to get data from some device's. (tension drive's) the supplier has made an program with what we can read the value's, but i want to make it automated.

since the supplier wont give me any feedback, i need some help. i think i've got pritty far but just the last steps are missing i think…

i've used snipper to see what data my computer sends and recives from is com port to recieve data. that worked pritty well.

now the problem. i'm using this code for test. at my mega 2560
having the RX1 and TX1 to the serial port of the tension controller.

void setup() {
  // initialize both serial ports:
  Serial.begin(9600);
  Serial1.begin(9600);
}

void loop() {
  if (Serial1.available()) {
    int inByte = Serial1.read();
    Serial.write(inByte);
  }

  if (Serial.available()) {
    int inByte = Serial.read();
    Serial1.write(inByte);
  }
}

now when i send the question, (AA 01 55 3B 55 3C 55 00)
i should recieve 34 bytes back, (thats what snipper shows me) but i dont get anything...
i've been trying for days now and i'm done. anyone has an idea?

Best regards, Nick

Serial.write will cause the ASCII representation of the bytes received to be printed to the Serial Monitor. Depending on what the response is from the tension controller, that might be non-printing characters. You might try changing that to Serial.print(inByte) instead, which will print the numerical representation of the data to the Serial monitor. You could also cause it to be formatted as hexadecimal using Serial.print(inByte, HEX).

It might also be helpful if you provide more information about the tension controller and how you have it wired to the Arduino. Often, devices will use RS-232 serial communication. RS-232 uses voltage levels that are not safe to connect directly to your Arduino board. You need to make sure to provide TTL logic levels to the Arduino board. Another thing that people often get wrong with serial communication is that the connections between devices need to be made RX-TX, TX-RX, not RX-RX, TX-TX. The reason for this is that RX stands for "receive" and TX stands for "transmit".

Try writing your Arduino program so that it sends the data so that there is no "human" delay between bytes.

Do you know if the AA and 00 bytes are start-and end-markers?

...R
Serial Input Basics - simple reliable ways to receive data.

thanks for the reply's this evening i will try again.

pert:
Serial.write will cause the ASCII representation of the bytes received to be printed to the Serial Monitor. Depending on what the response is from the tension controller, that might be non-printing characters. You might try changing that to Serial.print(inByte) instead, which will print the numerical representation of the data to the Serial monitor. You could also cause it to be formatted as hexadecimal using Serial.print(inByte, HEX).

It might also be helpful if you provide more information about the tension controller and how you have it wired to the Arduino. Often, devices will use RS-232 serial communication. RS-232 uses voltage levels that are not safe to connect directly to your Arduino board. You need to make sure to provide TTL logic levels to the Arduino board. Another thing that people often get wrong with serial communication is that the connections between devices need to be made RX-TX, TX-RX, not RX-RX, TX-TX. The reason for this is that RX stands for "receive" and TX stands for "transmit".

RX-TX i've noticed. tried to switch them, i dont think the supplier like's what i'm doing. that's why i dont gave a name of the controller. i'm a PLC programmer, and don't have much experience with arduino but at the PLC i could get data als over a serial port, so i think the Voltage should be fine.
i think the Serial.print(inByte, HEX) would be a good shot.

Robin2:
Try writing your Arduino program so that it sends the data so that there is no "human" delay between bytes.

Do you know if the AA and 00 bytes are start-and end-markers?

...R
Serial Input Basics - simple reliable ways to receive data.

i dont know for sure, but i think those are the start and end markers.
and i was using this way for testing, tought that it shoelt not be such a problem?

Best Regards Nick.

If your PC can talk to the tension controller over serial, it's almost certainly RS232 which means that the voltage is entirely unsuited to being read directly by an Arduino. Your PLC may well be able to deal with it, but that doesn't mean that the Mega can.

If your device uses RS232 voltage levels you need to convert them to the Arduino's TTL voltage levels. The MAX232 is commonly used for this.

RS232 voltage levels might damage an Arduinp.

...R

Robin2:
If your device uses RS232 voltage levels you need to convert them to the Arduino's TTL voltage levels. The MAX232 is commonly used for this.

RS232 voltage levels might damage an Arduinp.

...R

nice to know,

ordered one

Best Regards, Nick Bakker