/* take voltage off port so you can flip switch */ void safe_exit(int value) { printf("Graceful Exit. Turn off switch.\n\n"); /* testing */ outb(0, BASEPORT); close_port(); exit(value); }
SLooper::~SLooper() { status_t ignored; // closing the thread causes the thread to exit close_port(finder); wait_for_thread(finderThread, &ignored); }
static err_t idc_close_port(uint16_t port, int port_type) { LWIPBF_DEBUG("idc_close_port: called\n"); if (is_owner) { close_port((uint64_t) port, port_type); return ERR_OK; } LWIPBF_DEBUG("idc_close_port: called\n"); errval_t err, msgerr; err = net_ports_rpc.vtbl.close_port(&net_ports_rpc, port_type, port, appid_delete, qid_delete, &msgerr); if (err_is_fail(err)) { USER_PANIC_ERR(err, "error sending get_ip_info"); } LWIPBF_DEBUG("idc_close_tcp_port: returning\n"); if (msgerr == PORT_ERR_IN_USE) { return ERR_USE; } // FIXME: other errors? return ERR_OK; }
void Terminal::port_error(QSerialPort::SerialPortError error) { if (error == QSerialPort::ResourceError) { QMessageBox::critical(this, "Error", "Problem with serial port. Closing port."); close_port(); } }
/*** Deallocate ressources properly ***/ void cleanup(UBYTE *msg, int errcode) { CBClose(); close_port(); CloseMainWnd(1); CleanupLocale(); free_macros(); free_diskio_alloc(); /* ASL */ if(args.sa_Free) FreeVec(args.sa_ArgLst); if(DiskfontBase) CloseLibrary(DiskfontBase); if(LocaleBase) CloseLibrary((struct Library *)LocaleBase); if(AslBase) CloseLibrary(AslBase); if(IFFParseBase) CloseLibrary(IFFParseBase); if(UtilityBase) CloseLibrary((struct Library *)UtilityBase); if(KeymapBase) CloseLibrary(KeymapBase); if(GadToolsBase) CloseLibrary(GadToolsBase); if(GfxBase) CloseLibrary((struct Library *)GfxBase); if(IntuitionBase) CloseLibrary((struct Library *)IntuitionBase); if(msg) puts(msg); #if DEBUG /* Here can be compared good programs with the others :-) */ amem = AvailMem( MEMF_PUBLIC ); if(amem < bmem) printf("Possible memory lost of %d bytes\n", bmem-amem); #endif exit(errcode); }
int main(int argc,char* argv[]) { int port_fd; int len; char recv_buf[9]; int i; if(argc!=3){ printf("Usage: %s /dev/ttySn 0(send data)/1(receive data)\n",argv[0]); return -1; } port_fd=open_port(argv[1]); if(port_fd==-1){ printf("Program Exit\n"); return -1; } //设置串口通信参数 struct port_info info; info.baud_rate=9600; info.data_bits=8; info.flow_ctrl=2; info.port_fd=port_fd; info.stop_bit=1; info.parity=0; if(set_port(&info)==-1){ printf("Program Exit\n"); return -1; } if(strcmp(argv[2],"0")==0){ for(i=0;i<10;i++){ len=send_data(port_fd,"Test Data",9); if(len>0) printf("%d send data successfully\n",i); else printf("send data failed\n"); sleep(2); } close_port(port_fd); }else{ while(1){ len=recv_data(port_fd,recv_buf,9); if(len>0){ for(i=0;i<len;i++) printf("receive data is %s\n",recv_buf); }else printf("cannot receive data\n"); sleep(2); } } return 0; }
void die(const char *format, ...) { va_list args; va_start(args, format); vfprintf(stderr, format, args); close_port(); exit(1); }
void nsToolkit::Kill() { if(localthread) { GetInterface(); // interrupt message flow close_port(eventport); } }
static int set_lcd_brightness(char *brightness) { struct stdio_dev *cop_port; char *env; char cmd_buf[20]; int val = 0; int cs = 0; int len, i; if (brightness) { val = simple_strtol(brightness, NULL, 10); } else { env = getenv("brightness"); if (env) val = simple_strtol(env, NULL, 10); } if (val < 0) val = 0; if (val > MAX_BRIGHTNESS) val = MAX_BRIGHTNESS; sprintf(cmd_buf, "$SB;%04d;", val); len = strlen(cmd_buf); for (i = 1; i <= len; i++) cs += cmd_buf[i]; cs = (~cs + 1) & 0xff; sprintf(cmd_buf + len, "%02X\n", cs); /* IO Coprocessor communication */ cop_port = open_port(4, CONFIG_SYS_PDM360NG_COPROC_BAUDRATE); if (!cop_port) { printf("Error: Can't open IO Coprocessor port.\n"); return -1; } debug("%s: cmd: %s", __func__, cmd_buf); write_port(cop_port, cmd_buf); /* * Wait for transmission and maybe response data * before closing the port. */ udelay(CONFIG_SYS_PDM360NG_COPROC_READ_DELAY); memset(cmd_buf, 0, sizeof(cmd_buf)); len = read_port(cop_port, cmd_buf, sizeof(cmd_buf)); if (len) printf("Error: %s\n", cmd_buf); close_port(4); return 0; }
int main() { fd = open_port(); flush_port(); write_port(); printf("FIONBIO value %d\n", FIONBIO); usleep(2); printf("FIONREAD value %d\n", FIONREAD); read_port(); close_port(); }
SystemTimeSource::~SystemTimeSource() { TRACE("SystemTimeSource::~SystemTimeSource enter\n"); close_port(ControlPort()); if (fControlThread != -1) { status_t err; wait_for_thread(fControlThread, &err); } TRACE("SystemTimeSource::~SystemTimeSource exit\n"); }
int main(){ srand(time(NULL)); data_item_header ignition_angle = {"Ignition angle", Real32_Type, Degrees}; data_item_header engine_torque = {"Engine torque", Real32_Type, Newton_Metres}; data_item_header engine_speed = {"Engine speed", UInt32_Type, Revolutions_Per_Second}; int ignition_angle_port = -1; int engine_torque_port = -1; int engine_speed_port = -1; unsigned int ignition_angle_port_size = sizeof(data_item_header)+4; unsigned int engine_torque_port_size = sizeof(data_item_header)+4; unsigned int engine_speed_port_size = sizeof(data_item_header)+4; ignition_angle_data = setup_port(port_ignition_angle_btdc, &ignition_angle_port, ignition_angle_port_size); engine_torque_data = setup_port(port_engine_torque, &engine_torque_port, engine_torque_port_size); engine_speed_data = setup_port(port_engine_speed, &engine_speed_port, engine_speed_port_size); initialize_simulation(); sleep(5); memcpy(ignition_angle_data, &ignition_angle, sizeof(data_item_header) ); memcpy(engine_torque_data, &engine_torque, sizeof(data_item_header) ); memcpy(engine_speed_data, &engine_speed, sizeof(data_item_header) ); int i = 0; for(; i < 1000000000; i++){ update_rpm(); update_ignition_angle(); update_torque(); } sleep(5); close_port(port_ignition_angle_btdc, ignition_angle_data, ignition_angle_port_size); close_port(port_engine_torque, engine_torque_data, engine_torque_port_size); close_port(port_engine_speed, engine_speed_data, engine_speed_port_size); }
int serial_com::open_port(const char *device) { close_port(); struct termios oldtio,newtio; printf("open1\n");fflush(stdout); fd = open(device,O_RDWR|O_NOCTTY|O_NDELAY); if(fd<0) return -1; close(fd); printf("open2\n");fflush(stdout); fd = open(device,O_RDWR|O_NOCTTY/*|O_NDELAY*/); if(fd<0) return -1; printf("open3\n");fflush(stdout); tcgetattr(fd,&oldtio); bzero(&newtio,sizeof(newtio)); newtio.c_cflag = B38400|CS8|CLOCAL|CREAD; newtio.c_iflag = IGNPAR; newtio.c_oflag = 0; newtio.c_lflag = ICANON; newtio.c_cc[VTIME] = 10; // inter-character timer =5 newtio.c_cc[VMIN] = 1; // blocking read until 1 character arrives newtio.c_cc[VINTR] = 0; // Ctrl-c newtio.c_cc[VQUIT] = 0; newtio.c_cc[VERASE] = 0; // del newtio.c_cc[VKILL] = 0; // @ newtio.c_cc[VEOF] = 4; // Ctrl-d newtio.c_cc[VSWTC] = 0; // '\0' newtio.c_cc[VSTART] = 0; // Ctrl-q newtio.c_cc[VSTOP] = 0; // Ctrl-s newtio.c_cc[VSUSP] = 0; // Ctrl-z newtio.c_cc[VEOL] = 0x0a; newtio.c_cc[VREPRINT] = 0; // Ctrl-r newtio.c_cc[VDISCARD] = 0; // Ctrl-u newtio.c_cc[VWERASE] = 0; // Ctrl-w newtio.c_cc[VLNEXT] = 0; // Ctrl-v newtio.c_cc[VEOL2] = 0x0a; // '\0' tcflush(fd, TCIFLUSH); tcsetattr(fd,TCSANOW,&newtio); printf("open4\n");fflush(stdout); return 0; }
void SerialInterface::on_error() { { Glib::Mutex::Lock lock(running_mutex); if (!running) return; } m_port_error.emit(); close_port(); }
status_t QuitConnectionPurgeThread() { status_t status; port_id fPort = find_port(BLUETOOTH_CONNECTION_SCHED_PORT); if (fPort != B_NAME_NOT_FOUND) close_port(fPort); flowf("Connection port deleted\n"); wait_for_thread(sConnectionThread, &status); return status; }
gint delete_event( GtkWidget *widget, GdkEvent *event, gpointer data ) { g_print ("CLEAN STOP\n"); close_port(); IvyStop(); exit(0); return(FALSE); // false = delete window, FALSE = keep active }
void MyFrame::OnPortList(wxCommandEvent& event) { int selected = m_port_list->GetSelection(); if (selected == wxNOT_FOUND) return; wxString name = m_port_list->GetString(selected); //printf("OnPortList, %s\n", (const char *)name); close_port(); port_name = name; if (name == "(none)") return; raw_data_reset(); open_port((const char *)name); m_button_clear->Enable(true); }
status_t HaikuRTSPClient::WaitForInit(bigtime_t timeout) { status_t status = B_ERROR; if (read_port_etc(fInitPort, NULL, &status, sizeof(status), B_RELATIVE_TIMEOUT, timeout) < 0) { return B_ERROR; } close_port(fInitPort); delete_port(fInitPort); fInitPort = -1; return status; }
int main( int argc, char *argv[] ) { int i; int len; int port_fd; char recv_buf[MAX_BUF_LEN]; struct port_info info; if ( argc != 2 ) { fprintf( stdout, "%s /dev/ttySn\n", argv[0] ); return -1; } port_fd = open_port( argv[1] ); if ( port_fd == -1 ) { fprintf( stderr, "open_port err" ); return -1; } /* 设置串口参数 */ info.baud_rate = 9600; info.data_bits = 8; info.flow_ctrl = 2; info.port_fd = port_fd; info.stop_bit = 1; info.parity = 0; if ( set_port( &info ) == -1 ) { fprintf( stderr, "set_port err\n" ); close(port_fd); return -1; } /* 接受数据 */ while (1) { len = recv_data( port_fd, recv_buf, MAX_BUF_LEN ); if ( len > 0 ) { for ( i = 0; i < len; i++ ) { fprintf( stdout, "recv data is: %s\n", recv_buf ); } } else { fprintf( stderr, "recv data failed\n" ); } sleep(2); } close_port(port_fd); return 0; }
void MyFrame::OnPortMenu(wxCommandEvent &event) { int id = event.GetId(); wxString name = m_port_menu->FindItem(id)->GetItemLabelText(); close_port(); //printf("OnPortMenu, id = %d, name = %s\n", id, (const char *)name); port_name = name; m_port_list->Clear(); m_port_list->Append(port_name); m_port_list->SetSelection(0); if (id == 9000) return; raw_data_reset(); open_port((const char *)name); m_button_clear->Enable(true); }
void streaming(){ int res; /* Streaming loop */ while (STOP==FALSE) { // signal if (wait_flag==FALSE) { res = read(fd,&buf,1); // read 33 bytes from serial and place at buf printf("%d",res); byte_parser(*buf,res); // send the read to byte_parser() // memset(buf,0,res); wait_flag = TRUE; // wait for new input // } } close_port(); }
void BMediaEventLooper::Quit() { CALLED(); if (fRunState == B_TERMINATED) return; SetRunState(B_QUITTING); close_port(ControlPort()); if (fControlThread != -1) { status_t err; wait_for_thread(fControlThread, &err); fControlThread = -1; } SetRunState(B_TERMINATED); }
void SerialInterface::on_receive_data() { in_on_receive_data = true; { Glib::Mutex::Lock lock(running_mutex); if (!running) return; } { Glib::Mutex::Lock read_lock(read_mutex); m_port_receive_data.emit(); read_cond.signal(); } in_on_receive_data = false; if (called_close_port) close_port(); }
EffectDriver::~EffectDriver() { try { stop(); } catch (...) {} try { close_port(); } catch (...) {} // Exit the processing thread m_exit_thread = true; m_cond.notify_all(); m_thread.join(); }
int main(int argc, char *argv[]) { raw_data_reset(); glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(600, 500); glutCreateWindow("IMU Read"); visualize_init(); glutReshapeFunc(resize_callback); glutDisplayFunc(glut_display_callback); glutTimerFunc(TIMEOUT_MSEC, timer_callback, 0); glutKeyboardFunc(glut_keystroke_callback); if (!open_port(PORT)) die("Unable to open %s\n", PORT); glutMainLoop(); close_port(); return 0; }
/** \fn int Serial::initialize(void); * \brief Opens and configures a serial port connection. * * The function opens a connection to the pathname stored in the Serial class * data member, serial_device_name_. Returns the file descriptor to that port location. * * Configuration: * 8 data bits per character * No parity bit * 2 stop bits * No hardware flow control * No software flow control * * * \return success: file descriptor * \return failure: -1 */ int Serial::initialize_port(void) { struct termios oldtio,newtio; int serial_speed = set_baud_speed(baud_rate); fprintf(stderr, "device name: %s\n", serial_device_name.c_str()); /** open() system call is used to convert a pathname into a file descriptor * (a small, non-negative integer for use in subsequent I/O). * * on success, the file descriptor returned will be the lowest file descriptor * not currently open for the process. * * on failure, returns -1 * * O_RDWR open for read and write access * * O_NDELAY program doesn't care what state the DCD signal line is at - whether the * other end of the port is up and running. If you do not specify this flag, * your process will be put to sleep until the DCD signal line is set to the * space voltage. */ if( (serial_file_descriptor = open(serial_device_name.c_str(), O_RDWR | O_NDELAY)) == -1 ) { fprintf(stderr, "[ERROR] (%s: %s: %d) errno: %s\n", __FILE__, __FUNCTION__, __LINE__ , strerror(errno)); return serial_file_descriptor; } // Get current serial port settings if( tcgetattr(serial_file_descriptor, &oldtio) < 0) { fprintf(stderr, "[ERROR] (%s: %s: %d) errno: %s\n", __FILE__, __FUNCTION__, __LINE__ , strerror(errno)); close_port(); return serial_file_descriptor; } // New port settings memset(&newtio, 0, sizeof(newtio)); // set all struct values to zero /* Set Control mode * CS8 - 8 data bits, no parity, 1 stop bit * CLOCAL - local connnection, no modem control * CREAD - enable receiving characters * IGNBRK - ignore break condition */ newtio.c_cflag = serial_speed | CS8 | CLOCAL | CREAD | IGNBRK; /* IGNPAR - ignore bytes with parity errors * ICRNL - map CR to NL (otherwise a CR input on the other computer will not terminate input) * */ newtio.c_iflag = IGNPAR | ICRNL; newtio.c_oflag = 0; // raw output /* * ICANON : enable canonical input * disable all echo functionality, and don't send signals to calling program */ newtio.c_lflag = ICANON; // Empty serial port buffers tcflush(serial_file_descriptor, TCIFLUSH); // Load new settings if( tcsetattr(serial_file_descriptor, TCSANOW, &newtio) , 0) { fprintf(stderr, "[ERROR] (%s: %s: %d) errno: %s\n", __FILE__, __FUNCTION__, __LINE__ , strerror(errno)); close(serial_file_descriptor); serial_file_descriptor = -1; return serial_file_descriptor; } return serial_file_descriptor; }
/** Destructor **/ Serial::~Serial(){ /** call close_port() in case user has not closed the port or in case of early termination of other programs. */ close_port(); }
/* Service entry point */ pipes_main() { int id; struct stdservice_cmd service_cmd; struct stdservice_res servres; struct stdservice_res dieres; struct pipes_cmd pcmd; char *service_name = "fs/pipes"; struct directory_register reg_cmd; struct directory_response dir_res; init_mem(malloc_buffer, 1024 * 30); avl_init(&pipes); // open ports with permisions for services only (lv 0, 1, 2) // open_port(1, 2, PRIV_LEVEL_ONLY); open_port(STDSERVICE_PORT, 2, PRIV_LEVEL_ONLY); open_port(PIPES_PORT, 2, PRIV_LEVEL_ONLY); _sti; // set interrupts // register with directory // register service with directory // reg_cmd.command = DIRECTORY_REGISTER_SERVICE; reg_cmd.ret_port = 1; reg_cmd.service_name_smo = share_mem(DIRECTORY_TASK, service_name, len(service_name) + 1, READ_PERM); while (send_msg(DIRECTORY_TASK, DIRECTORY_PORT, ®_cmd) < 0) { reschedule(); } while (get_msg_count(1) == 0) { reschedule(); } get_msg(1, &dir_res, &id); close_port(1); claim_mem(reg_cmd.service_name_smo); for(;;) { while(get_msg_count(PIPES_PORT) == 0 && get_msg_count(STDSERVICE_PORT) == 0) { reschedule(); } // process incoming STDSERVICE messages int service_count = get_msg_count(STDSERVICE_PORT); while(service_count != 0) { get_msg(STDSERVICE_PORT, &service_cmd, &id); servres.ret = STDSERVICE_RESPONSE_OK; servres.command = service_cmd.command; if(service_cmd.command == STDSERVICE_DIE) { // FIXME: return failure to al pending commands and die dieres.ret = STDSERVICE_RESPONSE_OK; dieres.command = service_cmd.command; send_msg(id, service_cmd.ret_port, &dieres); } else if(service_cmd.command == STDSERVICE_QUERYINTERFACE) { process_query_interface((struct stdservice_query_interface *)&service_cmd, id); service_count--; continue; } send_msg(id, service_cmd.ret_port, &servres); service_count--; } // process incoming pipes messages int pipes_count = get_msg_count(PIPES_PORT); while(pipes_count != 0) { get_msg(PIPES_PORT, &pcmd, &id); process_pipes_cmd(&pcmd, id); pipes_count--; } } }
void serial_close(){ close_port(fd_serial); }
void SerialPort::end_serial() { close_port(); }