The Perl Advent Calendar needs more articles for 2022. Submit your idea today!

NAME

Slinke - module to control the Slink-e product produced by Nirvis - visit Nirvis at http://www.nirvis.com

SYNOPSIS

    use Slinke;

    # Create a Slinke and read from the infrared port
    my $slinke = new Slinke;
    my $data = $slinke->requestInput();

    foreach my $i ( @$data ) {
       print "$i\n";
    }

DESCRIPTION

Slink-e is a product that can speak to many different Sony products over the S-Link port. Also, it can receive and transmit infrared signals over 8 different transmitters/receivers.

For now, the bulk of this code deals with the transmission and reception of these infrared signals.

Note that this code borrows heavily from C++ code from Colby Boles. In fact, sometimes I just copied his code and comments verbatim.

METHODS

EXPORT

The different port names are exported. These are the following:

 PORT_SL0 PORT_SL1 PORT_SL2 PORT_SL3 PORT_IR PORT_PAR PORT_SER PORT_SYS

$slinke = new Slinke( [ DEVICE => $device, SERIALPORT => $serialport ] );

Returns a newly created Slinke object.

$device is the name of the device that the Slink-e is connected to.

If no device is provided, a search is made on the following devices: /dev/ttyS0 /dev/ttyS1 /dev/ttyS2 /dev/ttyS3

On windows, COM ports 1-8 are searched

If you would rather provide a SerialPort object, you can do that by setting the SERIALPORT argument

$slinke->requestInput();

This function returns any input from the S-Link ports, the IR ports or the Parallel port

The returned element is a hash reference.

PORT is always set, and it will contain the port that returned the data

DATA is a reference to an array of values.

TIME is set for data coming from the IR port and this lists the total amount of time that was needed to produce the IR signal

IRPORT is set for data coming from the IR port. It tells which IR receiver (1-8) the data was received on. Note that you must have a Slink-e of version 2.0 or higher for IRPORT to be greater than 0

$slinke->requestSerialNumber()

This returns the 8 byte serial number of the Slink-e.

$slinke->requestBaud()

This returns the baud rate in bps of the Slink-e.

$slinke->setBaud()

This sets the baud rate in bps of the Slink-e.

$slinke->requestFirmwareVersion()

This returns the firmware version of the Slink-e

$slinke->enablePort( $port )

Enables reception on specified port. If port == PORT_SYS all ports are not enabled, instead each port is returned to its enabled/disabled state previous to the global disablement.

$slinke->disablePort( $port )

Disables reception on specified port. If port == PORT_SYS, all ports are disabled. Disabling a port does not prevent the host from sending messages out the port, only receiving them.

$slinke->requestIRSamplingPeriod()

This returns the infrared sampling period of the Slink-e. Values can range from 50 microseconds to 1 millisecond.

The IR sampling period determines the maximum timing resolution which can be achieved when decoding IR signals. In general, the sampling period should be at least 3 times shorter than the shortest pulse you wish to detect. Short sampling periods are necessary when acquiring timing information about new remote signals, but are not necessarily need to output known remote signals since the sampling period need only be the least common multiple of the pulse widths in the signal.

The IR sampling period is also used as a timebase for parallel port output signals.

$slinke->setIRSamplingPeriod( $time )

This sets the infrared sampling period of the Slink-e. Values can range from 50 microseconds to 1 millisecond in 1/5 microsecond steps. Upon success, this function will return the sampling period. On value, it will return undef.

The IR sampling period determines the maximum timing resolution which can be achieved when decoding IR signals. In general, the sampling period should be at least 3 times shorter than the shortest pulse you wish to detect. Short sampling periods are necessary when acquiring timing information about new remote signals, but are not necessarily need to output known remote signals since the sampling period need only be the least common multiple of the pulse widths in the signal.

The IR sampling period is also used as a timebase for parallel port output signals.

$slinke->requestIRCarrier()

This returns the IR carrier frequency of the Slink-e.

$slinke->setIRCarrier( $frequency )

This sets the IR carrier frequency of the Slink-e. Note that because of the way that the frequency gets set, it will be very unlikely that you will be able to set the exact frequency that you want. However, the Slink-e should be able to handle your frequency within several hundred hertz.

Upon success, the frequency that the Slink-e is using will be returned.

Upon failure, undef is returned.

$slinke->requestIRTimeoutPeriod()

This returns the IR timeout period of the Slink-e as measured in sample periods. The timeout period defines how ling the IR receiver module must be inactive for the Slink-e to consider a message to be completed.

$slinke->setIRTimeoutPeriod( $sample_periods )

This returns the IR timeout period of the Slink-e as measured in sample periods. The timeout period defines how ling the IR receiver module must be inactive for the Slink-e to consider a message to be completed. Most IR remotes repeat commands many times for one keypress. If you want to see each command as a separate message, set the timeout period to be less than the off time between commands. If you to see the keypress as one long message with repeated commands, set the timeout period to be longer than the off time between commands. The latter mode is particularly useful for initially determining the timing information for a new remote.

On success, the new value of the timeout period will be returned.

On failure, undef is returned.

$slinke->requestIRMinimumLength()

This returns the length of the shortest IR receive message in bytes which will be considered a valid message.

$slinke->setIRMinimumLength( $bytes )

This set the length of the shortest IR receive message in bytes which will be considered a valid message. IR receiver modules such as the one on the Slink-e tend to be very sensitive to both optical and electrical noise, causing them to occasionally generate false pulses when there is no actual IR signal. The false pulses are generally of short duration and do not contain the large number of on/off alternations present in a true IR remote signal. By setting a minimum message length, false pulses will be ignored and not reported to the host. The minimum length can range from 0 to 15 bytes.

Upon success, the new minimum message length is returned.

Upon failure, undef is returned.

$slinke->requestIRTransmitPorts()

This returns the value of the ports that the Slink-e uses for IR transmissions. The bits represent the 8 IR ports, IR0 being the LSB, IR7 the MSB. A "1" indicates the port will be used.

This command requires a firmware version of 2.0 and above

$slinke->setIRTransmitPorts( $ports )

This sets the ports that the Slink-e uses for IR transmissions. The bits represent the 8 IR ports, IR0 being the LSB, IR7 the MSB. A "1" indicates the port will be used.

This command requires a firmware version of 2.0 and above

$slinke->requestIRPolarity()

Reports the polarity sense of each of the IR ports. These settings will also affect the IR routing system. The bits of the response represent the 8 IR ports, IR0 being the LSB, IR7 the MSB. A "1" bit indicates that the input is active-low (when the input goes to 0 Volts), a "0" bit indicates that the input is active-high (when the input goes to 5 Volts). All ports are active-low by default so that they will work correctly with the IR receiver modules. If you have some other low-speed serial device which is active-high (e.g. a Control-S input) that you would like to connect, you will want to change the polarity on that port. Be careful with this option - if you set the wrong polarity for a port, the Slink-e will be locked into a constant receive state and will become unresponsive.

This command requires a firmware version of 2.0 and above

$slinke->setIRPolarity( $ports )

Sets the polarity sense of each of the IR ports. These settings will also affect the IR routing system. The bits of $ports represent the 8 IR ports, IR0 being the LSB, IR7 the MSB. A "1" bit indicates that the input is active-low (when the input goes to 0 Volts), a "0" bit indicates that the input is active-high (when the input goes to 5 Volts). All ports are active-low by default so that they will work correctly with the IR receiver modules. If you have some other low-speed serial device which is active-high (e.g. a Control-S input) that you would like to connect, you will want to change the polarity on that port. Be careful with this option - if you set the wrong polarity for a port, the Slink-e will be locked into a constant receive state and will become unresponsive.

This command requires a firmware version of 2.0 and above

$slinke->requestIRReceivePorts()

This returns the value of the ports that the Slink-e uses for IR reception. The bits represent the 8 IR ports, IR0 being the LSB, IR7 the MSB. A "1" indicates the port will be used.

This command requires a firmware version of 2.0 and above

$slinke->setIRReceivePorts( $ports )

This sets the ports that the Slink-e uses for IR reception. The bits represent the 8 IR ports, IR0 being the LSB, IR7 the MSB. A "1" indicates the port will be used.

This command requires a firmware version of 2.0 and above

Upon success, this returns the ports that the Slink-e is using for IR reception.

Upon failure, undef is returned.

$slinke->requestIRRoutingTable()

This response describes the IR routing table. The routelist byte for each IRRX port specifies which IRTX ports the received signal will be echoed to. The format for this byte is the same as the Set IR transmit ports command. The carrier byte specifes the carrier frequency to be used in the routed signals from a given IRRX port. This byte is equivalent to the CC byte in the Set IR carrier command. To reduce data storage requirements, no prescaler value can be specified and the prescaler is defaulted to 0 instead. This means that 15.7khz is the lowest available carrier frequency for IR routing.

This command requires a firmware version of 2.0 and above

$slinke->setIRRoutingTable( @data )

This command sets up the IR routing table. The routelist byte for each IRRX port specifies which IRTX ports the received signal will be echoed to. The format for this byte is the same as the Set IR transmit ports command. The carrier byte specifes the carrier frequency to be used in the routed signals from a given IRRX port. This byte is equivalent to the CC byte in the Set IR carrier command. To reduce data storage requirements, no prescaler value can be specified and the prescaler is defaulted to 0 instead. This means that 15.7khz is the lowest available carrier frequency for IR routing.

This command requires a firmware version of 2.0 and above

$slinke->requestHandshaking()

Reports the input and output handshaking mode for the Parallel Port.

As a binary number, the output looks as follows: [0 0 0 0 0 0 in out]

Only the bits in and out are used.

in = 0 : Disable Input Handshaking (default at startup). Disable the use of DISTB/DIO7 as a handshaking pin, in turn freeing it for general I/O use. When input handshaking is enabled, rising edges on the DISTB input cause the Parallel Port data to be sampled and sent to the host in the form of a port receive message. When disabled, sampling of the Parallel Port only occurs when a sample port message is issued.

in = 1 : Enable Input Handshaking Enables the use of DISTB/DIO7 as a handshaking pin, in turn removing it from general I/O use. When input handshaking is enabled, rising edges on the DISTB input cause the Parallel Port data to be sampled and sent to the host in the form of a port receive message. When disabled, sampling of the Parallel Port only occurs when a sample port message is issued.

out= 0 : Disable Output Handshaking (default at startup). Disable the use of DOSTB/DIO6 as a handshaking pin, in turn freeing it for general I/O use. When output handshaking is enabled, each data byte sent out the Parallel Port using the port send command will be accompanied by a positive DOSTB pulse lasting one IR sampling period.

out = 1 : Enable Output Handshaking Enable the use of DOSTB/DIO6 as a handshaking pin, in turn removing it from general I/O use. When output handshaking is enabled, each data byte sent out the Parallel Port using the port send command will be accompanied by a positive DOSTB pulse lasting one IR sampling period.

$slinke->setHandshaking( $handshaking )

Sets the input and output handshaking mode for the Parallel Port.

As a binary number, $handshaking looks as follows: [0 0 0 0 0 0 in out]

Only the bits in and out are used.

in = 0 : Disable Input Handshaking (default at startup). Disable the use of DISTB/DIO7 as a handshaking pin, in turn freeing it for general I/O use. When input handshaking is enabled, rising edges on the DISTB input cause the Parallel Port data to be sampled and sent to the host in the form of a port receive message. When disabled, sampling of the Parallel Port only occurs when a sample port message is issued.

in = 1 : Enable Input Handshaking Enables the use of DISTB/DIO7 as a handshaking pin, in turn removing it from general I/O use. When input handshaking is enabled, rising edges on the DISTB input cause the Parallel Port data to be sampled and sent to the host in the form of a port receive message. When disabled, sampling of the Parallel Port only occurs when a sample port message is issued.

out= 0 : Disable Output Handshaking (default at startup). Disable the use of DOSTB/DIO6 as a handshaking pin, in turn freeing it for general I/O use. When output handshaking is enabled, each data byte sent out the Parallel Port using the port send command will be accompanied by a positive DOSTB pulse lasting one IR sampling period.

out = 1 : Enable Output Handshaking Enable the use of DOSTB/DIO6 as a handshaking pin, in turn removing it from general I/O use. When output handshaking is enabled, each data byte sent out the Parallel Port using the port send command will be accompanied by a positive DOSTB pulse lasting one IR sampling period.

Upon success, the new handshaking setting is returned

Upon failure, undef is returned.

$slinke->requestDirection()

Reports which parallel port lines are inputs or outputs. The bits d7:d0 in the output correspond 1 to 1 with the Parallel Port I/O lines DIO7:DIO0. Setting a direction bit to 1 assigns the corresponding DIO line as an input, while setting it to 0 make it an output. At startup, all DIO lines are configured as inputs. The use of handshaking on lines DISTB/DIO7 and DOSTB/DIO6 overrides the direction configuration for these lines while enabled.

$slinke->setDirection( $direction )

Configures the parallel port lines as inputs or outputs. The bits d7:d0 in the direction byte correspond 1 to 1 with the Parallel Port I/O lines DIO7:DIO0. Setting a direction bit to 1 assigns the corresponding DIO line as an input, while setting it to 0 make it an output. At startup, all DIO lines are configured as inputs. The use of handshaking on lines DISTB/DIO7 and DOSTB/DIO6 overrides the direction configuration for these lines while enabled. Slink-e will return a configuration direction equals response to verify your command.

$slinke->sampleParPort()

Causes the Slink-e to sample the Parallel Port inputs just as if it had seen a rising edge on DISTB when input handshaking is enabled. This command works whether input handshaking is enabled or not. The Slink-e will respond with a port receive message containing the Parallel Port data.

Note that this function does not actually return the parallel port data. To get that, you must call the requestInput function.

$slinke->sendIR( DATA => $data [, IRPORT => $ports ] )

This function allows you to send IR signals. The DATA element should be an array reference of run length coded signals. If you wish to send the IR on specific ports, set the IRPORT element.

This function will automatically mute the IR Receivers while data is being sent so that the receiver will not capture what the transmitter is sending.

$slinke->sendData( DATA => $data, PORT => $port )

This allows data to be sent over a S-Link port or the parallel port. The PORT element must be set to either PORT_SL0, PORT_SL1, PORT_SL2 or PORT_PAR. The data element should be an array reference of the data to be sent.

$slinke->reset()

Warm-boots the Slink-e, resetting all defaults including the baud rate. In version 2.0 or greater, these defaults are loaded from an EEPROM which is user programmable.

$slinke->loadDefaults()

Causes the Slink-e to load all of the current user settings from EEPROM memory so that they are returned to their default values, Be wary of the fact that the baud rate stored in EEPROM could be different than the current baud rate. In this case communications will be lost until the host detects the new baud rate. If successful, the Slink-e will send a defaults loaded response.

This command requires a firmware version of 2.0 and above

$slinke->saveDefaults()

Causes the Slink-e to save all of the current user settings to EEPROM memory so that they will become the defaults the next time the Slink-e is reset or powered-up. If successful, the Slink-e will send a defaults saved response.

This command requires a firmware version of 2.0 and above

decodeIR( @data )

This will take the data returned by requestInput and attempt to convert it to a bit string. This function returns a hash reference.

Elements of the hash reference

   HEAD => The wakeup call for the device.  These are typically the first two
           bytes in the data array.  This is an array reference.

   CODE => This is a bit string indicating the command that was sent.
           For Sony devices, a "P" is thrown in when a pause in the data array
           is detected.

   TAIL => The bytes that indicate the end of the data string.  These are 
           typically the last five bytes of the data array.  This is an array
           reference.

   ENCODING => This is an array reference of two array references that describes
           how zeroes and ones are encoded.

TODO

Add bin mode for S-Link ports

AUTHOR

Brian Paulsen <Brian@ThePaulsens.com>

Copyright 2000, Brian Paulsen. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Bug reports and comments to Brian@ThePaulsens.com.

For further information about the Slink-e, visit http://www.nirvis.com