15 int read_eeprom(comedi_t *it,unsigned int **eeprom, struct parsed_options options);
16 void dump_eeprom(unsigned int *eeprom,int len);
20 int main(int argc, char *argv[])
24 struct parsed_options options;
26 init_parsed_options(&options);
27 options.subdevice = -1;
28 parse_options(&options, argc, argv);
30 device = comedi_open(options.filename);
32 comedi_perror(options.filename);
36 len = read_eeprom(device, &eeprom, options);
37 dump_eeprom(eeprom,len);
45 int read_eeprom(comedi_t *it, unsigned int **eeprom, struct parsed_options options)
52 if(options.subdevice < 0)
54 options.subdevice = comedi_find_subdevice_by_type(it, COMEDI_SUBD_MEMORY, 0);
55 if(options.subdevice < 0){
56 fprintf(stderr,"No memory subdevice\n");
61 n = comedi_get_n_channels(it, options.subdevice);
62 maxdata = comedi_get_maxdata(it, options.subdevice, 0);
65 fprintf(stderr,"Demo only supports 8-bit memory subdevice has strange maxdata, aborting\n");
69 ptr = malloc(sizeof(unsigned int) * n);
71 for(i = 0; i < n; i++){
72 ret = comedi_data_read(it, options.subdevice, i, 0, 0, &data);
75 comedi_perror("comedi_data_read");
85 void dump_eeprom(unsigned int *eeprom,int len)
89 for (i = 0; i < len - 16; i+=16) {
91 for (j = 0; j < 16; j++) {
92 printf("%02x", eeprom[i + j] & 0xff);
95 for (j = 0; j < 16; j++) {
96 c = eeprom[i + j] & 0xff;
97 printf("%c", isprint(c) ? c : '.');
103 for (j = 0; j < len-i; j++) {
104 printf("%02x", eeprom[i + j] & 0xff);
110 for (j = 0; j < len-i; j++) {
111 c = eeprom[i + j] & 0xff;
112 printf("%c", isprint(c) ? c : '.');