Hi everybody,
I have a digit programmable multimeter HM8012 (Hameg Instruments) that has a RS232 serial communication.
I want to plug it in the TX1 RX1 (pins 18/19) of my Arduino Mega2560 and then read the multimeter from my computer (which is plug to Arduino through usb).
I've read the manual so i know the commands, like the one to get the current value of the multimeter (S? = carriage return).
I wrote something in arduino but that doesn't work at all, i'm receiving random values.
The manual indicates the settings (4800 baud, 8N1) : "Each control must have two ascii code characters followed by a character 13 (). On reception of terminator the equipment sends the character 19 () to indicate that the dialogue is suspended. As soon as it is possible to resume the dialogue, the instruments sends 17 ()".
I tried to wrote a little something to test it but it doesn't work
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 the code wrong (i know it's not perfect but just to test something it should be enough right?)
Or is it a physical issue? I've read somewhere that the RS232 serial comm needed 12V, and the arduino provides only 5.
Any thoughts?
Thanks for reading this