吳振華
(赤峰學院 物理與電子信息工程學院, 內蒙古 赤峰 024000)
關于郵件分揀的模擬設計
吳振華
(赤峰學院 物理與電子信息工程學院, 內蒙古 赤峰 024000)
郵件分揀在 EDA 實驗中作為數控式實驗的內容,其程序設計有其鮮明的專業性、實用性和獨特性.在對學生開放該實驗前,筆者對該實驗所用的 FLASH 進行了模擬設計,以便學生更加直觀地了解和認識該實驗并針對模擬過程用 EDA 進行程序設計.
郵件;分揀;模擬;設計
1、將郵件分為郵件 A(maila_mc)、郵件 B(mailb_mc)、郵件 C(mailc_mc)、郵編不規范部分(maild_mc)和尺寸不規范部分(maile_mc)等.
2、準備檢測指示燈(detectLnght)和郵件進入郵箱指示燈(lnghtA.lnghtB.lnghtC.lnghtD.lnghtE).
3、郵件檢測啟動按鈕和停止按鈕.

郵件分揀系統的模擬演示最終界面組合圖
1、郵件進入分揀流水線后經檢測屬哪一類后,送到相應的郵件容器里.
2、根據信號功能表進行程序設計,從演示界面中我們看到一個“開始”按鈕.按下“開始”按鈕后程序才開始工作,顯示“停止”按鈕并隱藏“開始”按鈕,按下“停止”按鈕后終止程序運行并再次顯示“開始”按鈕.
3、程序運行后即循環工作,演示界面自動隨機流出郵件,送流水線檢測.
4、當郵件經過郵件檢測裝置時,將檢測出該郵件的類型,并發出相應的信號,程序根據檢測裝置發出的信號,也發出命令,打開相應的郵件箱接收該郵件.
5、按下“停止”按鈕,郵件分揀工作終止.
//定義初始狀態
var vy:int=1.3;
var vx:int=1.3;
detectLnght.visible=false;
lnghtA.visible=false;
lnghtB.visible=false;
lnghtC.visible=false;
lnghtD.visible=false;
lnghtE.visible=false;
maila_mc.visible=false;
mailb_mc.visible=false;
mailc_mc.visible=false;
maild_mc.visible=false;
maile_mc.visible=false;
stop_btn.visible=false;
random_btn.visible=true;
//開始按鈕的事件偵聽器
random_btn.addEventListener(MouseEvent.CLICK,randomF);
function randomF(e){
//為防止調用郵件自定義函數出現 13秒的延時,加一次調用
var timer1:Timer=new Timer(3,1);
timer1.addEventListener(TimerEvent.TIMER,timerF1);
timer1.start();
function timerF1(e:TimerEvent){
var k:int=Math.floor(Math.random()*5+1);
switch(k){
case 1:
mail1();
break;
case 2:
mail2();
break;
case 3:
mail3();
break;
case 4:
mail4();
break;
case 5:
mail5();
break;
}}
init();//調用郵件自定義函數
}
//郵件自定義函數
function init(){
random_btn.visible=false;
stop_btn.visible=true;
var timer:Timer=new Timer(14000);
timer.addEventListener(TimerEvent.TIMER,timerF);
timer.start();
function timerF(e:TimerEvent){
var n:int=Math.floor(Math.random()*5+1);
switch(n){
case 1:
mail1();
break;
case 2:
mail2();
break;
case 3:
mail3();
break;
case 4:
mail4();
break;
case 5:
mail5();
break;
}
}
stop_btn.addEventListener(MouseEvent.MOUSE_DOWN, stopF);
function stopF(e){
random_btn.visible=true;
stop_btn.visible=false;
timer.removeEventListener(TimerEvent.TIMER,timerF);
random_btn.addEventListener(MouseEvent.CLICK,
randomF);
timer.stop();
}
}
//5個郵件事件處理函數
function mail1(){
maila_mc.addEventListener(Event.ENTER_FRAME,
mailAmc);
function mailAmc(e){
maila_mc.visible=true;
if(maila_mc.y<212){
maila_mc.y+=vy;
if(maila_mc.y>=159&&maila_mc.y<182){
detectLnght.visible=true;
lnghtA.visible=true;
lnghtB.visible=false;
lnghtC.visible=false;
}else{
detectLnght.visible=false;
}
}else if(maila_mc.x<315){
maila_mc.x+=vx;
if(maila_mc.x>312){
maila_mc.visible=false;
maila_mc.x=215;
maila_mc.y=125;
maila_mc.removeEventListener(Event.ENTER_
FRAME,mailAmc);
}
}
}
}
function mail2(){
mailb_mc.addEventListener(Event.ENTER_FRAME, mailBmc);
function mailBmc(e){
mailb_mc.visible=true;
if(mailb_mc.y<256){
mailb_mc.y+=vy;
if(mailb_mc.y>=159&&mailb_mc.y<182){
detectLnght.visible=true;
lnghtB.visible=true;
lnghtA.visible=false;
lnghtC.visible=false;
}else{
detectLnght.visible=false;
}
}else if(mailb_mc.x<315){
mailb_mc.x+=vx;
if(mailb_mc.x>312){
mailb_mc.visible=false;
mailb_mc.x=215;
mailb_mc.y=125;
mailb_mc.removeEventListener(Event.ENTER_ FRAME,mailBmc);
}
}
}
}
function mail3(){
mailc_mc.addEventListener(Event.ENTER_FRAME,mail-Cmc);
function mailCmc(e){
mailc_mc.visible=true;
if(mailc_mc.y<300){
mailc_mc.y+=vy;
if(mailc_mc.y>=159&&mailc_mc.y<182){
detectLnght.visible=true;
lnghtC.visible=true;
lnghtA.visible=false;
lnghtB.visible=false;
}else{
detectLnght.visible=false;
}
}else if(mailc_mc.x<315){
mailc_mc.x+=vx;
if(mailc_mc.x>312){
mailc_mc.visible=false;
mailc_mc.x=215;
mailc_mc.y=125;
mailc_mc.removeEventListener(Event.ENTER_ FRAME,mailCmc);
}
}
}
}
function mail4(){
maild_mc.addEventListener(Event.ENTER_FRAME, mailDmc);
function mailDmc(e){
maild_mc.visible=true;
if(maild_mc.y<344){
maild_mc.y+=vy;
if(maild_mc.y>=159&&maild_mc.y<182){
detectLnght.visible=true;
lnghtD.visible=true;
lnghtA.visible=false;
lnghtB.visible=false;
lnghtC.visible=false;
}else{
detectLnght.visible=false;
}
}else if(maild_mc.x<315){
maild_mc.x+=vx;
if(maild_mc.x>312){
maild_mc.visible=false;
maild_mc.x=215;
maild_mc.y=125;
maild_mc.removeEventListener(Event.ENTER_ FRAME,mailDmc);
}
}
}
}
function mail5(){
maile_mc.addEventListener(Event.ENTER_FRAME, mailEmc);
function mailEmc(e){
maile_mc.visible=true;
if(maile_mc.y<386){
maile_mc.y+=vy+.1;
if(maile_mc.y>=159&&maile_mc.y<182){
detectLnght.visible=true;
lnghtE.visible=true;
lnghtA.visible=false;
lnghtB.visible=false;
lnghtC.visible=false;
}else{
detectLnght.visible=false;
}
}else if(maile_mc.x<315){
maile_mc.x+=vx+.1;
if(maile_mc.x>312){
maile_mc.visible=false;
maile_mc.x=215;
maile_mc.y=125;
maile_mc.removeEventListener(Event.ENTER_ FRAME,mailEmc);
}
}
}}
.
TP29;TP311.11
A
1673-260X(2014)08-0020-03