Talking Serial with a PSU

Hi there,

My apologies if this topic has already been covered. I have been looking through the forums for help, but as it happens, there is always a chance somebody else could have had this issue before me.

Here is my problem in simple terms:

I am trying to communicate with a Glassman PSU (High voltage, comms over serial) using serial protocol. It allows communication at 9600 Baud, and it allows you to send communication using the following format

Byte 1: SOH (CTRL A, Ascii 0x01)
Byte 2-(length-1): Command
Byte (Length): Carriage Return

Now I have connected it to my computer, and I can send the commands and read back responses properly. It works and works well.

I tried sending the same kind of commands using Arduino UNO to begin with, but realized that since the same serial port is being shared between computer and output, there could be issues.

So I moved onto the Mega, with its 4 available serial ports.

I left Serial 0 (or pins 0,1) for computer communication, and decided to use Serial1 (pins 18,19) for this communication.

Before I did that, I verified by sending and receiving commands between Serial1 and Serial 2(pins 16,17), and that communication happened successfully.

However, when I try and communicate with the PSU, I get nothing back, or sometimes, rarely, a CR back.

I am confused as to what I could be doing that is wrong. I have tried a few variations, I have tried adding delays, but it all seems to be unreliable.

For your perusal, here is the code:

  // Initialize Serial communication with the computer
  Serial.begin(9600); // For Serial monitor
  
  //Initialize Serial communication with the PSU
  
  Serial1.begin(9600);
  
  // Send in the following ASCII code in hex: 01, 56, 35, 36, 0D (SOH, V, 5, 6, CR);
  
  sendCommand = " V56 ";
  
  sendCommand.setCharAt(0, 0x01);
 // sendCommand.setCharAt(1, 0x56);
 // sendCommand.setCharAt(2, 0x35);
 //sendCommand.setCharAt(3, 0x36);
  sendCommand.setCharAt(4, 0x0D);


  Serial.println(sendCommand);
  //Serial.println(sendCommand.length());
  sendCommand.toCharArray(sendCMDArray,sendCommand.length());
  Serial1.write(sendCMDArray, sendCommand.length()); // Tried sending Serial1.print() or println() too

x = 0;
  response = "yo";
  while (Serial1.available() == 0 && x < 10) {
    Serial.println(" Waiting! ");
    delay(500);
    //Serial1.print(sendCommand);
    Serial1.print(0x01);
    Serial1.print("hello\n");
    Serial1.println();
    x++;
    if (x == 10) Serial.println ("Tried 10 times, failed!");
  }
  while (Serial1.available() > 0){
    Serial.println(Serial1.available());
    
    //Serial.print(Serial1.read());
    inByte = Serial1.read();
    //if (inByte == 'B') x = 12;
    response.concat(inByte);
    x++;
    //delay(33);
    //Serial.print(response);
    
  }

As can be seen, I have added delays, I am also trying to enter text before or after so I can get some values out, but nothing.

Any help will be appreciated.

I imagine I am doing something silly here, so not sure.

I do have a reasonable understanding of the String class on Arduino, and in fact on my blog one of the best hits I get are for the Arduino Serial help article I wrote (won't link, but you can look up "oxgadgets arduino serial" on Google if you have doubts about my understanding.)

Thank you very much

Just a further comment. I have tried to do the same with Processing, using the computer's Serial port, but it is acting the same.

However, it works if I use PUTTY.

Okay, further to my last test, I have been sending stuff to the Arduino board using PUTTY.

This is what I am reading

Send RCVD

a(0x61) > 4F
b > 27
c > 4E
d > 13
e > 4D
f > 26
g > 4C
h > 9

and so on...

I can't seem to find a pattern. These are not 1s compliments or 2s compliments...
sending abcd using Processing gives me the following numbers:
4F, A7, BA, 2 for abcd...
Sorry for modifying,