By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,931 Members | 2,015 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,931 IT Pros & Developers. It's quick & easy.

Pyserial transposing characters

P: 1
Peoples...

I'm trying to write a simple read/write application for a Magnetic Card Reader/writer (Tyner) I'm able to get everything off the card just fine, and it appears to to be working to write. However, when I scan the card it reads like this:

I wrote to the card (first track only):
abcdefghijklmnopqrstuvwxyz

got back:
!"#$%&'()*+,-./0123456789:

Appears to be transposing.

wx button code

Expand|Select|Wrap|Line Numbers
  1.                 def Write(self, event):
  2.                                 chk = False
  3.                                 Connection = SerialConnection()
  4.                                 Connection.flush()
  5.                                 dialog = wx.TextEntryDialog(None, "*****:", caption="Paste here...", defaultValue="", style=wx.OK|wx.CANCEL)
  6.                                 if dialog.ShowModal() == wx.ID_OK:
  7.                                     if Connection.chkConnection(chk) == True :                                    
  8.                                         print dialog.Value
  9.                                         str = dialog.Value                                           
  10.                                         Connection.write(str)
  11.                                         #wx.Exit()
  12.  
  13.                                     else:
  14.                                         print 'Connection Error!'
  15.                                 else:
  16.                                     print 'User canceled'
  17.  
Serial class I made, write method:
Expand|Select|Wrap|Line Numbers
  1.  
  2.     def write(self,str):
  3.         #Byte Codes:
  4.         escape = 0x1b
  5.         track1 = 0x01
  6.         EndMark = 0x3f
  7.         FileSeparator = 0x1c
  8.         #input string
  9.         input = chr(escape) + chr(track1) + str
  10.  
  11.  
  12.         self.ser.write(chr(escape) + '\x77')
  13.         output = self.ser.read(size=100)
  14.         time.sleep(.1)
  15.         self.ser.write(chr(escape) + '\x73' + input)
  16.         self.ser.write(chr(EndMark) + chr(FileSeparator))
  17.  
  18.         output = self.ser.read(size=100)
  19.         print output + ' ' + ' --Error'
  20.         print "wrote: " + ' ' + input
  21.  
  22.  
I should mention I'm pretty new to Python :) sorry for the messy code.
Apr 26 '11 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.