NAME

Device::MegaSquirt::Serial - Low level serial commands for MegaSquirt.

SYNOPSIS

use Device::MegaSquirt::Serial;
$mss = new Device::MegaSquirt::Serial('/dev/ttyUSB0');

@data = $mss->read_r(9, 0, 0, 256);

DESCRIPTION

This library is used for the low level serial commands needed to communicate with a MegaSquirt [2] controller.

The only concern at this level is how the data is read and written. The specific details of what the data actually represents is not defined here. That should be defined at a higher level where defintions are made relevant to the Megasquirt version number.

OPERATIONS

Device::MegaSquirt::Serial->new($serial)

Returns: defined object on success, FALSE otherwise

The new constructor takes a single argument specifying which serial device to use (e.g. '/dev/ttyUSB0'). If initiation of the device is successful the returned objected can be used to call other functions.

$mss->read_Q()

Returns: the Megasquirt version number, FALSE on error

Executes the Q command [1] to read the version number.

$version = $mss->read_Q();

Q' and 'S' commands (both caps) are used to retrieve two indicators of the MS-II code version. The first is the 20-byte ASCII string for the Rev Number of the code version, the second is for a 32-byte Signature string. The latter is changed in the code whenever a new feature is added, the first is changed in the code whenever there has been an input parameter or output variable added. [1]

$mss->read_S()

Returns: the Megasquirt signature, FALSE on error

Executes the S command [1] to read the signature.

$version = $mss->read_S();

See also documentation of read_Q();

$mss->read_A($num_bytes)

Returns: hash reference of bytes on success, FALSE on error

Executes the A command [1] (Burst Mode) to read a frame of live variables.

$dat = $mss->read_A($num_bytes);
# process $dat elsewhere

The values of the data that is returned is dependent on the Megasquirt version so the data is returned in its raw form and processing must be done at a higher level.

The size of data is also version dependent so this is given as an argument so that it can it can be tested here to see if the correct amount of data was read.

$mss->read_r($tbl_idx, $offset, $num_bytes)

Returns: array of bytes on success, FALSE on error

Executes the r command [1] to read bytes from the controller.

$tbl_idx - table index/offset; also called 'page'
$offset - offset
$num_bytes - the number of bytes to request

$mss->write_w($tbl_idx, $offset, @bytes)

Returns: TRUE on success, FALSE on error

Executes the w command [1] to write bytes to the controller.

$tbl_idx - table index/offset; also called 'page'
$offset - offset
@bytes - data bytes to be written

It is expected that @bytes are only 1 byte chunks. For example to write a two byte integer it must be broken down in to 2 bytes.

$pack = pack("n", $integer);
@bytes = unpack("CC", $pack);

PREREQUISITES

Module                Version
------                -------
Device::SerialPort    1.04
 
The version number given has been tested and shown to work.
Other version may also work.

REFERENCES

[1]  RS232 communication with Megasquirt 2-Extra
     http://home.comcast.net/~whaussmann/RS232_MS2E/RS232_MS2_E.htm

[2]  MegaSquirt Engine Management System
     http://www.msextra.com/

AUTHOR

Jeremiah Mahler
CPAN ID: JERI
mailto:jmmahler@gmail.com
http://www.google.com/profiles/jmmahler#about 

COPYRIGHT

Copyright (c) 2010, Jeremiah Mahler. All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.

SEE ALSO

Device::SerialPort