connectors/LPC/LPCAppObject.py
changeset 557 b155ada1c14a
parent 548 1428fd553988
child 558 e7ce2b3f1d5d
equal deleted inserted replaced
556:1ad4e7f1e89e 557:b155ada1c14a
    43                 self.SerialConnection = None
    43                 self.SerialConnection = None
    44                 self.PLCStatus = "Disconnected"
    44                 self.PLCStatus = "Disconnected"
    45                 return None
    45                 return None
    46 
    46 
    47     def StartPLC(self, debug=False):
    47     def StartPLC(self, debug=False):
    48         PLCprint("StartPLC")
       
    49         self.HandleSerialTransaction(STARTTransaction())
    48         self.HandleSerialTransaction(STARTTransaction())
    50             
    49             
    51     def StopPLC(self):
    50     def StopPLC(self):
    52         PLCprint("StopPLC")
       
    53         self.HandleSerialTransaction(STOPTransaction())
    51         self.HandleSerialTransaction(STOPTransaction())
    54 
    52 
    55     def ResetPLC(self):
    53     def ResetPLC(self):
    56         self.HandleSerialTransaction(RESETTransaction())
    54         self.HandleSerialTransaction(RESETTransaction())
    57         return self.PLCStatus
    55         return self.PLCStatus
    60         self.HandleSerialTransaction(IDLETransaction())
    58         self.HandleSerialTransaction(IDLETransaction())
    61         return self.PLCStatus
    59         return self.PLCStatus
    62 
    60 
    63     def MatchMD5(self, MD5):
    61     def MatchMD5(self, MD5):
    64         data = self.HandleSerialTransaction(GET_PLCIDTransaction())
    62         data = self.HandleSerialTransaction(GET_PLCIDTransaction())
    65         print "PLCINFO",data
       
    66         return data[:32] == MD5
    63         return data[:32] == MD5
    67 
    64 
    68     class IEC_STRING(ctypes.Structure):
    65     class IEC_STRING(ctypes.Structure):
    69         """
    66         """
    70         Must be changed according to changes in iec_types.h
    67         Must be changed according to changes in iec_types.h
   143                 if c_type is not None and offset < size:
   140                 if c_type is not None and offset < size:
   144                     res.append(unpack_func(ctypes.cast(cursor,
   141                     res.append(unpack_func(ctypes.cast(cursor,
   145                                                        ctypes.POINTER(c_type)).contents))
   142                                                        ctypes.POINTER(c_type)).contents))
   146                     offset += ctypes.sizeof(c_type)
   143                     offset += ctypes.sizeof(c_type)
   147                 else:
   144                 else:
   148                     if c_type is None:
   145                     #if c_type is None:
   149                         PLCprint("Debug error - " + iectype + " not supported !")
   146                         #PLCprint("Debug error - " + iectype + " not supported !")
   150                     if offset >= size:
   147                     #if offset >= size:
   151                         PLCprint("Debug error - buffer too small !")
   148                         #PLCprint("Debug error - buffer too small !")
   152                     break
   149                     break
   153             if offset and offset == size:
   150             if offset and offset == size:
   154                 return self.PLCStatus, tick.value, res
   151                 return self.PLCStatus, tick.value, res
   155             PLCprint("Debug error - wrong buffer unpack !")
   152             #PLCprint("Debug error - wrong buffer unpack !")
   156         return self.PLCStatus, None, None
   153         return self.PLCStatus, None, None
   157 
   154