void CGridFlashDlg::OnDestroy() { CDialog::OnDestroy(); m_bStopLoadingfile=TRUE; Sleep(3000); DWORD dwExidCode; GetExitCodeThread(m_pBackCheckThread->m_hThread,&dwExidCode); if(dwExidCode==STILL_ACTIVE) { TerminateThread(m_pBackCheckThread->m_hThread,dwExidCode); m_pBackCheckThread=NULL; Sleep(100); } GetExitCodeThread(pThread_flash->m_hThread,&dwExidCode); if(dwExidCode==STILL_ACTIVE) { TerminateThread(pThread_flash->m_hThread,dwExidCode); pThread_flash=NULL; Sleep(100); } SetCommunicationType(0); close_com(); SetCommunicationType(1); close_com(); ContinueRefreshTreeviewThread(); }
void CReg_ControlDlg::OnDisconnect() { close_com(); CString strInfo = _T("No Connnection"); m_port.EnableWindow(1); m_port_open = false; }
//---------------------------------------------------------------------------------------- //Function:use this function to close the com port and enable the combobox (port and baud rate) //Add Time:2013-03-20 //author :Fan Du //Modify Time:N/A //---------------------------------------------------------------------------------------- void CRegisterMonitorDlg::OnDisconnect() { //AfxMessageBox(_T("DisConnect.")); close_com(); CString strInfo = _T("No Connnection"); m_port.EnableWindow(1); //m_baudrate.EnableWindow(1); m_port_open = false; }
int main1(void) { int k, x, i; /* defining parameters for serial port part */ unsigned char charFromNewton; char buffer[80]; char o[10]; printf("1. Setting for serial port\n"); comm_setting(); /* initializing communication */ printf("Serial port initialized\n"); k=0; printf("Entering while loop...\n"); while(1) { /* Read a char from serial port and print it to screen */ charFromNewton = com_rx(); /* Note: 0X7F is "DEL" char. Receive data from com_port */ if(kbhit()) { /* If a key is hit then gracefully exit by closing the port first */ close_com(); printf("Bye!\n"); exit(0); } printf("%c", charFromNewton); } /* end of while motion loop */ printf("while loop finished... kill serial port\n"); /* Finished with serial port so close it */ close_com(); printf("Exiting program\n"); return (0); } /* end of MAIN */
void disp_scan(void) { static xd_u8 cnt = 0; xd_u8 temp; static bool flash; custom_buf_update(); #if 0 init_disp_buf(); disp_putchar('0',0); disp_putchar('1',1); disp_putchar('2',2); disp_putchar('3',3); #endif TRADEMARK_ICON |=TRADEMARK_MASK; lcd_flash_timer++; if (lcd_flash_timer == 220) { lcd_flash_timer = 0; flash = !flash; } if (flash) { disp_clr_icon(lcd_flash_icon); } else { disp_icon(lcd_flash_icon); } temp = cnt>>1; close_com(temp); if(cnt & 0x01){ seg07_port(lcd_buff[temp]); seg8_port( ( ((lcd_buff[temp]&0x0100)>0)?1:0 ) ); seg9_port( ( ((lcd_buff[temp]&0x0200)>0)?1:0 ) ); clr_com(temp); } else { seg07_port(~lcd_buff[temp]); seg8_port(( ((lcd_buff[temp]&0x0100)>0)?0:1 )); seg9_port(( ((lcd_buff[temp]&0x0200)>0)?0:1 )); set_com(temp); } cnt++; if(cnt>7)cnt = 0; }
void seg_lcd_disp_scan(void) { static u8 cnt = 0; u8 temp; static bool flash; //seg_lcd_flash_icon(USB_ICON); lcd_flash_timer++; if (lcd_flash_timer == 220) { lcd_flash_timer = 0; flash = !flash; } if (flash) { seg_lcd_flash_section(); } else { seg_lcd_disp_icon(lcd_flash_icon); } temp = cnt>>1; close_com(temp); if(cnt & 0x01){ seg07_port(lcd_buff[temp]); seg8_port( ( ((lcd_buff[temp]&0x0100)>0)?1:0 ) ); clr_com(temp); } else { seg07_port(~lcd_buff[temp]); seg8_port(( ((lcd_buff[temp]&0x0100)>0)?0:1 )); set_com(temp); } cnt++; if(cnt>7)cnt = 0; }
void disp_scan(void) { static xd_u8 cnt = 0; xd_u8 temp; static bool flash; custom_buf_update(); lcd_flash_timer++; if (lcd_flash_timer == 220) { lcd_flash_timer = 0; flash = !flash; } if (flash) { disp_clr_icon(lcd_flash_icon); } else { disp_icon(lcd_flash_icon); } temp = cnt>>1; close_com(temp); if(cnt & 0x01){ seg07_port(lcd_buff[temp]); clr_com(temp); } else { seg07_port(~lcd_buff[temp]); set_com(temp); } cnt++; if(cnt>9)cnt = 0; }
Calibrator::~Calibrator() { close_com(_(HPORT)); delete m_data; }
bool COM_interface::open_com(const char* com_port) { #ifndef LINUX hCom = CreateFile(com_port,GENERIC_READ | GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL); if(hCom == INVALID_HANDLE_VALUE) { dwError = GetLastError(); return false; } delay(10); fSuccess = GetCommState(hCom, &dcb); if(!fSuccess) { close_com(); return false; } dcb.BaudRate = 9600; dcb.ByteSize = 8; dcb.Parity = FALSE; dcb.StopBits = ONESTOPBIT; dcb.XonLim = 4086; dcb.XoffLim = 4086; fSuccess = SetCommState(hCom, &dcb); if(!fSuccess) { close_com(); return false; } commTimeOuts.ReadIntervalTimeout = 0; commTimeOuts.ReadTotalTimeoutConstant = 0; commTimeOuts.ReadTotalTimeoutMultiplier = 0; commTimeOuts.WriteTotalTimeoutMultiplier = 0; commTimeOuts.WriteTotalTimeoutConstant = 0; SetCommTimeouts(hCom, &commTimeOuts); SetupComm(hCom, 4096, 4096); PurgeComm(hCom, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR); #else /* LINUX */ hCom = open(com_port, O_RDWR | O_NOCTTY ); if(hCom <= 0) { return false; } tcgetattr(hCom, &termParam); memset(&termSetParam, 0, sizeof(termSetParam)); termSetParam.c_cflag |= ( CLOCAL | CREAD); cfsetispeed(&termSetParam, B9600); cfsetospeed(&termSetParam, B9600); termSetParam.c_cflag &= ~PARENB; termSetParam.c_cflag &= ~CSIZE; termSetParam.c_cflag |= CS8; termSetParam.c_cflag &= ~CSTOPB; tcsetattr(hCom, TCSADRAIN, &termSetParam); fcntl(hCom, F_SETFL, FNDELAY); #endif gps_communication_ok = true; return true; }
COM_interface::~COM_interface() { close_com(); }