Copyright (c) Hyperion Entertainment and contributors.

Difference between revisions of "AmigaOS Manual: Serial and parallel ports"

From AmigaOS Documentation Wiki
Jump to navigation Jump to search
m
 
(15 intermediate revisions by the same user not shown)
Line 5: Line 5:
 
= Serial port communication =
 
= Serial port communication =
   
Depending on your Amiga hardware you have one or more serial ports. The first serial port device is '''SER:''', second is '''SER1:''', third is '''SER2:''', and so on. The first serial port can be configured through the Serial Preferences editor and the other ports by editing their mount configuration files stored in the 'DEVS:DOSDrivers' directory.
+
Depending on your Amiga hardware you have one or more serial ports. The first serial port device is '''SER:''', second is '''SER1:''', third is '''SER2:''', and so on. The first serial port can be configured through the [[AmigaOS Manual:Serial Preferences editor|Serial Preferences editor]] and the other ports by editing their mount configuration files stored in the 'DEVS:DOSDrivers' directory.
   
 
The Serial Preferences editor allows you to change all serial port properties: unit, baud rate, handshaking, parity, data bits, and stop bits.
 
The Serial Preferences editor allows you to change all serial port properties: unit, baud rate, handshaking, parity, data bits, and stop bits.
Line 17: Line 17:
 
# Close the device.
 
# Close the device.
   
When opening the serial port device, you can request custom serial port settings for your communication session. The default settings will be restored when you close the device.
+
When opening the serial port device, you can request custom serial port settings for your communication session. The following settings are available:
 
The following settings are available:
 
   
 
{| class="wikitable"
 
{| class="wikitable"
Line 28: Line 26:
 
| UNIT || UNIT/K/N || Device unit to be used.
 
| UNIT || UNIT/K/N || Device unit to be used.
 
|-
 
|-
| FLOW=HANDSHAKE || FLOW=HANDSHAKE/K || Flow control setting: SOFT=SOFTWARE, HARD=HARDWARE=7WIRE, or NONE.
+
| FLOW or HANDSHAKE || FLOW=HANDSHAKE/K || Flow control setting: SOFT=SOFTWARE, HARD=HARDWARE=7WIRE, or NONE.
 
|-
 
|-
 
| CONTROL || CONTROL/F || Data bits, parity, and stop bits setting. A three letter sequence is expected. The first letter is the number of data bits, the second letter tells which parity should be used, and the third letter is the number of stop bits. The valid setting for each letter is: 1st letter: 7 or 8, 2nd letter: N, O, E, M, or S (N = No parity, O = Odd parity, E = Even parity, M = Mark parity, and S = Space parity), 3rd letter: 1 or 2.
 
| CONTROL || CONTROL/F || Data bits, parity, and stop bits setting. A three letter sequence is expected. The first letter is the number of data bits, the second letter tells which parity should be used, and the third letter is the number of stop bits. The valid setting for each letter is: 1st letter: 7 or 8, 2nd letter: N, O, E, M, or S (N = No parity, O = Odd parity, E = Even parity, M = Mark parity, and S = Space parity), 3rd letter: 1 or 2.
Line 38: Line 36:
 
</syntaxhighlight>
 
</syntaxhighlight>
   
== Program 19: WriteToSerial.rexx ==
+
== Program 30: WriteToSerial.rexx ==
  +
<syntaxhighlight lang="rexx">
  +
/*
  +
** Send a line of text through the serial port
  +
*/
   
  +
/* Open serial port for writing */
  +
IF ( ~OPEN( 'serial', 'SER:', 'W' ) ) THEN DO
  +
SAY 'Failed to open serial port.'
  +
EXIT 0
  +
END
  +
  +
/* Read line */
  +
OPTIONS PROMPT 'Enter text to be send: '
  +
PARSE PULL line
  +
  +
/* Write line to serial port */
  +
WRITELN( 'serial', line )
  +
  +
/* Close serial port */
  +
CLOSE( 'serial' )
  +
  +
SAY 'Text sent.'
  +
</syntaxhighlight>
   
 
== Receiving data through the serial port ==
 
== Receiving data through the serial port ==
Line 51: Line 71:
 
Different serial port settings can be requested when opening the device for reading. For the available settings, see the settings table above.
 
Different serial port settings can be requested when opening the device for reading. For the available settings, see the settings table above.
   
== Program 20: ReadFromSerial.rexx ==
+
== Program 31: ReadFromSerial.rexx ==
  +
<syntaxhighlight lang="rexx">
  +
/*
  +
** Read a line of text from the serial port
  +
*/
   
  +
/* Open serial port for reading */
  +
IF ( ~OPEN( 'serial', 'SER:', 'R' ) ) THEN DO
  +
SAY 'Failed to open serial port.'
  +
EXIT 0
  +
END
  +
  +
line = ''
  +
/* Read characters until line feed */
  +
DO UNTIL ( C2D( char ) = 10 )
  +
char = READCH( 'serial' )
  +
line = line || char
  +
END
  +
  +
/* Strip line feed */
  +
line = STRIP( line, 'T', D2C( 10 ) )
  +
  +
/* Print the received line */
  +
SAY line
  +
  +
/* Close serial port */
  +
CLOSE( 'serial' )
  +
</syntaxhighlight>
   
 
= Parallel port communication =
 
= Parallel port communication =
  +
An unexpanded Amiga has one parallel port which appears as a '''PAR:''' device in AmigaOS. The device can be used for sending and receiving data from the device connected to the parallel port.
  +
== Sending data through the parallel port ==
  +
Sending data through the parallel port is simple:
  +
  +
# Open the parallel port device for writing.
  +
# Write data to be send to the device.
  +
# Close the device.
  +
  +
By default parallel device unit 0 is used for parallel port communication. If you need to use other than the default unit, you can request the preferred unit when opening the device. For example:
  +
<syntaxhighlight lang="rexx">
  +
OPEN( 'parallel', 'PAR:UNIT=1', 'W' )
  +
</syntaxhighlight>
  +
Device unit is the only setting for the parallel device:
  +
{| class="wikitable"
  +
! Keyword !! Template !! Description
  +
|-
  +
| UNIT || UNIT/K/N || Device unit to be used.
  +
|}
  +
  +
== Program 32: WriteToParallel.rexx ==
  +
<syntaxhighlight lang="rexx">
  +
/*
  +
** Send byte through the parallel port
  +
*/
  +
  +
byte = '10101010' /* Byte to send (binary value) */
  +
  +
/* Open parallel port for writing */
  +
IF ( ~OPEN( 'parallel', 'PAR:', 'W' ) ) THEN DO
  +
SAY 'Failed to open parallel port.'
  +
EXIT 0
  +
END
  +
  +
SAY 'Sending byte:'
  +
SAY ''
  +
SAY 'Hex Dec Binary'
  +
SAY '--------------------'
  +
SAY LEFT( C2X( B2C( byte ) ), 3 ) || ' ' || LEFT( C2D( B2C( byte ) ), 3 ) || ' ' || byte
  +
  +
/* Send byte */
  +
WRITECH( 'parallel', B2C( byte ) )
  +
  +
/* Close parallel port */
  +
CLOSE( 'parallel' )
  +
</syntaxhighlight>
  +
  +
== Receiving data through the parallel port ==
  +
To read data from the parallel port, do as follows:
  +
  +
# Open the parallel port device for reading.
  +
# Read data from the device.
  +
# Close the device.
  +
  +
As when writing to the parallel port, you can request any device unit for reading too. For example, to use unit 1 for reading:
  +
<syntaxhighlight lang="rexx">
  +
OPEN( 'parallel', 'PAR:UNIT=1', 'R' )
  +
</syntaxhighlight>
  +
== Program 33: ReadFromParallel.rexx ==
  +
<syntaxhighlight lang="rexx">
  +
/*
  +
** Read byte from the parallel port
  +
*/
  +
  +
/* Open parallel port for reading */
  +
IF ( ~OPEN( 'parallel', 'PAR:', 'R' ) ) THEN DO
  +
SAY 'Failed to open parallel port.'
  +
EXIT 0
  +
END
  +
  +
/* Read byte */
  +
byte = C2B( READCH( 'parallel' ) )
  +
  +
SAY 'Byte read:'
  +
SAY ''
  +
SAY 'Hex Dec Binary'
  +
SAY '--------------------'
  +
SAY LEFT( C2X( B2C( byte ) ), 3 ) || ' ' || LEFT( C2D( B2C( byte ) ), 3 ) || ' ' || byte
  +
  +
/* Close parallel port */
  +
CLOSE( 'parallel' )
  +
</syntaxhighlight>

Latest revision as of 14:18, 27 March 2019

A serial port can be used for communicating with all kinds of serial devices: modems, bar code scanners, UPSes, sound digitizers, other computers, etc. Many non-serial devices have a serial port too for configuring the device and/or updating its firmware.

A parallel port is faster than a serial port and it has no baud rate or flow control settings like the serial port. Typical parallel port devices are printers, scanners, ZIP drives, and EPROM programmers.

Serial port communication

Depending on your Amiga hardware you have one or more serial ports. The first serial port device is SER:, second is SER1:, third is SER2:, and so on. The first serial port can be configured through the Serial Preferences editor and the other ports by editing their mount configuration files stored in the 'DEVS:DOSDrivers' directory.

The Serial Preferences editor allows you to change all serial port properties: unit, baud rate, handshaking, parity, data bits, and stop bits.

Sending data through the serial port

A serial port can be used for receiving and sending data. The procedure of using serial port for sending data is as follows:

  1. Open the serial port device for writing.
  2. Write data to be send to the device.
  3. Close the device.

When opening the serial port device, you can request custom serial port settings for your communication session. The following settings are available:

Keyword Template Description
BAUD BAUD/N Baud rate.
UNIT UNIT/K/N Device unit to be used.
FLOW or HANDSHAKE FLOW=HANDSHAKE/K Flow control setting: SOFT=SOFTWARE, HARD=HARDWARE=7WIRE, or NONE.
CONTROL CONTROL/F Data bits, parity, and stop bits setting. A three letter sequence is expected. The first letter is the number of data bits, the second letter tells which parity should be used, and the third letter is the number of stop bits. The valid setting for each letter is: 1st letter: 7 or 8, 2nd letter: N, O, E, M, or S (N = No parity, O = Odd parity, E = Even parity, M = Mark parity, and S = Space parity), 3rd letter: 1 or 2.

If you supply several parameters when opening the device, the parameter must be separated with slashes (/). For example:

OPEN( 'serial', 'SER:UNIT=0/BAUD=19200/FLOW=NONE', 'W' )

Program 30: WriteToSerial.rexx

/*
** Send a line of text through the serial port
*/
 
/* Open serial port for writing */
IF ( ~OPEN( 'serial', 'SER:', 'W' ) ) THEN DO
    SAY 'Failed to open serial port.'
    EXIT 0
END
 
/* Read line */
OPTIONS PROMPT 'Enter text to be send: '
PARSE PULL line
 
/* Write line to serial port */
WRITELN( 'serial', line )
 
/* Close serial port */
CLOSE( 'serial' )
 
SAY 'Text sent.'

Receiving data through the serial port

When you want to read data from the serial port, do as follows:

  1. Open the serial port device for reading.
  2. Read data from the device.
  3. Close the device.

Different serial port settings can be requested when opening the device for reading. For the available settings, see the settings table above.

Program 31: ReadFromSerial.rexx

/*
** Read a line of text from the serial port
*/
 
/* Open serial port for reading */
IF ( ~OPEN( 'serial', 'SER:', 'R' ) ) THEN DO
    SAY 'Failed to open serial port.'
    EXIT 0
END
 
line = ''
/* Read characters until line feed */
DO UNTIL ( C2D( char ) = 10 )
    char = READCH( 'serial' )
    line = line || char
END
 
/* Strip line feed */
line = STRIP( line, 'T', D2C( 10 ) )
 
/* Print the received line */
SAY line
 
/* Close serial port */
CLOSE( 'serial' )

Parallel port communication

An unexpanded Amiga has one parallel port which appears as a PAR: device in AmigaOS. The device can be used for sending and receiving data from the device connected to the parallel port.

Sending data through the parallel port

Sending data through the parallel port is simple:

  1. Open the parallel port device for writing.
  2. Write data to be send to the device.
  3. Close the device.

By default parallel device unit 0 is used for parallel port communication. If you need to use other than the default unit, you can request the preferred unit when opening the device. For example:

OPEN( 'parallel', 'PAR:UNIT=1', 'W' )

Device unit is the only setting for the parallel device:

Keyword Template Description
UNIT UNIT/K/N Device unit to be used.

Program 32: WriteToParallel.rexx

/*
** Send byte through the parallel port
*/
 
byte = '10101010' /* Byte to send (binary value) */
 
/* Open parallel port for writing */
IF ( ~OPEN( 'parallel', 'PAR:', 'W' ) ) THEN DO
    SAY 'Failed to open parallel port.'
    EXIT 0
END
 
SAY 'Sending byte:'
SAY ''
SAY 'Hex   Dec   Binary'
SAY '--------------------'
SAY LEFT( C2X( B2C( byte ) ), 3 ) || '   ' || LEFT( C2D( B2C( byte ) ), 3 ) || '   ' || byte
 
/* Send byte */
WRITECH( 'parallel', B2C( byte ) )
 
/* Close parallel port */
CLOSE( 'parallel' )

Receiving data through the parallel port

To read data from the parallel port, do as follows:

  1. Open the parallel port device for reading.
  2. Read data from the device.
  3. Close the device.

As when writing to the parallel port, you can request any device unit for reading too. For example, to use unit 1 for reading:

OPEN( 'parallel', 'PAR:UNIT=1', 'R' )

Program 33: ReadFromParallel.rexx

/*
** Read byte from the parallel port
*/
 
/* Open parallel port for reading */
IF ( ~OPEN( 'parallel', 'PAR:', 'R' ) ) THEN DO
    SAY 'Failed to open parallel port.'
    EXIT 0
END
 
/* Read byte */
byte = C2B( READCH( 'parallel' ) )
 
SAY 'Byte read:'
SAY ''
SAY 'Hex   Dec   Binary'
SAY '--------------------'
SAY LEFT( C2X( B2C( byte ) ), 3 ) || '   ' || LEFT( C2D( B2C( byte ) ), 3 ) || '   ' || byte
 
/* Close parallel port */
CLOSE( 'parallel' )