What is the maximum length of serial cable I can use, to connection work properly? Is length of serial cable in connection with baud rate? I am using about 5 meter cable at speed 38400 bauds and RS232 communication, is it too long?
Capacitance in the cable begins to affect serial communications, typically many manufacturers/devices set a limit of approximatly 15m or 50ft on cable lengths for anything up to 9600 baud, and about 4m for 38.4k. That being said, with decent cable it is easily possible to go longer in tested or non-commercial use, but I would stick to the guidelines for a commercial product, if only to leave an out for support calls.
If you really need length, RS232 to RS422/485 converters are very inexpensive, and you can run the differential modes (422/485) over two wires for well over 100m.
In your case, 5m really shouldn't be a problem at 38.4, as long as your cable is of reasonably quality. Almost any shielded multi-conductor cable should work at that distance, and probably three times it.
When I was young I railed against non-spec RS-232 hardware, as it made it difficult to reach the maximum distances RS-232 could reach. After all if your driving voltage is 9 V instead of 12 V you lost about a third of your distance right there. I also griped about other perceived shortcomings in the protocol.
Then I read the spec.
RS-232 is an interface protocol. It is not designed for long lengths; it is designed to connect endpoints to more capable communications equipment. RS-232 allows you to connect to a modem that is not on your desk, but the one next to it, even if you have to run the cable high enough that people can walk under it. You can even cheat and build a passive modem to connect two computers on the same bench out of paperclips (use the plastic coated ones, they don't need bubble gum as insulation).
The rule of thumb is: if you have to measure the distance, don't use RS-232; use RS-422/485 or fiber optic instead. RS-232 is however still a good choice for connecting your endpoint to your RS-422/485 (or fiber optic) repeater.
Too long is defined by your acceptable error rate.
My experience is that the lower the baudrate, the longer distance it will work. The company I work for installs rs232 runs longer than 100 feet using cat5, then just adjusts the baud until it works properly, which could end as low as 9600.
To figure this out, you could put a loopback on the far end and use the legacy digi xctu tool, which has a range test tab that can do this sort of thing. However, this may not tell the whole story, as the far end device may have different receive characteristics.
I would like to point your attention not only on error rate or transition rate. In my practice, rs232 is limited by several meters by problems arising from (bad) grounding. Voltage between local device ground and rs232 cable GND may be up to dozen of Volts, which could lead to system malfunction. So, it is worth to consider using differential pair communications like rs485 or ethernet.
Four factors determine the length that can be used:
1) Quality and type of the cable, and the speed and protocol used, as described above. Good quality cable with a shield that's grounded behaves differently than using unshielded twisted pairs/UTP/Cat-something (cable covered under EIA/TIA TSB 56x)
2) The chipset used on the two devices connected, and whether they use pull-up resistors to increase their UART/USART (the serial chipset on each host) sensitivity (a design thing)
3) Crosstalk introduced by sharp bends or lack of shield grounding where needed (non-UTP cable)
4) Overall capacitance and time delay; do protocol signals fall out of synch with the control lines being set, or does induced capacitance cause intermodulation/crosstalk/inductive-reactance delays, etc.
This is for asynch cables, not synch or bi-synch cables. You probably have an asynch cable connection (meaning neither side sends a clock signal).
General guidelines says most cables will support 115k baud, using x-on/x-off protocol (stop start is data on tx/rx lines) are limited to 30M, or about 100' with shielded cable. UTP cables using this same protocol setup are limited to about half the speed, so maybe 56k.
You can make realllllly long serial cables-- if at slow speed and shielded. The speed of light gets in your way at some point.
In my experience well installed RS232 lines over decent telephone and Cat5e cable can go quite a considerable distance. We have a serial dot matrix printer hooked up to a PC that's nearly 600m away. Other places that have the same requirements have managed to get 1km. Of course the baud rate is critical, we run it at 2400 so no good for high volumes of data but for 20 lines of text on a receipt printer it works just fine, the only issue we have is a poor mains electrical supply to the printer.