📄 cwp39.htm
字号:
<!-- saved from url=(0007)http:// -->
<HTML><HEAD><META http-equiv="Content-Type" content="text/html; charset=UTF-8"><TITLE>WJ.MPR.Reader.MPRComm</TITLE><LINK REL=STYLESHEET HREF="../CommentReport.css" TYPE="text/css"></HEAD><BODY topmargin=0 rightmargin=0 leftmargin=0 style="background-image: url(../titletile.jpg); background-repeat:repeat-x; background-position: 0 0;" ><DIV CLASS="PageHeading">WJ.MPR.Reader.MPRComm Class</DIV><DIV CLASS="Description">
Responsible for handling messages bound for the MPR over a serial port.
- Manages an underlying Serial Port object
- Handles Serial Port Events
- Generates Request Frames and parses Response Frames, and stores all frames for
a single transaction in an MPRMsg.
- Handles and reports Serial Port or MPR API errors.
- Fires two events,
1) BLData, when data arrives (always asynchronously) from the bootloader.
2) IsOpenChanged, when the underlying serial port closes.
- Performs the twiddling needed for Reseting the MPR and entering the bootloader.
<P></DIV><IMG src="../GradLeft.jpg" width=7 height=378 alt="" border="0" style="position:absolute; left:10; top:18;z-Index:2"><IMG src="../GradTop.jpg" width=352 height=7 alt="" border="0" align="top" style="position:absolute; left:10; top:18; z-index:1"><DIV CLASS="Remarks"><SPAN CLASS="RemarkHdrX">Access: </SPAN>Public</DIV><DIV CLASS="Remarks"><SPAN CLASS="RemarkHdrX">Base Classes: </SPAN>Object</DIV><DIV CLASS="Remarks"><SPAN CLASS="RemarkHdrX">Implemented interfaces: </SPAN>IDisposable</DIV><TABLE CLASS="InfoTable" cellpadding=0 cellspacing=0><TR height=20><TD width=20> </TD><TD valign=top align=left width=9 bgcolor="#cccc66"><IMG SRC="../graycorner.jpg" align=top></TD><TD CLASS="TableLightLabel" WIDTH=206>Members</TD><TD CLASS="TableLightLabel" >Description</TD><TD width=20> </TD></TR><TR height=20><TD width=20> </TD><TD CLASS="TableLightDesc"> </TD><TD CLASS="TableLightDesc"><A HREF="CWP40.HTM" TARGET="CNTFRAME">portSettings</A></TD><TD CLASS="TableLightDesc">
create the port settings:
default has no Handshake
Bootloader uses XonXoff
<P></TD><TD width=20> </TD></TR><TR height=20><TD width=20> </TD><TD CLASS="TableLightDesc"> </TD><TD CLASS="TableLightDesc"><A HREF="CWP42.HTM" TARGET="CNTFRAME">SerialPort</A></TD><TD CLASS="TableLightDesc">
The underlying Serial Port which we'll use to talk to the MPR
<P></TD><TD width=20> </TD></TR><TR height=20><TD width=20> </TD><TD CLASS="TableLightDesc"> </TD><TD CLASS="TableLightDesc"><A HREF="CWP44.HTM" TARGET="CNTFRAME">BaudRate</A></TD><TD CLASS="TableLightDesc">
The Baud Rate of the underlying Serial Port (default = 57600)
<P></TD><TD width=20> </TD></TR><TR height=20><TD width=20> </TD><TD CLASS="TableLightDesc"> </TD><TD CLASS="TableLightDesc"><A HREF="CWP46.HTM" TARGET="CNTFRAME">TimeOutTimer</A></TD><TD CLASS="TableLightDesc"> </TD><TD width=20> </TD></TR><TR height=20><TD width=20> </TD><TD CLASS="TableLightDesc"> </TD><TD CLASS="TableLightDesc"><A HREF="CWP47.HTM" TARGET="CNTFRAME">KickTimer</A></TD><TD CLASS="TableLightDesc">
Reset the TimeOutTimer, by changing it to expire, just once, in 750 milliseconds.
<P></TD><TD width=20> </TD></TR><TR height=20><TD width=20> </TD><TD CLASS="TableLightDesc"> </TD><TD CLASS="TableLightDesc"><A HREF="CWP48.HTM" TARGET="CNTFRAME">KillTimer</A></TD><TD CLASS="TableLightDesc">
Kill the TimeOutTimer, by changing it to never expire.
<P></TD><TD width=20> </TD></TR><TR height=20><TD width=20> </TD><TD CLASS="TableLightDesc"> </TD><TD CLASS="TableLightDesc"><A HREF="CWP49.HTM" TARGET="CNTFRAME">TimeOutFunction</A></TD><TD CLASS="TableLightDesc">
The timer callback function. Notify the current Msg that a comm timeout has occurred.
<P></TD><TD width=20> </TD></TR><TR height=20><TD width=20> </TD><TD CLASS="TableLightDesc"> </TD><TD CLASS="TableLightDesc"><A HREF="CWP50.HTM" TARGET="CNTFRAME">CurrentMessage</A></TD><TD CLASS="TableLightDesc">
The currently active Message.
<P></TD><TD width=20> </TD></TR><TR height=20><TD width=20> </TD><TD CLASS="TableLightDesc"> </TD><TD CLASS="TableLightDesc"><A HREF="CWP52.HTM" TARGET="CNTFRAME">rxTmpFrame</A></TD><TD CLASS="TableLightDesc">
A temporary frame within which to store arriving bytes.
<P></TD><TD width=20> </TD></TR><TR height=20><TD width=20> </TD><TD CLASS="TableLightDesc"> </TD><TD CLASS="TableLightDesc"><A HREF="CWP54.HTM" TARGET="CNTFRAME">ConvertToBaudRateEnum</A></TD><TD CLASS="TableLightDesc"> </TD><TD width=20> </TD></TR><TR height=20><TD width=20> </TD><TD CLASS="TableLightDesc"> </TD><TD CLASS="TableLightDesc"><A HREF="CWP55.HTM" TARGET="CNTFRAME">MPRComm</A></TD><TD CLASS="TableLightDesc">
Constructor that initializes, but doesn't open, the underlying serial port
through which to communicate with an MPR.
<P></TD><TD width=20> </TD></TR><TR height=20><TD width=20> </TD><TD CLASS="TableLightDesc"> </TD><TD CLASS="TableLightDesc"><A HREF="CWP56.HTM" TARGET="CNTFRAME">Open</A></TD><TD CLASS="TableLightDesc">
Try to open the underlying Serial Port.
<P></TD><TD width=20> </TD></TR><TR height=20><TD width=20> </TD><TD CLASS="TableLightDesc"> </TD><TD CLASS="TableLightDesc"><A HREF="CWP57.HTM" TARGET="CNTFRAME">IsOpen</A></TD><TD CLASS="TableLightDesc">
Just map the underlying ports IsOpen property.
<P></TD><TD width=20> </TD></TR><TR height=20><TD width=20> </TD><TD CLASS="TableLightDesc"> </TD><TD CLASS="TableLightDesc"><A HREF="CWP59.HTM" TARGET="CNTFRAME">Close</A></TD><TD CLASS="TableLightDesc">
Close the underlying serial port immediately...
<P></TD><TD width=20> </TD></TR><TR height=20><TD width=20> </TD><TD CLASS="TableLightDesc"> </TD><TD CLASS="TableLightDesc"><A HREF="CWP60.HTM" TARGET="CNTFRAME">Send</A></TD><TD CLASS="TableLightDesc">
Build an MPRMsg using command and parameters,
send the request frame, and wait for and receive
response packets.
<P></TD><TD width=20> </TD></TR><TR height=20><TD width=20> </TD><TD CLASS="TableLightDesc"> </TD><TD CLASS="TableLightDesc"><A HREF="CWP63.HTM" TARGET="CNTFRAME">SendFrame</A></TD><TD CLASS="TableLightDesc">
Send a request frame to the MPR via the Serial Port
Kicks the receiver timer after sending a frame
<P></TD><TD width=20> </TD></TR><TR height=20><TD width=20> </TD><TD CLASS="TableLightDesc"> </TD><TD CLASS="TableLightDesc"><A HREF="CWP64.HTM" TARGET="CNTFRAME">SendBLLine</A></TD><TD CLASS="TableLightDesc">
Send one line of text
<P></TD><TD width=20> </TD></TR><TR height=20><TD width=20> </TD><TD CLASS="TableLightDesc"> </TD><TD CLASS="TableLightDesc"><A HREF="CWP65.HTM" TARGET="CNTFRAME">SendBytes</A></TD><TD CLASS="TableLightDesc">
Just send raw bytes out the serial port.
<P></TD><TD width=20> </TD></TR><TR height=20><TD width=20> </TD><TD CLASS="TableLightDesc"> </TD><TD CLASS="TableLightDesc"><A HREF="CWP66.HTM" TARGET="CNTFRAME">Dispose</A></TD><TD CLASS="TableLightDesc">
Free resources:
Dispose the underlying Serial port.
<P></TD><TD width=20> </TD></TR><TR height=20><TD width=20> </TD><TD CLASS="TableLightDesc"> </TD><TD CLASS="TableLightDesc"><A HREF="CWP67.HTM" TARGET="CNTFRAME">SerialPort_DataReceived</A></TD><TD CLASS="TableLightDesc"> </TD><TD width=20> </TD></TR><TR height=20><TD width=20> </TD><TD CLASS="TableLightDesc"> </TD><TD CLASS="TableLightDesc"><A HREF="CWP68.HTM" TARGET="CNTFRAME">SerialPortBL_DataReceived</A></TD><TD CLASS="TableLightDesc"> </TD><TD width=20> </TD></TR><TR height=20><TD width=20> </TD><TD CLASS="TableLightDesc"> </TD><TD CLASS="TableLightDesc"><A HREF="CWP69.HTM" TARGET="CNTFRAME">SerialPort_TxDone</A></TD><TD CLASS="TableLightDesc">
Not used: Fired when the Serial Port is done transmitting the whole Input buffer.
<P></TD><TD width=20> </TD></TR><TR height=20><TD width=20> </TD><TD CLASS="TableLightDesc"> </TD><TD CLASS="TableLightDesc"><A HREF="CWP70.HTM" TARGET="CNTFRAME">SerialPort_OnError</A></TD><TD CLASS="TableLightDesc">
Fired when the Serial Port detects an error condition.
<P></TD><TD width=20> </TD></TR><TR height=20><TD width=20> </TD><TD CLASS="TableLightDesc"> </TD><TD CLASS="TableLightDesc"><A HREF="CWP71.HTM" TARGET="CNTFRAME">SerialPort_IsOpenChanged</A></TD><TD CLASS="TableLightDesc">
Just a thin wrapper around the underlying Port's
IsOpenChanged event
<P></TD><TD width=20> </TD></TR><TR height=20><TD width=20> </TD><TD CLASS="TableLightDesc"> </TD><TD CLASS="TableLightDesc"><A HREF="CWP72.HTM" TARGET="CNTFRAME">PortSetting</A></TD><TD CLASS="TableLightDesc">
Returns a string with the serial port and baud rate : "COMx 57600".
<P></TD><TD width=20> </TD></TR><TR height=20><TD width=20> </TD><TD CLASS="TableLightDesc"> </TD><TD CLASS="TableLightDesc"><A HREF="CWP74.HTM" TARGET="CNTFRAME">blModeSetup</A></TD><TD CLASS="TableLightDesc">
Setup Event Handlers and Port Settings for Bootloader communications mode.
<P></TD><TD width=20> </TD></TR><TR height=20><TD width=20> </TD><TD CLASS="TableLightDesc"> </TD><TD CLASS="TableLightDesc"><A HREF="CWP75.HTM" TARGET="CNTFRAME">appModeSetup</A></TD><TD CLASS="TableLightDesc">
Setup Event Handlers and Port Settings for Application (normal) communications mode.
<P></TD><TD width=20> </TD></TR><TR height=20><TD width=20> </TD><TD CLASS="TableLightDesc"> </TD><TD CLASS="TableLightDesc"><A HREF="CWP76.HTM" TARGET="CNTFRAME">ResetMPR</A></TD><TD CLASS="TableLightDesc">
Hard reboot the MPR's processor.
Resetting can bring the MPR up in one of two programs.
If the Bootloader line is high, we enter the bootloader.
Else, the normal Application is started.
The Application uses no Handshaking, 57600 baud, and communicates through MPRMsg Frames.
The Bootloader uses XonXoff Handshaking, 115200 baud, and communicates through ASCII text.
The two different types of message require different Message handlers
(SerialPort_DataRecevied and SerialPortBL_DataRecevied).
This Method waits 100 msec after toggling the Reset Line, for the MPR to reboot.
There are two ways of communicating with the MPR, serial mode and PC Card mode.
In serial mode, the BOOTLOAD and RESET lines are brought out to the 68-pin connector,
and must be toggled with dedicated hardware lines.
In PC Card mode, the BOOTLOAD and RESET lines are internal to the MPR and are toggled
by special commands. These special commands are accessed by changing the serial port
settings to {57600 BPS, 5 Data bits, 1.5 stop bits, no parity}.
The reset line is then accessed as bit 4 (0x10).
The BOOTLOAD line is then accessed as bit 0 (0x01).
This MPRComm.ResetMPR Method only works in the PC Card Mode.
<P></TD><TD width=20> </TD></TR></TABLE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -