http://www.newton-inc.com/dev/techinfo/qa/qa.htm
cookie := OpenRemoteControl();
Call this function once to initialize the remote control functions. It returns a magic cookie that must be passed to subsequent remote control calls, or nil if the initialization failed.CloseRemoteControl(cookie);
Call this function once when all remote control operations are completed, passing cookie returned from OpenRemoteControl
. Always returns nil
. cookie is invalid after this call returns.SendRemoteControlCode(cookie, command, count);
Given the cookie returned from OpenRemoteControl
, this function sends the remote control command (see below for format of data). The command is sent count times. count must be at least 1. Returns after the command has been sent (or after the last loop for count
> 1). (see diagram)
struct IRCodeWord {
unsigned long name;
unsigned long timeBase;
unsigned long leadIn;
unsigned long repeat;
unsigned long leadOut;
unsigned long count;
unsigned long transitions[];
};
name
identifies the command code; set to anything you liketimeBase
in microseconds; sets the bit time baseleadIn
duration in timeBase units of the lead bit cellrepeat
duration in timeBase units of the last bit cell for loop commandsleadOut
duration timeBase units of the last bit cell for non-loop commandscount
one-based count of transitions followingtransitions
[ ] array of transition durations in timeBase units
Note that the repeat time is used only when the code is sent multiple times.GetNamedResource
and when you send data, use the constant as the resource used. OpenRemoteControl
is called in viewSetupFormscript
, and closeRemoteControl
is called in viewQuitScript
. Note that these are methods, not global functions; same is true of SendRemoteControlCode
.byteCount
slot of your input spec to the minimum packet size. In your input script, call Partial
to read in the entire packet, and then call FlushInput
to empty everything out for your next receive completion.partialScripts
with partialFrequencies
. Call the Ticks
global function if necessary to determine the exact execution time of a partialScript
.Instantiate
, Bind
or Connect
touch the hardware?{
type: 'service,
label: kCMSAsyncSerial,
opCode: opSetRequired
}
<see diagram section A>
Bind
request the CommTool acquires access to any physical hardware it controls, such as powering up the device. The endpoint is ready-to-go.<see diagram section B>
<see diagram section C>
<see diagram section D>
Disconnect
functions similarly to Connect
, moving the endpoint into a disconnected state. Unbind
releases any hardware controlled by the CommTool. Dispose
deallocates the CommTool task.kMacRomanEncoding
is the default encoding system for strings on most Newtons, you can specify it explicitly by adding one of the following encoding slots to your endpoint:encoding: kMacRomanEncoding; // Unicode<->Mac translation
encoding:
kWizardEncoding ; // Unicode<->Sharp Wizard translation
encoding:
kShiftJISEncoding ; // Unicode<->Japanese ShiftJIS translation
kMacRomanEncoding
, the upper 128 characters of the MacOS character encoding are sparse-mapped to/from their corresponding unicode equivalents. The map table can be found in Appendix B of the NewtonScript Programming Language reference. The upper-bit translation matrix is as follows:short gASCIIToUnicode[128] = {
0x00C4, 0x00C5, 0x00C7, 0x00C9, 0x00D1, 0x00D6, 0x00DC, 0x00E1,
0x00E0, 0x00E2, 0x00E4, 0x00E3, 0x00E5, 0x00E7, 0x00E9, 0x00E8,
0x00EA, 0x00EB, 0x00ED, 0x00EC, 0x00EE, 0x00EF, 0x00F1, 0x00F3,
0x00F2, 0x00F4, 0x00F6, 0x00F5, 0x00FA, 0x00F9, 0x00FB, 0x00FC,
0x2020, 0x00B0, 0x00A2, 0x00A3, 0x00A7, 0x2022, 0x00B6, 0x00DF,
0x00AE, 0x00A9, 0x2122, 0x00B4, 0x00A8, 0x2260, 0x00C6, 0x00D8,
0x221E, 0x00B1, 0x2264, 0x2265, 0x00A5, 0x00B5, 0x2202, 0x2211,
0x220F, 0x03C0, 0x222B, 0x00AA, 0x00BA, 0x2126, 0x00E6, 0x00F8,
0x00BF, 0x00A1, 0x00AC, 0x221A, 0x0192, 0x2248, 0x2206, 0x00AB,
0x00BB, 0x2026, 0x00A0, 0x00C0, 0x00C3, 0x00D5, 0x0152, 0x0153,
0x2013, 0x2014, 0x201C, 0x201D, 0x2018, 0x2019, 0x00F7, 0x25CA,
0x00FF, 0x0178, 0x2044, 0x00A4, 0x2039, 0x203A, 0xFB01, 0xFB02,
0x2021, 0x00B7, 0x201A, 0x201E, 0x2030, 0x00C2, 0x00CA, 0x00C1,
0x00CB, 0x00C8, 0x00CD, 0x00CE, 0x00CF, 0x00CC, 0x00D3, 0x00D4,
0xF7FF, 0x00D2, 0x00DA, 0x00DB, 0x00D9, 0x0131, 0x02C6, 0x02DC,
0x00AF, 0x02D8, 0x02D9, 0x02DA, 0x00B8, 0x02DD, 0x02DB, 0x02C7
};
Connect
and Listen
methods of protoBasicEndpoint
?nil
before attempting to access the array, while others assume they will always be passed an array of options. Some also assume that the array will always contain at least one element. ep:Connect([nil], nil);
data := [....];
for item := 0 to Length(data) - 1 do
ep:Output(data[ item ], nil, nil);
A: When protoBasicEndpoint
performs a function synchronously, it creates a special kind of "sub-task" to perform the interprocess call to the comm tool task. The sub-task causes the main NewtonScript task to suspend execution until the sub-task receives the "operation completed" response from the comm tool task, at which time the sub-task returns control to the main NewtonScript task, and execution continues.ep.fData := [....];
ep.fIndex := 0;
ep.fOutSpec := {
async: true,
completionScript:
func(ep, options, error)
if ep.fIndex >= Length(ep.fData) - 1 then
// indicate we're done
else
ep:Output(ep.fData[ ep.fIndex := ep.fIndex + 1 ],
nil, ep.fOutSpec )
};
ep:Output(ep.fData[ ep.fIndex ], nil, ep.fOutSpec );
completionScript
) and exit gracefully. Such code is left as an excercise for the reader.XON/XOFF
flow control can be set with the kCMOInputFlowControlParms
and kCMOOutputFlowControlParms
options. In the case of hardware handshaking (RTS/CTS)
you should use the following options:{ label: kCMOInputFlowControlParms,
type: 'option,
opCode: opSetRequired,
data: { arglist: [
kDefaultXonChar,
kDefaultXoffChar,
NIL,
TRUE,
0,
0, ],
typelist: ['struct,
'byte,
'byte,
'boolean,
'boolean,
'boolean,
'boolean, ],
},
},
{ label: kCMOOutputFlowControlParms,
type: 'option,
opCode: opSetRequired,
data: { arglist: [
kDefaultXonChar,
kDefaultXoffChar,
NIL,
TRUE,
0,
0, ],
typelist: ['struct,
'byte,
'byte,
'boolean,
'boolean,
'boolean,
'boolean, ],
},
}
MakeModemOption
call.MakeModemOption
when setting up options to intiailize an endpoint. So you would call MakeModemOption
to get your initial option array, then add your own custom options after that. MakeModemOption
will return correct options based on the user settings for ignore DialTone, use PC Card Modem, etc.inputSpec
of form 'string
. When its inputScript
triggers, I switch to an input form of 'binary
. When the binary inputScript
triggers, the first few bytes of the data are garbage, and sometimes the inputScript
doesn't trigger at all. The same behavior occurs when switching to the 'frame
input form. Why?endSequence
and filter
processing.byteCount
, or end-of-packet (EOP
) detection failure.
1. receive data using a non-B/F input form
{
type: 'option,
label: kCMOSerialHWChipLoc,
opCode: opSetRequired,
form: 'template,
result: nil,
data: {
argList: [kHWLocPCMCIASlot1, 0], // or kHWLocPCMCIASlot2
typeList: ['struct, ['array, 'char, 4], 'uLong]
}
}
'char
fields in the endpoint option is preventing the correct flow control characters from being set in the serial driver. The solution is to use the 'byte
symbol rather than the 'char
symbol for these fields, thus avoiding the Unicode-to-ASCII conversion that would normally take place. The Newton Programmer's Guide is incorrect; the correct option frames are as follows:{ label: kCMOInputFlowControlParms,
type: 'option,
opCode: opSetRequired,
result: nil,
form: 'template,
data: {
arglist: [
unicodeDC1, // xonChar
unicodeDC3, // xoffChar
true, // useSoftFlowControl
nil, // useHardFlowControl
0, // not needed; returned
0, ], // not needed; returned
typelist: ['struct,
'byte, // XON character
'byte, // XOFF character
'boolean, // software flow control
'boolean, // hardware flow control
'boolean, // hardware flow blocked
'boolean, ], }, }, // software flow blocked
{ label: kCMOOutputFlowControlParms,
type: 'option,
opCode: opSetRequired,
result: nil,
form: 'template,
data: {
arglist: [
unicodeDC1, // xonChar
unicodeDC3, // xoffChar
true, // useSoftFlowControl
nil, // useHardFlowControl
0, // not needed; returned
0, ], // not needed; returned
typelist: ['struct,
'byte, // XON character
'byte, // XOFF character
'boolean, // software flow control
'boolean, // hardware flow control
'boolean, // hardware flow blocked
'boolean, ], }, }, // software flow blocked
Baud rate 9600
Data bits 8
Stop bits 1
Parity Odd
DUMMY (5 bytes of null code (0x00))
and START ID (0x96)
begin both packet types. At least two null bytes must be processed by the receiver as DUMMY
before the START ID
of a packet is considered. After this (DUMMY, START ID)
sequence the PACKET ID
is transmitted. Code 0x82
is the packet ID for a PACKET I transmission, and code 0x81
is the packet ID for a PACKET II transmission.ENQ (0x05)
SYN (0x16)
ACK (0x06)
NAK (0x15)
CAN (0x18)
Byte length Set value in transmission Detection method in reception
DUMMY 5 0x00 * 5 Only 2 bytes are detected when received.
START ID 1 0x96
PACKET ID 1 0x82
DATA 1 above mentioned data
DUMMY START ID PACKET ID DATA
0x00, 0x00, 0x00, 0x00 0x96 0x82 0x05
BLOCK NO
value of 0xFFFF
. Byte length Set value in transmission Detection method in reception
DUMMY 5 0x00 * 5 Only 2 bytes are detected.
START ID 1 0x96
PACKET ID 1 0x81
VERSION 1 0x10 Judge only bits 7-4
BLOCK NO 2 (L/H) 0x0001 ~ 0xFFFF
CTRL CODE 1 0x01 Don't judge
DEV CODE 1 0x40 Don't judge
ID CODE 1 0xFE Don't judge
DLENGTH 2 (L/H) 0x0001 ~ 0x0200
DATA 1 ~ 512
CHKSUM 2 (L/H)
BLOCK NO
in last block must be set to 0xFFFF
.CHKSUM
is the two-byte sum of all of the data bytes of DATA
where any overflow or carry is discarded immediately.DUMMY START ID PACKET ID VERSION BLOCK NO CTRL CODE
0x00, 0x00, 0x00, 0x00 0x96 0x81 0x10 Low High 0x01
DEV CODE ID CODE DLENGTH data CHECKSUM
0x40 0xFE Low High ???? Low High
4 ProtocolENQ
(type I) packet. The receiving device (B) will acknowledge the ENQ
by transmitting a SYN
packet.SYN
packet, it goes to step 4.1.4 below.CAN
packet, or when 6 minutes have elapsed without a SYN
packet reply to an ENQ
packet, (A) terminates the session. If (A) receives any other packet, no packet, or an incomplete packet, it begins sending ENQ
packets every 0.5 seconds.SYN
packet, it transmits a single type II data packet, then awaits an ACK
packet from (B).ACK
packet, the transmission is considered successful.ACK
packet is received within 1 second from completion of step 4.1.4, or if any other packet is received, (A) goes to step 4.1.1 and transmits the data again. Retransmission is attempted once. The session is terminated if the second transmission is unsuccessful.ENQ
(type I) packet. If no ENQ
packet is received after 6 minutes (B) terminates the session.ENQ
packet, (B) transmits either a SYN
packet to continue the session or a CAN
packet to terminate the session.ACK
packet.ACK
packet (this will cause (A) to retransmit the packet after a one second delay).NAK
packet (this will cause (A) to retransmit the packet immediately).AddProcrastinatedCall
or AddProcrastinatedSend
repeatedly with the same symbol from my input specification's InputScript
method sometimes causes an out of memory exception on pre-Newton 2.1 devices. What's going wrong?InputScript
, it may not be executed until a much later time. Due to a bug in the way procrastinated actions with the same symbol are queued, it's possible to queue so many events that you run out of NewtonScript heap memory. This bug is fixed in the Newton 2.1 OS.AddDelayedCall
or AddDelayedSend
in place of a procrastinated action.'time
slot of the event frame passed to an endpoint's EventHandler
is in ticks. After some experimentation, I've discovered that it is not in ticks. What is this time value?0x3FFFFFFF
, or -536870912
decimal. Therefore, the time value will start counting at zero, count up to 536870911
, wrap to -536870912
then start to count back up to 536870911
.