author | Laurent Bessard |
Wed, 20 Feb 2013 19:17:49 +0100 | |
changeset 25 | c5b5509bd224 |
parent 0 | 51f5a3138405 |
child 45 | 786b12887e91 |
permissions | -rwxr-xr-x |
0
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
1 |
#!/usr/bin/env python |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
2 |
# -*- coding: utf-8 -*- |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
3 |
|
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
4 |
#This file is part of Beremiz, a Integrated Development Environment for |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
5 |
#programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
6 |
# |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
7 |
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
8 |
# |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
9 |
#See COPYING file for copyrights details. |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
10 |
# |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
11 |
#This library is free software; you can redistribute it and/or |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
12 |
#modify it under the terms of the GNU General Public |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
13 |
#License as published by the Free Software Foundation; either |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
14 |
#version 2.1 of the License, or (at your option) any later version. |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
15 |
# |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
16 |
#This library is distributed in the hope that it will be useful, |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
17 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
18 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
19 |
#General Public License for more details. |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
20 |
# |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
21 |
#You should have received a copy of the GNU General Public |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
22 |
#License along with this library; if not, write to the Free Software |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
23 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
24 |
|
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
25 |
from LPCProto import * |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
26 |
|
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
27 |
|
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
28 |
|
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
29 |
class LPCObject(): |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
30 |
def __init__(self, confnodesroot, comportstr): |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
31 |
self.PLCStatus = "Disconnected" |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
32 |
self.confnodesroot = confnodesroot |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
33 |
self.PLCprint = confnodesroot.logger.writeyield |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
34 |
self._Idxs = [] |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
35 |
comport = int(comportstr[3:]) - 1 |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
36 |
try: |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
37 |
self.connect(comportstr) |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
38 |
except Exception,e: |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
39 |
self.confnodesroot.logger.write_error(str(e)+"\n") |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
40 |
self.SerialConnection = None |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
41 |
self.PLCStatus = "Disconnected" |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
42 |
|
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
43 |
def HandleSerialTransaction(self, transaction): |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
44 |
if self.SerialConnection is not None: |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
45 |
try: |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
46 |
self.PLCStatus, res = self.SerialConnection.HandleTransaction(transaction) |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
47 |
return res |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
48 |
except LPCProtoError,e: |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
49 |
self.confnodesroot.logger.write(_("PLC disconnected\n")) |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
50 |
if self.SerialConnection is not None: |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
51 |
self.SerialConnection.close() |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
52 |
self.SerialConnection = None |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
53 |
self.PLCStatus = "Disconnected" |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
54 |
return None |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
55 |
except Exception,e: |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
56 |
self.confnodesroot.logger.write_warning(str(e)+"\n") |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
57 |
|
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
58 |
def StartPLC(self, debug=False): |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
59 |
raise LPCProtoError("Not implemented") |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
60 |
|
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
61 |
def StopPLC(self): |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
62 |
raise LPCProtoError("Not implemented") |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
63 |
|
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
64 |
def GetPLCstatus(self): |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
65 |
raise LPCProtoError("Not implemented") |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
66 |
|
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
67 |
def NewPLC(self, md5sum, data, extrafiles): |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
68 |
raise LPCProtoError("Not implemented") |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
69 |
|
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
70 |
def MatchMD5(self, MD5): |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
71 |
raise LPCProtoError("Not implemented") |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
72 |
|
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
73 |
def SetTraceVariablesList(self, idxs): |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
74 |
raise LPCProtoError("Not implemented") |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
75 |
|
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
76 |
def GetTraceVariables(self): |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
77 |
raise LPCProtoError("Not implemented") |
51f5a3138405
Initial commit, LPC files taken out of beremiz revision 915be999f3f0
Edouard Tisserant
parents:
diff
changeset
|
78 |