is there a problem on this simple code

Jan Rienyer Gadil jrlen97 at gmail.com
Sun Mar 13 11:48:55 EST 2005


@ sir Peter
so you mean that it is correct (at least on the unpack() part) 

when i run this program on IDLE , Python 2.3 (enthought edition),
nothing is outputted on the shell, until i decide to close the shell,
wherein it tells me if i would like to kill a process...

import serial
import string
import time
from struct import *

ser = serial.Serial()

ser.baudrate = 9600
ser.port = 0
ser
ser.close()
ser.open()

command = 67
message_no = 1
total_data = 2

item = 10000

for item in range(10000, 30001, 250):
   data_hi, data_lo = divmod(item, 0x100)
   checksum = -(data_hi + data_lo + 0x46) & 0xff
   ser.write(pack('6B', command, message_no, total_data, data_lo,
                data_hi, checksum))

   rx_data1=0
   while (rx_data1 != 0x46):
           rx_data1 = ser.read(1)
           (rx_command) = unpack('1B', rx_data1)

    rx_data2=ser.read(9)
    (rx_msg_no, rx_no_databyte, temp1, temp2, pyra1, pyra2, voltage,
             current, rx_checksum) = unpack('9B', data)
     print rx_command, rx_msg_no, rx_no_databyte, temp1, temp2, pyra1,
             pyra2, voltage, current, rx_checksum

ser.close()



More information about the Python-list mailing list