Using the JXFSMsd Service

The following is an example of an operation using the JXFS Magnetic Stripe Reader Service. It performs a read operation of track2 only, using the record format with the "track2" ID value to unformat data read into the operation context. For selecting track 2, a JxfsTrackSelection object with its track2 property set to true is instantiated. An MSDReadData object is also instantiated and passed to the function to get the return information about the tracks that are actually read. After calling the reading function and if it returns a successful result, we can access the data read into the operation context: branch, account, and balance.

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);
}