[Tutor] why are these two uses different?

Stanfield, Vicki {D167~Indianapolis} vicki.stanfield at ROCHE.COM
Mon Mar 1 09:40:16 EST 2004


I have a project which includes a big if/elif. I select on the value
selected from a pulldown menu of the dictionary values created thusly:

self.combo=wxComboBox(self, 30, " ",
     wxPoint(wxALIGN_LEFT),
     wxDefaultSize,
     self.Dict.values(),wxCB_DROPDOWN)

I match the selected value with a hexadecimal value like this:

if command in ('1D','48','52','50','73','65','67'):
<snip>
     #Get command from dictionary
     fcommand=self.Dict.keys()[self.Dict.values().index(command)]

I have this in the dictionary:

     self.Dict=('\x78':'78','\x65':'65','\x60':'60',<SNIP>'\x1D':'1D')

Each command triggers a whole sequence of serial writes and reads. This
works fine. Now I want to create a section which allows me to do them
individually. There are no timing issues since I am able to turn that
off
for the device I am writing to. But when I try to do this:

     do_it = wxMessageDialog(self,"do you want to continue?",
         "Send", wxYES_NO | wxICON_QUESTION)
     if do_it.ShowModal() == wxID_NO:
         do_it.Destroy()
     else:
         singledlg = wxTextEntryDialog (self,
         "Enter the hex value you'd like to send.", "Send Single",
"Enter
value here", wxOK | wxCANCEL)
         if singledlg.ShowModal() == wxID_OK:
             hexval = singledlg.GetValue()
             fcommand=self.Dict.keys()[self.Dict.values().index(hexval)]
port.write(fcommand)
<snip>

If I type in the same string that is in the if statement, it sends the
each digit of the hex value in hex itself. As in this example:

hex 1D gets sent as 31 64.

I have tried binascii.hexlify, but this didn't work. I have tried
inputting the data with '1D', but that doesn't match the dictionary. Can
I
get a hint? I keep running into this same problem, so there must be a
key
piece of the pie that I'm still missing.

--vicki


"A pessimist sees the difficulty in every opportunity; an optimist sees
the opportunity in every difficulty."
  --  Winston Churchill
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20040301/c787291c/attachment.html


More information about the Tutor mailing list