LPCconnector/LPCAppProto.py
changeset 45 786b12887e91
parent 36 73360d0bacbc
child 47 f860aa7e90e5
equal deleted inserted replaced
44:a6577420a27b 45:786b12887e91
     4 LPC_STATUS={0xaa : "Started",
     4 LPC_STATUS={0xaa : "Started",
     5             0x55 : "Stopped"}
     5             0x55 : "Stopped"}
     6 
     6 
     7 class LPCAppProto(LPCProto):
     7 class LPCAppProto(LPCProto):
     8     def HandleTransaction(self, transaction):
     8     def HandleTransaction(self, transaction):
     9         self.TransactionLock.acquire()
       
    10         try:
     9         try:
    11             transaction.SetPseudoFile(self.serialPort)
    10             transaction.SetPseudoFile(self.serialPort)
    12             # send command, wait ack (timeout)
    11             # send command, wait ack (timeout)
    13             transaction.SendCommand()
    12             transaction.SendCommand()
    14             current_plc_status = transaction.GetCommandAck()
    13             current_plc_status = transaction.GetCommandAck()
    16                 res = transaction.ExchangeData()
    15                 res = transaction.ExchangeData()
    17             else:
    16             else:
    18                 raise LPCProtoError("controller did not answer as expected")
    17                 raise LPCProtoError("controller did not answer as expected")
    19         except Exception, e:
    18         except Exception, e:
    20             raise LPCProtoError("application mode transaction error : "+str(e))
    19             raise LPCProtoError("application mode transaction error : "+str(e))
    21         finally:
       
    22             self.TransactionLock.release()
       
    23         return LPC_STATUS.get(current_plc_status,"Broken"), res
    20         return LPC_STATUS.get(current_plc_status,"Broken"), res
    24     
    21     
    25 class LPCAppTransaction:
    22 class LPCAppTransaction:
    26     def __init__(self, command):
    23     def __init__(self, command):
    27         self.Command = command
    24         self.Command = command