home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / mycamx.zip / mycamx.cmd
OS/2 REXX Batch file  |  2001-11-19  |  21KB  |  473 lines

  1. /*** ThirdEye REXX Interface API Usage Example ***/
  2. /*** (c) 2001 Andrei A. Porodko             ******/
  3. /*                                                                         */
  4. /* this REXX cmdfile downloads all available pictures from the camera to   */
  5. /* the harddisk, if they are new or modified (different size, optional     */
  6. /* different date/time)                                                    */
  7. /*                                                                         */
  8. /*  F. Beythien     2001-10-25   fbeythien@gmx.de                          */
  9. /*                                                                         */
  10. /*To customize, modify  the lines  with                                    */
  11. /*                                 <----- to be changed                    */
  12. /*                                       as comment                        */
  13. pgmvers="V 2.5 2001-11-19 18.55"                         /* current Version*/
  14.  
  15. Signal On SYNTAX                                        /* trap REXX errors*/
  16. Signal On NOVALUE                                          /* trap bad vars*/
  17. Signal On HALT                                                /* trap ctl-C*/
  18.  
  19. /***************************************************************************/
  20. /*  Init environment                                                       */
  21. /***************************************************************************/
  22. Call Initos
  23.  
  24. Signal Firsttime   /* Delete this line when customized <----- to be changed*/
  25.  
  26. /***************************************************************************/
  27. /*  Location of ThirdEye Registration Key dataset                          */
  28. /*  assign nullstring for demoversion                                      */
  29. /***************************************************************************/
  30. thirdkey=""                     /* This is for running with the demoversion*/
  31. thirdkey="E:\coolpix9\thirdeye\thirdeye.key"        /* <----- to be changed*/
  32.  
  33. /***************************************************************************/
  34. /*  here goes our message output                                           */
  35. /***************************************************************************/
  36. logdat="E:\coolpix9\thirdeye\mycamx.log"            /* <----- to be changed*/
  37.  
  38. /***************************************************************************/
  39. /*  Here are the pictures stored                                           */
  40. /***************************************************************************/
  41. picdir="E:\coolpix9\thirdeye\rexxpic2\"             /* <----- to be changed*/
  42.  
  43. /***************************************************************************/
  44. /*  The following directory should be different from 'picdir'              */
  45. /*  It contains filenames which are ignored for download                   */
  46. /*  i.e. even if these files are not in picdir but available in the camera */
  47. /*  they will not be downloaded.                                           */
  48. /*  only the filename is compared ( no size/date/time)                     */
  49. /***************************************************************************/
  50. igndir="E:\coolpix9\pics\"                          /* <----- to be changed*/
  51.  
  52. /***************************************************************************/
  53. /*  If the 3eyerexx.dll supports picture timestamp i.e. creation date/time */
  54. /*  of the picture, set the following to "YES"                             */
  55. /*  for NIKON coolpix 990 it is not (yet) supported                        */
  56. /***************************************************************************/
  57. picdatetime ="NO"    /* Picture has creation timestamp <----- to be changed*/
  58.  
  59. port = "COM1"                          /* Used comport <----- to be changed*/
  60. baud = 115200                             /* Baud rate <----- to be changed*/
  61. camera = "Olympus"                /* Camera / Protocol <----- to be changed*/
  62.  
  63. /* Don't modify anything below or you better know what your are doing.     */
  64. /* Don't modify anything below or you better know what your are doing.     */
  65. /* Don't modify anything below or you better know what your are doing.     */
  66. dlcount=0
  67.  
  68. tab="09"x
  69.  
  70. If Right(picdir,1)<>"\" Then picdir=picdir"\"            /* must end with \*/
  71. picdir=Translate(Strip(picdir))                     /* convert to UPPERCASE*/
  72. pospicname=Length(picdir)+1
  73.  
  74. If Right(igndir,1)<>"\" Then igndir=igndir"\"            /* must end with \*/
  75. igndir=Translate(Strip(igndir))                     /* convert to UPPERCASE*/
  76. posignname=Length(igndir)+1
  77.  
  78. /*** camx REXX Function Return Code Definitions ************/
  79. ret_ok               =  0
  80. ret_not_enough_mem   = -1
  81. ret_insuff_params    = -2
  82. ret_not_connected    = -3
  83. ret_not_loaded       = -4
  84. ret_cant_get_picture = -5
  85. ret_cant_del_picture = -6
  86. ret_cant_get_number  = -7
  87. ret_cant_get_camname = -8
  88. ret_cant_take_pic    = -9
  89.  
  90. Call Logger 2,1,0,os invoke sourcefn xx 'ThirdEye REXX Interface' pgmvers
  91. Call Logger 2,0,0,'(c) 2001 Andrei A. Porodko modified by Frank Beythien'
  92.  
  93. Call Logger 2,0,0,langproc langlvl rday rmon ryear
  94. Call Logger 0,0,1,'Starting' Date() 'at' Time()
  95.  
  96. Call Logger 2,0,0,'Registering all Functions for further usage'
  97. Call Rxfuncadd 'camxInit', '3eyeRexx', 'camxInit'
  98.  
  99. /***************************************************************************/
  100. /*  Trap invalid registration key                                          */
  101. /***************************************************************************/
  102.  
  103. Signal On SYNTAX name notregistered
  104. Call Camxinit thirdkey                          /* try to init 3eyeREXX.dll*/
  105. Signal On SYNTAX                        /* restore 'normal' Syntax checking*/
  106.  
  107. Call Logger 2,0,0,camxgetversion()                      /* output Version*/
  108.  
  109. Call Logger 2,1,0,'Connecting to' camera 'on' port 'with' baud 'baud'
  110.  
  111. rc = camxconnect(port,baud,camera)
  112. If  rc \== ret_ok Then Do
  113.   Call Logger 2,0,0,'Err: Connection to Camera Failure, code =' rc
  114.   Call Logger 1,0,0,'     Check the Connection or Parameters.'
  115.   Call Camxquit
  116.   Exit 99
  117. End
  118.  
  119. Call Logger 2,1,1,'Getting Various Information from Camera'
  120. Call Logger 2,0,0,'Camera name  =' camxgetcameraname()
  121. framesavail = camxframestaken()    /* save availabe picture count for later*/
  122. Call Logger 2,0,0,'Frames taken =' Format(framesavail,3),
  123.   '<-- available for download'
  124. Call Logger 2,0,0,'Frames left  =' Format(camxframesleft(),3),
  125.   '<-- available for taking pictures'
  126.  
  127. /***************************************************************************/
  128. /*  Get info about pictures in picdir                                      */
  129. /***************************************************************************/
  130. rc=sysfiletree(picdir"*.jpg","pics","FT")
  131. If rc<>0 Then pics.0=0
  132.  
  133. /***************************************************************************/
  134. /*  reformat the info for easier compare                                   */
  135. /***************************************************************************/
  136. Do k=1 To pics.0
  137.  
  138.   If k=1 Then Say pics.1
  139.  
  140. /***************************************************************************/
  141. /* handle blanks in filename don't rely on fixed offset for filename start */
  142. /***************************************************************************/
  143.   fnpos=Pos(picdir,pics.k)
  144.   work=Strip(Substr(pics.k,fnpos))
  145.   work=Substr(work,pospicname)
  146.   picname.k=Translate(work)
  147.   picsize.k=Strip(Word(pics.k,2))
  148.   picdate.k="20"Strip(Word(pics.k,1))         /* date/time 20YY/MM/DD/hh/mm*/
  149.  
  150.   /*************************************************************************/
  151.   /*  Handle 19xx case                                                     */
  152.   /*************************************************************************/
  153.   If Substr(picdate.k,3,2)>"79" Then  Do
  154.     picdate.k=Overlay("19",picdate.k,1)
  155.   End
  156.  
  157.   /*************************************************************************/
  158.   /*  Dateformat is now YYYY/MM/DD/hh/mm                                   */
  159.   /*************************************************************************/
  160.  
  161. End
  162.  
  163. /***************************************************************************/
  164. /*  Show all stored picture data                                           */
  165. /***************************************************************************/
  166.  
  167. Call Logger 2,0,0,"stored picture count:" pics.0 "in directory:" picdir
  168. sizem=Length(pics.0)
  169.  
  170. Do m=1 To pics.0
  171.   Call Logger 2,0,(m=pics.0),"stored picture" Format(m,sizem)":",
  172.     picname.m Format(picsize.m,12) "   " picdate.m
  173. End
  174.  
  175.  
  176. /***************************************************************************/
  177. /*  Get info about files    in igndir                                      */
  178. /***************************************************************************/
  179. rc=sysfiletree(igndir"*.jpg","igns","FT")
  180. If rc<>0 Then igns.0=0
  181.  
  182. /***************************************************************************/
  183. /*  reformat the info for easier compare                                   */
  184. /***************************************************************************/
  185. Do k=1 To igns.0
  186.  
  187.   If k=1 Then Say igns.1
  188.  
  189. /***************************************************************************/
  190. /* handle blanks in filename don't rely on fixed offset for filename start */
  191. /***************************************************************************/
  192.   fnpos=Pos(igndir,igns.k)
  193.   work=Strip(Substr(igns.k,fnpos))
  194.   work=Substr(work,posignname)
  195.   ignname.k=Translate(work)
  196. End
  197.  
  198. /***************************************************************************/
  199. /*  Show all files to be ignored                                           */
  200. /***************************************************************************/
  201.  
  202. Call Logger 2,1,0,"stored ignore file count:" igns.0 "in directory:" igndir
  203. sizem=Length(igns.0)
  204.  
  205. Do k=1 To igns.0
  206.   Call Logger 2,0,(k=igns.0),"ignore picture" Format(k,sizem)":" ignname.k
  207. End
  208.  
  209. /***************************************************************************/
  210. /*  for all available pictures                                             */
  211. /***************************************************************************/
  212. Do k = 1 To framesavail
  213.   cpicname=Translate(camxgetpicturename(k))
  214.  
  215.   /*************************************************************************/
  216.   /*  compare with ignore list                                             */
  217.   /*************************************************************************/
  218.  
  219.   Do m=1 To igns.0
  220.     If  cpicname=ignname.m Then Do
  221.       /***********************************************************************/
  222.       /*  We are to ignore this picture                                      */
  223.       /***********************************************************************/
  224.       Call Logger 2,0,0,"Picture is on ignore list:" cpicname
  225.       Iterate k                                  /* try next camera picture*/
  226.     End
  227.   End
  228.   cpicsize=camxgetpicturesize(k,0)
  229.   cpicdate=camxgetpicturedate(k)          /* Dateformat YYYY/MM/DD/hh/mm/ss*/
  230.   cpicdate2=Left(cpicdate,16)             /* Dateformat YYYY/MM/DD/hh/mm   */
  231.  
  232.   /*************************************************************************/
  233.   /*  Compare with all stored pictures                                     */
  234.   /*************************************************************************/
  235.   Do m=1 To pics.0
  236.     If  cpicname=picname.m Then Do
  237.  
  238.       /***********************************************************************/
  239.       /*  We already have a picture with same name                           */
  240.       /***********************************************************************/
  241.       Call Logger 2,1,0,"Picture with same name exists:"
  242.       Call Logger 2,0,0,"stored picture data:",
  243.         picname.m Format(picsize.m,12) "   " picdate.m
  244.       Call Logger 2,0,0,"camera picture data:",
  245.         cpicname Format(cpicsize,12) "   " cpicdate2
  246.  
  247.       If cpicsize=picsize.m Then Do
  248.         Call Logger 2,0,0," ... and same size."
  249.  
  250.         /*******************************************************************/
  251.         /*  If the "real" creation timestamp cannot be retrieved from the  */
  252.         /*  camera (coolpix 990 does not (yet) support this)               */
  253.         /*  treat picture as equal (skip download)                         */
  254.         /*******************************************************************/
  255.         If picdatetime="NO" Then Iterate k       /* try next camera picture*/
  256.         If cpicdate2=picdate.m Then Do
  257.           Call Logger 2,0,0," ... and same date."
  258.         End
  259.         Else Do
  260.           If cpicdate2 > picdate.m Then Do
  261.             Call Logger 2,0,0," ... but older date:" cpicdate2
  262.           End
  263.           Else Do
  264.             Call Logger 2,0,0," ... but newer date:" cpicdate2
  265.           End
  266.           Leave m                                    /* go get the picture*/
  267.         End
  268.       End
  269.       Else Do
  270.         Call Logger 2,0,0," ... but different size:" cpicsize
  271.         Leave m                                      /* go get the picture*/
  272.       End
  273.     End
  274.   End
  275.  
  276.   name = picdir||cpicname
  277.   dlcount=dlcount+1
  278.   Call Logger 1,1,0,'download' dlcount '('cpicsize 'Bytes) as --->' name
  279.   start=Time("E")
  280.   gp = camxgetpicture(k,name,0)
  281.   dur=Format(Time("E")-start,,0)
  282.   Call Logger 2,0,0,"camxGetPicture rc="gp " " cpicsize "Bytes duration" dur,
  283.     "seconds (" Format(cpicsize/dur/1024,,0) "KB/sec) for" cpicname
  284.   If gp=ret_ok Then Do
  285.     gp=camxsetfiledate(name,cpicdate)
  286.     Call Logger 2,0,0, "camxSetfiledate rc="gp
  287.   End
  288. End
  289.  
  290. /***************************************************************************/
  291. /*  We are done                                                            */
  292. /***************************************************************************/
  293.  
  294. Call Cleanup
  295. Call Logger 2,0,1,'Ending' Date() 'at' Time()
  296. Exit 0
  297.  
  298. /***************************************************************************/
  299. /*  CTL-C handler                                                          */
  300. /***************************************************************************/
  301. HALT:
  302. Call Logger 2,1,0,"CTL-C detected, aborting..."
  303. Call Cleanup
  304. Exit 3
  305.  
  306.  
  307. /***************************************************************************/
  308. /*  Subroutines                                                            */
  309. /***************************************************************************/
  310.  
  311. /***************************************************************************/
  312. /*  Disconnect from camera                                                 */
  313. /***************************************************************************/
  314.  
  315. CLEANUP:
  316. Call Camxdisconnect
  317. Call Camxquit
  318. Return
  319.  
  320. /***************************************************************************/
  321. /*  Error message if camxInit call fails                                   */
  322. /***************************************************************************/
  323. NOTREGISTERED:
  324. Call Logger 2,1,1,"Error in call to camxInit. Invalid Key dataset?"
  325. Exit 5
  326.  
  327.  
  328. /***************************************************************************/
  329. /*  determine                NT / OS/2  + REXX version                     */
  330. /***************************************************************************/
  331. INITOS:
  332. Parse Source os invoke sourcefn xx
  333.  
  334. Parse version langproc langlvl rday rmon ryear
  335.  
  336. If os="OS/2" Then Do
  337.   nt=0
  338.   os2=1
  339.   umgebung="OS2ENVIRONMENT"
  340.   cmdext="cmd"
  341.   bskz="O"
  342. End
  343. Else Do
  344.   nt=1
  345.   os2=0
  346.   umgebung="ENVIRONMENT"
  347.   cmdext="rex"
  348.   bskz="N"
  349.  
  350.   /*************************************************************************/
  351.   /* Call Rxfuncadd 'w32loadfuncs', 'w32util', 'w32loadfuncs'              */
  352.   /* Call W32loadfuncs                                                     */
  353.   /*************************************************************************/
  354.  
  355. End
  356.  
  357. /***************************************************************************/
  358. /*  Load rexxutils                                                         */
  359. /***************************************************************************/
  360.  
  361. rc=rxfuncadd( "sysloadfuncs","rexxutil","sysloadfuncs")
  362. Call Sysloadfuncs
  363.  
  364. Return
  365.  
  366. /***************************************************************************/
  367. /*  Error handling                                                         */
  368. /***************************************************************************/
  369. NOVALUE:
  370. Drop rc
  371. SYNTAX:
  372. ERROR:
  373. Signal Off NOVALUE
  374. Signal Off SYNTAX
  375. Signal Off ERROR
  376. If Datatype(rc,"W") Then Do                     /* check RC & set a message*/
  377.   If (rc<100) & (rc>-1)
  378.     Then mmm="Rexx error" rc ":" Errortext(rc)
  379.     Else mmm="Bad return code" rc Condition("D")
  380.   If Datatype(dlcount,"W") Then Do
  381.     If (dlcount=7) & (rc=40) Then Do
  382.       mmz="The Demo Version of 3eyeREXX is limited to downloading 6 pictures."
  383.       Say mmz
  384.       Call Lineout logdat,mmz
  385.       mmz="Maybe that is the reason for the following error message."
  386.       Say mmz
  387.       Call Lineout logdat,mmz
  388.     End
  389.   End
  390. End
  391. Else mmm="Uninitialized variable:" Condition("D")
  392.  
  393. Parse Source . . program                           /* find the program name*/
  394. mmz=program||"("||sigl||"):"|| mmm || " Programm error"
  395. Say mmz
  396.  
  397. errfile=Substr(program,1,Lastpos(".",program))"err"    /* make errfile name*/
  398. Call Sysfiledelete errfile                   /* delete errfile if it exists*/
  399. Call Lineout errfile, mmz                                  /* write errfile*/
  400. Call Stream errfile, "C", "Close"                          /* close errfile*/
  401. Call Lineout logdat, mmz
  402. Call Lineout logdat
  403.  
  404. Call Cleanup                                      /* disconnect from camera*/
  405.  
  406. /*If os2 Then 'x' program '/err' sigl  */
  407. /*Trace '?i'*/
  408. Nop
  409. Exit 99
  410.  
  411.  
  412.  
  413. /***************************************************************************/
  414. /*  Upro Logger   option,         before,      after,         message      */
  415. /*                0 only log           empty lines                         */
  416. /*                1 only say                                               */
  417. /*                2 say + log                                              */
  418. /*                                                                         */
  419. /***************************************************************************/
  420. LOGGER: Procedure Expose logdat
  421. Parse Arg opt, vor, nach, text
  422.  
  423. /*  check params                                                           */
  424. If text="" Then Return
  425. If vor<"0" Then vor=0;Else If vor>"9" Then vor=1
  426. If nach<"0" Then nach=0;Else If nach>"9" Then nach=1
  427.  
  428. /*  with say                                                               */
  429. If opt>"0" Then Do
  430.   Do k=1 To vor;Say;End
  431.   Say text
  432.   Do k=1 To nach;Say;End
  433. End
  434.  
  435. /*  with log dataset                                                       */
  436. If opt<>"1" Then Do
  437.   Do k=1 To vor;Call Lineout logdat,"";End
  438.   Call Lineout logdat,text
  439.   Do k=1 To nach;Call Lineout logdat,"";End
  440. End
  441. Call Stream logdat,"C","Close"
  442. Return
  443.  
  444. FIRSTTIME:
  445. zigl=sigl
  446.  
  447. Say
  448. Say "Please edit" sourcefn "and change line" zigl "and following"
  449.  
  450. Do k=zigl
  451.   zeil=Strip(Sourceline(k))
  452.   If zeil="" Then Iterate k
  453.   If Pos("/* Don't modify a",zeil)>0 Then Leave k
  454.   Say zeil
  455. End
  456. Say
  457. Say "Please edit" sourcefn "and change lines" zigl "to" k-1 "for customization."
  458. Return 99
  459. /***************************************************************************/
  460. /*  Change history: partial                                                */
  461. /*  v 2.3                                                                  */
  462. /*      messages txt changed                                               */
  463. /*      timer for DL                                                       */
  464. /*  v 2.4                                                                  */
  465. /*      Date/time compare optional                                         */
  466. /*  v 2.5                                                                  */
  467. /*      ignore list for pictures not to DL, even if available              */
  468. /*      program documentation (comments)                                   */
  469. /*      Better Errormsg trying to DL more than 6 pics with demoversion     */
  470. /*      Force customization                                                */
  471. /***************************************************************************/
  472.  
  473.