I am using Arduino UNO and Relay Kit to operate electrical appliance from my computer. I am using visual basic 6 for serial communication.
Everything works fine for sometime (I mean for 10-15 communications) but after that Arduino doesn't respond and my visual basic application hangs until i re-plug the USB cable of Arduino.
Here is my Arduino Program...
int led = 13;
int led1 = 12;
String incoming;
void setup()
{
Serial.begin(9600);
pinMode(led, OUTPUT);
digitalWrite(led, HIGH);
pinMode(led1, OUTPUT);
digitalWrite(led1, HIGH);
}
void loop()
{
if (Serial.available() > 0)
{
incoming = Serial.readString();
if (incoming == "352")
{
Serial.print("Arduino");
}
else if (incoming == "Led ON 1")
{
digitalWrite(led, HIGH);
}
else if (incoming == "Led OFF 1")
{
digitalWrite(led, LOW);
}
else if (incoming == "Led ON 2")
{
digitalWrite(led1, HIGH);
}
else if (incoming == "Led OFF 2")
{
digitalWrite(led1, LOW);
}
}
}
Your symptom is a common feature of the use of the String class.
It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. Just use cstrings - char arrays terminated with 0.
And have a look at the examples in Serial Input Basics - simple reliable ways to receive data.
post your VB code? is it a console or a Windows Form project?
I assume you are using the SerialPort component - which method are you using to read the serial data?
Take care if you are using a Form with a SerialPort event handler such as
' character received from serial port
Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
TextBox1.AppendText(SerialPort1.ReadExisting())
End Sub
it is not thread safe in that the event handler is directly communicating with the TextBox GUI component
e.g. it crashes if you attempt to run with debug
I checked different combinations( I mean different Arduino boards and with different PC) and finally came to conclusion that everything is good from programming side.
I am close enough to solve this problem but just need your help…
I programmed everything in my laptop and when I check my arduino in my laptop, everything works good.
did you use Visual Studio to rebuild your VB code on each of the PCs to suit the 32 or 64 bit environment?
the 32 bit code should run on 64bit windows OK - I tend to build 32bit code when porting around different windows systems
I doubt if 64 bit code would run on 32bit windows at all (never tried it though!)
does a terminal emulator such as teraterm pro run of the two systems display the same problems as VB?
I had missed that you are using VB6 - I would expect it to have problems on modern operating systems
You could instal 64 bit windows on the desktop if you have a spare licence
can you port the VB to Visual Studio 2017?
e.g. download Visual Express and try it
try installing 64bit windows if you have a spare licence or an upgrade
I would still recommend upgrading to an upto date version of VB - how complex is the code?
if you do a web search for convert vb6 to visual studio 2017 you will get plenty of links