Unlike with some other operating systems, in Windows, a script should refrain from directly reading and writing hardware ports on a sound/MIDI card. Whenever possible, a script should instead call functions in RxMidiIO such as MidiIoOutShort or MidiIoInput, which will do the actual hardware writing and reading for you (in conjunction with the sound card's Windows device driver. As long as a MIDI interface or sound card ships with a Windows driver, and virtually all do, then it will work with RxMidiIO. You don't even need to know the name of the driver, because you call it indirectly via functions in RxMidiIO).
Windows' lists of ports
In any computer, there can be more than one installed card capable of inputting or outputting MIDI data. Likewise, there can be more than one installed card capable of recording/playing digital audio data. (Needless to say, each card will have its own driver installed). For this reason, Windows maintains a list of all of the installed ports for MIDI and Digital Audio. The list of MIDI ports is a separate list from the list of Digital Audio ports. So, if one card happens to support both Digital Audio and MIDI, a name for it will appear in both lists. In fact, Windows differentiates between ports for MIDI input and ports for MIDI output, and maintains separate lists for each. So, if one card happens to support both MIDI input and output, a name for it will appear in both lists. Likewise, Windows maintains separate lists for ports that record Digital Audio as well as ports that play Digital Audio.
Therefore, Windows maintains 4 lists:
For a card that can input/output MIDI data, as well as record/play Digital Audio data, a name for it will appear in all 4 lists. From here on, a device is synonymous with a port, as far as your script is concerned.
What name for a port appears in each list? Well, that is entirely up to the card's device driver. It is the card's device driver that tells Windows into which lists Windows should place the card's name, and what name to use for each list. And in fact, if the card has several different components that can logically fit into one list, then the device driver may tell Windows to put several component names into that list.
Let's take an example for illustration: A Creative Labs' AWE32 sound card. This card has the following components:
Notice that the last 3 components can all fit into the list of ports for outputting or playing MIDI data. So, the AWE32 driver is going to tell Windows to put 3 names into that one list. For example, the driver may tell Windows to put the name "AWE32 MIDI Out" into the list. The driver may tell Windows to also put the name "AWE32 FM Synth" into that same list. Finally, the driver may tell Windows to also put the name "AWE32 Wavetable Synth" into that same list. Although these 3 components are all on the same card, to Windows, they represent 3 individual ports that are capable of outputting/playing MIDI data, and Windows treats them as if they really are 3 separate cards. (Incidentally, there is no particular rules about naming the components. I just arbitrarily picked the above 3 names, although they do make sense. A manufacturer can put any names he wants into his driver for inclusion into those Windows lists).
Of course, the AWE32 driver will also tell Windows to put the name "AWE32 Digital Audio In" into the list of ports for recording Digital Audio. The driver will also tell Windows to put the name "AWE32 Digital Audio Out" into the list of ports for playing Digital Audio. Finally, the driver will also tell Windows to put the name "AWE32 MIDI In" into the list of ports for recording or creating MIDI data.
RxMidiIO assigns a Port ID (ie, merely a numeric value) to each name in its lists. The first port in each list gets a value of 1, and the subsequent ports have increasing values for their IDs. (ie, The second port in a list has a Port ID of 2, the third port has an ID of 3, etc).
So in our above example, the 3 components that the AWE32 device driver told Windows to add to the list of ports for playing MIDI data ("AWE32 MIDI Out", "AWE32 FM Synth", and "AWE32 Wavetable Synth") will have Port IDs of 1, 2, and 3 respectively (assuming that they were added to the list in that order and are the first 3 names to be added to the list).
In fact, drivers for MIDI interfaces that have multiple MIDI Outputs typically add a separate name to the list for each MIDI Output, for example "MIDI Out #1 for Brand X card", "MIDI Out #2 for Brand X card", etc.
One special, MIDI output port is the "MIDI Mapper" which is part of Windows. This isn't tied to any specific MIDI device that plays/outputs MIDI data, although the MIDI Mapper is indeed a port to which your program can output MIDI data. Rather, the user can choose which of his available MIDI playback devices he wishes the MIDI Mapper to utilize. He can even choose several devices to be controlled by it simultaneously. As far as RxMidiIO is concerned, MIDI Mapper always has a Port ID of 0.