⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utils.c

📁 功能丰富的串口通讯程序
💻 C
📖 第 1 页 / 共 3 页
字号:
 switch(Baud){ case 300: Menu->Focus = 0; break; case 600: Menu->Focus = 1; break; case 1200: Menu->Focus = 2; break; case 2400: Menu->Focus = 3; break; case 4800: Menu->Focus = 4; break; case 9600: Menu->Focus = 5; break; case 19200: Menu->Focus = 6; break; case 38400: Menu->Focus = 7; break; case 57600: Menu->Focus = 8; break; case 115200: Menu->Focus = 9; break; case 230400: Menu->Focus = 10; break; default:break; } if ((Menu->Focus == 1 || Menu->Focus == 2) && WhichBook == 1) Menu->Focus = 3; Menu->Show(); wrefresh(Window); Key = 0; while (Key != '\n' && Key != '\e'){  Key = getEscChar();  Menu->GetInput(Key); } if (Key == '\n'){   if ((Menu->Focus == 1 || Menu->Focus == 2) && WhichBook == 1) Menu->Focus = 3;   switch(Menu->Focus){   case 0: Baud = 300; break;   case 1: Baud = 600; break;   case 2: Baud = 1200; break;   case 3: Baud = 2400; break;   case 4: Baud = 4800; break;   case 5: Baud = 9600; break;   case 6: Baud = 19200; break;   case 7: Baud = 38400; break;   case 8: Baud = 57600; break;   case 9: Baud = 115200; break;   case 10: Baud = 230400; break;   default:break; } }  delete Menu; delete Win;  Window->_attrs = Attr; wmove(Window, y, x); return Baud;}int ChooseParity(WINDOW *Window, char Parity){ int Key, Which, Center, y, x, Attr; tWindow *Win; tMenu *Menu;  Attr = Window->_attrs; getyx(Window, y, x); Which = 0; Center = findCenter(0, COLS, 13);  Win = new tWindow(Window, Center, (LINES-1)/2-1, Center+13+1,(LINES-1)/2+3, Integers[cMenu] >> 4,            Integers[cMenu] % 16); Win->Frame(1, Integers[cMenu]); Win->Headline("Choose parity", Integers[cMenuTitle]); Menu = new tMenu(Window, Integers[cMenu], Integers[cMenuHot], Integers[cMenuBar], Integers[cMenuText],  ALIGNMID); Menu->Add("~N~one", Center+1, Center+13+1, (LINES-1)/2); Menu->Add("~O~dd ", Center+1, Center+13+1, (LINES-1)/2+1); Menu->Add("~E~ven", Center+1, Center+13+1, (LINES-1)/2+2); switch(Parity){ case 'N':   Parity = 0;   break; case 'O':   Parity = 1;   break; case 'E':   Parity = 2;   break; default:break; } Menu->Focus = Parity; Menu->Show(); wrefresh(Window); Key = 0; while (Key != '\n'){  Key = getEscChar();  Menu->GetInput(Key);  wrefresh(Window); }  Which = Menu->Focus;  delete Menu; delete Win;  wmove(Window, y, x); Window->_attrs = Attr;  switch(Which){ case 0:   Which = 'N';   break; case 1:   Which = 'O';   break; case 2:   Which = 'E';   break; default:break; }  return Which; }int ChooseDatabits(WINDOW *Window, char Databit){ int Key, Which, Center, y, x, Attr; tWindow *Win; tMenu *Menu;  Attr = Window->_attrs; getyx(Window, y, x); Which = 0; Center = findCenter(0, COLS, 17);  Win = new tWindow(Window, Center, (LINES-1)/2-1, Center+17+1,(LINES-1)/2+2, Integers[cMenu] >> 4,            Integers[cMenu] % 16); Win->Frame(1, Integers[cMenu]); Win->Headline("Choose databits", Integers[cMenuTitle]); Menu = new tMenu(Window, Integers[cMenu], Integers[cMenuHot], Integers[cMenuBar], Integers[cMenuText],  ALIGNMID); Menu->Add("~7~", Center+1, Center+17+1, (LINES-1)/2); Menu->Add("~8~", Center+1, Center+17+1, (LINES-1)/2+1); Menu->Focus = Databit-7; Menu->Show(); wrefresh(Window); Key = 0; while (Key != '\n'){  Key = getEscChar();  Menu->GetInput(Key);  wrefresh(Window); }  Which = Menu->Focus+7;  delete Menu; delete Win;  wmove(Window, y, x); Window->_attrs = Attr;  return Which; }int ChooseStopbits(WINDOW *Window, char Stopbit){ int Key, Which, Center, y, x, Attr; tWindow *Win; tMenu *Menu;  Attr = Window->_attrs; getyx(Window, y, x); Which = 0; Center = findCenter(0, COLS, 17);  Win = new tWindow(Window, Center, (LINES-1)/2-1, Center+17+1,(LINES-1)/2+2, Integers[cMenu] >> 4,            Integers[cMenu] % 16); Win->Frame(1, Integers[cMenu]); Win->Headline("Choose stopbits", Integers[cMenuTitle]); Menu = new tMenu(Window, Integers[cMenu], Integers[cMenuHot], Integers[cMenuBar], Integers[cMenuText],  ALIGNMID); Menu->Add("~1~", Center+1, Center+17+1, (LINES-1)/2); Menu->Add("~2~", Center+1, Center+17+1, (LINES-1)/2+1); Menu->Focus = Stopbit; Menu->Show(); wrefresh(Window); Key = 0; while (Key != '\n'){  Key = getEscChar();  Menu->GetInput(Key);  wrefresh(Window); }  Which = Menu->Focus;  delete Menu; delete Win;  wmove(Window, y, x); Window->_attrs = Attr; return Which; }int ChooseFlow(WINDOW *Window, char Flow){ int Key, Which, Center, y, x, Attr; tWindow *Win; tMenu *Menu;  Attr = Window->_attrs; getyx(Window, y, x); Which = 0; Center = findCenter(0, COLS, 23);  Win = new tWindow(Window, Center, (LINES-1)/2-1, Center+23+1,(LINES-1)/2+2, Integers[cMenu] >> 4,            Integers[cMenu] % 16); Win->Frame(1, Integers[cMenu]); Win->Headline("Choose flow control", Integers[cMenuTitle]); Menu = new tMenu(Window, Integers[cMenu], Integers[cMenuHot], Integers[cMenuBar], Integers[cMenuText],  ALIGNLEFT); Menu->Add("[ ] ~H~ardware (CTS/RTS)", Center+1, Center+23+1, (LINES-1)/2); Menu->Add("[ ] ~S~oftware (XON/XOFF)", Center+1, Center+23+1, (LINES-1)/2+1); if (Flow & 1) *(((menuItem *)(Menu->Base))->Text+1) = 'x'; if (Flow & 2) *(((menuItem *)(Menu->Base->Next))->Text+1) = 'x'; Menu->Focus = 0; Menu->Show(); wrefresh(Window); Key = 0; while (Key != '\n'){  Key = getEscChar();  Menu->GetInput(Key);  if (Key == ' ') {   Flow ^= Menu->Focus+1;   if (Flow & 1) *(((menuItem *)(Menu->Base))->Text+1) = 'x';   else *(((menuItem *)(Menu->Base))->Text+1) = ' ';   if (Flow & 2) *(((menuItem *)(Menu->Base->Next))->Text+1) = 'x';   else *(((menuItem *)(Menu->Base->Next))->Text+1) = ' ';   Menu->Show();  }  wrefresh(Window); }  Which = Flow;  delete Menu; delete Win;  wmove(Window, y, x); Window->_attrs = Attr; return Which; }int ChooseYesno(WINDOW *Window, char *Headline){ int Key, Which, Center, y, x, Attr; tWindow *Win; tMenu *Menu;  Attr = Window->_attrs; getyx(Window, y, x); Which = 0; Center = findCenter(0, COLS, strlen(Headline));  Win = new tWindow(Window, Center, (LINES-1)/2-1, Center+strlen(Headline)+1,(LINES-1)/2+2, Integers[cMenu] >> 4,            Integers[cMenu] % 16); Win->Frame(1, Integers[cMenu]); Win->Headline(Headline, Integers[cMenuTitle]); Menu = new tMenu(Window, Integers[cMenu], Integers[cMenuHot], Integers[cMenuBar], Integers[cMenuText],  ALIGNMID); Menu->Add("~Y~es", Center+1, Center+strlen(Headline)+1, (LINES-1)/2); Menu->Add("~N~o", Center+1, Center+strlen(Headline)+1, (LINES-1)/2+1); Menu->Focus = 1; Menu->Show(); wrefresh(Window); Key = 0; while (Key != '\n'){  Key = getEscChar();  if (Menu->GetInput(Key) > 127) Key = '\n';  wrefresh(Window); }  Which = Menu->Focus ^ 1;  delete Menu; delete Win;  wmove(Window, y, x); Window->_attrs = Attr; return Which; }int ChooseUser(WINDOW *Window){ int Key, i; tWindow *Win; char Temp[256]; tMenu *Menu; menuItem *Tmp; Win = new tWindow(Window, 40,5,70,16, Integers[cMenu] >> 4, Integers[cMenu] % 16); Win->Frame(1, Integers[cMenu]); Win->Headline("Choose user, E - edits", Integers[cMenuTitle]);  Menu = new tMenu(Window, Integers[cMenu], Integers[cMenuHot], Integers[cMenuBar], Integers[cMenuText], ALIGNLEFT); for (i=0;i<10;i++) {  if (strlen(Strings[User1+i])<28)  {   Menu->Add(Strings[User1+i], 41, 70, 6+i);  }  else  {   strncpy(Temp, Strings[User1+i], 28);   Temp[28] = 0;   Menu->Add(Temp, 41, 70, 6+i);  } } Menu->Show(); wrefresh(Window);  Key = 0; while (Key != '\e' && Key != '\n'){   Key = getEscChar();   if (Key == 'e' || Key == 'E')   {    clearok(Window, TRUE);    if (getstring(Window, 6+Menu->Focus, 41, Strings[User1+Menu->Focus],ValidEdit,"\n\e",29,-1,Temp) == '\n')    {     Strings[User1+Menu->Focus] = (char *)realloc(Strings[User1+Menu->Focus], strlen(Temp)+1);     strcpy(Strings[User1+Menu->Focus], Temp);     Tmp = Menu->Base;     for (i=0;i<Menu->Focus;i++)      Tmp = Tmp->Next;     Tmp->Text = (char *)realloc(Tmp->Text, strlen(Temp)+1);     strcpy(Tmp->Text, Temp);    }    Menu->Show();    wrefresh(Window);   }   Menu->GetInput(Key); }  i = Menu->Focus+1;  delete Menu; delete Win; return i;}int ChoosePrefix(WINDOW *Window, int prefix){ int Key, i, y, x; tWindow *Win; char Temp[256]; tMenu *Menu; menuItem *Tmp; getyx(Window, y ,x); Win = new tWindow(Window, 40,5,70,12, Integers[cMenu] >> 4, Integers[cMenu] % 16); Win->Frame(1, Integers[cMenu]); Win->Headline("Choose prefix, E - edits", Integers[cMenuTitle]);  Menu = new tMenu(Window, Integers[cMenu], Integers[cMenuHot], Integers[cMenuBar], Integers[cMenuText], ALIGNLEFT); for (i=0;i<6;i++) {  if (strlen(Strings[Prefix1+i])<28)  {   Menu->Add(Strings[Prefix1+i], 41, 70, 6+i);  }  else  {   strncpy(Temp, Strings[Prefix1+i], 28);   Temp[28] = 0;   Menu->Add(Temp, 41, 70, 6+i);  } } Menu->Focus = prefix-1; Menu->Show(); wrefresh(Window);  Key = 0; while (Key != '\e' && Key != '\n'){   Key = getEscChar();   if (Key == 'e' || Key == 'E')   {    clearok(Window, TRUE);    if (getstring(Window, 6+Menu->Focus, 41, Strings[Prefix1+Menu->Focus],ValidEdit,"\n\e",29,-1,Temp) == '\n')    {     Strings[Prefix1+Menu->Focus] = (char *)realloc(Strings[Prefix1+Menu->Focus], strlen(Temp)+1);     strcpy(Strings[Prefix1+Menu->Focus], Temp);     Tmp = Menu->Base;     for (i=0;i<Menu->Focus;i++)      Tmp = Tmp->Next;     Tmp->Text = (char *)realloc(Tmp->Text, strlen(Temp)+1);     strcpy(Tmp->Text, Temp);    }    Menu->Show();    wrefresh(Window);   }   Menu->GetInput(Key); }  if (WhichBook == 1) Menu->Focus &= 3; i = Menu->Focus+1;  delete Menu; delete Win;  wmove(Window, y ,x); return i;}int ChooseSuffix(WINDOW *Window, int suffix){ int Key, i, y, x; tWindow *Win; char Temp[256]; tMenu *Menu; menuItem *Tmp; getyx(Window, y, x); Win = new tWindow(Window, 40,5,70,11, Integers[cMenu] >> 4, Integers[cMenu] % 16); Win->Frame(1, Integers[cMenu]); Win->Headline("Choose suffix, E - edits", Integers[cMenuTitle]);  Menu = new tMenu(Window, Integers[cMenu], Integers[cMenuHot], Integers[cMenuBar], Integers[cMenuText], ALIGNLEFT); for (i=0;i<5;i++) {  if (strlen(Strings[Suffix1+i])<28)  {   Menu->Add(Strings[Suffix1+i], 41, 70, 6+i);  }  else  {   strncpy(Temp, Strings[Suffix1+i], 28);   Temp[28] = 0;   Menu->Add(Temp, 41, 70, 6+i);  } } Menu->Focus = suffix-1; Menu->Show(); wrefresh(Window);  Key = 0; while (Key != '\e' && Key != '\n'){   Key = getEscChar();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -