VOC Optimation
[owSlave2.git] / tools_cmd / rwOW / main.cpp
index 184ffd7..fa6df19 100644 (file)
-#define _CRT_SECURE_NO_WARNINGS 1
-extern "C" {
-#include "ownet.h"
-}
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-FILE *fio;
-char s[100], fname[254];
-
-
-SMALLINT ReadDS2430(int portnum, uchar SerialNum[8]) {
-       uchar rt = FALSE;
-       uchar send_block[145];
-       uchar send_cnt = 0, i;
-       int address;
-       char s[100];
-       FILE *f;
-       sprintf(s, "%02X%02X%02X%02X%02X%02X%02X%02X.bin", SerialNum[7], SerialNum[6], SerialNum[5], SerialNum[4], SerialNum[3], SerialNum[2], SerialNum[1], SerialNum[0]);
-       fprintf(fio, ">14\n");
-       send_cnt = 0;
-       printf("Read Data MEM  \n");
-       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
-       send_block[send_cnt++] = 0xF0;
-       send_block[send_cnt++] = 0x00;
-       for (i = 0; i<32; i++) send_block[send_cnt++] = 0xFF;
-       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
-       for (i = 2; i<send_cnt; i++) { printf("%02X ", send_block[i]); fprintf(fio,"%02X ", send_block[i]); }
-       printf("\n");
-       fprintf(fio, "\n");
-       send_cnt = 0;
-       printf("Read App MEM  \n");
-       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
-       send_block[send_cnt++] = 0xC3;
-       send_block[send_cnt++] = 0x00;
-       for (i = 0; i<8; i++) send_block[send_cnt++] = 0xFF;
-       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
-       for (i = 2; i<send_cnt; i++) { printf("%02X ", send_block[i]); fprintf(fio, "%02X ", send_block[i]); }
-       printf("\n");
-       fprintf(fio, "\n");
-
-       send_cnt = 0;
-       printf("Read App State  \n");
-       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
-       send_block[send_cnt++] = 0x66;
-       for (i = 0; i<1; i++) send_block[send_cnt++] = 0xFF;
-       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
-       for (i = 1; i<send_cnt; i++) { printf("%02X ", send_block[i]);  fprintf(fio, "%02X ", send_block[i]); }
-       printf("\n");
-       fprintf(fio, "\n");
-}
-
-
-SMALLINT ReadDS2433(int portnum, uchar SerialNum[8]) {
-       uchar rt = FALSE;
-       uchar send_block[145];
-       uchar send_cnt = 0, i, j;
-       int address;
-       send_cnt = 0;
-       printf("-----> TEST DS2433 \n");
-       fprintf(fio, ">23\n");
-
-       send_cnt = 0;
-       printf("\nRead MEM ALL \n");
-       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
-       send_block[send_cnt++] = 0xF0;
-       send_block[send_cnt++] = 0x00;
-       send_block[send_cnt++] = 0x00;
-       for (j = 0; j<16; j++) {
-               for (i = 0; i<32; i++) send_block[send_cnt++] = 0xFF;
-               if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
-               for (i = j?0:3; i < send_cnt; i++) { printf("%02X ", send_block[i]); fprintf(fio, "%02X ", send_block[i]); }
-               send_cnt = 0;
-               printf("\n");
-               fprintf(fio, "\n");
-       }
-
-}
-
-
-int findDev(uchar code) {
-       int find = 0;
-       fio = fopen(fname, "r");
-       while (!feof(fio)) {
-               s[0] = fgetc(fio);
-               if (s[0] == '>') {
-                       s[0] = fgetc(fio);
-                       s[1] = fgetc(fio);
-                       s[2] = 0;
-                       uchar w = strtol(s, NULL, 16);
-                       if (code ==w) return 1;
-               }
-       }
-       fclose(fio);
-       return 0;
-}
-
-
-
-SMALLINT WriteDS2433(int portnum, uchar SerialNum[8]) {
-       uchar rt = FALSE;
-       uchar send_block[145];
-       uchar send_cnt = 0, i, j;
-       int address;
-       send_cnt = 0;
-       printf("-----> TEST DS2433 \n");
-       if (findDev(0x23)) {
-               for (j = 0; j < 16; j++) {
-                       for (i = 0; i < 32; i++) {
-                               fscanf(fio, "%02X", &send_block[i + 3]);
-                       }
-                       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
-                       send_block[0] = 0x0F;
-                       send_block[1] = j << 5;
-                       send_block[2] = j >> 3;
-                       if (!owBlock(portnum, FALSE, send_block, 32 + 3))  { printf("ERROR RUN COMMAND \n"); return 1; }
-                       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
-                       send_cnt = 0;
-                       send_block[send_cnt++] = 0xAA;
-                       for (i = 0; i < 32 + 3; i++) send_block[send_cnt++] = 0xFF;
-                       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
-                       for (i = 0; i < send_cnt; i++) { printf("%02X ", send_block[i]); }
-                       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
-                       send_cnt = 0;
-                       send_block[send_cnt++] = 0x55;
-                       send_cnt += 3;
-                       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
-                       msDelay(100);
-                       printf("\n");
-               }
-       
-       }
-       fclose(fio);
-       return 0;
-
-
-}
-
-
-SMALLINT WriteDS2430(int portnum, uchar SerialNum[8]) {
-       uchar rt = FALSE;
-       uchar send_block[145];
-       uchar send_cnt = 0, i, j;
-       int address;
-       send_cnt = 0;
-       printf("-----> TEST DS2430 \n");
-       if (findDev(0x14)) {
-               for (i = 0; i < 32; i++) {
-                       fscanf(fio, "%02X", &send_block[i + 2]);
-               }
-               if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
-               send_block[0] = 0x0F;
-               send_block[1] = 0;
-               if (!owBlock(portnum, FALSE, send_block, 32 + 2))  { printf("ERROR RUN COMMAND \n"); return 1; }
-               if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
-               send_cnt = 0;
-               send_block[send_cnt++] = 0xAA;
-               send_block[send_cnt++] = 0x00;
-               for (i = 0; i < 32 + 2; i++) send_block[send_cnt++] = 0xFF;
-               if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
-               for (i = 0; i < send_cnt; i++) { printf("%02X ", send_block[i]); }
-               if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
-               send_cnt = 0;
-               send_block[send_cnt++] = 0x55;
-               send_block[send_cnt++] = 0xA5;
-               if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
-               msDelay(100);
-               printf("\n");
-       }
-       fclose(fio);
-
-}
-/*
-SMALLINT WriteDS2430(int portnum, uchar SerialNum[8], const char *fname) {
-       uchar rt = FALSE;
-       uchar send_block[145];
-       uchar send_cnt = 0, i;
-       int address;
-       uchar readbl[64];
-       FILE *f;
-       f = fopen(fname, "rb");
-       fread(readbl, 1, 32 + 16, f);
-       fclose(f);
-       ResetDS2430(portnum, SerialNum);
-       msDelay(1000);
-       send_cnt = 0;
-       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
-       send_block[send_cnt++] = 0x0F;
-       send_block[send_cnt++] = 0x00;
-       for (i = 0; i<32; i++) send_block[send_cnt++] = readbl[i + 8];
-       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
-       send_cnt = 0;
-       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
-       send_block[send_cnt++] = 0xAA;
-       send_block[send_cnt++] = 0x00;
-       for (i = 0; i<32; i++) send_block[send_cnt++] = 0xFF;
-       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
-       for (i = 0; i<send_cnt; i++) { printf("%02X ", send_block[i]); if ((i - 1) % 16 == 0) printf("\n"); }
-
-       send_cnt = 0;
-       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
-       send_block[send_cnt++] = 0x55;
-       send_block[send_cnt++] = 0xA5;
-       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
-       msDelay(10);
-
-       send_cnt = 0;
-       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
-       send_block[send_cnt++] = 0xF0;
-       send_block[send_cnt++] = 0x00;
-       for (i = 0; i<32; i++) send_block[send_cnt++] = 0xFF;
-       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
-       for (i = 0; i<send_cnt; i++) { printf("%02X ", send_block[i]); if ((i - 1) % 16 == 0) printf("\n"); }
-
-       send_cnt = 0;
-       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
-       send_block[send_cnt++] = 0x99;
-       send_block[send_cnt++] = 0x00;
-       for (i = 0; i<8; i++) send_block[send_cnt++] = readbl[i + 8 + 32];
-       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
-
-       send_cnt = 0;
-       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
-       send_block[send_cnt++] = 0x5A;
-       send_block[send_cnt++] = 0xA5;
-       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
-       msDelay(10);
-       SetIDDS2430(portnum, SerialNum, readbl);
-
-
-}
-*/
-
-
-
-unsigned char conf2(const char *s) {
-       unsigned char b = 0;
-       for (int i = 0; i < 2; i++) {
-               b = b * 16;
-               if ((s[i] >= '0') && (s[i] <= '9')) {
-                       b += s[i] - '0';
-               } else
-               if ((s[i] >= 'A') && (s[i] <= 'F')) {
-                       b += s[i] - 'A'+10;
-               } else
-               if ((s[i] >= 'a') && (s[i] <= 'f')) {
-                       b += s[i] - 'a'+10;
-               }
-               
-       }
-       return b;
-}
-
-void strcpys(char *s, const char* d,bool up) {
-       if (strlen(d) > 7990) {
-               strncpy(s, d, 7990);
-               s[200] = 0;
-       }
-       else strcpy(s, d);
-       if (up) {
-               for (int i = 0; i<strlen(s); i++)
-                       if ((s[i] >= 'a') && (s[i] <= 'z'))
-                               s[i] += 'A' - 'a';
-       }
-}
-
-int main(int argc, char *argv[]) {
-       uchar SNum[8];
-       int rslt, cnt, i;
-       uchar send_block[256];
-       uchar send_cnt = 0;
-       int portnum;
-       char adapter[20];
-       int found = 0;
-       int rw = 0;
-       int err = 0;
-       char s[8000];
-       int adt = 0;
-       int mod = 0;
-       if (argc >= 2) {
-               strcpys(s, argv[1],true);
-               
-               
-               if (strncmp(s,"USB",3)==0) {adt = 6;}
-               if (strncmp(s, "COM", 3) == 0) { adt = 5; }
-               if (adt != 0) {
-                       strcpy(s, argv[1] + 3);
-                       sprintf(adapter, "{%s,%i}\0",s,adt);
-                       printf("Open Port %s\n", argv[1]);
-                       if ((portnum = owAcquireEx(adapter)) < 0) {
-                               printf("ERROR \n", adt);
-                       }
-                       else mod = 1;
-
-               } 
-               if ((argc == 2) && (mod == 1)) mod = 2;
-               if (argc > 2) {
-                       strcpys(s, argv[2],true);
-                       if (strncmp(s, "DC", 2) == 0) {
-                               if (argc > 3) {
-                                       if (strlen(argv[3])>=16)
-                                       for (int i = 0; i < 16; i += 2) {
-                                               SNum[7 - (i / 2)] = conf2(argv[3] + i);
-
-                                       }
-                                       printf("Select: %02X%02X%02X%02X%02X%02X%02X%02X\n", SNum[7], SNum[6], SNum[5], SNum[4], SNum[3], SNum[2], SNum[1], SNum[0]);
-                                       mod = 3;
-                               }
-
-                       }
-               }
-               if ((mod == 3) && (argc>4)) {
-                       strcpys(s, argv[4], true);
-                       mod = 4;
-               }
-       
-       }
-
-       if (mod == 2) {
-               rslt = owFirst(portnum, TRUE, FALSE);
-               cnt = 0;
-               while (rslt) {
-                       cnt++;
-                       owSerialNum(portnum, &SNum[0], TRUE);
-                       printf("%02X%02X%02X%02X%02X%02X%02X%02X\n", SNum[7], SNum[6], SNum[5], SNum[4], SNum[3], SNum[2], SNum[1], SNum[0]);
-                       //                      fprintf(ft,"%02X%02X%02X%02X%02X%02X%02X%02X\n",SNum[7],SNum[6],SNum[5],SNum[4],SNum[3],SNum[2],SNum[1],SNum[0]);
-/*                     switch (SNum[0]) {
-
-
-                               case 0x14: {
-                                       //TestDS2430(portnum,&SNum[0]);
-                                       //scanf("%i",&i);
-                                       //ResetDS2430(portnum,&SNum[0]);
-                                       //uchar id[]={0x14,0xF5 ,0xEA ,0x24 ,0x06 ,0x00 ,0x00 ,0x5E};
-                                       //SetIDDS2430(portnum,&SNum[0],id);
-                                       if (rw) WriteDS2430(portnum, &SNum[0]); else ReadDS2430(portnum, &SNum[0]);
-                                       //WriteDS2430(portnum,&SNum[0],"5E00000624EAF514.bin");
-                                       break;
-                               }
-                               case 0x23: {
-                                       //TestDS2433(portnum,&SNum[0]);
-                                       //TestDS2433_reset(portnum,&SNum[0]);
-                                       //scanf("%i",&i);
-                                       if (rw) WriteDS2433(portnum, &SNum[0]); else ReadDS2433(portnum, &SNum[0]);
-                                       break;
-                               }
-                               }*/
-                       rslt = owNext(portnum, TRUE, FALSE);
-               }
-       }
-       if (mod == 4) {
-               owSerialNum(portnum, SNum, FALSE);
-               strcat(s, "_R");
-               int len = strlen(s);
-               int i = 0;
-               while (i < len) {
-                       if (s[i] == '_') {
-                               if (s[i + 1] == 'R') {
-                                       if (owAccess(portnum)) {
-                                               if (owBlock(portnum, FALSE, send_block, send_cnt)) {
-                                                       for (int j = 0; j < send_cnt; j++) {
-                                                               printf("%02X", send_block[j]);
-                                                       }
-                                                       printf("\n");
-                                               }
-                                               else printf("ERROR RESET\n");
-                                       }
-                                       else printf("ERROR SEND\n");
-                                       send_cnt = 0;
-                               }
-                               if (s[i + 1] == 'P') {
-                                       if (i + 2 < len) {
-                                               i += 2;
-                                               msDelay(conf2(s + i));
-                                               
-                                       }
-                               }
-                       }
-                       else {
-                               send_block[send_cnt++] = conf2(s + i);
-                       }
-                       i += 2;
-               
-                       
-               }
-       }
-       if (mod>0) owRelease(portnum);
-       
-       return 0;
+#define _CRT_SECURE_NO_WARNINGS 1\r
+extern "C" {\r
+#include "ownet.h"\r
+}\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+\r
+FILE *fio;\r
+char s[100], fname[254];\r
+\r
+\r
+SMALLINT ReadDS2430(int portnum, uchar SerialNum[8]) {\r
+       uchar rt = FALSE;\r
+       uchar send_block[145];\r
+       uchar send_cnt = 0, i;\r
+       int address;\r
+       char s[100];\r
+       FILE *f;\r
+       sprintf(s, "%02X%02X%02X%02X%02X%02X%02X%02X.bin", SerialNum[7], SerialNum[6], SerialNum[5], SerialNum[4], SerialNum[3], SerialNum[2], SerialNum[1], SerialNum[0]);\r
+       fprintf(fio, ">14\n");\r
+       send_cnt = 0;\r
+       printf("Read Data MEM  \n");\r
+       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }\r
+       send_block[send_cnt++] = 0xF0;\r
+       send_block[send_cnt++] = 0x00;\r
+       for (i = 0; i<32; i++) send_block[send_cnt++] = 0xFF;\r
+       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }\r
+       for (i = 2; i<send_cnt; i++) { printf("%02X ", send_block[i]); fprintf(fio,"%02X ", send_block[i]); }\r
+       printf("\n");\r
+       fprintf(fio, "\n");\r
+       send_cnt = 0;\r
+       printf("Read App MEM  \n");\r
+       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }\r
+       send_block[send_cnt++] = 0xC3;\r
+       send_block[send_cnt++] = 0x00;\r
+       for (i = 0; i<8; i++) send_block[send_cnt++] = 0xFF;\r
+       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }\r
+       for (i = 2; i<send_cnt; i++) { printf("%02X ", send_block[i]); fprintf(fio, "%02X ", send_block[i]); }\r
+       printf("\n");\r
+       fprintf(fio, "\n");\r
+\r
+       send_cnt = 0;\r
+       printf("Read App State  \n");\r
+       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }\r
+       send_block[send_cnt++] = 0x66;\r
+       for (i = 0; i<1; i++) send_block[send_cnt++] = 0xFF;\r
+       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }\r
+       for (i = 1; i<send_cnt; i++) { printf("%02X ", send_block[i]);  fprintf(fio, "%02X ", send_block[i]); }\r
+       printf("\n");\r
+       fprintf(fio, "\n");\r
+}\r
+\r
+\r
+SMALLINT ReadDS2433(int portnum, uchar SerialNum[8]) {\r
+       uchar rt = FALSE;\r
+       uchar send_block[145];\r
+       uchar send_cnt = 0, i, j;\r
+       int address;\r
+       send_cnt = 0;\r
+       printf("-----> TEST DS2433 \n");\r
+       fprintf(fio, ">23\n");\r
+\r
+       send_cnt = 0;\r
+       printf("\nRead MEM ALL \n");\r
+       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }\r
+       send_block[send_cnt++] = 0xF0;\r
+       send_block[send_cnt++] = 0x00;\r
+       send_block[send_cnt++] = 0x00;\r
+       for (j = 0; j<16; j++) {\r
+               for (i = 0; i<32; i++) send_block[send_cnt++] = 0xFF;\r
+               if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }\r
+               for (i = j?0:3; i < send_cnt; i++) { printf("%02X ", send_block[i]); fprintf(fio, "%02X ", send_block[i]); }\r
+               send_cnt = 0;\r
+               printf("\n");\r
+               fprintf(fio, "\n");\r
+       }\r
+\r
+}\r
+\r
+\r
+int findDev(uchar code) {\r
+       int find = 0;\r
+       fio = fopen(fname, "r");\r
+       while (!feof(fio)) {\r
+               s[0] = fgetc(fio);\r
+               if (s[0] == '>') {\r
+                       s[0] = fgetc(fio);\r
+                       s[1] = fgetc(fio);\r
+                       s[2] = 0;\r
+                       uchar w = strtol(s, NULL, 16);\r
+                       if (code ==w) return 1;\r
+               }\r
+       }\r
+       fclose(fio);\r
+       return 0;\r
+}\r
+\r
+\r
+\r
+SMALLINT WriteDS2433(int portnum, uchar SerialNum[8]) {\r
+       uchar rt = FALSE;\r
+       uchar send_block[145];\r
+       uchar send_cnt = 0, i, j;\r
+       int address;\r
+       send_cnt = 0;\r
+       printf("-----> TEST DS2433 \n");\r
+       if (findDev(0x23)) {\r
+               for (j = 0; j < 16; j++) {\r
+                       for (i = 0; i < 32; i++) {\r
+                               fscanf(fio, "%02X", &send_block[i + 3]);\r
+                       }\r
+                       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }\r
+                       send_block[0] = 0x0F;\r
+                       send_block[1] = j << 5;\r
+                       send_block[2] = j >> 3;\r
+                       if (!owBlock(portnum, FALSE, send_block, 32 + 3))  { printf("ERROR RUN COMMAND \n"); return 1; }\r
+                       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }\r
+                       send_cnt = 0;\r
+                       send_block[send_cnt++] = 0xAA;\r
+                       for (i = 0; i < 32 + 3; i++) send_block[send_cnt++] = 0xFF;\r
+                       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }\r
+                       for (i = 0; i < send_cnt; i++) { printf("%02X ", send_block[i]); }\r
+                       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }\r
+                       send_cnt = 0;\r
+                       send_block[send_cnt++] = 0x55;\r
+                       send_cnt += 3;\r
+                       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }\r
+                       msDelay(100);\r
+                       printf("\n");\r
+               }\r
+       \r
+       }\r
+       fclose(fio);\r
+       return 0;\r
+\r
+\r
+}\r
+\r
+\r
+SMALLINT WriteDS2430(int portnum, uchar SerialNum[8]) {\r
+       uchar rt = FALSE;\r
+       uchar send_block[145];\r
+       uchar send_cnt = 0, i, j;\r
+       int address;\r
+       send_cnt = 0;\r
+       printf("-----> TEST DS2430 \n");\r
+       if (findDev(0x14)) {\r
+               for (i = 0; i < 32; i++) {\r
+                       fscanf(fio, "%02X", &send_block[i + 2]);\r
+               }\r
+               if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }\r
+               send_block[0] = 0x0F;\r
+               send_block[1] = 0;\r
+               if (!owBlock(portnum, FALSE, send_block, 32 + 2))  { printf("ERROR RUN COMMAND \n"); return 1; }\r
+               if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }\r
+               send_cnt = 0;\r
+               send_block[send_cnt++] = 0xAA;\r
+               send_block[send_cnt++] = 0x00;\r
+               for (i = 0; i < 32 + 2; i++) send_block[send_cnt++] = 0xFF;\r
+               if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }\r
+               for (i = 0; i < send_cnt; i++) { printf("%02X ", send_block[i]); }\r
+               if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }\r
+               send_cnt = 0;\r
+               send_block[send_cnt++] = 0x55;\r
+               send_block[send_cnt++] = 0xA5;\r
+               if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }\r
+               msDelay(100);\r
+               printf("\n");\r
+       }\r
+       fclose(fio);\r
+\r
+}\r
+/*\r
+SMALLINT WriteDS2430(int portnum, uchar SerialNum[8], const char *fname) {\r
+       uchar rt = FALSE;\r
+       uchar send_block[145];\r
+       uchar send_cnt = 0, i;\r
+       int address;\r
+       uchar readbl[64];\r
+       FILE *f;\r
+       f = fopen(fname, "rb");\r
+       fread(readbl, 1, 32 + 16, f);\r
+       fclose(f);\r
+       ResetDS2430(portnum, SerialNum);\r
+       msDelay(1000);\r
+       send_cnt = 0;\r
+       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }\r
+       send_block[send_cnt++] = 0x0F;\r
+       send_block[send_cnt++] = 0x00;\r
+       for (i = 0; i<32; i++) send_block[send_cnt++] = readbl[i + 8];\r
+       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }\r
+       send_cnt = 0;\r
+       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }\r
+       send_block[send_cnt++] = 0xAA;\r
+       send_block[send_cnt++] = 0x00;\r
+       for (i = 0; i<32; i++) send_block[send_cnt++] = 0xFF;\r
+       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }\r
+       for (i = 0; i<send_cnt; i++) { printf("%02X ", send_block[i]); if ((i - 1) % 16 == 0) printf("\n"); }\r
+\r
+       send_cnt = 0;\r
+       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }\r
+       send_block[send_cnt++] = 0x55;\r
+       send_block[send_cnt++] = 0xA5;\r
+       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }\r
+       msDelay(10);\r
+\r
+       send_cnt = 0;\r
+       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }\r
+       send_block[send_cnt++] = 0xF0;\r
+       send_block[send_cnt++] = 0x00;\r
+       for (i = 0; i<32; i++) send_block[send_cnt++] = 0xFF;\r
+       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }\r
+       for (i = 0; i<send_cnt; i++) { printf("%02X ", send_block[i]); if ((i - 1) % 16 == 0) printf("\n"); }\r
+\r
+       send_cnt = 0;\r
+       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }\r
+       send_block[send_cnt++] = 0x99;\r
+       send_block[send_cnt++] = 0x00;\r
+       for (i = 0; i<8; i++) send_block[send_cnt++] = readbl[i + 8 + 32];\r
+       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }\r
+\r
+       send_cnt = 0;\r
+       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }\r
+       send_block[send_cnt++] = 0x5A;\r
+       send_block[send_cnt++] = 0xA5;\r
+       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }\r
+       msDelay(10);\r
+       SetIDDS2430(portnum, SerialNum, readbl);\r
+\r
+\r
+}\r
+*/\r
+\r
+\r
+\r
+unsigned char conf2(const char *s) {\r
+       unsigned char b = 0;\r
+       for (int i = 0; i < 2; i++) {\r
+               b = b * 16;\r
+               if ((s[i] >= '0') && (s[i] <= '9')) {\r
+                       b += s[i] - '0';\r
+               } else\r
+               if ((s[i] >= 'A') && (s[i] <= 'F')) {\r
+                       b += s[i] - 'A'+10;\r
+               } else\r
+               if ((s[i] >= 'a') && (s[i] <= 'f')) {\r
+                       b += s[i] - 'a'+10;\r
+               }\r
+               \r
+       }\r
+       return b;\r
+}\r
+\r
+void strcpys(char *s, const char* d,bool up) {\r
+       if (strlen(d) > 7990) {\r
+               strncpy(s, d, 7990);\r
+               s[200] = 0;\r
+       }\r
+       else strcpy(s, d);\r
+       if (up) {\r
+               for (int i = 0; i<strlen(s); i++)\r
+                       if ((s[i] >= 'a') && (s[i] <= 'z'))\r
+                               s[i] += 'A' - 'a';\r
+       }\r
+}\r
+\r
+int main(int argc, char *argv[]) {\r
+       uchar SNum[8];\r
+       int rslt, cnt, i;\r
+       uchar send_block[256];\r
+       uchar send_cnt = 0;\r
+       int portnum;\r
+       char adapter[20];\r
+       int found = 0;\r
+       int rw = 0;\r
+       int err = 0;\r
+       char s[8000];\r
+       int adt = 0;\r
+       int mod = 0;\r
+       if (argc >= 2) {\r
+               strcpys(s, argv[1],true);\r
+               \r
+               \r
+               if (strncmp(s,"USB",3)==0) {adt = 6;}\r
+               if (strncmp(s, "COM", 3) == 0) { adt = 5; }\r
+               if (adt != 0) {\r
+                       strcpy(s, argv[1] + 3);\r
+                       sprintf(adapter, "{%s,%i}\0",s,adt);\r
+                       printf("Open Port %s\n", argv[1]);\r
+                       if ((portnum = owAcquireEx(adapter)) < 0) {\r
+                               printf("ERROR \n", adt);\r
+                       }\r
+                       else mod = 1;\r
+\r
+               } \r
+               if ((argc == 2) && (mod == 1)) mod = 2;\r
+               if (argc > 2) {\r
+                       strcpys(s, argv[2],true);\r
+                       if (strncmp(s, "DC", 2) == 0) {\r
+                               if (argc > 3) {\r
+                                       if (strlen(argv[3])>=16)\r
+                                       for (int i = 0; i < 16; i += 2) {\r
+                                               SNum[7 - (i / 2)] = conf2(argv[3] + i);\r
+\r
+                                       }\r
+                                       printf("Select: %02X%02X%02X%02X%02X%02X%02X%02X\n", SNum[7], SNum[6], SNum[5], SNum[4], SNum[3], SNum[2], SNum[1], SNum[0]);\r
+                                       mod = 3;\r
+                               }\r
+\r
+                       }\r
+               }\r
+               if ((mod == 3) && (argc>4)) {\r
+                       strcpys(s, argv[4], true);\r
+                       mod = 4;\r
+               }\r
+       \r
+       }\r
+\r
+       if (mod == 2) {\r
+               rslt = owFirst(portnum, TRUE, FALSE);\r
+               cnt = 0;\r
+               while (rslt) {\r
+                       cnt++;\r
+                       owSerialNum(portnum, &SNum[0], TRUE);\r
+                       printf("%02X%02X%02X%02X%02X%02X%02X%02X\n", SNum[7], SNum[6], SNum[5], SNum[4], SNum[3], SNum[2], SNum[1], SNum[0]);\r
+                       //                      fprintf(ft,"%02X%02X%02X%02X%02X%02X%02X%02X\n",SNum[7],SNum[6],SNum[5],SNum[4],SNum[3],SNum[2],SNum[1],SNum[0]);\r
+/*                     switch (SNum[0]) {\r
+\r
+\r
+                               case 0x14: {\r
+                                       //TestDS2430(portnum,&SNum[0]);\r
+                                       //scanf("%i",&i);\r
+                                       //ResetDS2430(portnum,&SNum[0]);\r
+                                       //uchar id[]={0x14,0xF5 ,0xEA ,0x24 ,0x06 ,0x00 ,0x00 ,0x5E};\r
+                                       //SetIDDS2430(portnum,&SNum[0],id);\r
+                                       if (rw) WriteDS2430(portnum, &SNum[0]); else ReadDS2430(portnum, &SNum[0]);\r
+                                       //WriteDS2430(portnum,&SNum[0],"5E00000624EAF514.bin");\r
+                                       break;\r
+                               }\r
+                               case 0x23: {\r
+                                       //TestDS2433(portnum,&SNum[0]);\r
+                                       //TestDS2433_reset(portnum,&SNum[0]);\r
+                                       //scanf("%i",&i);\r
+                                       if (rw) WriteDS2433(portnum, &SNum[0]); else ReadDS2433(portnum, &SNum[0]);\r
+                                       break;\r
+                               }\r
+                               }*/\r
+                       rslt = owNext(portnum, TRUE, FALSE);\r
+               }\r
+       }\r
+       if (mod == 4) {\r
+               owSerialNum(portnum, SNum, FALSE);\r
+               strcat(s, "_R");\r
+               int len = strlen(s);\r
+               int i = 0;\r
+               while (i < len) {\r
+                       if (s[i] == '_') {\r
+                               if (s[i + 1] == 'R') {\r
+                                       if (owAccess(portnum)) {\r
+                                               if (owBlock(portnum, FALSE, send_block, send_cnt)) {\r
+                                                       for (int j = 0; j < send_cnt; j++) {\r
+                                                               printf("%02X", send_block[j]);\r
+                                                       }\r
+                                                       printf("\n");\r
+                                               }\r
+                                               else printf("ERROR RESET\n");\r
+                                       }\r
+                                       else printf("ERROR SEND\n");\r
+                                       send_cnt = 0;\r
+                               }\r
+                               if (s[i + 1] == 'P') {\r
+                                       if (i + 2 < len) {\r
+                                               i += 2;\r
+                                               msDelay(conf2(s + i));\r
+                                               \r
+                                       }\r
+                               }\r
+                       }\r
+                       else {\r
+                               send_block[send_cnt++] = conf2(s + i);\r
+                       }\r
+                       i += 2;\r
+               \r
+                       \r
+               }\r
+       }\r
+       if (mod>0) owRelease(portnum);\r
+       \r
+       return 0;\r
 }
\ No newline at end of file