#include #include #include "/home/jeblack3/libusblinux300/ownet.h" void echoBlock (int portnum, unsigned char *buf, SMALLINT len, char op[7]); int main (int argc, char *argv[]) { char portname[9] = "DS2490-1"; unsigned char SN[8], buf[19]; int portnum, i, n, byte; // Get serial number from command-line argument if (argc < 2) { printf ("ERROR: Expected: therm-read serial-number\n"); return 0; } for (i = 0; i < 8; i++) { n = sscanf (argv[1] + 2 * i, "%02x", &byte); SN[7 - i] = (unsigned char) byte; if (n != 1) break; } if (i < 8) { printf ("ERROR: Invalid serial number\n"); return 0; } // Acquire adapter portnum = owAcquireEx (portname); if (portnum < 0) { printf ("ERROR: Adapter not found\n"); return 0; } while (1) { // Reset devices if ( !owTouchReset(portnum) ) { printf ("ERROR: No one-wire devices present on network\n"); return 0; } // Send serial number, read scratchpad buf[0] = 0x55; for (i = 0; i < 8; i++) { buf[i + 1] = SN[i]; } buf[9] = 0xBE; for (i = 0; i < 9; i++) { buf[i + 10] = 0xFF; } echoBlock (portnum, buf, 19, "READ "); } } void echoBlock (int portnum, unsigned char *buf, SMALLINT len, char op[7]) { int i; time_t time_seconds; struct tm *time_calendar; char *time_string; time_seconds = time (NULL); printf ("%s Secs1: %10lu\n", op, time_seconds); time_calendar = localtime (&time_seconds); time_string = asctime (time_calendar); printf ("%s Time1: %s", op, time_string); printf ("%s Sent: ", op); for (i = 0; i < len; i++) { printf ("%02X ", buf[i]); } printf ("\n"); owBlock (portnum, FALSE, buf, len); printf ("%s Recvd: ", op); for (i = 0; i < len; i++) { printf ("%02X ", buf[i]); } printf ("\n"); time_seconds = time (NULL); printf ("%s Secs2: %10lu\n", op, time_seconds); time_calendar = localtime (&time_seconds); time_string = asctime (time_calendar); printf ("%s Time2: %s", op, time_string); printf ("\n"); return; }