Sending command to rs232 device

Hello ,
I have a problem with sending command to my device.
But I can smoothly receive the data analyzed by the device,
So I think my rs232 connection should be fine,
In addition, my rs232 uses MAX3232 module to connect.
The following attachment is the manual of my device (there are instructions for operation)
can anyone help me please,thanks
59-00075-01_RA-620_600_RS-232C_Operation_manual_Ver03.pdf (524.8 KB)
RS-232.ino (1.2 KB)

@kemjasonwang you posted this in installation and troubleshooting section. This is for getting the system up and running not for problems with your project, so I have moved it here.

Please read the getting the best out of this forum sticky post at the start of each forum section.

Well why should half a circuit be fine if only the other half is working?
Never been on a zoom call when the audio only works one way?

Please post your code so we can see what and how you are trying to send stuff. What Arduino are you using?

@kemjasonwang, your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advise on) your project :wink: See About the Installation & Troubleshooting category.

Please post your sketch in a post, not as an attachment; please properly ident it in the IDE. Done it this time for you.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(6, 7);  // RX, TX
byte STX = 0x02;                //STX=02h
byte ETX = 0x03;                //ETX=03h
byte CR = 0x0D;                 //CR=0Dh
byte LF = 0x0A;                 //LF=0A
byte EOT = 0x04;

byte NUL = 0x0;
byte SOH = 0x1;
byte ENQ = 0x5;
byte ACK = 0x6;
byte BEL = 0x7;
byte BS = 0x8;
byte HT = 0x9;
byte VT = 0xB;
byte FF = 0xC;
byte SO = 0xE;
byte SI = 0xF;

byte DLE = 0x10;
byte DC1 = 0x11;
byte DC2 = 0x12;
byte DC3 = 0x13;
byte DC4 = 0x14;

byte NAK = 0x15;
byte SYN = 0x16;
byte ETB = 0x17;
byte CAN = 0x18;
byte EM = 0x19;

byte SUB = 0x1A;
byte ESC = 0x1B;
byte FS = 0x1C;
byte GS = 0x1D;
byte RS = 0x1E;
byte US = 0x1F;
byte y = 0x30;

byte A = 0x41;
byte R = 0x52;
byte H = 0x48;
byte U = 0x55;
byte start = 0;



void setup() {

  Serial.begin(9600);
  Serial.println("USB Serial is up and running");
  mySerial.begin(4800);
  mySerial.write(0x30);
  mySerial.write(0x02);
  mySerial.write(0x55);
  mySerial.write(0x32);
  mySerial.write(0x0D);
  mySerial.write(0x0A);
  mySerial.write(0x0D);
  mySerial.write(0x0A);
  mySerial.write(0x04);
}
void loop() {
  mySerial.println("STX");
  mySerial.println("A");
  mySerial.println("ETX");
  if (mySerial.available()) {
    Serial.println(mySerial.read());
  }
}

mySerial.println("STX") will send the word STX (so 3 characters), not the character STX (hex 0x02) that's at the beginning of your code. It also sends a <CR><LF>.

Use mySerial.write(STX); and so on for a start (like you did in setup()).

What happens with this code?

#include <SoftwareSerial.h>

void setup()
{
  Serial.begin(9600);
  Serial.println("USB Serial is up and running");
  mySerial.begin(4800);
  mySerial.write(0x30);
  mySerial.write(0x02);
  mySerial.write(0x55);
  mySerial.write(0x32);
  mySerial.write(0x0D);
  mySerial.write(0x0A);
  mySerial.write(0x0D);
  mySerial.write(0x0A);
  mySerial.write(0x04);
}
void loop()
{

  if (mySerial.available()) {
    Serial.write(mySerial.read());
  }
}

Do you get a reply from the device?

Note:
I did not dig too deep into the manual.

Thanks, next time i will pay attention

the code is Not working

@ sterretje
When I press Analyze on the instrument, the data will be sent back after completion.
But I want to send a command to the instrument to make it analyze automatically, but it can't. I don't know if my command format is wrong?

This is what I would try for the U command that you use in setup().

#include <SoftwareSerial.h>

void setup()
{
  Serial.begin(9600);
  Serial.println("USB Serial is up and running");
  mySerial.begin(4800);
  mySerial.write(0x02);
  mySerial.write(0x24);
  mySerial.write(0x55);
  mySerial.write(0x04);
}
void loop()
{
  if (mySerial.available()) {
    Serial.write(mySerial.read());
  }
}

Or more readable

#include <SoftwareSerial.h>

SoftwareSerial mySerial(6, 7);  // RX, TX
const byte STX = 0x02;                //STX=02h
const byte EOT = 0x04;

void setup()
{
  Serial.begin(9600);
  Serial.println("USB Serial is up and running");
  mySerial.begin(4800);
  mySerial.write(STX);
  mySerial.write('$');
  mySerial.write('U');
  mySerial.write(EOT);
}

void loop()
{

  if (mySerial.available())
  {
    Serial.write(mySerial.read());
  }
}

@ sterretje

The command is still not sent

@sterretje
There is another problem. If the ASC code is not declared above, the data returned will be garbled

@sterretje uses EOT to terminate the command transmission but the datasheet indicates ETX is to be used. Can you try this slightly modified version:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(6, 7);  // RX, TX
const byte STX = 0x02;                //STX=02h
const byte ETX = 0x03;

void setup()
{
  Serial.begin(9600);
  Serial.println("USB Serial is up and running");
  mySerial.begin(4800);
  mySerial.write(STX);
  mySerial.write('$');
  mySerial.write('U');
  mySerial.write(ETX);
}

void loop()
{

  if (mySerial.available())
  {
    Serial.write(mySerial.read());
  }
}

@Blackfin
same,the command did not work.
The command I hope to send is the following
擷取
The code I entered is :

mySerial.write(0x02);
mySerial.write(0x41);
mySerial.write(0x03);

But it seems unsuccessful.
The other thing I have questions is
When I receive the data after the device analysis is completed, the tx light on the uno will flash.
But why flash tx instead of rx in the latter pattern of the command I sent?

TBH, it sounds like you're not physically transmitting to the refractometer.

@Grumpy_Mike alluded to this earlier when he said:

Well why should half a circuit be fine if only the other half is working?
Never been on a zoom call when the audio only works one way?

Which MAX3232 "module" are you using? Do you have a DVM available? If so, can you run the following and use the voltmeter to check the transmitter output to the refractometer:

const uint8_t pinTX = 7;

void setup( void )
{
    pinMode( pinTX, OUTPUT );
    
}//setup

void loop( void )
{
    digitalWrite( pinTX, LOW );
    delay( 1000 );
    digitalWrite( pinTX, HIGH );
    delay( 1000 );
        
}//loop

Also, the MAX3232 has two full-duplex channels (so two RS232 transmitters and two receivers); are you certain you have the TX from the Arduino to the refractometer on the correct transmitter? That is, check to see you don't have the Arduino connected to DIN1 and the DOUT2 then connected to the refractometer.

@ Blackfin
thank u~
I do not understand what is "DVM"
and I have try the code you gave me, the tx pin voltage will go back and forth from -8.5 to 8v.

This is the max3232 module I use

I do not understand what is DIN1 and DOUT2 ?
Also my device is 8pin RS232
Is my connection wrong?

Can you swap the connections at pin 4 and pin 6 at one end?

Everything looks good except these two: DTR is currently connected to DTR and DSR to DSR; these signals should cross like RTS and CTS.

@ Blackfin
It still not working