-
Notifications
You must be signed in to change notification settings - Fork 2
/
moteurRSAIFDB.py
571 lines (502 loc) · 23.5 KB
/
moteurRSAIFDB.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
# -*- coding: utf-8 -*-
"""
Created on 01 December 2023
@author: Julien Gautier (LOA)
last modified 22 decembre 2023
Dialog to RSAI motors rack via firebird database
"""
from firebird.driver import connect ### pip install firebird-driver et installer biblioteque client firebird
import time
from PyQt6 import QtCore
from PyQt6.QtWidgets import QMessageBox,QApplication
import socket
from PyQt6.QtCore import QUuid, QMutex
import sys
IPSoft = socket.gethostbyname(socket.gethostname()) # get the ip adress of the computer
UUIDSoftware = QUuid.createUuid() # create unique Id for software
UUIDSoftware = str(UUIDSoftware.toString()).replace("{","")
UUIDSoftware = UUIDSoftware.replace("}","")
mut=QMutex()
# if not local dsn=10.0.5.X/ ??
## connection to data base
con = connect('10.0.48.1/3050:C:/PilMotDB/PILMOTCONFIG.FDB', user='sysdba', password='masterkey')
cur = con.cursor()
curCWD=con.cursor()
def closeConnection():
# close connection
con.close()
# " dict for table values"
listParaStr ={'nomAxe' : 2 ,'nomEquip':10, 'nomRef1': 1201 , 'nomRef2':1202 , 'nomRef3':1203 , 'nomRef4':1204 , 'nomRef5':1205 , 'nomRef6':1206 , 'nomRef7':1207 , 'nomRef8':1208 , 'nomRef9':1209 , 'nomRef10':1210}
listParaReal = {'Step':1106 , 'Ref1Val': 1211 , 'Ref2Val':1212 , 'Ref3Val':1213 , 'Ref4Val':1214 , 'Ref5Val':1215 , 'Ref6Val':1216 , 'Ref7Val':1217 , 'Ref8Val':1218 , 'Ref9Val':1219 , 'Ref10Val':1220}
listParaInt = {'ButLogPlus': 1009 , 'ButLogNeg':1010 }
def addSoftToConnectedList():
# add adress ip of the soft in the data base
# not working yet to do ...
# need to create new Pikd for the table ...
insert = ( "INSERT INTO TbConnectedList(d_ParaDbUUID, d_ParaDbConnectName,d_ParaDbAlias) values(%s,%s,%s)" % (str(UUIDSoftware),str(IPSoft),"" ))
cur.execute(insert)
con.commit()
def listProgConnected():
# Read the list of programs connected to database
# nbProgConnected : number of programs connected into database
# p_ListPrg (returned): Described list of programs into database
# (Format of the field of the list for one program: PkId, UUID, SoftName, Alias, Hostname, IpAddress, TimeConnection, HeartCnt)
SoftName = []
HostName = []
IpProgram = []
cur.execute("SELECT * FROM " + "TBCONNECTEDLIST" + " ORDER BY PkId;" )
for row in cur:
SoftName.append(row[2])
HostName.append(row[4])
IpProgram.append(row[5])
nbProgConnected = len(SoftName)
return nbProgConnected, SoftName, HostName, IpProgram
if 'PilMotServer' in listProgConnected()[1]:
print('server RSAI connected')
else :
print('Server RSAI not launched')
appli = QApplication(sys.argv)
msg = QMessageBox()
msg.setIcon(QMessageBox.Icon.Critical)
msg.setText("Server RSAI not launched")
msg.setInformativeText("Server RSAI not launched : start server ")
msg.setWindowTitle("Warning ...")
msg.setWindowFlags(QtCore.Qt.WindowType.WindowStaysOnTopHint)
msg.exec()
def rEquipmentList():
'''
Read the list of Equipment connected to database equipement =Rack =IPadress
Described list of equipment into database
Format of the field of the list for one equipment: PkId, Address, Category, Status)
'''
addressEquipement=[]
cur.execute("SELECT * FROM " + "TBEQUIPMENT")
for row in cur:
addressEquipement.append (row[1])
return addressEquipement
def getValueWhere1ConditionAND(cursor,TableName, ValToRead, ConditionColName,ConditionValue):
'''
Read the field value in a table where the 'column' equals 'value' corresponding Query = SELECT 'ValToRead' FROM TableName WHERE ConditionColName = ConditionValue
TableName : Table in which execute query
ValToRead : Field Value to read
ConditionColName : Column name for the condition of the query search
ConditionValue : Value name for the condition of the query search
return param p_DataRead : values read
'''
Prepare1Cond= "SELECT " + ValToRead + " FROM " + TableName + " WHERE " + ConditionColName + " = '" + ConditionValue + "' ;"
cursor.execute(Prepare1Cond )
p_DataRead = cursor.fetchone()[0]
return p_DataRead
def rEquipmentIdNbr(IpAddress):
''' Get Identification number of one PilMot equipement from its IP Address
IpAddress: IP Address
p_IdEquipment: Identification number of the equipement
'''
p_IdEquipment = getValueWhere1ConditionAND(cur,"TbEquipment", "PkId", "Address", IpAddress)
return p_IdEquipment
def getSlotNumber(NoMotor):
'''
Get the slot number of ESBIM corresponding to the motor number
return Slot number (value from 1 to 7)
'''
SlotNbr = 0
SlotNbr = (NoMotor + 1 ) / 2
return SlotNbr
def getAxisNumber(NoMotor):
'''
Get the axis number of module corresponding to the motor number
return Slot number (value 1 or 2)
'''
AxisNbr = 1
if(NoMotor % 2) == 0:
AxisNbr = 2
return AxisNbr
def readPkModBim2BOC(cursor,PkEsbim, NumSlotMod, NumAxis, FlgReadWrite=1):
'''
Read Primary key identifier of an axis module Bim2BOC : p_PkModBim
PkEsbim : numero Equipment on which the module is plugged
NumSlotMod : Number of the slot of the module to get PK
NumAxis : Axis number of the module
param FlgReadWrite : Indicate if the function accesses to Read or Write table (value : 1=ReadTb, 0=WriteTb)
'''
TbToRead = "TbBim2Boc_1Axis_W"
cursor.execute( "SELECT m.PkId FROM TbModule m INNER JOIN TbEquipment e ON m.idEquipment = e.PKID WHERE (e.PkId = " + str(int(PkEsbim)) + " and m.NumSlot = " + str(int(NumSlotMod)) + ");" )
# for row in cur :
# TmpPkModBim=row[0] # cle dans TbModule correspondant cle Esbim dans TbEquipement et numero du slot
TmpPkModBim = cursor.fetchone()[0]
cursor.execute( "SELECT b.PkId FROM " + TbToRead + " b WHERE IdModule = " + str(TmpPkModBim) + " AND NumAxis = " + str(int(NumAxis)) + ";" );
# for row in cur :
# p_PKModBim =row[0]
p_PKModBim = cursor.fetchone()[0]
return p_PKModBim # cle dans TbBim2Boc_1Axis_W correpondant idmodule et au numero d axe
def nameMoteur(IpAdress,NoMotor):
'''
Get motor name from Ipadress et axe number
'''
IdEquipt = rEquipmentIdNbr(IpAdress)
NoMod = getSlotNumber(NoMotor)
NoAxis = getAxisNumber(NoMotor)
PkIdTbBoc = readPkModBim2BOC(cur,IdEquipt, NoMod, NoAxis, FlgReadWrite=1) # Read Primary key identifier of an axis module Bim2BOC : p_PkModBim
name = rStepperParameter(cur,PkIdTbBoc,NoMotor,listParaStr['nomAxe'])
return name
def listMotorName(IpAdress):
'''List des moteurs sur l'equipement IpAdress
'''
IdEquipt = rEquipmentIdNbr(IpAdress)
listSlot=[]
SELECT = 'select NumSlot from %s where IdEquipment= %s and NumSlot>=0'% ('TbModule',str(IdEquipt)) # list SLot
cur.execute(SELECT)
for row in cur :
listSlot.append(row[0])
listNameMotor=[]
for noMot in range (1,2*len(listSlot)+1): # dans notre cas 1...14
listNameMotor.append(nameMoteur(IpAdress,noMot))
return listNameMotor
def nameEquipment(IpAdress):
'''
return the equipment name defined by IpAdress
'''
IdEquipt = rEquipmentIdNbr(IpAdress)
SELECT = 'select PkId from %s where IdEquipment = %s and NumSlot = -1'% ('TbModule',str(IdEquipt)) # list Pkid module
cur.execute(SELECT)
PkIdMod = cur.fetchone()[0]
SELECT = 'select ValParam from %s where IDMODULE = %s and IDNAME = 10 '% ('TbParameterSTR',str(PkIdMod))
cur.execute(SELECT)
nameEquip=cur.fetchone()[0]
return nameEquip
def getValueWhere2ConditionAND(cursor,TableName, ValToRead, ConditionColName1, ConditionValue1, ConditionColName2, ConditionValue2):
'''
Read the field value in a table where the 'column' equals 'value' corresponding Query = SELECT 'ValToRead' FROM TableName WHERE 'ConditionColName1' = 'ConditionValue1' AND 'ConditionColName2' = 'ConditionValue2' "
TableName : Table in which execute query
ValToRead : Field Value to read
ConditionColName1 : First column name for the condition of the query search
ConditionValue1 : First value name for the condition of the query search
ConditionColName2 : Second column name for the condition of the query search
ConditionValue2 : Second value name for the condition of the query search
return p_DataRead : values read
'''
cursor.execute("SELECT " + ValToRead + " FROM " + TableName + " WHERE " + ConditionColName1 + " = '" + ConditionValue1 + "' AND " + ConditionColName2 + " = '" + ConditionValue2 + "' ;" )
p_DataRead = cursor.fetchone()[0]
# for row in cursor:
# p_DataRead=row[0]
#con.commit()
return p_DataRead
def getValueWhere3ConditionAND(cursor,TableName, ValToRead, ConditionColName1, ConditionValue1, ConditionColName2, ConditionValue2, ConditionColName3, ConditionValue3):
'''
Read the field value in a table where the 'column' equals 'value' corresponding Query = SELECT 'ValToRead' FROM TableName WHERE 'ConditionColName1' = 'ConditionValue1' AND 'ConditionColName2' = 'ConditionValue2' " ...
param TableName : Table in which execute query
ValToRead : Field Value to read
ConditionColName1 : First column name for the condition of the query search
ConditionValue1 : First value name for the condition of the query search
ConditionColName2 : Second column name for the condition of the query search
ConditionValue2 : Second value name for the condition of the query search
ConditionColName3 : Third column name for the condition of the query search
ConditionValue3 : Third value name for the condition of the query search
'''
cursor.execute( "SELECT " + ValToRead + " FROM " + TableName + " WHERE " + ConditionColName1 + " = '" + ConditionValue1 + "' AND " + ConditionColName2 + " = '" + ConditionValue2 + "' AND " + ConditionColName3 + " = '" + ConditionValue3 + "' ;" )
# for row in cur:
# p_DataRead=row[0]
p_DataRead = cursor.fetchone()[0]
#con.commit()
return p_DataRead
def rEquipmentStatus(IpAddress):
'''
Read the status of an equipment from its IP Address
'''
status =getValueWhere1ConditionAND(cur,"TbEquipment", "status", "Address", IpAddress)
return status
def rStepperParameter(cursor,PkIdTbBoc,NoMotor, NoParam):
'''
Read one stepper parameter
PkIdTbBoc: Primary key identifier of an axis module Bim2BOC
NoMotor: number of the motor on the equipment
NoParam: number(Id) of the parameter to read
'''
NoMod = getSlotNumber(NoMotor)
NoAxis = getAxisNumber(NoMotor)
#PkIdTbBoc = readPkModBim2BOC(IdEquipt, NoMod, NoAxis, FlgReadWrite=1) # Read Primary key identifier of an axis module Bim2BOC : p_PkModBim
PkIdModuleBIM = getValueWhere2ConditionAND(cursor, "TbBim2BOC_1Axis_R", "IdModule", "PkId", str(PkIdTbBoc), "NumAxis", str(NoAxis))
if NoParam in listParaStr.values() : # str
tbToread = "TbParameterSTR"
p_ReadValue = getValueWhere3ConditionAND(cursor,tbToread, "ValParam", "IdName", str(NoParam), "IdModule", str(PkIdModuleBIM), "NumAxis", str(NoAxis))
return p_ReadValue
elif NoParam in listParaReal.values(): # Real
tbToread="TbParameterREAL"
p_ReadValue = getValueWhere3ConditionAND(cursor,tbToread, "ValParam", "IdName", str(NoParam), "IdModule", str(PkIdModuleBIM), "NumAxis", str(NoAxis))
return p_ReadValue
elif NoParam in listParaInt.values(): # Int
tbToread="TbParameterINT"
p_ReadValue = getValueWhere3ConditionAND(cursor,tbToread, "ValParam", "IdName", str(NoParam), "IdModule", str(PkIdModuleBIM), "NumAxis", str(NoAxis))
return p_ReadValue
else :
print( 'parameter value not valid')
return 0
def wStepperParameter(cursor,IdEquipt,NoMotor, NoParam,valParam):
'''
write one stepper parameter
param IdEquipt: Ident of equipment to read
NoMotor: number of the motor on the equipment
NoParam: number(Id) of the parameter to read
'''
NoMod = getSlotNumber(NoMotor)
NoAxis = getAxisNumber(NoMotor)
PkIdTbBoc = readPkModBim2BOC(cursor,IdEquipt, NoMod, NoAxis, FlgReadWrite=1) # Read Primary key identifier of an axis module Bim2BOC : p_PkModBim
PkIdModuleBIM = getValueWhere2ConditionAND( cursor,"TbBim2BOC_1Axis_R", "IdModule", "PkId", str(PkIdTbBoc), "NumAxis", str(NoAxis))
if NoParam in listParaStr.values() : # str
tbToread = "TbParameterSTR"
UPDATE = "UPDATE %s set ValParam ='%s' WHERE IdName= %s and IdModule =%s and NumAxis =%s ;" % (tbToread,valParam,str(NoParam),str(PkIdModuleBIM),str(NoAxis))
a=cursor.execute(UPDATE)
con.commit()
elif NoParam in listParaReal.values():
tbToread="TbParameterREAL"
UPDATE = "UPDATE %s set ValParam =%s WHERE IdName= %s and IdModule =%s and NumAxis =%s ; " % (tbToread,valParam,str(NoParam),str(PkIdModuleBIM),str(NoAxis))
a=cursor.execute(UPDATE)
con.commit()
elif NoParam in listParaInt.values():
tbToread="TbParameterINT"
UPDATE= "UPDATE %s set ValParam =%s WHERE IdName= %s and IdModule =%s and NumAxis =%s ; " % (tbToread,valParam,str(NoParam),str(PkIdModuleBIM),str(NoAxis))
a=cursor.execute(UPDATE)
con.commit()
else :
print( 'parameter value is not valid')
a = 0
return a
def wStepperCmd(cursor,PkIdTbBoc, RegOrder, RegPosition, RegVelocity=1000):
'''
Write a command to a stepper axis (BOCM) with a cursor
cursor firbird cursor
PkIdTbBoc = readPkModBim2BOC(IdEquipt, NoMod, NoAxis, FlgReadWrite=1)
CmdRegister: command register to write
SetpointPosition: Position setpoint
SetpointVelocity: Velocity setpoint
IdEquipt = rEquipmentIdNbr(IpAdress)
NoMod = getSlotNumber(NoMotor)
NoAxis = getAxisNumber(NoMotor)
'''
# test si pas de commande en cours
if getValueWhere1ConditionAND(cursor,'TBBIM2BOC_1AXIS_W','Cmd','PkId',str(PkIdTbBoc)) == 0 or getValueWhere1ConditionAND(cursor,'TBBIM2BOC_1AXIS_R','StateCmd','PkId',str(PkIdTbBoc)) == (0 or 3 or 4):
# write parameter cmd
UPDATE = 'UPDATE %s set RegOrder = %s, RegPosition = %s, RegVelocity = %s WHERE PkId =%s ;' % ('TBBIM2BOC_1AXIS_W',str(RegOrder),str(RegPosition),str(RegVelocity),str(PkIdTbBoc))
cursor.execute(UPDATE)
# take write right
UPDATE = 'UPDATE %s set cmd=1 WHERE PkId =%s ;' % ('TBBIM2BOC_1AXIS_W',str(PkIdTbBoc))
cursor.execute(UPDATE)
con.commit()
time.sleep(0.15) # ?? sinon ca marche pas ...
# test si commande est terminé cmd=3 ou 4 (erreur ?)
select = "SELECT " + "StateCmd" + " FROM " + "TbBim2BOC_1Axis_R" + " WHERE " + "PkId" + " = " + str(PkIdTbBoc) + ";"
cursor.execute(select )
cmd = cursor.fetchone()
# liberer le champ cmd =0
UPDATE = 'UPDATE %s set Cmd = 0 WHERE PkId =%s ;' % ('TBBIM2BOC_1AXIS_W',str(PkIdTbBoc)) # clear commande right
cursor.execute(UPDATE)
con.commit()
time.sleep(0.15)
if cmd == 4:
return'cmd error'
else:
return 'cmd ok'
class MOTORRSAI():
"""
MOTORRSAI(IpAdrress,NoMotor)
class is defined by Ipadress of the rack and axis number
"""
def __init__(self, IpAdrress,NoMotor,parent=None):
self.IpAdress = IpAdrress
self.NoMotor = NoMotor
self.IdEquipt = rEquipmentIdNbr(self.IpAdress)
self.NoMod = getSlotNumber(self.NoMotor)
self.NoAxis = getAxisNumber(self.NoMotor)
# each action to database have different cursor
self.cur = con.cursor() # def cursor to read postion
self.curcwd = con.cursor() # def cursor to write cmd
self.curEtat = con.cursor() # def cursor to read state
self.cursorRead =con.cursor() # def cursor to read parameter value
self.cursorWrite=con.cursor() # def cursor to write parameter value
self.PkIdTbBoc = readPkModBim2BOC(self.cursorRead,self.IdEquipt, self.NoMod, self.NoAxis, FlgReadWrite=1) # Read Primary key identifier of an axis module Bim2BOC : p_PkModBim
self._name = rStepperParameter(self.cursorRead,self.PkIdTbBoc,NoMotor,listParaStr['nomAxe'])
self.update()
def update(self):
'''update from the data base')
'''
self.name = self.getName()
self.step = self.getStepValue()
self.butPlus = self.getButLogPlusValue()
self.butMoins = self.getButLogMoinsValue()
self.refName=[]
for i in range (1,7):
r = self.getRefName(i)
self.refName.append(r)
# time.sleep(0.01)
self.refValue=[]
for i in range (1,7):
rr = self.getRefValue(i)/self.step
self.refValue.append(rr)
# time.sleep(0.01)
def position(self):
'''
return motor postion
'''
mut.lock()
TableName = "TbBim2BOC_1Axis_R"
ValToRead = "PosAxis"
ConditionColName = "PkId"
ConditionValue = str(self.PkIdTbBoc)
Prepare1Cond= "SELECT " + ValToRead + " FROM " + TableName + " WHERE " + ConditionColName + " = '" + ConditionValue + "' ;"
self.cur.execute(Prepare1Cond )
posi = self.cur.fetchone()[0]
mut.unlock()
return posi
def getName(self):
'''
get motor name
'''
mut.lock()
self._name = rStepperParameter(self.cursorRead,self.PkIdTbBoc,self.NoMotor,listParaStr['nomAxe'])
mut.unlock()
return self._name
def setName(self,nom):
'''
set motor name
'''
valParam = nom
mut.lock()
a = wStepperParameter(self.cursorWrite,self.IdEquipt,self.NoMotor, listParaStr['nomAxe'],valParam)
time.sleep(0.05)
mut.unlock()
def getRefName(self,nRef) :
'''
set ref n° name
'''
mut.lock()
key = listParaStr['nomRef'+str(nRef)]
mut.unlock()
return rStepperParameter(self.cursorRead,self.PkIdTbBoc, self.NoMotor, key)
def setRefName(self,nRef,name) :
'''
set ref n° name
'''
mut.lock()
key = listParaStr['nomRef'+str(nRef)]
a = wStepperParameter(self.cursorWrite,self.IdEquipt, self.NoMotor, key, name) # to do change to self.PkIdTbBoc?
mut.unlock()
def getRefValue(self,nRef) :
'''
get value of the refereence position nRef
'''
mut.lock()
key = listParaReal['Ref'+str(nRef)+'Val']
ref = rStepperParameter(self.cursorRead,self.PkIdTbBoc, self.NoMotor, key)
mut.unlock()
return ref
def setRefValue(self,nReff,value) :
'''
set value of the refereence position nRef
'''
key = listParaReal['Ref'+str(nReff)+'Val']
wStepperParameter(self.cursorWrite,self.IdEquipt, self.NoMotor, key, value) # to do change to self.PkIdTbBoc? change for self.cur?
def getStepValue(self):
'''Valeur de 1 pas dans l'unites
'''
mut.lock()
key = listParaReal['Step'] #1106
step = rStepperParameter(self.cursorRead,self.PkIdTbBoc, self.NoMotor, key)
mut.unlock()
return step
def getButLogPlusValue(self):
key = listParaInt['ButLogPlus']
mut.lock()
but = rStepperParameter(self.cursorRead,self.PkIdTbBoc, self.NoMotor, key)
mut.unlock()
return but
def setButLogPlusValue(self,butPlus):
key = listParaInt['ButLogPlus']
wStepperParameter(self.cursorWrite,self.IdEquipt, self.NoMotor, key, butPlus) # to do change to self.PkIdTbBoc?
def getButLogMoinsValue(self):
key = listParaInt['ButLogNeg']
mut.lock()
b = rStepperParameter(self.cursorRead,self.PkIdTbBoc, self.NoMotor, key)
mut.unlock()
return b
def setButLogMoinsValue(self,butMoins):
key = listParaInt['ButLogNeg']
wStepperParameter(self.cursorWrite,self.IdEquipt, self.NoMotor, key, butMoins) # to do change to self.PkIdTbBoc?
def rmove(self,posrelatif,vitesse=1000):
'''
relative move of NoMotor of IpAdress
posrelatif = position to move in step
#to do faire self.curcwd
'''
RegOrder = 3
posrelatif = int(posrelatif)
print(self._name,'relative move of ',posrelatif,' step')
mut.lock()
a = wStepperCmd(cursor=self.curcwd, PkIdTbBoc=self.PkIdTbBoc, RegOrder=RegOrder, RegPosition=posrelatif,RegVelocity=vitesse)
mut.unlock()
def move(self,pos,vitesse=1000):
'''absolue move of NoMotor of IpAdress
pos = position to move in step
'''
mut.lock()
RegOrder = 2
a = wStepperCmd(cursor =self.curcwd, PkIdTbBoc=self.PkIdTbBoc,RegOrder=RegOrder, RegPosition=pos,RegVelocity=vitesse)
print(self._name, 'absolue move of ',pos,' step')
mut.unlock()
def setzero(self):
"""
setzero(self.moteurname):Set Zero
"""
mut.lock()
RegOrder=10 # commande pour zero le moteur
a=wStepperCmd(cursor =self.curcwd,PkIdTbBoc=self.PkIdTbBoc, RegOrder=RegOrder, RegPosition=0,RegVelocity=0)
mut.unlock()
def stopMotor(self): # stop le moteur motor
"""
stopMotor(motor): stop le moteur motor
"""
mut.lock()
RegOrder = 4
a = wStepperCmd(cursor =self.curcwd,PkIdTbBoc=self.PkIdTbBoc, RegOrder=RegOrder, RegPosition=0,RegVelocity=0)
mut.unlock()
def etatMotor(self):
'''
read status of the motor
'''
mut.lock()
TbToRead = "TbBim2Boc_1Axis_R"
# PkIdTbBoc = readPkModBim2BOC(self.IdEquipt, self.NoMod, self.NoAxis, FlgReadWrite=1) # Read Primary key identifier of an axis module Bim2BOC : p_PkModBim
#a =str( hex(getValueWhere1ConditionAND(TbToRead , "StatusAxis", "PkId", str(self.PkIdTbBoc))))
# ecire direct la fonction
Prepare1Cond = "SELECT " + "StatusAxis" + " FROM " + TbToRead + " WHERE " + "PkId" + " = " + str(self.PkIdTbBoc) + ";"
self.curEtat.execute(Prepare1Cond )
a=self.curEtat.fetchone()[0]
a=str(hex(a))
con.commit()
time.sleep(0.1)
mut.unlock()
# a refaire prendre que les dernier bits ?
if a == '0x2030' or a == '0x30' or a == '0x20':
etat='mvt'
elif a=='0x2012' or a=='0x12' or a=='0x92' or a=='0x2082' or a== '0x2002' or a== '0x2':
etat='FDC-'
elif a=='0x2011' or a=='0x11' or a=='0x91' or a=='0x2081' or a== '0x2001' or a =='0x1':
etat='FDC+'
elif a=='0x2010' or a=='0x10' :
etat='ok'
elif a=='0x2090' or a=='0x90' or a=='0x4000':
etat='ok'
elif a=='0x2090' or a=='0x80'or a=='0x0':
etat='ok'
elif a=='0x890' or a == '0x2890' or a == '0x880' or a=='0x8c0' or a=='0x2883' :
etat='Power off'
else:
etat=str(a)
# print('etat',etat)
return etat
def getEquipementName(self):
'''
return the name of the equipement of which the motor is connected
'''
return nameEquipment(self.IpAdress)
if __name__ == '__main__':
closeConnection()