The following is an example of using this service:
XML service definition:
<JXFSPrt id="msd" DeviceName="MSDevice" AutomaticOpen="true" JXFSIniConfig="c:\\jxfs\\jxfs.cfg"/>
XML context definition:
<context id="workstation" type="wks"> <refKColl refId="workstation"> </refKColl> <refService refId="msd" alias="myMsd"/> </context>
XML format definition, corresponding to the data to read:
<fmtDef id="track2"> <record dataName="track2Kcoll"> <fstring dataName="branch"/> <fstring dataName="account"/> <fstring dataName="balance"/> </record> </fmtDef>
Application flow:
// Synchronous reading of track 2 in an operation execution JXFSPrt msd = getContext().getService("myMsd"); try { // not necessary doing prt.openSync(), because it has been specified // AutomaticOpen = true. if (msd.waitOpen(60000)) if (msd.claim(60000)) { RecordFormat fmt = (RecordFormat)FormatElement.readObject("track2"); JxfsMSDTrackSelection ts = new JxfsMSDTrackSelection(false,true,false); //select track 2 MSDTracks t = new MSDTracks(false,false,false); MSDReadData mrd = new MSDReadData(t, 0, 0, 0); int ret = msd.readDataAndUnformatSync(ts, getContext(), null, fmt, null, mrd); if (ret == JXFS_RC_SUCCESSFUL){ // if read successful data is now in the context. String branch = getContext().getValueAt("branch"); String account = getContext().getValueAt("account"); String balance = getContext().getValueAt("balance"); } if (!msd.release(60000) ) System.out.println ("timeout releasing device"); // there should be any user way //to try to release the msd } else System.out.println ("timeout claiming device"); else System.out.println ("timeout opening device"); catch ( JxfsException jxfse) { // analyze jxfsE.errorCode . . System.out.println("JxfsException: " + jxfse.description); }