Go Down

Topic: Renaming Serial, Serial1, Serial2, Serial3 in Mega (Read 185 times) previous topic - next topic

roboticist

Hi Techies,
This post is about renaming Serial,Serial1 to my custom name for easy & understandable program.
I am using all the 4 Serial in Mega which is connected to 4 different peripheral. I wanna debug my code. Virtronics arduino Simulator is what i am using for debug. The below codes are working well with Arduino IDE but throws error with that software.

Code: [Select]

#define rfid Serial  // Method 1
#define dbg Serial
or
HardwareSerial &rfid = Serial;  // Method 2
HardwareSerial &dbg = Serial;

void setup()
{
  dbg.begin(9600);
  rfid.begin(9600);   
}



Both of the above methods are working with Arduino IDE. But when i am testing my code with virtronics arduino simulator this shows up some error. But arduino library codes(SoftSerial Programs) are working fine with that softwares. So i want to change the "Serial" to "dbg" as it is done in softserial library. How can i change? I dont know anything about libraries? please help.

So my point is simple "dbg", "rfid" should directly come from library. The colour of function changes when we call the library functions in arduino ide right, I expect something like this! How can i do that? Please help. I dont know C++ much... This is my first post ever. Hope someone will helps me...


roboticist


pert

I don't know enough to comment on method 2 but I don't see any reason why method 1 should cause an error. The preprocessor will just replace every instance of dbg or rfid with Serial. Please post the full content of the errors you got from virtronics arduino simulator from each method. Please use code tags for the error output.

pert

As was mentioned on Stack Exchange, don't get hung up on the coloration thing. Every library has a file named keywords.txt with a list of keywords. The Arduino IDE just reads all the keywords.txt files for all the libraries and colors those keywords. There's no intelligent behavior behind it, the IDE doesn't say "hey look, roboticist defined dbg as Serial so now I need to color dbg". If you really wanted rfid and dbg to be colored you could put them in a keywords.txt file but this is purely an aesthetic change, there will be no functional difference.

roboticist

Thanks for the reply. I have attached the error message i have got.

One more clarification is that Softserial program is running well without any error. Is there any way similar to how softserial is accessing the Serial library, so that we can try here.

pert

Please post text as text. You're much less likely to get help if people have to download and open an image just to see a 10 word error message. If you do post an image please attach and embed it following these instructions:
http://forum.arduino.cc/index.php?topic=364156.0
that will make it easy for people to view the image and thus you will have a greater chance of getting a solution for your problem.

That error is regarding the code:
Code: [Select]
HardwareSerial gsm = Serial;
that's different from either method you listed above. That sort of behavior is not conducive to us helping you. If you want to ask about that method then you should test it to be sure it actually works and explain that is another method you want to know about. If you want us to help you with method 1 and 2 in your question you need to post the virtronics arduino simulator error output for method 1 and for method 2.

roboticist

Thanks for your help for suggesting a better idea for me to post image. I will do so from next time.

Now coming to my question. The error which came there was for the method 2. Error responded by that software was so poor. I am sorry about that. The error came for the below quoted text.

Quote
HardwareSerial &gsm = Serial;  // Method 2
HardwareSerial &dbg = Serial1;
A Simple question again. Can i rename Serial, Serial1, Serial2, Serial3 in arduino hardware serial libraries to my custom words. Is there anything to be noted to make it work, because i did once by changing the word "Serial1" to "dbg" which didnt allow my program to get compile. Then i had to replace with old wordings again. So where am i wrong? What should be done to replace with custom words?

Serial,Serial1,Serial2,Serial3 are confusing a bit while i program. I see them wrong and makes tough to debug.

pert

I wouldn't recommend messing with the library source code for this purpose. I think method 1 will work fine. Someone else will have to comment on method 2. Generally you should avoid using #define unless absolutely necessary. What virtronics arduino simulator error message do you get from method 1?

roboticist

1. Method 1 also get the same reply as we get for method2. only if i put
Quote
Serial.begin, Serial.available
its working. Others are getting error. There is a option to skip error. but even if i skip errors and run the simulation the
Quote
virtual serial monitor is not opening
and i am unable to give serial inputs to simulator. Thats the problem. So i think the only way is to change in library. Any suggestions?

2. Are there any better simulator for arduino? i tried Visual Micro. but there is no option of line tracing like virtronics. And i know about VSM Arduino from proteus but its too much costly to buy. Any sugesstions?

pert

1. Method 1 also get the same reply as we get for method2.
Are you trying to tell me that if you run this code in the simulator:
Code: [Select]

#define rfid Serial  // Method 1
#define dbg Serial

void setup()
{
  dbg.begin(9600);
  rfid.begin(9600);   
}


You get this exact error message:
Code: [Select]
Sketch error - Unknown declaration HardwareSerial gsm = Serial;
 Line 6:0006 HardwareSerial gsm = Serial;

I have trouble believing that because it makes absolutely no sense.

Go Up