int WriteComPort(int fd, void *data, int datalength) { int write_byte, write_size; unsigned char *p_write; errno = 0; write_size = datalength; p_write = (unsigned char *)data; while(write_size>0) { while(select_port(fd, WRITE_PORT));// if ((write_byte = write(fd, p_write, write_size))>0) { write_size -= write_byte; p_write += write_byte; // printf("write :%d byte success \n", write_byte); } else { printf("write error:write_byte:%d\n", write_byte); return -1; } } return 0; }
void PortConfig::refresh_ports() { int ind = -1; int i = 0; std::vector<std::string> ports = SerialInterface::enumerate_ports(); std::vector<std::string>::iterator it; Gtk::TreeModel::Row row; cmbtPort.clear_items(); for (it = ports.begin(); it != ports.end(); ++it) { cmbtPort.append_text(*it); #ifdef __unix__ if (ind == -1 && (*it).find("ttyUSB") != std::string::npos) ind = i; #endif i++; } if (ind == -1) ind = 0; if (port == "" && ind > 0) port = ports[ind]; select_port(port); }
////////////////////////////////////////////////////////// // Inicia UART0 void inicia_uart0(void) { init_uart(_UART0,_DEFFREQ, _DEFBAUD); // Setup Uart0 select_port(_UART0); // Select port PAADDR = P_AF; PACTL |= 0x20; // - Habilita TXD0 PAADDR = P_AFS1; PACTL &= 0xDF; // - Desabilita RXD0 PAADDR = P_AFS2; PACTL &= 0xDF; // PAADDR = P_NUL; // Clear to protect sub register U0CTL0 = 0x80 ; // Transmissor ligado, Receptor inibido, sem Paridade, 1 Stop bit. }
void PortConfig::on_show() { refresh_ports(); select_port(port); select_baud(baud); select_parity(parity); select_bits(bits); select_stop_bits(stop_bits); select_flow_control(flow_control); Gtk::Dialog::on_show(); }
static ngx_http_core_srv_conf_t * __get_core_srv_conf(ngx_http_core_main_conf_t * cmcf, ngx_http_fetch_selector_t * selector) { ngx_http_fetch_select_port_t select_port = (selector && selector->select_port ) ? selector->select_port : __select_port; ngx_http_fetch_select_addr_t select_addr = (selector && selector->select_addr ) ? selector->select_addr : __select_addr; ngx_http_conf_port_t * port = select_port((ngx_http_conf_port_t *)cmcf->ports->elts, cmcf->ports->nelts); if (!port) { return NULL; } ngx_http_conf_addr_t * addr = select_addr((ngx_http_conf_addr_t *)port->addrs.elts, port->addrs.nelts); if (!addr) { return NULL; } return addr->default_server; }
int ReadComPort(int fd, void *data, int datalength) { int RxCount,nread=0; unsigned char *p_read; int ret=0; errno = 0; RxCount = datalength; p_read = (unsigned char *)data; while(RxCount>0) { ret = select_port(fd, READ_PORT); if(SELECT_PORT_SUCCESS==ret) { if ((nread = read(fd, p_read, RxCount))>0) { RxCount -= nread; p_read += nread; } else { printf("read error:nread:%d.\n", nread); return -1; } } else { //printf("read select err:%d.\n", ret); return ret; } } return 0; }
int main(void) { // struct socket_type get_sockettype; u8 i = 0; u8 last_state = 0; init_all(); module_discriminate(); module_config(); relay_all = 0; relay_splithex(0x00); relay_all = 1; delay_ms(200); relay_all = 0; select_port(); while (1) { if(g_ms==4000) { relay_splithex( array_hex()); i=0; g_ms=0; } if (key3 == 0) { g_ms=0; if ( get_sockettype.select_array[i][0] == 1) { sigelarray_init(); if (temp_sigelarry[i] != 1) { temp_sigelarry[i] = 1; } else { temp_sigelarry[i] = 0; } relay_splithex( sigelarry_hex()); do { i++; } while (get_sockettype.select_array[i][0] != 1); while (key3 == 0); if (i >= 8) i = 0; } } if (key1 == 0) { doublearry_init(); relay_splithex( array_hex()); relay_all = 1; while (key3 == 0); relay_all = 0; } command_handle(); } }
void PortConfig::set_port(Glib::ustring p) { port = select_port(p); }
int parport_daisy_init(struct parport *port) { int detected = 0; char *deviceid; static const char *th[] = { "th", "st", "nd", "rd", "th" }; int num_ports; int i; int last_try = 0; again: if (port->muxport < 0 && mux_present(port) && ((num_ports = num_mux_ports(port)) == 2 || num_ports == 4)) { port->muxport = 0; printk(KERN_INFO "%s: 1st (default) port of %d-way multiplexor\n", port->name, num_ports); for (i = 1; i < num_ports; i++) { struct parport *extra = clone_parport(port, i); if (!extra) { if (signal_pending(current)) break; schedule(); continue; } printk(KERN_INFO "%s: %d%s port of %d-way multiplexor on %s\n", extra->name, i + 1, th[i + 1], num_ports, port->name); parport_daisy_init(extra); } } if (port->muxport >= 0) select_port(port); parport_daisy_deselect_all(port); detected += assign_addrs(port); add_dev(numdevs++, port, -1); deviceid = kmalloc(1024, GFP_KERNEL); if (deviceid) { if (parport_device_id(numdevs - 1, deviceid, 1024) > 2) detected++; kfree(deviceid); } if (!detected && !last_try) { parport_daisy_fini(port); parport_write_control(port, PARPORT_CONTROL_SELECT); udelay(50); parport_write_control(port, PARPORT_CONTROL_SELECT | PARPORT_CONTROL_INIT); udelay(50); last_try = 1; goto again; } return detected; }
int parport_daisy_init(struct parport *port) { int detected = 0; char *deviceid; static const char *th[] = { /*0*/"th", "st", "nd", "rd", "th" }; int num_ports; int i; int last_try = 0; again: /* Because this is called before any other devices exist, * we don't have to claim exclusive access. */ /* If mux present on normal port, need to create new * parports for each extra port. */ if (port->muxport < 0 && mux_present(port) && /* don't be fooled: a mux must have 2 or 4 ports. */ ((num_ports = num_mux_ports(port)) == 2 || num_ports == 4)) { /* Leave original as port zero. */ port->muxport = 0; printk(KERN_INFO "%s: 1st (default) port of %d-way multiplexor\n", port->name, num_ports); for (i = 1; i < num_ports; i++) { /* Clone the port. */ struct parport *extra = clone_parport(port, i); if (!extra) { if (signal_pending(current)) break; schedule(); continue; } printk(KERN_INFO "%s: %d%s port of %d-way multiplexor on %s\n", extra->name, i + 1, th[i + 1], num_ports, port->name); /* Analyse that port too. We won't recurse forever because of the 'port->muxport < 0' test above. */ parport_daisy_init(extra); } } if (port->muxport >= 0) select_port(port); parport_daisy_deselect_all(port); detected += assign_addrs(port); /* Count the potential legacy device at the end. */ add_dev(numdevs++, port, -1); /* Find out the legacy device's IEEE 1284 device ID. */ deviceid = kmalloc(1024, GFP_KERNEL); if (deviceid) { if (parport_device_id(numdevs - 1, deviceid, 1024) > 2) detected++; kfree(deviceid); } if (!detected && !last_try) { /* No devices were detected. Perhaps they are in some funny state; let's try to reset them and see if they wake up. */ parport_daisy_fini(port); parport_write_control(port, PARPORT_CONTROL_SELECT); udelay(50); parport_write_control(port, PARPORT_CONTROL_SELECT | PARPORT_CONTROL_INIT); udelay(50); last_try = 1; goto again; } return detected; }