home *** CD-ROM | disk | FTP | other *** search
/ Master Technician / MASTER_TECHNICIAN.ISO / mtech / library / online / hardware / comtest / comtest.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-22  |  15.6 KB  |  758 lines

  1. //------------------------------------------
  2. //    COMTEST - Communication Tester
  3. // v2.0
  4. // 8/12/93
  5. // by Bert Whetstone
  6. //------------------------------------------
  7.  
  8. #define Uses_TEditor
  9. #define Uses_TSItem
  10. #define Uses_TInputLine
  11. #define Uses_TLabel
  12. #define Uses_TStringCollection
  13. #define Uses_TScrollBar
  14. #define Uses_TSortedListBox
  15. #define Uses_TKeys
  16. #define Uses_TApplication
  17. #define Uses_TEvent
  18. #define Uses_TRect
  19. #define Uses_TDialog
  20. #define Uses_TStaticText
  21. #define Uses_TButton
  22. #define Uses_TMenuBar
  23. #define Uses_TSubMenu
  24. #define Uses_TMenuItem
  25. #define Uses_TScreen
  26. #define Uses_TStatusLine
  27. #define Uses_TStatusItem
  28. #define Uses_TStatusDef
  29. #define Uses_TDeskTop
  30. #define Uses_MsgBox
  31.  
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. #include <dos.h>
  35. #include <bios.h>
  36. #include <ctype.h>
  37. #include <string.h>
  38. #include <iostream.h>
  39. #include <fstream.h>
  40. #include <tv.h>
  41. #include "gadgets.h"
  42. #include "listbox.h"
  43. #include "infoview.h"
  44. #include "getmod.h"
  45.  
  46.  
  47. //---------- GENERAL DEFS ------------
  48. #define DATA_FILE            "COMTEST.TXT"
  49. #define INFOVIEW_WIDTH    79
  50. #define MAX_DATA_SIZE    200
  51.  
  52.  
  53. //---------- COM DEFS ------------
  54. #define COM_ERROR_MASK    0x8e00
  55. #define COM1        0
  56. #define COM2        1
  57. #define COM3        2
  58. #define COM4        3
  59.  
  60.  
  61. //---------- CONTROL ID DEFS -------------
  62. enum buttonID {ID_ABOUT_BUTTON=101,
  63.                     ID_AUTOSEND_BUTTON,
  64.                     ID_BAUD1200_BUTTON,
  65.                     ID_BAUD2400_BUTTON,
  66.                     ID_BAUD4800_BUTTON,
  67.                     ID_BAUD9600_BUTTON,
  68.                     ID_CLEAR_BUTTON,
  69.                     ID_COM1_BUTTON,
  70.                     ID_COM2_BUTTON,
  71.                     ID_COM3_BUTTON,
  72.                     ID_COM4_BUTTON,
  73.                     ID_QUIT_BUTTON,
  74.                     ID_RESET_BUTTON,
  75.                     ID_SCREENHEIGHT_BUTTON,
  76.                     ID_SEND_BUTTON,
  77.                     ID_TILE_BUTTON};
  78.  
  79.  
  80. //------------- PUBLIC DATA -------------
  81.     Boolean handler_installed=False;
  82. char main_title[]="ComTest v2.0";
  83. char    *recv_buff;
  84. int    recv_buff_count=0;
  85. int    com_port=COM1;
  86. int    baud_rate=_COM_1200;
  87. unsigned long xmit_count,recv_count;
  88. unsigned int recv_errors;
  89. TClockView    *clock;
  90. InfoView        *info_view;
  91. TEditor        *recv_editor;
  92.  
  93. char MyPalette[32]={0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,
  94.                             0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,
  95.                             0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,
  96.                             0x3E,0x3F};
  97.  
  98.  
  99. //------------ PUBLIC PROTOTYPES -------------
  100. void SetupCom();
  101. void Transmit(char *buff);
  102.  
  103.  
  104. //-------------- AUTOSEND DIALOG TRANSFER STRUCT ------------------
  105. typedef struct TransferStruct {
  106.                                             char count[6];
  107.                                             char from[6];
  108.                                             char to[6];
  109.                                         } TransferStruct;
  110.  
  111.  
  112. //-------------- XMIT WINDOW CLASS DECLARATION ------------------
  113. class XmitWindow : public TWindow
  114. {
  115.     int auto_count,auto_from,auto_to;
  116.     TScrollBar    *scroll_bar;
  117.     ListBox        *data_listbox;
  118.  
  119. public:
  120.     XmitWindow(const TRect& r,const char *Title);
  121.     ~XmitWindow();
  122.     void IdleAction();
  123.  
  124. private:
  125.     TPalette& getPalette() const;
  126.     void handleEvent(TEvent& event);
  127.     void LoadData();
  128.     void SendData();
  129.     void SetupAutoSend();
  130.     void sizeLimits(TPoint &min,TPoint &max);
  131. };
  132.  
  133.  
  134. //-------------- RECV WINDOW CLASS DECLARATION ------------------
  135. class RecvWindow : public TWindow
  136. {
  137. public:
  138.     RecvWindow(const TRect& r,const char *Title);
  139.     volatile static void CheckRecv(void);
  140.  
  141. private:
  142.     void sizeLimits(TPoint &min,TPoint &max);
  143. };
  144.  
  145.  
  146. //-------------- APPLICATION CLASS DECLARATION ----------------
  147. class TestApp : public TApplication
  148. {
  149.     XmitWindow    *xmit_win;
  150.     RecvWindow    *recv_win;
  151.  
  152. public:
  153.     TestApp::TestApp();
  154.     static TMenuBar *initMenuBar(TRect);
  155.     static TStatusLine *initStatusLine(TRect);
  156.  
  157. private:
  158.     void About();
  159.     void handleEvent(TEvent& event);
  160.     void idle();
  161.     void ScreenHeight();
  162.     void Tile();
  163. };
  164.  
  165.  
  166.  
  167. //-----------------------------------------------
  168. //            XMIT WINDOW FUNCTION DEFINITIONS
  169. //-----------------------------------------------
  170. XmitWindow::XmitWindow(const TRect& Bounds,const char *Title) :
  171.                                 TWindow(Bounds,Title,0),TWindowInit(&XmitWindow::initFrame)
  172. {
  173.     TRect r=getExtent();
  174.     r.b.x-=2;
  175.     r.b.y--;
  176.     options|=ofTileable;
  177.     flags=wfMove | wfGrow | wfZoom;
  178.  
  179.     auto_count=0;
  180.     auto_from=0;
  181.     auto_to=0;
  182.     scroll_bar=new TScrollBar(TRect(r.b.x-1,3,r.b.x,r.b.y));
  183.     data_listbox=new ListBox(TRect(2,3,r.b.x-1,r.b.y),1,scroll_bar);
  184.     data_listbox->newList(new TStringCollection(50,10));
  185.  
  186.     data_listbox->growMode|=gfGrowHiX | gfGrowHiY;
  187.     LoadData();
  188.  
  189.     insert(new TButton(TRect(2,1,12,3),"~A~uto",ID_AUTOSEND_BUTTON,bfNormal));
  190.     insert(new TButton(TRect(14,1,24,3),"~S~end",ID_SEND_BUTTON,bfDefault));
  191.     insert(new TButton(TRect(26,1,36,3),"~R~eset",ID_RESET_BUTTON,bfNormal));
  192.     insert(new TButton(TRect(38,1,48,3),"~Q~uit",cmQuit,bfNormal));
  193.     insert(scroll_bar);
  194.     insert(data_listbox);
  195.     SetupCom();
  196. }
  197.  
  198.  
  199. XmitWindow::~XmitWindow()
  200. {
  201.     if(handler_installed)
  202.         sp_uninstall();
  203. }
  204.  
  205.  
  206. TPalette& XmitWindow::getPalette() const
  207. {
  208. static TPalette palette(MyPalette,sizeof(MyPalette)-1);
  209.  
  210.     return palette;
  211. }
  212.  
  213.  
  214. void XmitWindow::handleEvent(TEvent& event)
  215. {
  216. ushort t;
  217.  
  218.     TWindow::handleEvent(event);
  219.     switch(event.what)
  220.     {
  221.         case evCommand:
  222.             switch(event.message.command)
  223.             {
  224.                 case ID_AUTOSEND_BUTTON:
  225.                     SetupAutoSend();
  226.                     break;
  227.  
  228.                 case ID_RESET_BUTTON:
  229.                     SetupCom();
  230.                     break;
  231.  
  232.                 case ID_SEND_BUTTON:
  233.                     SendData();
  234.                     break;
  235.  
  236.                 default:
  237.                     return;
  238.             }
  239.             break;
  240.  
  241.         case evKeyDown:
  242.             switch(event.keyDown.keyCode)
  243.             {
  244.                 case kbEnter:
  245.                     SendData();
  246.                     break;
  247.  
  248.                 default:
  249.                     return;
  250.             }
  251.             break;
  252.  
  253.         case evBroadcast:
  254.             switch(event.message.command)
  255.             {
  256.                 case cmListItemSelected:
  257.                     SendData();
  258.                     break;
  259.  
  260.                 default:
  261.                     return;
  262.             }
  263.             break;
  264.  
  265.         default:
  266.             return;
  267.     }
  268.  
  269.     data_listbox->select();
  270.     clearEvent(event);
  271. }
  272.  
  273.  
  274. void XmitWindow::IdleAction()
  275. {
  276.     if(!auto_count)
  277.         return;
  278.  
  279.     auto_count--;
  280.     data_listbox->focusItem(auto_from+random(auto_to-auto_from));
  281.     SendData();
  282. }
  283.  
  284.  
  285. void XmitWindow::LoadData()
  286. {
  287. static char    buff[MAX_DATA_SIZE];
  288. char    *temp;
  289.  
  290.     ifstream fp(DATA_FILE,ios::binary);
  291.     if(!fp)
  292.         return;
  293.  
  294.     while(1)
  295.     {
  296.         fp.getline(buff,sizeof(buff)-2);
  297.         if(fp.eof())
  298.             break;
  299.  
  300.         strcat(buff,"\n");
  301.         temp=new char[strlen(buff)+1];
  302.         if(!temp)
  303.             break;
  304.  
  305.         strcpy(temp,buff);
  306.         data_listbox->insert(temp);
  307.     }
  308.  
  309.     auto_to=data_listbox->range;
  310. }
  311.  
  312.  
  313. void XmitWindow::SendData()
  314. {
  315. static char    buff[MAX_DATA_SIZE];
  316.  
  317.     data_listbox->getText(buff,data_listbox->focused,sizeof(buff));
  318.     Transmit(buff);
  319. }
  320.  
  321.  
  322. void XmitWindow::SetupAutoSend()
  323. {
  324. int    t;
  325. TDialog         *dlg;
  326. TInputLine    *count_input,*from_input,*to_input;
  327. TransferStruct ts;
  328.  
  329.     dlg=new TDialog(TRect(0,0,27,12),"Auto Send Options");
  330.     if(!dlg)
  331.         return;
  332.  
  333.     itoa(auto_count,ts.count,10);
  334.     itoa(auto_from,ts.from,10);
  335.     itoa(auto_to,ts.to,10);
  336.  
  337.     count_input=new TInputLine(TRect(10,2,18,3),sizeof(ts.count));
  338.     from_input=new TInputLine(TRect(10,4,18,5),sizeof(ts.from));
  339.     to_input=new TInputLine(TRect(10,6,18,7),sizeof(ts.to));
  340.  
  341.     dlg->options|=ofCentered;
  342.     dlg->insert(count_input);
  343.     dlg->insert(new TLabel(TRect(3,2,9,3),"~C~ount",count_input));
  344.     dlg->insert(from_input);
  345.     dlg->insert(new TLabel(TRect(3,4,9,5),"~F~rom",from_input));
  346.     dlg->insert(to_input);
  347.     dlg->insert(new TLabel(TRect(3,6,9,7),"~T~o",to_input));
  348.     dlg->insert(new TButton(TRect(2,9,12,11),"~O~k",cmOK,bfDefault));
  349.     dlg->insert(new TButton(TRect(14,9,24,11),"~C~ancel",cmCancel,bfNormal));
  350.     count_input->select();
  351.  
  352.     dlg->setData(&ts);
  353.  
  354.     if(TProgram::deskTop->execView(dlg)==cmCancel)
  355.         return;
  356.  
  357.     dlg->getData(&ts);
  358.     destroy(dlg);
  359.  
  360.     auto_count=atoi(ts.count);
  361.     auto_from=atoi(ts.from);
  362.     auto_to=atoi(ts.to);
  363.  
  364.     if(auto_to<auto_from)
  365.     {
  366.         t=auto_to;
  367.         auto_to=auto_from;
  368.         auto_from=t;
  369.     }
  370.  
  371.     if(auto_to>data_listbox->range)
  372.         auto_to=data_listbox->range;
  373. }
  374.  
  375.  
  376. void XmitWindow::sizeLimits(TPoint &min,TPoint &max)
  377. {
  378.     TWindow::sizeLimits(min,max);
  379.     min.x=37;
  380.     min.y=7;
  381. }
  382.  
  383.  
  384.  
  385. //-----------------------------------------------
  386. //            RECV WINDOW FUNCTION DEFINITIONS
  387. //-----------------------------------------------
  388. RecvWindow::RecvWindow(const TRect& Bounds,const char *Title) :
  389.                                 TWindow(Bounds,Title,0),TWindowInit(&XmitWindow::initFrame)
  390. {
  391. TScrollBar    *h_scroll_bar;
  392. TScrollBar    *v_scroll_bar;
  393.  
  394.     options|=ofTileable;
  395.     flags=wfMove | wfGrow | wfZoom;
  396.  
  397.     TRect r=getExtent();
  398.     r.b.x--;
  399.     r.b.y-=2;
  400.     r.a.x++;
  401.     r.a.y++;
  402.     h_scroll_bar=new TScrollBar(TRect(r.a.x,r.b.y,r.b.x-1,r.b.y+1));
  403.     v_scroll_bar=new TScrollBar(TRect(r.b.x-1,r.a.y,r.b.x,r.b.y));
  404.  
  405.     r.b.x--;
  406.     recv_editor=new TEditor(r,h_scroll_bar,v_scroll_bar,NULL,10240);
  407.     recv_editor->eventMask&=~(evKeyboard | evMouseDown);
  408.  
  409.     insert(h_scroll_bar);
  410.     insert(v_scroll_bar);
  411.     insert(recv_editor);
  412. }
  413.  
  414.  
  415. void RecvWindow::CheckRecv(void)
  416. {
  417.     recv_buff[recv_buff_count]=get_byte();
  418.     recv_buff_count++;
  419. }
  420.  
  421.  
  422. void RecvWindow::sizeLimits(TPoint &min,TPoint &max)
  423. {
  424.     TWindow::sizeLimits(min,max);
  425.     min.x=37;
  426.     min.y=7;
  427. }
  428.  
  429.  
  430.  
  431. //-----------------------------------------------
  432. //            APPLICATION FUNCTION DEFINITIONS
  433. //-----------------------------------------------
  434. TestApp::TestApp() : TProgInit(&TestApp::initStatusLine,
  435.                                             &TestApp::initMenuBar,
  436.                                             &TestApp::initDeskTop)
  437. {
  438. TRect r=getExtent();
  439.  
  440.     r.a.x=r.b.x-9;
  441.     r.b.y=r.a.y+1;
  442.     clock=new TClockView(r);    //Create the clock view.
  443.     insert(clock);
  444.  
  445.     r=getExtent();
  446.     r.a.x=r.b.x-INFOVIEW_WIDTH;
  447.     r.a.y=r.b.y-1;
  448.     info_view=new InfoView(r);    //Create the InfoView.
  449.     insert(info_view);
  450.  
  451.     xmit_win=new XmitWindow(TRect(0,0,TDisplay::getCols(),TDisplay::getRows()),
  452.                                     "Transmission Window");
  453.     recv_win=new RecvWindow(TRect(0,0,TDisplay::getCols(),TDisplay::getRows()),
  454.                                     "Receive Window");
  455.  
  456.     deskTop->insert(recv_win);
  457.     deskTop->insert(xmit_win);
  458.  
  459.     r=getExtent();
  460.     r.b.y-=2;
  461.     deskTop->tile(r);
  462. }
  463.  
  464.  
  465. void TestApp::About()
  466. {
  467. char    buff[200];
  468. TDialog *pd;
  469.  
  470.     pd=new TDialog(TRect(0,0,35,12),"About ComTest");
  471.     if(pd)
  472.     {
  473.         sprintf(buff,"\003%s\n\003Communication Tester\n\003by Bert Whetstone\n\0031993",main_title);
  474.         pd->options|=ofCentered;
  475.         pd->insert(new TStaticText(TRect(1,2,34,7),buff));
  476.         pd->insert(new TButton(TRect(3,9,32,11),"~O~k",cmOK,bfDefault));
  477.         deskTop->execView(pd);
  478.     }
  479.  
  480.     destroy(pd);
  481. }
  482.  
  483.  
  484. void TestApp::handleEvent(TEvent& event)
  485. {
  486. ushort t;
  487.  
  488.     TApplication::handleEvent(event);
  489.     if(event.what==evCommand)
  490.     {
  491.         switch(event.message.command)
  492.         {
  493.             case ID_CLEAR_BUTTON:
  494.                 recv_editor->deleteRange(0,recv_editor->bufLen,False);
  495.                 recv_editor->scrollTo(0,0);
  496.                 break;
  497.  
  498.             case ID_ABOUT_BUTTON:
  499.                 About();
  500.                 break;
  501.  
  502.             case ID_BAUD1200_BUTTON:
  503.                 baud_rate=_COM_1200;
  504.                 SetupCom();
  505.                 break;
  506.  
  507.             case ID_BAUD2400_BUTTON:
  508.                 baud_rate=_COM_2400;
  509.                 SetupCom();
  510.                 break;
  511.  
  512.             case ID_BAUD4800_BUTTON:
  513.                 baud_rate=_COM_4800;
  514.                 SetupCom();
  515.                 break;
  516.  
  517.             case ID_BAUD9600_BUTTON:
  518.                 baud_rate=_COM_9600;
  519.                 SetupCom();
  520.                 break;
  521.  
  522.             case ID_COM1_BUTTON:
  523.                 com_port=COM1;
  524.                 SetupCom();
  525.                 break;
  526.  
  527.             case ID_COM2_BUTTON:
  528.                 com_port=COM2;
  529.                 SetupCom();
  530.                 break;
  531.  
  532.             case ID_COM3_BUTTON:
  533.                 com_port=COM3;
  534.                 SetupCom();
  535.                 break;
  536.  
  537.             case ID_COM4_BUTTON:
  538.                 com_port=COM4;
  539.                 SetupCom();
  540.                 break;
  541.  
  542.             case ID_SCREENHEIGHT_BUTTON:
  543.                 ScreenHeight();
  544.                 break;
  545.  
  546.             case ID_TILE_BUTTON:
  547.                 Tile();
  548.                 break;
  549.  
  550.             default:
  551.                 return;
  552.         }
  553.  
  554.         clearEvent(event);
  555.     }
  556. }
  557.  
  558.  
  559. void TestApp::idle()
  560. {
  561. int    x;
  562.  
  563.     TProgram::idle();
  564.     clock->update();
  565.  
  566.     while(recv_buff_count)
  567.     {
  568.         x=recv_buff_count;
  569.         recv_buff_count=0;
  570.  
  571.         if((recv_editor->bufLen+x)>=recv_editor->bufSize)
  572.             recv_editor->deleteRange(0,x,False);
  573.  
  574.         recv_editor->insertText(recv_buff,x,False);
  575.         recv_editor->scrollTo(0,recv_editor->curPos.y);
  576.         recv_count+=x;
  577.     }
  578.  
  579.     info_view->update();
  580.     xmit_win->IdleAction();
  581. }
  582.  
  583.  
  584. TMenuBar *TestApp::initMenuBar(TRect r)
  585. {
  586.     r.b.y=r.a.y+1;
  587.     TSubMenu& sys_menu=*new TSubMenu("~F~ile",kbAltF)+
  588.                                 *new TMenuItem("~A~bout",    ID_ABOUT_BUTTON,            kbAltA)+
  589.                                 *new TMenuItem("~H~eight",    ID_SCREENHEIGHT_BUTTON,    kbAltH)+
  590.                                 newLine()+
  591.                                 *new TMenuItem("~Q~uit",cmQuit,kbAltX);
  592.  
  593.     TSubMenu& baud_menu=*new TSubMenu("~B~aud",kbAltB)+
  594.                                 *new TMenuItem("~1~200",ID_BAUD1200_BUTTON,kbAltF1,hcNoContext,"AltF1")+
  595.                                 *new TMenuItem("~2~400",ID_BAUD2400_BUTTON,kbAltF2,hcNoContext,"AltF2")+
  596.                                 *new TMenuItem("~4~800",ID_BAUD4800_BUTTON,kbAltF3,hcNoContext,"AltF3")+
  597.                                 *new TMenuItem("~9~600",ID_BAUD9600_BUTTON,kbAltF4,hcNoContext,"AltF4");
  598.  
  599.     TSubMenu& com_menu=*new TSubMenu("~C~OM Port",kbAltC)+
  600.                                 *new TMenuItem("COM ~1~",ID_COM1_BUTTON,kbAltF5,hcNoContext,"AltF5")+
  601.                                 *new TMenuItem("COM ~2~",ID_COM2_BUTTON,kbAltF6,hcNoContext,"AltF6")+
  602.                                 *new TMenuItem("COM ~3~",ID_COM3_BUTTON,kbAltF7,hcNoContext,"AltF7")+
  603.                                 *new TMenuItem("COM ~4~",ID_COM4_BUTTON,kbAltF8,hcNoContext,"AltF8")+
  604.                                 newLine()+
  605.                                 *new TMenuItem("~R~eset",ID_RESET_BUTTON,(ushort)0);
  606.  
  607.     TSubMenu& recv_menu=*new TSubMenu("~R~eceiver",kbAltR)+
  608.                                 *new TMenuItem("~C~lear",ID_CLEAR_BUTTON,(ushort)0);
  609.  
  610.     TSubMenu& xmit_menu=*new TSubMenu("~T~ransmitter",kbAltT)+
  611.                                 *new TMenuItem("~A~uto Send",ID_AUTOSEND_BUTTON,(ushort)0);
  612.  
  613.     TSubMenu& window_menu=*new TSubMenu("~W~indow",kbAltW)+
  614.                                 *new TMenuItem("~N~ext",        cmNext,    kbF6,        hcNoContext,"F6")+
  615.                                 *new TMenuItem("~P~revious",    cmPrev,    kbShiftF6,hcNoContext,"ShiftF6")+
  616.                                 *new TMenuItem("~S~ize/Move",    cmResize,kbCtrlF5,hcNoContext,"CtrlF5")+
  617.                                 *new TMenuItem("~T~ile",ID_TILE_BUTTON,kbAltT,    hcNoContext,"AltT")+
  618.                                 *new TMenuItem("~Z~oom",        cmZoom,    kbF5,        hcNoContext,"F5");
  619.  
  620.     TSubMenu& full_menu=sys_menu+baud_menu+com_menu+recv_menu+xmit_menu+window_menu;
  621.     return new TMenuBar(r,full_menu);
  622. }
  623.  
  624.  
  625. TStatusLine *TestApp::initStatusLine(TRect r)
  626. {
  627.     r.a.y=r.b.y-1;
  628.     return new TStatusLine(r,*new TStatusDef(0,0xFFFF));
  629. }
  630.  
  631.  
  632. void TestApp::ScreenHeight()
  633. {
  634.     info_view->hide();
  635.     setScreenMode(TScreen::screenMode^TDisplay::smFont8x8);
  636.     Tile();
  637.     TRect r=getExtent();
  638.     info_view->moveTo(r.b.x-INFOVIEW_WIDTH,r.b.y-1);
  639.     info_view->show();
  640. }
  641.  
  642.  
  643. void TestApp::Tile()
  644. {
  645.     TRect r=getExtent();
  646.     r.b.y-=2;
  647.     deskTop->tile(r);
  648. }
  649.  
  650.  
  651.  
  652. //-----------------------------------
  653. //            PROGRAM STARTS HERE
  654. //-----------------------------------
  655. int main(int argc,char *argv[])
  656. {
  657.     if(argc>1)
  658.         com_port=atoi(argv[1]);
  659.  
  660.     if(argc>3)
  661.     {
  662.         switch(atoi(argv[2]))
  663.         {
  664.             case 1200:
  665.                 baud_rate=_COM_1200;
  666.                 break;
  667.  
  668.             case 2400:
  669.                 baud_rate=_COM_2400;
  670.                 break;
  671.  
  672.             case 4800:
  673.                 baud_rate=_COM_4800;
  674.                 break;
  675.  
  676.             case 9600:
  677.                 baud_rate=_COM_9600;
  678.                 break;
  679.  
  680.             default:
  681.                 printf("\nInvalid baud rate!\nUse 1200,2400,4800, or 9600");
  682.                 return 0;
  683.         }
  684.     }
  685.  
  686.     recv_buff=(char *)malloc(5*1024);
  687.     if(!recv_buff)
  688.     {
  689.         printf("\nUnable to allocate buffer memory!");
  690.         return 0;
  691.     }
  692.  
  693.     TestApp comtest;
  694.     TScreen::checkSnow=False;
  695.     comtest.run();
  696.     return 0;
  697. }
  698.  
  699.  
  700. void ComError(char *mess,int x)
  701. {
  702. char    buff[30];
  703.  
  704.     buff[0]=0;
  705.     if(x & 0x0800)
  706.         strcat(buff,"Frame ");
  707.  
  708.     if(x & 0x0400)
  709.         strcat(buff,"Parity ");
  710.  
  711.     if(x & 0x0200)
  712.         strcat(buff,"Overrun ");
  713.  
  714.     if(x & 0x8000)
  715.         strcat(buff,"Timeout");
  716.  
  717.     messageBox(mfError | mfOKButton,"\003%s - %x\n\003%s",mess,x,buff);
  718. }
  719.  
  720.  
  721. void SetupCom()
  722. {
  723. unsigned int    x;
  724.  
  725.     if(handler_installed)
  726.         sp_uninstall();
  727.  
  728.     x=bioscom(_COM_INIT,_COM_CHR8 | _COM_STOP1 | _COM_NOPARITY | baud_rate,com_port);
  729.     if(x & COM_ERROR_MASK)
  730.         ComError("Initialization Error",x);
  731.  
  732.     sp_install(RecvWindow::CheckRecv,com_port);
  733.     handler_installed=True;
  734.     info_view->update();
  735. }
  736.  
  737.  
  738. void Transmit(char *buff)
  739. {
  740. unsigned int    x;
  741.  
  742.     while(*buff)
  743.     {
  744.         x=send_byte(*buff++);
  745.         if(x & COM_ERROR_MASK)
  746.         {
  747.             ComError("Transmission Error",x);
  748.             break;
  749.         }
  750.  
  751.         xmit_count++;
  752.     }
  753.  
  754.     info_view->update();
  755. }
  756.  
  757.  
  758.