Output data to comms port

I wonder if it is easy without too much messing around to output data to a serial interface if one exists or via a usb port to a usb-serial adapter.

my idea would be to add a line in the dial plan at the relevant place that caused a small amount of data to be sent. this could then be printed or used to connect to a PLC to control anything you like.

this would have all kinds of uses from call logging to possibly controlling hardware from your phones.

someone must have done it, but is the functionality readily available and documented?

Dave