What do you mean by regular usb. I have read data transmitted by Arduino in scada software.
In scada i have written vbscript to read usb port.
I am able to see data transmitted by arduino on serial monitor but somehow it is not coming on usb port continuously means it works for few time then it stops.
The one that you use to upload sketches to the Arduino.
I am able to see data transmitted by arduino on serial monitor but somehow it is not coming on usb port continuously means it works for few time then it stops.
I still suspect that there is something wrong with your code.
I am able to send data from arduino via serial to USB converter to scada and receive back feedback also but problem is it is not working continuously .
I am able to send data and receive feedback some 50-100 time and then it stop and after that i have to reset the system or power off and it will work again for 50-100 time but i want it to work continuously 24x7.
One more point when i am not receiving data at output of converter at that time also i am able to see arduino transmitted data (checked on serial monitor)
Krunalsidd:
I am able to send data only around 100 times then i have to reset arduino to start resending data.
Now that I can see your program my first suspect is your 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. This can happen after the program has been running perfectly for some time. Just use cstrings - char arrays terminated with '\0' (NULL).
Separately, it looks like your code for receiving data is similar to the code in Serial Input Basics. If that is where it came from it would have made your program much easier to figure out if you had left the code for reading data in functions rather than copying it into loop() where it just gets in the way of seeing what you are trying to do.
My understanding is correct that if my Serial.print's output is visible on serial monitor that means arduino has transmitted data.
If above my understanding is correct then there is some issue in converter because after sometime when communication stops still at that time i am able to see data on serial monitor but scada is not receiving it.
Krunalsidd:
My understanding is correct that if my Serial.print's output is visible on serial monitor that means arduino has transmitted data.
Yes, if it is continuing to output the correct data. But it is still not wise to use the String class
If above my understanding is correct then there is some issue in converter because after sometime when communication stops still at that time i am able to see data on serial monitor but scada is not receiving it.
I don't have your converter and I don't think you have posted a link to its datasheet or a diagram showing how everything is connected.
It could also be a problem in the software that is receiving the data from the converter - in fact that seems more likely.
Krunalsidd:
With above converter i am getting less then 10 output
There is something very strange going on.
I regularly use a USB-TTL converter (not the exact same one as your link) and have NEVER had a problem with it ceasing to function after X iterations.
You need to write a pair of short test programs - one for the PC and one for the Arduino - as an aid to figuring this out. This Python - Arduino demo may help get you started.
This line is diasbled; but it contains a bug if enabled
//sprintf(char1,"%02X",msg[index]);
char1 is only two bytes in size so there is no space for a terminating nul character.
Below has a similar problem
if (index < 16) // Make sure there is room
{
msg[index] = incomingByte; // Add char to array
//sprintf(char1,"%02X",msg[index]);
strmsg += msg[index] ;
index++;
msg[index] = '\0'; // Add NULL to end
}
msg is only 4 bytes in size; you however happily allow to store 16 bytes in there.
So you have a good chance of writing outside the boundaries of your arrays and when hat happens your code usually crashes.
But I can able to see arduino is transmitting data . I am able to see serial.pint output on serial monitor only somehow that ttl output is not getting converted in usb after few iterations.
If i reset my arduino then again it is working for few iterations.
My received data is of fix size and with modbus it is working fine
Fix the bugs that I pointed out. The behaviour that you observe is typical for memory issues; the bugs that I pointed out result in memory issues.
Not behind my computer at the moment but from memory those bugs are on the receiving code, so yes, if your scada does not send data, you will not have the problem.