static int dev_open(struct sr_dev_inst *sdi) { struct dev_context *devc = sdi->priv; int i; if (ieee1284_open(sdi->conn, 0, &i) != E1284_OK) goto fail1; if (ieee1284_claim(sdi->conn) != E1284_OK) goto fail2; if (ieee1284_data_dir(sdi->conn, 1) != E1284_OK) goto fail3; if (hung_chang_dso_2100_move_to(sdi, 1)) goto fail3; devc->samples = g_try_malloc(1000 * sizeof(*devc->samples)); if (!devc->samples) goto fail3; return SR_OK; fail3: hung_chang_dso_2100_reset_port(sdi->conn); ieee1284_release(sdi->conn); fail2: ieee1284_close(sdi->conn); fail1: return SR_ERR; }
void test_open (struct parport_list *pl) { int i; for (i = 0; i < pl->portc; i++) { struct parport *port = pl->portv[i]; unsigned int cap; /* Just try to open the port, then close it. */ if (ieee1284_open (port, 0, &cap)) printf ("%s: inaccessible\n", port->name); else { printf ("%s: %#lx", port->name, port->base_addr); if (port->hibase_addr) printf (" (ECR at %#lx)", port->hibase_addr); printf ("\n "); show_capabilities (cap); if (cap & CAP1284_IRQ) { int fd = ieee1284_get_irq_fd (port); if (fd < 0) printf ("Couldn't get IRQ fd: %d\n", fd); else { int r = ieee1284_claim (port); if (r != E1284_OK) printf ("Couldn't claim port: %d\n", r); else r = ieee1284_clear_irq (port, NULL); if (r != E1284_OK) printf ("Couldn't clear IRQ: %d\n", r); ieee1284_release (port); } } ieee1284_close (port); } } }
static GSList *scan_port(GSList *devices, struct sr_dev_driver *di, struct parport *port) { struct sr_dev_inst *sdi; struct sr_channel *ch; struct sr_channel_group *cg; struct dev_context *devc; struct drv_context *drvc; int i; if (ieee1284_open(port, 0, &i) != E1284_OK) { sr_err("Can't open parallel port %s", port->name); goto fail1; } if ((i & (CAP1284_RAW | CAP1284_BYTE)) != (CAP1284_RAW | CAP1284_BYTE)) { sr_err("Parallel port %s does not provide low-level bidirection access", port->name); goto fail2; } if (ieee1284_claim(port) != E1284_OK) { sr_err("Parallel port %s already in use", port->name); goto fail2; } if (!hung_chang_dso_2100_check_id(port)) goto fail3; sdi = g_malloc0(sizeof(struct sr_dev_inst)); sdi->status = SR_ST_INACTIVE; sdi->vendor = g_strdup("Hung-Chang"); sdi->model = g_strdup("DSO-2100"); sdi->driver = di; drvc = di->context; sdi->inst_type = 0; /* FIXME */ sdi->conn = port; ieee1284_ref(port); for (i = 0; i < NUM_CHANNELS; i++) { cg = g_malloc0(sizeof(struct sr_channel_group)); cg->name = g_strdup(trigger_sources[i]); ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, FALSE, trigger_sources[i]); cg->channels = g_slist_append(cg->channels, ch); sdi->channel_groups = g_slist_append(sdi->channel_groups, cg); } devc = g_malloc0(sizeof(struct dev_context)); devc->enabled_channel = g_slist_append(NULL, NULL); devc->channel = 0; devc->rate = 0; devc->probe[0] = 10; devc->probe[1] = 10; devc->cctl[0] = 0x31; /* 1V/div, DC coupling, trigger on channel A*/ devc->cctl[1] = 0x31; /* 1V/div, DC coupling, no tv sync trigger */ devc->edge = 0; devc->tlevel = 0x80; devc->pos[0] = 0x80; devc->pos[1] = 0x80; devc->offset[0] = 0x80; devc->offset[1] = 0x80; devc->gain[0] = 0x80; devc->gain[1] = 0x80; devc->frame_limit = 0; devc->last_step = 0; /* buffersize = 1000 */ sdi->priv = devc; drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); fail3: ieee1284_release(port); fail2: ieee1284_close(port); fail1: return devices; }
int main(int argc, char **argv) { if (argc < 2) { fprintf(stderr, "usage: %s <data>\n", argv[0]); return -1; } uint32_t status; uint32_t capability; int i; status = ieee1284_find_ports( &port_list, 0); if( status == E1284_NOMEM) { perror("There is not enought memory.\n"); return -1; } printf("Number of ports: %d\n\n", port_list.portc); /* for(i = 0; i < port_list.portc; ++i) { curr_port = port_list.portv[i]; printf("Name: \t\t%s\n", curr_port->name); printf("Base address: \t%d\n", curr_port->base_addr); printf("ERC address: \t%d\n", curr_port->hibase_addr); printf("Filename: \t%s\n\n", curr_port->filename); //break; } */ curr_port = port_list.portv[1]; capability = CAP1284_RAW; printf("Try to open port \"%s\"\n\n", curr_port->name); status = ieee1284_open(curr_port, 0, &capability); print_status_open(status); status = ieee1284_claim(curr_port); printf("Status: %d\n", status); write_number(atoi(argv[1])); /* uint16_t info; sscanf(argv[1], "%x", &info); write_binary_data(info); */ ieee1284_release(curr_port); status = ieee1284_close(curr_port); printf("Status: %d\n", status); ieee1284_free_ports(&port_list); return 0; }