riseriallib
This library drives the Amiga’s serial port directly through the
hardware registers, without serial.device. SerialOpen installs a
receive and a transmit interrupt of the library: received bytes are
kept in a buffer of 256 bytes until SerialRead or SerialWait takes
them, and bytes written with SerialWrite go into a buffer of 128 and
are sent in the background. SerialClose removes the interrupts; the
port is also closed when the program ends. The commands that send or
receive blocks, strings and longs open the port themselves when it is
closed.
The port sends and receives 8 data bits with one stop bit. The baud rate
is set with SerialBaud or with SerialOpen baudrate; the calculation
uses the clock of a PAL Amiga. While the library’s interrupts are
installed, no other program may use the serial port, and serial.device
must not be in use.
A string is sent with SerialSendString and the 0 byte that ends it
with SerialWrite 0, and SerialReadString reads it up to that 0.
SerialWriteLong and SerialReadLong send and read a long as four
bytes, the low byte first.
SerialOpen 9600
SerialWrite 65
Repeat
Until SerialGot
b=SerialRead
NPrint "received ",b
SerialCloseLibrary number 22.
Commands
SerialBaud
Sets the baud rate of the serial port, for example 9600.
Statement. Help text: (rate)
Arguments: .l
The rate is calculated from the clock of a PAL Amiga.
SerialBuffer
The address of the receive buffer, 256 bytes used as a ring.
Function, result .l. No help text.
No arguments.
SerialClose
Removes the library’s interrupts and puts back the ones that were there before. Nothing happens if the port is not open.
Statement. No help text.
No arguments.
The library’s two serial interrupts are switched off and back on if
they were on at SerialOpen; the other interrupts stay as they are.
SerialFlush
Empties the receive buffer.
Statement. Help text: -- clears serial port read buffer
No arguments.
The command opens the port if it is closed, and leaves it open.
SerialGot
The number of received bytes waiting in the buffer, 0 to 255.
Function, result .w. Help text: -- returns num chars in serial buffer
No arguments.
The buffer keeps up to 255 bytes; bytes that arrive while it is full are lost.
SerialOpen
Installs the library’s receive and transmit interrupts and empties both buffers; with baudrate, it sets the baud rate first. A port already open keeps its interrupts and buffers; SerialOpen baudrate still sets the rate.
Statement. Help text: [baudrate]
2 forms:
- no arguments
.l
Without baudrate the port keeps the rate it has, from SerialBaud
or from the system. On a 68010 or later processor the interrupts are
installed in the vector table the processor uses, also when it has
been moved.
SerialProgress
The number of bytes still to send or receive of the last SerialSendBlock or SerialReceiveBlock.
Function, result .l. No help text.
No arguments.
SerialRead
The next received byte from the buffer, 0 to 255, or -1 if the buffer is empty. It does not wait.
Function, result .l. Help text: -- returns next byte, -1 if empty
No arguments.
SerialReadLong
Waits for four bytes and returns them as a long, the low byte first.
Function, result .l. No help text.
No arguments.
The command opens the port if it is closed. It reads what
SerialWriteLong sends.
SerialReadString
Waits for characters up to a 0 byte and returns them as a string, without the 0.
Function, result $. No help text.
No arguments.
The command opens the port if it is closed. The string ends at the end of the string work area (10240 bytes unless the compiler options set another size); the characters that do not fit stay in the receive buffer.
SerialReceiveBlock
Waits for length bytes and stores them from address on. SerialProgress gives the number still to come, and SerialStop ends the block after the next byte.
Statement. Help text: address,length
Arguments: .l, .l
The command opens the port if it is closed. The bytes already waiting
in the receive buffer are the first of the block; call SerialFlush
first to receive only bytes that arrive after the call. A length of 0
or less receives nothing.
SerialSendBlock
Sends length bytes from address, one after the other. SerialProgress gives the number of bytes still to send, and SerialStop ends the block early.
Statement. Help text: address,length
Arguments: .l, .l
The command opens the port if it is closed. A length of 0 or less sends nothing.
SerialSendString
Sends the characters of a string, without a 0 byte behind them.
Statement. Help text: (a$)
Arguments: $
The command opens the port if it is closed. If the other machine
reads with SerialReadString, send the 0 byte that ends the string
with SerialWrite 0.
SerialStop
Ends a SerialSendBlock or SerialReceiveBlock that is running, for example from an interrupt. Called while no block runs, it has no effect on the next one.
Statement. No help text.
No arguments.
SerialVersion
The version of the library, 1.
Function, result .b. No help text.
No arguments.
SerialWait
Waits until a byte has been received and returns it, 0 to 255.
Statement or function, result .w. Help text: -- waits for serial buffer to receive a byte
No arguments.
SerialWrite
Puts a byte into the transmit buffer; the library’s interrupt sends it in the background.
Statement. Help text: byte
Arguments: .w
The transmit buffer holds 127 bytes not sent yet. When it is full and the port is open, the command waits until the interrupt has sent a byte; with the interrupts disabled it then waits for ever, so send no more than 127 bytes there. With the port closed it does not wait.
SerialWriteLong
Sends a long as four bytes, the low byte first.
Statement. Help text: (longword)
Arguments: .l
The command opens the port if it is closed.