Device-MegaSquirt
view release on metacpan or search on metacpan
doc/devdoc/RS232_MS2_E.htm view on Meta::CPAN
<data array> <br>
'101 0 5 0 0 144', <data array> - example send 144bytes to MS2 and have
MS2 echo them back <br>
The 'e' (echo) command is the same as 'w', except that after MS2 has received
all the bytes from the sender, it echoes them back for verification. Thus
a sender who has sent n bytes to be written should expect n bytes back from
MS II starting after he has sent the last byte to be written. <br>
</p>
<h3><font color="#0000FF">"r" Command<a name="r_cmd"></a></font></h3>
<p>"r", 0, <tble_idx><offset_H>,<offset_L>,<numb_points_H><numb_points_L><br>
'114 0 5 0 0 144'- example, MS2 will reply with 144 bytes of the VE table
1<br>
Generic form of the 'a' command. The returned bytes from MS II are not buffered.
Send 'r', 0, <tble_idx>. followed by 2 bytes specifying the offset from
the array or structure corresponding to tble_idx, followed by 2 bytes specifying
the total number of data bytes to return. After all 7 bytes are received,
MS II will start sending the requested number of bytes. </p>
<p> In order to fetch the 256 byte VE table, we would need to send the following
out the serial port: </p>
<blockquote>
<p>114 (byte value for lower case 'r') <br>
0 (one byte for CANid, always zero for RS232) <br>
9 (one byte for tble_idx)</p>
<p> delay of >200 ms (if table index changes)</p>
<p> 0 (High byte of location index) <br>
0 (Low byte of location index) <br>
1 (High byte of the number of data points) <br>
0 (low byte of the number of data points)</p>
</blockquote>
<p><font color="#333333">The table definition and variables are contained in
the <strong>megasquirt-ii.ini</strong> file. Some commonly used tables are
repeated here for convenience</font></p>
<p><font color="#333333"><a href="RS232_MS2_tables.htm">AFR target</a>, <a href="RS232_MS2_tables.htm#ve_tbl">VE
fuel</a>, <a href="RS232_MS2_tables.htm#adv_tbl">Ignition Advance</a></font></p>
<p align="left"><font color="#333333">For scaling and more details, see the
<strong>megasquirt-ii.ini </strong>file.</font> Pages are somewhat different
than variables outlined above in the "A" command, but the concept
is the same. Here is a line with headings from the target AFR table 1 (<font size="-1" face="Courier New, Courier, mono">afrTable1</font>)
on Page = 1: </p>
<p><font size="-1" face="Courier New, Courier, mono"> <strong>Variable index &nbs...
name type, size, offset, shape, units,
scale. translate lo, hi, digits</strong><br>
afrTable1= array, U08, 48, [12x12], "AFR", 0.10000,
0.00000, 9.00, 20.00, 1</font></p>
<p>The <strong>type</strong> is either array, bits, or scalar where an array
is multiple bytes of data (e.g. tables) bits is a byte where each bit may
have a True/False meaning, and scalar is a single number.</p>
<p>The <strong>size</strong> indicates the memory size. U08 is an unsigned 8
bit number, U16 is an unsigned 16 bit number and will require two bytes of
data.</p>
<p><strong>Shape</strong> tells you the number of dimensions to the array. A
[12x12] shape indicates a two dimensional array such as a VE table. A [12]
is a one dimensional array such as the x or y axis table data for MAP and
rpm. The tables start on the lower left going from left to right and up. See
the example VB program for creating a table.</p>
<p><strong>Units</strong> are the human readable units. ADC means the value
from the analog to digital converter before they are scaled. ADC units typically
represent 0-5V max using 0-255 </p>
<p align="left">The scaling is done with a multiplier (<strong>scale</strong>)
and an offset (<strong>translate</strong>) to get to user units (in the above
example AFR) use this formula: <br>
userValue = (msValue + translate) * scale.</p>
<p align="left"> The<strong> lo</strong> and<strong> hi</strong> value indicate
the range of the values. In this example for an input of 0-5V (Innovate 0-5V
LC-1) the user units will range from an AFR of 10 to 20. The scaling values
will be different for different sensor settings. </p>
<p>The <strong>digits</strong> indicates the number of useful digits after the
decimal point. </p>
<p>Do a search of the variable in the <font color="#333333"><strong>megasquirt-ii.ini</strong></font>
file for details.</p>
<p><font color="#333333"><strong>VB example</strong></font></p>
<p>This snippet of code demonstrates how to read the VE table1 and constants
from page 5 (tbl_idx=9) into an array. This is only the table and does not
include the axis definition.</p>
<blockquote>
<p> <font size="-1" face="Courier New, Courier, mono">Dim DataOut As Variant<br>
Dim byteArray(6) As Byte</font></p>
<p><font size="-1" face="Courier New, Courier, mono">' Send commands as array
of bytes<br>
MSComm1.InputMode = comInputModeBinary</font></p>
<p> ReDim byteArray(2)<br>
' Select a page<br>
byteArray(0) = Asc("r")<br>
byteArray(1) = 0<br>
byteArray(2) = 9<br>
<font size="-1" face="Courier New, Courier, mono">MSComm1</font>.Output
= byteArray</p>
<p> delay 200<br>
<br>
' Sent starting address (0)<br>
ReDim byteArray(3)<br>
byteArray(0) = 0<br>
byteArray(1) = 0</p>
<p> ' Send size (256 bytes)<br>
byteArray(2) = 1<br>
byteArray(3) = 0</p>
<p> ' Send the commands to get a page and return the variables<br>
<font size="-1" face="Courier New, Courier, mono">MSComm1</font>.Output
= byteArray<br>
<br>
' wait 200msec<br>
delay 200</p>
<p> ' grab data from comm port.<br>
DataIn = <font size="-1" face="Courier New, Courier, mono">MSComm1</font>.Input<br>
</p>
</blockquote>
<h3><font color="#0000FF">"t" Command<a name="t_cmd"></a></font></h3>
<p>"t", 0, <tble_idx> <data array> <br>
'116 0 3' delay 50ms <table data> Example for re-flashing <br>
For changing calibration data in MS2. Use for re-flashing new coolant, MAT,
Ego, and MAF tables. These tables are all 1024 word (2 bytes) tables. The
't' command is followed by <tble_idx> of 0-3, to identify the
table of interest. At that point the MS II erases the table flash sector entirely
(that is why you do NOT want to be driving while this is going on). So you
want to delay about 50 ms before sending the the rest of the data, which consists
of the table words. These are sent in order of ascending index, msb byte first,
then lsb byte for each of the 1024 16-bit words. <br>
<font color="#0000FF"><br>
</font> </p>
<h3><font color="#0000FF">"w" Command<a name="w_cmd"></a></font></h3>
<p>"w",0,<tble_idx><offset_H>,<offset_L>,<numb_points_H><numb_points_L>
( run in 0.574 second using v1.01-cache-2.11-cpan-9581c071862 )