Kamis, 24 April 2014

menu.c

#include <stdio.h>   /* Standard input/output definitions */
#include <string.h>  /* String function definitions */
#include <unistd.h>  /* UNIX standard function definitions */
#include <fcntl.h>   /* File control definitions */
#include <errno.h>   /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */
#include <stdlib.h>
#include <ctype.h>
#include <curses.h>
#include <time.h>

int current_getch;
int doloop = 1,no=1;
static WINDOW *mainwnd;
static WINDOW *screen;
WINDOW *my_win;

char serialport[]="/dev/ttyUSB0";
char pilih,pil,back;
int fd;
int n,w;
int ch,i,b;
char buf[255];

int now_sec, now_min, now_hour, now_day, now_wday, now_month, now_year;
time_t now;
struct tm *now_tm;

void screen_init(void)
{
   mainwnd = initscr();
   noecho();
   cbreak();
   nodelay(mainwnd, TRUE);
   refresh();
   wrefresh(mainwnd);
   screen = newwin(5, 80, 0, 0);
   box(screen, ACS_VLINE, ACS_HLINE);
}

static void update_display(void) {
curs_set(0);
init_pair(2,COLOR_BLUE, COLOR_WHITE);
wbkgd(screen,COLOR_PAIR(2));  
attrset(COLOR_PAIR(1));
attron(A_BOLD);


   mvwprintw(screen,1,15,"TIME: %d:%d:%d", now_hour, now_min, now_sec);
   mvwprintw(screen,2,15,"DATE: %d-%d-%d", now_day, now_month, now_year);
   mvwprintw(screen,1, 1, " LTS 1.4 ");
   attroff(A_BOLD);
   wrefresh(screen);
   refresh();

       
}

void screen_end(void)
{
   endwin();
}

void maketime(void)
    {
        // Get the current date/time
        now = time (NULL);
        now_tm = localtime (&now);
        now_sec = now_tm->tm_sec;
        now_min = now_tm->tm_min;
        now_hour = now_tm->tm_hour;
        now_day = now_tm->tm_mday;
        now_wday = now_tm->tm_wday;
        now_month = now_tm->tm_mon + 1;
        now_year = now_tm->tm_year + 1900;
    }


int main ( int argc, char *argv[] )
{
    if (strcmp(argv[2], "0")==0) strcpy(serialport, "/dev/ttyUSB0");
    if (strcmp(argv[2], "1")==0) strcpy(serialport, "/dev/ttyS1");
    if (strcmp(argv[2], "2")==0) strcpy(serialport, "/dev/ttyUSB0");
    if (strcmp(argv[2], "3")==0) strcpy(serialport, "/dev/ttyS3");


if( argc == 3 ){
if(strcmp(argv[1], "L")==0){
initscr();
start_color();
init_pair(1,COLOR_WHITE, COLOR_BLACK);
bkgd(COLOR_PAIR(1));

//clear ( ); refresh ( );

if(!has_colors()){endwin();fprintf(stderr,"Error- no color support on this terminal\n");exit(1);}
if(start_color() != OK){endwin();fprintf(stderr,"Error- tidak dapat mewarnai\n");exit(2);}
//
LOOP:while(doloop)
{
//start_color();
screen_init();
maketime();
update_display();

 
    mvprintw ( 6, 1, " 1. Test Komunikasi Lts ");
mvprintw ( 7, 1, " 2. Test Firmware Lts");        
    mvprintw ( 8, 1, " 3. Test VCD");
mvprintw ( 9, 1, " 4. Test LLA");
mvprintw ( 10, 1, " 5. Test VIA");
mvprintw ( 11, 1, " 6. Test LLB");      
mvprintw ( 12, 1, " 7. Test LCB");
mvprintw ( 13, 1, " 8. Runing LED Indikator TCT ");
mvprintw ( 14, 1, " 9. LVD");

mvprintw ( 15, 1, " q. EXIT ");

    noecho ( ); pilih=getch( ); echo ( );

       if (pilih=='1')
        {
  clear (); refresh ();
  screen_init();
 
 
while(1){clear();
usleep(200000);
screen_init();
maketime();
update_display();
mainwnd;
mvprintw ( 13, 1, " q. Back << ");
refresh ( );
wrefresh(mainwnd);
refresh ();
open_serial();

w=write(fd,"\x36",1);
//usleep(200000);
n=read(fd, &buf, sizeof (buf));
buf[n]=0;

if (n == -1)
{
mvprintw(16,1, "open_port: Unable to open /dev/ttyUSB0 - ");
}

if(n == 1){mvprintw(16,1, "open_port: Open /dev/ttyUSB0 - ");}


if (getch()=='q'){
usleep(2000);
close(fd);
        clear();
        refresh();
        goto LOOP;}
}
 }


else if(pilih=='2')
{
clear (); refresh ();

screen_init();
open_serial();
w=write(fd,"?",1);
usleep(20000);
    mvprintw(8,1, "Write = %i",w);
 
clear (); refresh ();
n=read(fd, &buf, sizeof (buf));
buf[n]=0;
mvprintw (9, 1, "Buf = %i", n);
mvprintw (10,1, "Reply = %s", buf);

//close(fd);


while(1){

screen_init();
maketime();
update_display();
mainwnd;
refresh ( );
wrefresh(mainwnd);
refresh ();

 if (getch()=='q'){
        clear();
        refresh();
        goto LOOP;}}
 }

else if(pilih=='3'){

clear (); refresh ();
open_serial();


while(1)
{
screen_init();
maketime();
update_display();
mainwnd;
refresh ( );
wrefresh(mainwnd);
refresh ();

        mvprintw ( 6, 1, " a. Lamp All on ");        mvprintw ( 6, 26, " 1. Lamp All off ");
mvprintw ( 7, 1, " b. Lamp Gol 1 on ");      mvprintw ( 7, 26, " 2. Lamp Gol 1 off ");
mvprintw ( 8, 1, " c. Lamp Gol 2 on ");      mvprintw ( 8, 26, " 3. Lamp Gol 2 off ");
mvprintw ( 9, 1, " d. Lamp Gol 3 on ");      mvprintw ( 9, 26, " 4. Lamp Gol 3 off ");
mvprintw ( 10, 1, " e. Lamp Gol 4 on ");      mvprintw ( 10, 26, " 5. Lamp Gol 4 off ");
mvprintw ( 11, 1, " f. Lamp Gol 5 on ");      mvprintw ( 11, 26, " 6. Lamp Gol 5 off ");
mvprintw ( 12, 1, " g. Lamp Gol Dinas on ");  mvprintw ( 12, 26, " 7. Lamp Gol Dinas off ");

mvprintw ( 13, 1, " q. Back << ");

noecho ( ); back=getch( );echo ( );
if (back== 'a')
{
clear (); refresh ();
screen_init();
open_serial();

w=write(fd,"\x1f",1);
        usleep(20000);
        mvprintw(15,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;
mvprintw (16, 1, "Buf = %i", n);
mvprintw (17,1, "Reply = %s", buf);
//close(fd);
}



else if(back== 'b')
{
clear (); refresh ();
screen_init();
open_serial();


w=write(fd,"\x21",1);
        usleep(20000);
        mvprintw(15,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;
mvprintw (16, 1, "Buf = %i", n);
mvprintw (17,1, "Reply = %s", buf);

       }
       

else if (back=='c')
{
clear (); refresh ();
screen_init();
open_serial();

w=write(fd,"\x23",1);
        usleep(20000);
        mvprintw(15,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;
mvprintw (16, 1, "Buf = %i", n);
mvprintw (17,1, "Reply = %s", buf);
}


else if(back=='d')
{
clear (); refresh ();
screen_init();
open_serial();

w=write(fd,"\x25",1);
        usleep(20000);
        mvprintw(15,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;
mvprintw (16, 1, "Buf = %i", n);
mvprintw (17,1, "Reply = %s", buf);
}

else if(back=='e')
{
clear (); refresh ();
screen_init();
open_serial();

w=write(fd,"\x27",1);
        usleep(20000);
        mvprintw(15,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;
mvprintw (16, 1, "Buf = %i", n);
mvprintw (17,1, "Reply = %s", buf);
}


else if(back=='f')
{
clear (); refresh ();
screen_init();
open_serial();

w=write(fd,"\x29",1);
        usleep(20000);
        mvprintw(15,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;
mvprintw (16, 1, "Buf = %i", n);
mvprintw (17,1, "Reply = %s", buf);
}

else if(back=='g')
{
clear (); refresh ();
screen_init();
open_serial();

w=write(fd,"\x2b",1);
        usleep(20000);
        mvprintw(15,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;
mvprintw (16, 1, "Buf = %i", n);
mvprintw (17,1, "Reply = %s", buf);
}

else if(back=='1')
{
clear (); refresh ();
screen_init();
open_serial();

w=write(fd,"\x20",1);
        usleep(20000);
        mvprintw(15,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;
mvprintw (16, 1, "Buf = %i", n);
mvprintw (17,1, "Reply = %s", buf);
}

else if(back=='2')
{
clear (); refresh ();
screen_init();
open_serial();

w=write(fd,"\x22",1);
        usleep(20000);
        mvprintw(15,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;
mvprintw (16, 1, "Buf = %i", n);
mvprintw (17,1, "Reply = %s", buf);
}

else if(back=='3')
{
clear (); refresh ();
screen_init();
open_serial();

w=write(fd,"\x24",1);
        usleep(20000);
        mvprintw(15,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;
mvprintw (16, 1, "Buf = %i", n);
mvprintw (17,1, "Reply = %s", buf);
}

else if(back=='4')
{
clear (); refresh ();
screen_init();
open_serial();

w=write(fd,"\x26",1);
        usleep(20000);
        mvprintw(15,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;
mvprintw (16, 1, "Buf = %i", n);
mvprintw (17,1, "Reply = %s", buf);
}

else if(back=='5')
{
clear (); refresh ();
screen_init();
open_serial();

w=write(fd,"\x28",1);
        usleep(20000);
        mvprintw(15,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;
mvprintw (16, 1, "Buf = %i", n);
mvprintw (17,1, "Reply = %s", buf);
}

else if(back=='6')
{
clear (); refresh ();
screen_init();
open_serial();

w=write(fd,"\x2A",1);
        usleep(20000);
        mvprintw(15,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;
mvprintw (16, 1, "Buf = %i", n);
mvprintw (17,1, "Reply = %s", buf);
}

else if(back=='7')
{
clear (); refresh ();
screen_init();
open_serial();

w=write(fd,"\x2C",1);
        usleep(20000);
        mvprintw(15,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;
mvprintw (16, 1, "Buf = %i", n);
mvprintw (17,1, "Reply = %s", buf);
}


else if (back=='q'){
        clear();
        refresh();
        goto LOOP;}
}}




else if(pilih=='4'){

clear (); refresh ();
open_serial();


while(1)
{
screen_init();
maketime();
update_display();
mainwnd;
refresh ( );
wrefresh(mainwnd);
refresh ();


mvprintw ( 6, 1, " a. LLA Merah On, Hijau Off ");
mvprintw ( 7, 1, " b. LLA Merah Off,Hijau On ");    

mvprintw ( 9, 1, " q. Back << ");
noecho ( ); back=getch( );echo ( );

if(back=='a')
{
clear (); refresh ();
screen_init();
open_serial();


w=write(fd,"\x2d",1);
        usleep(20000);
        mvprintw(15,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;
mvprintw (16, 1, "Buf = %i", n);
mvprintw (17,1, "Reply = %s", buf);

}


else if(back=='b')
{
clear (); refresh ();
screen_init();
open_serial();


w=write(fd,"\x2e",1);
        usleep(20000);
        mvprintw(15,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;
mvprintw (16, 1, "Buf = %i", n);
mvprintw (17,1, "Reply = %s", buf);
}

else if (back=='q'){
        clear();
        refresh();
        goto LOOP;}


}}

else if(pilih=='5'){
clear (); refresh ();
open_serial();

while(1)
{
screen_init();
maketime();
update_display();
mainwnd;
refresh ( );
wrefresh(mainwnd);
refresh ();


mvprintw ( 6, 1, " a. VIA On");
mvprintw ( 7, 1, " b. VIA Off ");    

mvprintw ( 9, 1, " q. Back << ");
noecho ( ); back=getch( );echo ( );

if(back=='a')
{
clear (); refresh ();
screen_init();
open_serial();

w=write(fd,"\x2f",1);
        usleep(20000);
        mvprintw(15,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;
mvprintw (16, 1, "Buf = %i", n);
mvprintw (17,1, "Reply = %s", buf);
}

else if(back=='b')
{
clear (); refresh ();
screen_init();
open_serial();

w=write(fd,"\x30",1);
        usleep(20000);
        mvprintw(15,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;
mvprintw (16, 1, "Buf = %i", n);
mvprintw (17,1, "Reply = %s", buf);
}

else if (back=='q'){
        clear();
        refresh();
        goto LOOP;}


}}

else if(pilih=='6'){
clear (); refresh ();
open_serial();

while(1)
{
screen_init();
maketime();
update_display();
mainwnd;
refresh ( );
wrefresh(mainwnd);
refresh ();

mvprintw ( 6, 1, " a. LLB Merah On, Hijau Off ");
mvprintw ( 7, 1, " b. LLB Merah Off,Hijau On ");    

mvprintw ( 9, 1, " q. Back << ");
noecho ( ); back=getch( );echo ( );

if(back=='a')
{
clear (); refresh ();
screen_init();
open_serial();

w=write(fd,"\x31",1);
        usleep(50000);
        mvprintw(15,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;
mvprintw (16, 1, "Buf = %i", n);
mvprintw (17,1, "Reply = %s", buf);
}


else if(back=='b')
{
clear (); refresh ();
screen_init();
open_serial();

w=write(fd,"\x32",1);
        usleep(50000);
        mvprintw(15,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;
mvprintw (16, 1, "Buf = %i", n);
mvprintw (17, 1, "Reply = %s", buf);
}

else if (back=='q'){
        clear();
        refresh();
        goto LOOP;}


}}


else if(pilih=='7'){
clear (); refresh ();
open_serial();

while(1)
{
screen_init();
maketime();
update_display();
mainwnd;
refresh ( );
wrefresh(mainwnd);
refresh ();

mvprintw ( 6, 1, " a. LMS LCB Close Aktif ");
mvprintw ( 7, 1, " b. LMS LCB Open Aktif ");
mvprintw ( 8, 1, " c. LMS LCB Close & LMS LCB Open tidak Aktif ");

mvprintw ( 10, 1, " q. Back << ");
noecho ( ); back=getch( );echo ( );

if(back=='a')
{
clear (); refresh ();
screen_init();
open_serial();

w=write(fd,"\x70",1);
        usleep(20000);
        mvprintw(15,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;
mvprintw (16, 1, "Buf = %i", n);
mvprintw (17,1, "Reply = %s", buf);
}


else if(back== 'b')
{
clear (); refresh ();
screen_init();
open_serial();

w=write(fd,"\x71",1);
        usleep(20000);
        mvprintw(15,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;
mvprintw (16, 1, "Buf = %i", n);
mvprintw (17,1, "Reply = %s", buf);
}

else if(back=='c')
{
clear (); refresh ();
screen_init();
open_serial();

w=write(fd,"\x72",1);
        usleep(20000);
        mvprintw(15,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;
mvprintw (16, 1, "Buf = %i", n);
mvprintw (17,1, "Reply = %s", buf);
}

else if (back=='q'){
        clear();
        refresh();
        goto LOOP;}


}}

else if(pilih=='8'){
clear (); refresh ();
open_serial();

while(1)
{
screen_init();
maketime();
update_display();
mainwnd;
refresh ( );
wrefresh(mainwnd);
refresh ();

mvprintw ( 6, 1, "a. Runing LED Indikator TCT ");

mvprintw ( 8, 1, " q. Back << ");
noecho ( ); back=getch( );echo ( );

if(back=='a')
{
clear (); refresh ();
screen_init();
open_serial();

w=write(fd,"\x35",1);
        usleep(20000);
        mvprintw(12,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;
mvprintw (13, 1, "Buf = %i", n);
mvprintw (14,1, "Reply = %s", buf);
}

        else if (back=='q'){
        clear();
        refresh();
        goto LOOP;}


}}

else if(pilih=='9'){
clear (); refresh ();
open_serial();

while(1)
{
screen_init();
maketime();
update_display();
mainwnd;
refresh ( );
wrefresh(mainwnd);
refresh ();

mvprintw ( 6, 1, " a. Deteksi LVD Ch 1 On ");      mvprintw ( 6, 32, " 1. Deteksi LVD Ch 1 Off ");
mvprintw ( 7, 1, " b. Deteksi LVD Ch 2 On ");      mvprintw ( 7, 32, " 2. Deteksi LVD Ch 2 Off" );
mvprintw ( 8, 1, " c. Deteksi LVD Ch 3 On ");      mvprintw ( 8, 32, " 3. Deteksi LVD Ch 3 Off ");

mvprintw ( 10, 1, " d. Status Deteksi LVD Ch 1 ");  mvprintw ( 9, 32, " 4. Reset LVD Aktif( Ch 1, Ch 2, Ch 3 ) ");  
mvprintw ( 11, 1, " e. Status Deteksi LVD Ch 2 ");    
mvprintw ( 12, 1, " f. Status Deteksi LVD Ch 3 ");    


mvprintw ( 14, 1, " q. Back << ");
noecho ( ); back=getch( );echo ( );

if (back=='a')
{
clear (); refresh ();
screen_init();
open_serial();

//w=write(fd,"\x79",1);
        //usleep(20000);
        //mvprintw(12,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;
mvprintw (16, 1, "Buf = %i", n);
mvprintw (17,1, "Reply = %s", buf);
}


else if (back=='b')
{
clear (); refresh ();
screen_init();
open_serial();

//w=write(fd,"\x7b",1);
        //usleep(20000);
       // mvprintw(12,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;
mvprintw (16, 1, "Buf = %i", n);
mvprintw (17,1, "Reply = %s", buf);
}

else if(back=='c')
{
clear (); refresh ();
screen_init();
open_serial();

//w=write(fd,"\x7d",1);
       // usleep(20000);
       // mvprintw(12,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;

mvprintw (16, 1, "Buf = %i", n);
mvprintw (17,1, "Reply = %s", buf);
}


else if(back=='1')
{
clear (); refresh ();
screen_init();
open_serial();

w=write(fd,"\x7a",1);
        usleep(20000);
        mvprintw(15,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;
mvprintw (16, 1, "Buf = %i", n);
mvprintw (17,1, "Reply = %s", buf);
}

else if (back=='2')
{
clear (); refresh ();
screen_init();
open_serial();

w=write(fd,"\x7c",1);
        usleep(20000);
        mvprintw(15,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;
mvprintw (16, 1, "Buf = %i", n);
mvprintw (17,1, "Reply = %s", buf);
}

else if(back=='3')
{
clear (); refresh ();
screen_init();
open_serial();

w=write(fd,"\x7e",1);
        usleep(20000);
        mvprintw(15,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;
mvprintw (16, 1, "Buf = %i", n);
mvprintw (17,1, "Reply = %s", buf);
}

else if(back=='d')
{
clear (); refresh ();
screen_init();
open_serial();

w=write(fd,"\x49",1);
        usleep(20000);
        mvprintw(15,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;
mvprintw (16, 1, "Buf = %i", n);
mvprintw (17,1, "Reply = %s", buf);
}

else if(back== 'e')
{
clear (); refresh ();
screen_init();
open_serial();

w=write(fd,"\x4b",1);
        usleep(20000);
        mvprintw(15,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;
mvprintw (16, 1, "Buf = %i", n);
mvprintw (17,1, "Reply = %s", buf);
}

else if(back== 'f')
{
clear (); refresh ();
screen_init();
open_serial();

w=write(fd,"\x4d",1);
        usleep(20000);
        mvprintw(15,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;
mvprintw (16, 1, "Buf = %i", n);
mvprintw (17,1, "Reply = %s", buf);
}

else if(back=='4')
{
clear (); refresh ();
screen_init();
open_serial();

w=write(fd,"\x37",1);
        usleep(20000);
        mvprintw(15,1, "Write = %i",w);
n=read(fd, &buf, sizeof (buf));
        buf[n]=0;
mvprintw (16, 1, "Buf = %i", n);
mvprintw (17,1, "Reply = %s", buf);
}


else if (back=='q'){
        clear();
        refresh();
        goto LOOP;}


}}
else if (pilih=='q'){
        doloop=0;}


}

endwin();}}

else if(argc > 3)
{
printf("Command Line Error ./menu Cmd COM\n\n ");
printf("cmd      -> 'L' lts-test\n");
printf("          -> 'I' ivs-test\n");
printf("          -> 'A' alb-test\n");
printf("          -> 'C' cdp-test\n");
printf("          -> 'P' lpr-test\n\n");
printf(" port     -> '0'-'11'  Com1-Com12\n");
}


else if( argv[2] != 0 ){
printf("Command Line Error ./menu Cmd COM\n\n ");
printf("cmd      -> 'L' lts-test\n");
printf("          -> 'I' ivs-test\n");
printf("          -> 'A' alb-test\n");
printf("          -> 'C' cdp-test\n");
printf("          -> 'P' lpr-test\n\n");
printf(" port     -> '0'-'11'  Com1-Com12\n");
}

else if( argc == 2 ){
printf("Command Line Error ./menu Cmd COM\n\n ");
printf("cmd      -> 'L' lts-test\n");
printf("          -> 'I' ivs-test\n");
printf("          -> 'A' alb-test\n");
printf("          -> 'C' cdp-test\n");
printf("          -> 'P' lpr-test\n\n");
printf(" port     -> '0'-'11'  Com1-Com12\n");
}
 

else
{
printf("\033[2J");
//printf("\033[XA");


printf("Command Line Error ./menu Cmd COM\n\n ");
printf("cmd      -> 'L' lts-test\n");
printf("          -> 'I' ivs-test\n");
printf("          -> 'A' alb-test\n");
printf("          -> 'C' cdp-test\n");
printf("          -> 'P' lpr-test\n\n");
printf(" port     -> '0'-'11'  Com1-Com12\n");

}


}

int open_serial(void)
{

fd = open(serialport, O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1)
{
mvprintw(21,35, "open_port: Unable to open /dev/ttyUSB0 - ");

}

else{mvprintw(21,35, "open_port: Open /dev/ttyUSB0 - ");}

fcntl(fd, F_SETFL, FNDELAY);
struct termios options;
  tcgetattr( fd, &options );
  cfsetispeed( &options, B19200 );
  cfsetospeed( &options, B19200 );
  options.c_cflag |= ( CLOCAL | CREAD );
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS8;  
  options.c_cflag &= ~PARENB;
  options.c_cflag &= ~CSTOPB;
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS8;  
  options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
  options.c_iflag &= ~(IXON | IXOFF | IXANY);
  options.c_oflag &= ~OPOST;

if ( tcsetattr( fd, TCSANOW, &options ) == -1 )
mvprintw (22,35,"Error with tcsetattr = %s\n", strerror ( errno ) );
else
mvprintw (22,35,"%s\n", "tcsetattr succeed" );
return 0;
}


/* gcc menu.c -o menu -lncurses */




Tidak ada komentar:

Posting Komentar