Accessing a Serial Port

Here is the Chapter which explains how AMOS Professional is used as the gateway to the world of computerised communications.

The I/O Extension provides you with all the commands needed to exploit the Amiga's serial port for the following purposes:

Opening the Serial Port

A serial device refers to any machine that can communicate with the Amiga via its Serial Port. These devices include modems, MIDI systems and of course, other Amigas.


instruction: open a channel for Serial Input/Output
Serial Open Channel number,Port number
Serial Open Channel number, Port number,Shared,Xmode,7wires

The SERIAL OPEN command is used to open a communication channel between the Amiga and a serial device. The following parameters can be given with this instruction:

The Channel number is an identification number that will be used for all subsequent communication commands. The values for this number range from zero to 3.

The Port number is normally set to zero, and it specifies the logical device number of the Serial Port. For Amigas equipped with a Multi-Serial card that offers additional Serial Ports, these extra ports can be accessed by specifying a Port number from 1 upwards.

There are three optional parameters that can also be given, as follows:

The Shared parameter refers to a value which acts as a flag, telling AMOS Professional that the serial device can be shared with other tasks that are currently running on the computer. In other words, this parameter is used for multi-tasking. A value of zero (False) will grab the specified channel for AMOS Professional programs, and will deny access to any other programs. A value of -1 (True) will allow the Serial Port to be shared between several programs in memory. You are warned to use this system with great care, to avoid crashing your Amiga.

The Xmode is a val.-Lie which is used to toggle the checking system known as XON/XOFF. This system makes checks during the transmission of data over a serial line. It is essential to set this flag when the device is first opened, even if the device will not be required until later. The default value is zero (False), and this means that the system is normally disabled. To enable the checking system, a value of -1 (True) must be set. Once the port has been opened, the XON and XOFF characters must be set using a SERIAL X command, which is explained later.

The last of the three optional parameters concerns the "7 wires system" of communication. The default value for this parameter is set to zero (False), and a value of -1 (True) tells the device to use this system.

When the SERIAL OPEN command is called for the first time, the Serial Device library is loaded from the System disc automatically, so make sure that this disc is available in the current drive.


instruction: close one or more Serial channels
Serial Close
Serial Close Channel number

The use of this instruction closes all currently opened serial channels with no check for any errors. If an optional channel number is given, the specified channel will be closed using all normal error checks.

Whenever a program is run from AMOS Professional, any opened channels will be closed automatically.

Setting the serial parameters

The default settings for Serial Channels correspond to the standard Minitel protocol used in France, as follows:

1200 Baud
7 bits
1 stop bit
Even parity.

These settings can be changed using the instructions that are explained next.


instruction: set transfer rate for a serial channel
Serial Speed Channel number,Baud rate

This sets the current data transfer rate (the Baud rate) of the given channel, for both the sending and receiving operations. A Baud rate cannot be split for a. single channel. If the specified transfer rate is not supported by the current serial device, it may be rejected by the system.


instruction: set the number of bits for transmission of characters
Serial Bits Channel number,number of bits,number of Stop bits

This command is used to assign the number of bits that are to be used for each character that is transmitted. After the channel number is specified, give the number of bits followed by the number of Stop bits to be used.


instruction: set parity checking for a serial channel
Serial Parity Channel number, Parity

The SERIAL PARITY instruction sets the parity checking to be used for the specified serial channel.

Here is a list of the available settings for the Parity parameter:

-1 No parity
0 Even parity
1 Odd parity
2 Space parity
3 Mark parity

This Parity bit may be set using the BSET or BCLR instructions, as follows:

P=0 : Bset 0,P: Rem Odd parity Bclr 1,P : Rem Normal parity Serial Parity 1,P : Rem Set parity using the value in P


instruction: set handshaking system of serial channel
Serial X Channel number,Xmode

This command is used to enable or disable the XON/XOFF handshaking system, which checks data transmission. A value of -1 (True) will disable the system, whereas any other value will turn it on. The Xmode parameter should be loaded with the correct control characters, which must be specified in the following format:


Sending and receiving Serial information


instruction: output a string via a serial channel
Serial Send Channel number,string

This is used to send the given string directly to the selected serial channel, without waiting for the data to be transmitted through the actual port. This means that the SERIAL CHECK function must be used to detect when the transmission of data has been completed, and this is explained below.


instruction: output a block of raw data via a serial channel
Serial Out Channel number,address,length

This command is identical to SERIAL SEND, except for the fact that it works with raw data, instead of a string. Specify the channel number as usual, followed by the address in memory of the data to be transmitted, and the length of the data given in the number of bytes to be sent.


function: get a byte from a serial device
value=Serial Get(Channel number)

To read a single byte from a serial device, use the SERIAL GET function and specify which channel is to be examined. If no data is available, a value of -1 will be returned.


function: get a string from the Serial Port
string=Serial Input$(Channel number)

This function is used to read an entire string of characters from the Serial Port. If no data is available an empty string will be returned, otherwise the string will contain all the bytes that have been transmitted via the serial line up to the present moment.

Care should be taken when using this function with high speed transfers, such as those from MIDI devices. If the waiting time between each receive is too long, the system may overload and generate errors such as "string too long" or "serial device buffer overrun".

Transmitting a very large string can take a long time, especially at low Baud rates. With AMOS Professional multi-tasking, a program will only continue after a SERIAL SEND instruction. To avoid corrupting data, the following system should be employed:

Other Serial commands


instruction: set the size of the serial buffer
Serial Buffer Channel number,length

This allocates the length of the buffer space for the required channel, specified in the number of bytes to be allocated. The minimum allocation is 64 bytes, and the default setting is 512 bytes. You are recommended to increase the buffersize for high speed transfers of data.


instruction: engage fast mode for data transfer
Serial Fast Channel number

Use this command to set a special "fast" flag in the current serial device, which disables much of the internal checking process that can slow down the communication process. This is recommended for high speed transfers. Please note that when SERIAL FAST is called, the protocol is changed to: even parity, no XON/XOFF and 8 bits.


instruction: re-set slow mode for data transfer
Serial Slow Channel number

This instruction slows the serial device transmission back to normal speed, and all of the internal error checks are enabled once more.


function: report current serial device activity
status=Serial Check(Channel number)

This function obtains a report on the status of the current serial device. It can be used to check whether all of the information to be transmitted by a previous SERIAL SEND command has been sent. If a value of zero (False) is returned, the last Serial command is still being executed. If the value is -1 (True) the transmission has been completed.


function: report status of the serial port
bit-map=Serial Status(channel number)

The SERIAL STATUS function provides detailed information concerning the current status of the serial port. The channel number parameter refers to an open channel that has been previously assigned to the serial port with a SERIAL OPEN command. The report is returned in the form of a bit-map holding the status of fifteen different parameters. Here is a table of the various possibilities. If the relevant bit is set to the value under the "Active" column, the associated status has been successfully detected. Any other value indicates that the option is currently idle.

21Parallel "select" for A1000 machines. For the A500 and A2000, "select" is also connected to the serial port "Ring Indicator".
30DSR (Data Set Ready)
40CTS (Clear To Send)
50Carrier Detect
60RTS (Ready To Send)
70DTR (Data terminal Ready)
81Hardware overru
91Break sent (most recent output)
101Break received (as latest input)
111Transmit x-OFF
121Receive x-Off


function: report success of the last data transfer
status=Serial Error(Channel number)

The SERIAL ERROR function is used to look for the Error byte in the serial device. A value of zero (False) confirms that all is well, whereas 4 (True) indicates that there was an error in the last transmission.


instruction: stop current data transfer
Serial Abort(channel number)

This command halts any serial operations that have been commenced by a SERIAL SEND or SERIAL OUT command, and leaves the channel clear. It allows an instant quit from a transfer, without the need to wait for current activities to be completed.


function: get the address of the serial base
address=Serial Base

The SERIAL BASE function is especially useful for systems programmers. It returns the base address of the i/o structure of the current serial channel, allowing system functions to be called directly from an AMOS Professional program with EXEC. You are warned not to use this function unless you know precisely what you are doing, otherwise any mistakes can crash your computer.