Justin Rajewski <jus...@embeddedmicro.com> wrote:
>
>I need to print variables out over serial, however I need them to not be
>in ASCII, ie if the variable is 5 then print 5 not "5".
>
>The function that writes to the serial port requires a string and I can
>send non-variables out with the string "/x05" for 5.
>
>Is this even possible?

Of course.  The struct and array modules can help you with this.  Note that
you have to know how big each variable should be.

For example, if you want to sent 1, 2, and 3 out as bytes, you can do:

  a = 1
  b = 2
  c = 3
  serial = struct.pack( 'BBB', a, b, c )

If you need them as 16-bit ints, you can use H instead of B.
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to