cs00wsc@unccvax.uncc.edu (Wen-Shiang Chin) (01/29/91)
Hi, Does anyone know how to read the series number of a ID-MOUDLE (a HP-HIL device) by using C under Hp-UX 7.03. Thank you. Wen-Shinag Chin
rdg@hpfcmgw.HP.COM (Rob Gardner) (01/30/91)
> Does anyone know how to read the series number of > a ID-MOUDLE (a HP-HIL device) by using C under Hp-UX 7.03. See the hil(7) man page for the information. There's an ioctl() that does it. Rob
zap@indic.se (Jonas Petersson) (01/31/91)
In article <3104@unccvax.uncc.edu> cs00wsc@unccvax.uncc.edu (Wen-Shiang Chin) writes: > Does anyone know how to read the series number of >a ID-MOUDLE (a HP-HIL device) by using C under Hp-UX 7.03. dev=open("/dev/idmodule", 0); ioctl(dev, HILSC, buf); This will bring the id into buf (9 chars long). You might want to decode it since it is packed, but that really isn't needed - it's unique anyway. (Note: You ought to check return values etc, and your id module might not be /dev/idmodule) Regards / Jonas -- /// "Are you THE Zaphod Beeblebrox ????" # zap@indic.se __ /// # Air Quality Surveillance \\\/// "No, just A Zaphod Beeblebrox. # "I can feel it coming \/// Didn't you hear - I come in sixpacks !" # in the air..."
john@hpucph.dnk.hp.com (John Damm Srensen) (02/04/91)
Following small C program will give you the serial number in ASCII
format. It will search the entire HIL loop for ID module(s) and report
serial number(s) in plain ASCII.
As far as I remember this program was once publiced in the
HP9000 Communicator.
john@ejna.dnk.hp.com
Danish Response Center
#include <sys/hilioctl.h>
#include <string.h>
main()
{
int fd,status,i;
unsigned char hildev[7][10];
unsigned char describe[16],serial_number[11];
long int sr_number;
/*Open the device file for the first seven devices on the loop
and look for any ID modeules */
strcpy(hildev[0],"/dev/hil1");
strcpy(hildev[1],"/dev/hil2");
strcpy(hildev[2],"/dev/hil3");
strcpy(hildev[3],"/dev/hil4");
strcpy(hildev[4],"/dev/hil5");
strcpy(hildev[5],"/dev/hil6");
strcpy(hildev[6],"/dev/hil7");
for (i=0;i<7;i++)
{
fd=open(hildev[i],0);
/*This ioctl system call requests a describe record from the device. The
describe record contains information describing the amount and type of
data that can be returned by the device*/
status=ioctl(fd,HILID,&describe[0]);
/*Is there an HP-HIL device out there and is it an ID Module? */
if ((status != -1) && (describe[0]==0x34))
{
printf("\nID MODULE found at device %s \n",hildev[i]);
get_serial_number(fd,&serial_number[0],&sr_number);
printf("%s %ld\n",serial_number,sr_number);
}
}
}
get_serial_number(hil_fd,serial_number,sr_number)
int hil_fd;
char serial_number[];
long int *sr_number;
{
unsigned long int year_week, suffix;
int status;
union srnum {
unsigned long int number;
struct{
unsigned dummy :2;
unsigned byte8 :6;
unsigned byte7 :8;
unsigned byte6 :8;
unsigned byte5 :8;
} r;
} s;
union hil_sc {
unsigned char describe[9];
struct {
unsigned format :4;
unsigned undefined :4;
unsigned byte2 :8;
unsigned byte3 :8;
unsigned bit17 :1;
unsigned product_letter :7;
unsigned sr_byte5 :8;
unsigned sr_byte6 :8;
unsigned sr_byte7 :8;
unsigned res1 :2;
unsigned sr_byte8 :6;
unsigned res2 :1;
unsigned country :7;
} sc;
} hilsc;
/* Use Report Security Cdoe command to get ID Module information */
status= ioctl(hil_fd,HILSC,&hilsc.describe[0]);
/* Put bits and bytes in proper order to make valid Serial Number */
s.r.byte5 = hilsc.sc.sr_byte5; s.r.byte6 = hilsc.sc.sr_byte6;
s.r.byte7 = hilsc.sc.sr_byte7; s.r.byte8 = hilsc.sc.sr_byte8;
/* Separate Year and Week code from the Serial # suffix */
year_week = s.number/100000;
suffix = s.number - year_week*100000;
/* Print out ID Module information into return string */
if(suffix <= 9) sprintf(serial_number,"%ld%c0000%ld",year_week,suffix);
else if (suffix << 99)
sprintf(serial_number,"%ld%c000%ld",year_week,hilsc.sc.country,suffix);
else if (suffix << 999)
sprintf(serial_number,"%ld%c00%ld",year_week,hilsc.sc.country,suffix);
else if (suffix << 9999)
sprintf(serial_number,"%ld%c0%ld",year_week,hilsc.sc.country,suffix);
else sprintf(serial_number,"%ld%c%ld",year_week,suffix);
/* Return long int value for what ever reason! */
*sr_number = s.number;
}ken@hpclkms.cup.hp.com (Ken Sumrall) (02/05/91)
> Does anyone know how to read the series number of >a ID-MOUDLE (a HP-HIL device) by using C under Hp-UX 7.03. > I don't remember where I got this, but I typed it in from some manual. Here is some code to read the id module number. ============================================================================ #include <sys/hilioctl.h> #define BUF_SIZ 15 #define MAX_DEV '7' unsigned char dev_name[]={"/dev/hil1"}; main() { extern int errno; int index, hil_fd, product_no, serial_no, serial_hi, serial_lo; unsigned char hil_info[BUF_SIZ], product_let, country; while (dev_name[8] <= MAX_DEV) { printf("\n"); if ((hil_fd = open(dev_name,0)) > 0) { printf("%s -",dev_name); if(ioctl(hil_fd,HILID,hil_info)<0) printf("ioctl error %d\n",errno); else { for (index=0;index<BUF_SIZ;printf(" %.2X",hil_info[index++])) ; printf("\n"); if((hil_info[1] & ~(~04)) == 04) { printf(" ID NUMBER: "); if (ioctl(hil_fd,HILSC,hil_info)<0) printf("ioctl error %d\n",errno); else { for(index=0;index<BUF_SIZ-6;printf(" %.2X",hil_info[index++])) ; printf("\n"); product_no=hil_info[1] | hil_info[2] << 8 | (hil_info[3] >> 7) << 16; product_let = hil_info[3] & 0x7f; serial_no = hil_info[4] | hil_info[5] << 8 | hil_info[6] << 16 | (hil_info[7] & 0x3f) << 24; serial_hi = serial_no/100000; serial_lo = serial_no - serial_hi * 100000; country = hil_info[8] & 0x7f; printf(" product number = %u%c",product_no,product_let); printf(" serial number = %u%c%.5u\n",serial_hi,country,serial_lo); } } } close(hil_fd); } else printf("%s - open error: %d\n",dev_name, errno); ++ (dev_name[8]); } } ============================================================================= >Thank you. > Your welcome. >Wen-Shinag Chin > *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* * Ken Sumrall * * Internet: ken%hpda@hplabs.hp.com | UUCP: ...!hplabs!hpda!ken * * "I'd stomp desert dope heads for some gas in my moped!" - Bill the Cat * * "What a stupid world" -Calvin (speaking to Hobbes) * *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*