I want to connect 20 serial devices to the same Arduino Mega.How to do this?I know that multiplexing is the way but how to do that
You can use the SoftwareSerial library and declare instances to communicate with your serial devices. I am not sure if you can declare 20 such different instances but if at all you do, use the function: listen() to switch between those serial devices. This, probably, is as close as it gets to multiplexing as you mentioned.
I've tried with 2 such SoftwareSerial instances for communicating with GPS module and GSM module and the listen() function worked flawlessly.
You say that they are working on RS232 - which is an electrical standard. You may mean that they use standard UART style asynchronous serial communications - perhaps at 0 to 5V electrical levels.
It depends on how fast you need to communicate, and how continuously you need to communicate. If you can choose when to communicate with each device, you may be able to use Soft Serial with multiple pins. Be aware that it cannot both transmit and receive at the same time (one or the other), and it can only communicate with one port at a time. So it might work for you if you can communicate with one device for a while, then ignore it while you check with other devices, one at a time.
Otherwise maybe not. For example, if you need to receive from many devices at times of their choosing so you need an always-on hardware UART for each device. There are 4 hardware UARTs in the MEGA, so 4 would be your limit.
There are things like external UART peripherals, but managing that would likely be very hard for you.