picofuse-objc

Instance Methods | Class Methods | List of all members
NXSerialPort Class Reference

A UART, as a stream: a Pico's pins, or a host's serial device. More...

#import <Application/Application.h>

Inheritance diagram for NXSerialPort:
Inheritance graph
[legend]
Collaboration diagram for NXSerialPort:
Collaboration graph
[legend]

Instance Methods

(BOOL) - flushWithTimeout:
 Waits until what's been written has been sent. More...
 
- Instance Methods inherited from NXStream
(id) - initWithString:
 Initializes a stream which reads from a string. More...
 
(id) - initWithCapacity:
 Initializes a stream which reads and writes memory, and starts empty.
 
(id) - initWithBytes:length:
 Initializes a stream which reads and writes a copy of some bytes, from the start.
 
(id) - initWithStream:
 Initializes a stream with one from picofuse, which is closed when this is, or if this returns nil. More...
 
(int) - peek
 Returns the next byte, without reading it, or NXStreamEnd if there isn't one at present.
 
(size_t) - readBytes:length:
 Reads bytes. More...
 
(NXString *) - readStringWithLength:
 Reads a string. More...
 
(size_t) - writeBytes:length:
 Writes bytes. More...
 
(size_t) - writeString:
 Writes a string. More...
 
(NXString *) - hashWithAlgorithm:
 Reads the rest of the stream, and returns a hash of it. More...
 
(size_t) - hashWithAlgorithm:bytes:
 Reads the rest of the stream, and returns a hash of it, as bytes. More...
 
(size_t) - position
 Returns the position from the start, or NXNotFound if the stream doesn't have one.
 
(BOOL) - seek:relative:
 Changes the position. More...
 
(BOOL) - isEnded
 Returns YES if there'll never be anything else to read, as when a network connection has been closed, or the stream has. More...
 
(void) - close
 Closes the stream, which can't be used after that. More...
 
(BOOL) - isClosed
 Returns YES if the stream has been closed.
 
- Instance Methods inherited from NXObject
(void) - dealloc
 Frees the instance. More...
 
(NXZone *) - zone
 Returns the zone in which the instance was allocated. More...
 
(id) - retain
 Increases the retain count of the receiver. More...
 
(void) - release
 Decreases the retain count of the receiver. More...
 
(id) - autorelease
 Releases the receiver later, when the current autorelease pool of the thread is drained. More...
 
(id) - copy
 Returns a copy which can't be changed by anything else, which the caller owns and has to release. More...
 
(uintptr_t) - hash
 Returns a number for the object, which is the same for objects which are equal by isEqual:. More...
 
(NXString *) - description
 Returns a string which describes the instance, for logging. More...
 
- Instance Methods inherited from Object
(id) - init
 Initialize the instance, after allocation. More...
 
(Class) - class
 Returns the class of the instance. More...
 
(Class) - superclass
 Returns the superclass of the instance. More...
 
(BOOL) - isEqual:
 Compares the receiver to another object for equality. More...
 
(BOOL) - isKindOfClass:
 Returns a Boolean value that indicates whether the receiver is an instance of a given class. More...
 
(BOOL) - conformsTo:
 Checks if the receiver's class conforms to a protocol. More...
 
- Instance Methods inherited from <ObjectProtocol>
(BOOL) - respondsToSelector:
 Checks if the receiver responds to a selector. More...
 

Class Methods

(NXSerialPort *) + serialPortWithRx:tx:baudRate:
 Returns a serial port on a Pico's pins, in bank 0. More...
 
(NXSerialPort *) + serialPortWithDevice:baudRate:
 Returns a serial port on a host's device. More...
 
- Class Methods inherited from NXStream
(id) + streamWithString:
 Returns a stream which reads from a string. More...
 
(id) + streamWithCapacity:
 Returns a stream which reads and writes memory, and starts empty. More...
 
(id) + streamWithBytes:length:
 Returns a stream which reads and writes a copy of some bytes, from the start. More...
 
(id) + streamWithData:
 Returns a stream which reads and writes a copy of the bytes of data, from the start. More...
 
(NXStream *) + standardInput
 Returns a stream for the standard input, or nil if there isn't one.
 
(NXStream *) + standardOutput
 Returns a stream for the standard output, or nil if there isn't one.
 
- Class Methods inherited from NXObject
(id) + alloc
 Allocates a new instance in the default zone, or if there isn't one, with sys_calloc(). More...
 
(id) + allocWithZone:
 Allocates a new instance in a specific zone. More...
 
(id) + new
 Allocates and initializes a new instance, as [[cls alloc] init] does. More...
 
(NXString *) + description
 Returns the name of the class.
 
- Class Methods inherited from Object
(void) + initialize
 Performs one-time initialization for the class. More...
 
(Class) + class
 Returns the class object. More...
 
(Class) + superclass
 Returns the superclass of the class. More...
 
(const char *) + name
 Returns the name of the class. More...
 
(BOOL) + conformsTo:
 Checks if the class conforms to a protocol. More...
 

Additional Inherited Members

- Protected Attributes inherited from Object
Class isa
 A pointer to the object's class structure. More...
 

Detailed Description

A UART, as a stream: a Pico's pins, or a host's serial device.

It's read and written as any other NXStream, with eight data bits, no parity and one stop bit, and no flow control. To be sent a message when there's something to read, or room to write, attach it to the application with NXStreamSource.

On a Pico, what's read is buffered by an interrupt, and so is what's written: a write which doesn't all fit writes what does. On a host, a background thread reads, and a write waits until it's all been taken.

Definition at line 22 of file NXSerialPort.h.

Method Documentation

◆ flushWithTimeout:()

- (BOOL) flushWithTimeout: (NXDuration)  timeout

Waits until what's been written has been sent.

Parameters
timeoutHow long to wait at most, or 0 to only check. A host's device isn't bounded by it, but waits until it's sent.
Returns
YES if it's been sent, or NO if it hadn't when the timeout passed.

◆ serialPortWithDevice:baudRate:()

+ (NXSerialPort *) serialPortWithDevice: (NXString *)  path
baudRate: (uint32_t)  baudRate 

Returns a serial port on a host's device.

Parameters
pathThe device, such as "/dev/ttyUSB0" or "/dev/cu.usbserial-1420".
baudRateThe baud rate, one of the standard ones from 50 to 230400.
Returns
The port, or nil if the device can't be opened, the baud rate isn't supported, or it's a Pico.

◆ serialPortWithRx:tx:baudRate:()

+ (NXSerialPort *) serialPortWithRx: (uint8_t)  rxPin
tx: (uint8_t)  txPin
baudRate: (uint32_t)  baudRate 

Returns a serial port on a Pico's pins, in bank 0.

Parameters
rxPinThe pin it receives on.
txPinThe pin it transmits on, of the same UART.
baudRateThe baud rate.
Returns
The port, or nil if the pins aren't a UART's, the UART is in use, or it's not a Pico.

The documentation for this class was generated from the following file: