source: cprs/branches/tmg-cprs/m_files/TMGBARC.m@ 1376

Last change on this file since 1376 was 796, checked in by Kevin Toppenberg, 14 years ago

Initial upload

File size: 6.4 KB
Line 
1TMGDBAP2 ;TMG/kst/Barcode Interface to Linux ;12/20/07
2 ;;1.0;TMG-LIB;**1**;12/20/07
3
4
5 ;"=======================================================================
6 ;" API -- Public Functions.
7 ;"=======================================================================
8 ;"$$MAKEBC^TMGBARC(Message) -- shell to Linux, to create barcode image.
9 ;"$$READBC^TMGBARC(FPathName) -- shell to Linux, to read barcode image.
10
11 ;"=======================================================================
12 ;"PRIVATE API FUNCTIONS
13 ;"=======================================================================
14 ;"Test
15
16 ;"=======================================================================
17
18
19MAKEBC(Message,Option)
20 ;"Purpose: to shell out to Linux, and call dmtxwrite to create
21 ;" the barcode image.
22 ;"Input: Message -- the text to be encode in the barcode
23 ;" Note: the barcode function may limit what type of chars
24 ;" can be put it, and how long. (explore more later...)
25 ;" Option -- PASS BY REFERENCE. Array that may hold optional
26 ;" settings, as follows: Default value is "png"
27 ;" Option("IMAGE TYPE")="jpg" <-- output is desired in .jpg format
28 ;"Output: Returns filename, on host file system, of created image, or "" if error
29 ;"
30 ;"NOTE: dmtxwrite must be installed on linux host.
31 ;" I found source code here:
32 ;" http://sourceforge.net/projects/libdmtx/
33 ;" After installing (./configure --> make --> make install etc), I
34 ;" copied dmtxread and dmtxwrite, which were found in the
35 ;" (installdir)/util/dmtxread/.libs and (installdir)/util/dmtxwrite/.libs
36 ;" folders, into a folder on the system path. I chose /usr/bin/
37 ;" Also, to achieve compile of above, I had to install required libs.
38 ;" See notes included with source code.
39
40 new result set result=""
41 new msgFName set msgFName=$$UNIQUE^%ZISUTL("/tmp/msg.txt")
42 new imageFName set imageFName=$$UNIQUE^%ZISUTL("/tmp/barcode.png")
43 new imageType set imageType=$$LOW^XLFSTR($get(OPTION("IMAGE TYPE"),"png"))
44
45 ;"Write Message to host file .txt file
46 new %ZIS,IOP,POP
47 set %ZIS("HFSNAME")=msgFName
48 set IOP="HFS"
49 do ^%ZIS ;"standard device call
50 if POP goto MBCDone
51 use IO
52 write Message
53 do ^%ZISC ;"close device
54
55 ;"Setup and launch linux command to execute dmtxwrite
56 ;"Note: dmtxwrite only makes .png format images
57 new CmdStr
58 set CmdStr="cat "_msgFName_" | dmtxwrite -o "_imageFName
59 do
60 . new $ETRAP,$ZTRAP
61 . set $ETRAP="S $ECODE="""""
62 . zsystem CmdStr ;"Launch command
63
64 ;"get result of execution. (low byte only) -- if wanted
65 new CmdResult
66 set CmdResult=$ZSYSTEM&255
67 if CmdResult'=0 goto MBCDone
68
69 ;"No error, so successful
70
71 ;"Convert to specified image type, if needed
72 if imageType'="png" set imageFName=$$Convert^TMGKERNL(imageFName,imageType)
73
74 set result=imageFName
75
76 ;"Delete Message .txt file
77 new FName,FPath,FileSpec
78 do SplitFNamePath^TMGIOUTL(msgFName,.FPath,.FName,"/")
79 set FileSpec(FName)=""
80 new temp set temp=$$DEL^%ZISH(FPath,$name(FileSpec))
81
82MBCDone
83 quit result
84
85
86READBC(FPathName)
87 ;"Purpose: to shell out to Linux, and call dmtxread to read a
88 ;" barcode image.
89 ;"Input: FPathName -- valid host file name of image to be decoded.
90 ;"Output: Returns message stored in barcode, or "" if problem
91 ;"
92 ;"NOTE: dmtxread must be installed on linux host.
93 ;" I found source code here:
94 ;" http://sourceforge.net/projects/libdmtx/
95 ;" After installing (./configure --> make --> make install), I
96 ;" copied dmtxread and dmtxwrite, which were found in the
97 ;" (installdir)/util/dmtxread/.libs and (installdir)/util/dmtxwrite/.libs
98 ;" folders, into a folder on the system path. I chose /usr/bin/
99 ;" Also, to achieve compile of above, I had to install required libs.
100 ;" See notes included with source code.
101
102 new result set result=""
103
104 new msgFName set msgFName=$$UNIQUE^%ZISUTL("/tmp/msg.txt")
105 new FName,FPath,FileSpec
106 do SplitFNamePath^TMGIOUTL(msgFName,.FPath,.FName,"/")
107 set FileSpec(FName)=""
108
109 ;"Setup and launch linux command to execute dmtxwrite
110 new CmdStr
111 set CmdStr="dmtxread -g 32 "_FPathName_" >> "_msgFName
112 ;"Add a leading filler character to prevent possible read error
113 ;"from an empty file.
114 set CmdStr="echo ""#"" > "_msgFName_";"_CmdStr
115 do
116 . zsystem CmdStr ;"Launch command
117
118 ;"get result of execution. (low byte only) -- if wanted
119 new CmdResult set CmdResult=$ZSYSTEM&255
120 if CmdResult'=0 goto RBCDone
121
122 set ^TMG("TMP","BARCODE","LOG")="5d" ;"temp
123
124 new resultArray
125 if $$FTG^%ZISH(FPath,FName,"resultArray(0)",1)=0 do goto RBCDone
126 ;"First line should be just '#' (filler character)
127 ;"Second line should hold answer
128 set result=$get(resultArray(1))
129
130 merge ^TMG("TMP","BARCODE","RESULT FILE")=resultArray
131
132 ;"Read Message from host file .txt file
133 ;"do OPEN^%ZISH("FILE1",FPath,FName,"R")
134 ;"if POP goto RBCDone
135 ;"do
136 ;". use IO
137 ;". read result
138 ;"do CLOSE^%ZISH("FILE1")
139 ;"new resultArray
140 ;"do CleaveToArray^TMGSTUTL(result,$char(10),.resultArray)
141 ;"for now I am only going to pay attention to first line...
142 ;"set result=$get(resultArray(1))
143 ;"set result=$extract(result,2,999) ;"remove 1st character which is filler '#'
144
145
146 ;"Delete Message .txt file
147 ;"TEMP!!! DELETE LATER...
148 new temp set temp=$$DEL^%ZISH(FPath,$name(FileSpec))
149
150RBCDone
151 quit result
152
153
154Test
155 new msg,file
156 set msg="This is a test message"
157 write "Creating barcode...",!
158 set file=$$MAKEBC(msg)
159 write "reading barcode....",!,!
160 write $$READBC(file),!
161
162 ;"delete temp image file
163 new FName,FPath,FileSpec
164 do SplitFNamePath^TMGIOUTL(file,.FPath,.FName,"/")
165 set FileSpec(FName)=""
166 new temp set temp=$$DEL^%ZISH(FPath,"FileSpec")
167
168 quit
Note: See TracBrowser for help on using the repository browser.