Exactly how you do this will depend on what tools you have available, and what programming language you are familiar with.
Basically, a 9-pin D type is a serial communications port - it receives data which gets transferred to the system in bytes, which may be binary numbers or characters.
If you are using a .NET language then look at using the SerialPort class - it includes a DataReceived event
] which tells you when a byte has arrived at the port. The link includes a simple example.