RS232 Serial Communication with a digital multimeter


hi everybody,

i have digit programmable multimeter hm8012 (hameg instruments) has rs232 serial communication.
i want plug in tx1 rx1 (pins 18/19) of arduino mega2560 , read multimeter computer (which plug arduino through usb).

i've read manual know commands, 1 current value of multimeter (s?<cr>      <cr> = carriage return).
i wrote in arduino doesn't work @ all, i'm receiving random values.

the manual indicates settings (4800 baud, 8n1) : "each control must have 2 ascii code characters followed character 13 (<cr>). on reception of terminator <cr> equipment sends character 19 (<dc3>) indicate dialogue suspended. possible resume dialogue, instruments sends 17 (<dc1>)".
i tried wrote little test doesn't work
code: [select]
int octet = 0;
char caractere = 0;
string chaine = "";
int octet1 = 0;
char caractere1 = 0;
string chaine1 = "";
boolean flag = false;
boolean flag1 = false;
boolean flag_dialog = true;


void setup()
{
  serial.begin(9600);
  serial1.begin(4800);
  serial.flush();
  serial1.flush();
}

void loop()
{
  if (flag && flag_dialog)
  {
    serial.println(chaine);
    int nb = 0;
    nb = serial1.print(chaine);
    serial.println(nb);
    flag = false;
    chaine = "";
  }
  if (flag1)
  {
    serial.println(chaine1);
    flag1 = false;
    chaine1 = "";
  }
   
}

void serialevent()
{
  while (serial.available()>0)
   {
      octet = serial.read();
      caractere = char(octet);
      chaine += caractere;
      if (octet == 13)
      {
        flag = true;
        break;
      }
   }
}

void serialevent1()
{
  while (serial1.available() > 0)
  {
    octet1 = serial1.read();
    if(octet1 == 19 && flag_dialog == true)
    {
      flag_dialog = false;
      serial.println("no dialog");
    }
    else if(octet1 == 17 && flag_dialog == false)
    {
      flag_dialog = true;
      flag1 = true;
      serial.print("dialog resumed");
      break;
    }
    else
    {
      caractere = char(octet);
      chaine += caractere;
    }
  }
}

is code wrong (i know it's not perfect test should enough right?)
or physical issue? i've read somewhere rs232 serial comm needed 12v, , arduino provides 5.

any thoughts?

thanks reading this

the serial ports on mega ttl level (0-5 volts) , standard rs232 connection pc can -12v +12v. serial uses lower voltages -5 +5 point damage mega feeding <0 or >5v pins. need rs232 ttl converter or bypass mega , plug pc.


Arduino Forum > Using Arduino > General Electronics > RS232 Serial Communication with a digital multimeter


arduino

Comments

Popular posts from this blog

Convierte tu Raspberry en un NAS. Firmware fvdw-sl 15.3 - Raspberry Pi Forums

Rasperry Wifi LAN Controller - Raspberry Pi Forums

Unlock car with bluetooth and car key