Inherits from NSObject
Declared in ORSSerialPortManager.h

Overview

ORSSerialPortManager is a singleton class (one instance per application) that can be used to get a list of available serial ports. It will also handle closing open serial ports when the Mac goes to sleep, and reopening them automatically on wake. This prevents problems I’ve seen with serial port drivers that can hang if the port is left open when putting the machine to sleep. Note that using ORSSerialPortManager is optional. It provides some nice functionality, but only ORSSerialPort is necessary to simply send and received data.

Using ORSSerialPortManager

To get the shared serial port manager:

ORSSerialPortManager *portManager = [ORSSerialPortManager sharedSerialPortManager];

To get a list of available ports:

NSArray *availablePorts = portManager.availablePorts;

Notifications

ORSSerialPort posts notifications when a port is added to or removed from the system. ORSSerialPortsWereConnectedNotification is posted when one or more ports are added to the system. ORSSerialPortsWereDisconnectedNotification is posted when one ore more ports are removed from the system. The user info dictionary for each notification contains the list of ports added or removed. The keys to access these array are ORSConnectedSerialPortsKey, and ORSDisconnectedSerialPortsKey respectively.

KVO Compliance

ORSSerialPortManager is Key-Value Observing (KVO) compliant for its availablePorts property. This means that you can observe availablePorts to be notified when ports are added to or removed from the system. This also means that you can easily bind UI elements to the serial port manager’s availablePorts property using Cocoa-bindings. This makes it easy to create a popup menu that displays available serial ports and updates automatically, for example.

Close-On-Sleep

ORSSerialPortManager’s close-on-sleep, reopen-on-wake functionality is automatic. The only thing necessary to enable it is to make sure that the singleton instance of ORSSerialPortManager has been created by calling sharedSerialPortManager at least once. Note that this behavior is only available in Cocoa apps, and is disabled when ORSSerialPort is used in a command-line only app.

Tasks

Properties

availablePorts

@property (nonatomic, copy, readonly) NSArray *availablePorts
Discussion

An array containing ORSSerialPort instances representing the serial ports available on the system. (read-only)

As explained above, this property is Key Value Observing compliant, and can be bound to for example an NSPopUpMenu to easily give the user a way to select an available port on the system.

Declared In

ORSSerialPortManager.h

Class Methods

sharedSerialPortManager

+ (ORSSerialPortManager *)sharedSerialPortManager
Discussion

Returns the shared (singleton) serial port manager object.

Return Value

The shared serial port manager.

Declared In

ORSSerialPortManager.h