@@ -221,10 +221,10 @@ def send(self, msg):
221
221
def handle_message (self , msg ):
222
222
pass
223
223
224
- def send_request (self , msgreq_id , msgget_id , param1 = 0 , param2 = 0 ):
225
- Message (msgreq_id , param1 , param2 ).send (self .port )
224
+ def send_request (self , msgreq_id , wait_for_msgs , param1 = 0 , param2 = 0 , data = None ):
225
+ Message (msgreq_id , param1 , param2 , data = data ).send (self .port )
226
226
msg = msg_id = None
227
- while msg is None or msg_id != msgget_id :
227
+ while msg is None or msg_id not in wait_for_msgs :
228
228
msg = Message .recv (self .port )
229
229
self .handle_message (msg )
230
230
msg_id = msg .id
@@ -247,7 +247,7 @@ def set_channel_enable_state(self, activated):
247
247
248
248
def get_channel_enable_state (self ):
249
249
get_msg = self .send_request (MGMSG .MOD_REQ_CHANENABLESTATE ,
250
- MGMSG .MOD_GET_CHANENABLESTATE , 1 )
250
+ [ MGMSG .MOD_GET_CHANENABLESTATE ] , 1 )
251
251
self .chan_enabled = get_msg .param2
252
252
if self .chan_enabled == 1 :
253
253
self .chan_enabled = True
@@ -286,7 +286,7 @@ def hardware_stop_update_messages(self):
286
286
287
287
def hardware_request_information (self ):
288
288
return self .send_request (MGMSG .HW_REQ_INFO ,
289
- MGMSG .HW_GET_INFO )
289
+ [ MGMSG .HW_GET_INFO ] )
290
290
291
291
def is_channel_enabled (self ):
292
292
return self .chan_enabled
@@ -355,7 +355,7 @@ def get_position_control_mode(self):
355
355
"""
356
356
357
357
get_msg = self .send_request (MGMSG .PZ_REQ_POSCONTROLMODE ,
358
- MGMSG .PZ_GET_POSCONTROLMODE , 1 )
358
+ [ MGMSG .PZ_GET_POSCONTROLMODE ] , 1 )
359
359
return get_msg .param2
360
360
361
361
def set_output_volts (self , voltage ):
@@ -389,7 +389,7 @@ def get_output_volts(self):
389
389
"""
390
390
391
391
get_msg = self .send_request (MGMSG .PZ_REQ_OUTPUTVOLTS ,
392
- MGMSG .PZ_GET_OUTPUTVOLTS , 1 )
392
+ [ MGMSG .PZ_GET_OUTPUTVOLTS ] , 1 )
393
393
return st .unpack ("<H" , get_msg .data [2 :])[0 ]* self .voltage_limit * V / 32767
394
394
395
395
def set_output_position (self , position_sw ):
@@ -417,7 +417,7 @@ def get_output_position(self):
417
417
"""
418
418
419
419
get_msg = self .send_request (MGMSG .PZ_REQ_OUTPUTPOS ,
420
- MGMSG .PZ_GET_OUTPUTPOS , 1 )
420
+ [ MGMSG .PZ_GET_OUTPUTPOS ] , 1 )
421
421
return st .unpack ("<H" , get_msg .data [2 :])[0 ]
422
422
423
423
def set_input_volts_source (self , volt_src ):
@@ -459,7 +459,7 @@ def get_input_volts_source(self):
459
459
"""
460
460
461
461
get_msg = self .send_request (MGMSG .PZ_REQ_INPUTVOLTSSRC ,
462
- MGMSG .PZ_GET_INPUTVOLTSSRC , 1 )
462
+ [ MGMSG .PZ_GET_INPUTVOLTSSRC ] , 1 )
463
463
return st .unpack ("<H" , get_msg .data [2 :])[0 ]
464
464
465
465
def set_pi_constants (self , prop_const , int_const ):
@@ -488,7 +488,7 @@ def get_pi_constants(self):
488
488
"""
489
489
490
490
get_msg = self .send_request (MGMSG .PZ_REQ_PICONSTS ,
491
- MGMSG .PZ_GET_PICONSTS , 1 )
491
+ [ MGMSG .PZ_GET_PICONSTS ] , 1 )
492
492
return st .unpack ("<HH" , get_msg .data [2 :])
493
493
494
494
def set_output_lut (self , lut_index , output ):
@@ -546,7 +546,7 @@ def get_output_lut(self):
546
546
"""
547
547
548
548
get_msg = self .send_request (MGMSG .PZ_REQ_OUTPUTLUT ,
549
- MGMSG .PZ_GET_OUTPUTLUT , 1 )
549
+ [ MGMSG .PZ_GET_OUTPUTLUT ] , 1 )
550
550
(index , output ) = st .unpack ("<Hh" , get_msg .data [2 :])
551
551
return index , output * self .voltage_limit * V / 32767
552
552
@@ -626,7 +626,7 @@ def get_output_lut_parameters(self):
626
626
"""
627
627
628
628
get_msg = self .send_request (MGMSG .PZ_REQ_OUTPUTLUTPARAMS ,
629
- MGMSG .PZ_GET_OUTPUTLUTPARAMS , 1 )
629
+ [ MGMSG .PZ_GET_OUTPUTLUTPARAMS ] , 1 )
630
630
return st .unpack ("<HHLLLL" , get_msg .data [2 :22 ])
631
631
632
632
def start_lut_output (self ):
@@ -669,7 +669,7 @@ def get_tpz_display_settings(self):
669
669
"""
670
670
671
671
get_msg = self .send_request (MGMSG .PZ_REQ_TPZ_DISPSETTINGS ,
672
- MGMSG .PZ_GET_TPZ_DISPSETTINGS , 1 )
672
+ [ MGMSG .PZ_GET_TPZ_DISPSETTINGS ] , 1 )
673
673
return st .unpack ("<H" , get_msg .data )[0 ]
674
674
675
675
def set_tpz_io_settings (self , voltage_limit , hub_analog_input ):
@@ -731,7 +731,7 @@ def get_tpz_io_settings(self):
731
731
"""
732
732
733
733
get_msg = self .send_request (MGMSG .PZ_REQ_TPZ_IOSETTINGS ,
734
- MGMSG .PZ_GET_TPZ_IOSETTINGS , 1 )
734
+ [ MGMSG .PZ_GET_TPZ_IOSETTINGS ] , 1 )
735
735
voltage_limit , hub_analog_input = st .unpack ("<HH" , get_msg .data [2 :6 ])
736
736
if voltage_limit == 1 :
737
737
voltage_limit = 75 * V
@@ -763,8 +763,6 @@ def handle_message(self, msg):
763
763
raise MsgError ("Hardware error {}: {}"
764
764
.format (code ,
765
765
data [4 :].decode (encoding = "ascii" )))
766
- elif msg_id == MGMSG .MOT_MOVE_HOMED :
767
- pass
768
766
elif (msg_id == MGMSG .MOT_MOVE_COMPLETED or
769
767
msg_id == MGMSG .MOT_MOVE_STOPPED or
770
768
msg_id == MGMSG .MOT_GET_DCSTATUSUPDATE ):
@@ -777,6 +775,10 @@ def handle_message(self, msg):
777
775
(self .position , self .velocity , r , self .status ) = st .unpack (
778
776
"<LHHL" , data [2 :])
779
777
778
+ def is_moving (self ):
779
+ status_bits = self .get_status_bits ()
780
+ return (status_bits & 0x2F0 ) != 0
781
+
780
782
def set_pot_parameters (self , zero_wnd , vel1 , wnd1 , vel2 , wnd2 , vel3 ,
781
783
wnd3 , vel4 ):
782
784
"""Set pot parameters.
@@ -811,12 +813,12 @@ def get_pot_parameters(self):
811
813
"""
812
814
813
815
get_msg = self .send_request (MGMSG .MOT_REQ_POTPARAMS ,
814
- MGMSG .MOT_GET_POTPARAMS , 1 )
816
+ [ MGMSG .MOT_GET_POTPARAMS ] , 1 )
815
817
return st .unpack ("<HLHLHLHL" , get_msg .data [2 :])
816
818
817
819
def hub_get_bay_used (self ):
818
820
get_msg = self .send_request (MGMSG .HUB_REQ_BAYUSED ,
819
- MGMSG .HUB_GET_BAYUSED )
821
+ [ MGMSG .HUB_GET_BAYUSED ] )
820
822
return get_msg .param1
821
823
822
824
def set_position_counter (self , position ):
@@ -841,7 +843,7 @@ def get_position_counter(self):
841
843
"""
842
844
843
845
get_msg = self .send_request (MGMSG .MOT_REQ_POSCOUNTER ,
844
- MGMSG .MOT_GET_POSCOUNTER , 1 )
846
+ [ MGMSG .MOT_GET_POSCOUNTER ] , 1 )
845
847
return st .unpack ("<l" , get_msg .data [2 :])[0 ]
846
848
847
849
def set_encoder_counter (self , encoder_count ):
@@ -865,7 +867,7 @@ def get_encoder_counter(self):
865
867
"""
866
868
867
869
get_msg = self .send_request (MGMSG .MOT_REQ_ENCCOUNTER ,
868
- MGMSG .MOT_GET_ENCCOUNTER , 1 )
870
+ [ MGMSG .MOT_GET_ENCCOUNTER ] , 1 )
869
871
return st .unpack ("<l" , get_msg .data [2 :])[0 ]
870
872
871
873
def set_velocity_parameters (self , acceleration , max_velocity ):
@@ -886,7 +888,7 @@ def get_velocity_parameters(self):
886
888
"""
887
889
888
890
get_msg = self .send_request (MGMSG .MOT_REQ_VELPARAMS ,
889
- MGMSG .MOT_GET_VELPARAMS , 1 )
891
+ [ MGMSG .MOT_GET_VELPARAMS ] , 1 )
890
892
return st .unpack ("<LL" , get_msg .data [6 :])
891
893
892
894
def set_jog_parameters (self , mode , step_size , acceleration ,
@@ -915,7 +917,7 @@ def get_jog_parameters(self):
915
917
"""
916
918
917
919
get_msg = self .send_request (MGMSG .MOT_REQ_JOGPARAMS ,
918
- MGMSG .MOT_GET_JOGPARAMS , 1 )
920
+ [ MGMSG .MOT_GET_JOGPARAMS ] , 1 )
919
921
(jog_mode , step_size , _ , acceleration , max_velocity ,
920
922
stop_mode ) = st .unpack ("<HLLLLH" , get_msg .data [2 :])
921
923
return jog_mode , step_size , acceleration , max_velocity , stop_mode
@@ -938,7 +940,7 @@ def get_gen_move_parameters(self):
938
940
"""
939
941
940
942
get_msg = self .send_request (MGMSG .MOT_REQ_GENMOVEPARAMS ,
941
- MGMSG .MOT_GET_GENMOVEPARAMS , 1 )
943
+ [ MGMSG .MOT_GET_GENMOVEPARAMS ] , 1 )
942
944
return st .unpack ("<l" , get_msg .data [2 :])[0 ]
943
945
944
946
def set_move_relative_parameters (self , relative_distance ):
@@ -960,7 +962,7 @@ def get_move_relative_parameters(self):
960
962
"""
961
963
962
964
get_msg = self .send_request (MGMSG .MOT_REQ_MOVERELPARAMS ,
963
- MGMSG .MOT_GET_MOVERELPARAMS , 1 )
965
+ [ MGMSG .MOT_GET_MOVERELPARAMS ] , 1 )
964
966
return st .unpack ("<l" , get_msg .data [2 :])[0 ]
965
967
966
968
def set_move_absolute_parameters (self , absolute_position ):
@@ -982,7 +984,7 @@ def get_move_absolute_parameters(self):
982
984
"""
983
985
984
986
get_msg = self .send_request (MGMSG .MOT_REQ_MOVEABSPARAMS ,
985
- MGMSG .MOT_GET_MOVEABSPARAMS , 1 )
987
+ [ MGMSG .MOT_GET_MOVEABSPARAMS ] , 1 )
986
988
return st .unpack ("<l" , get_msg .data [2 :])[0 ]
987
989
988
990
def set_home_parameters (self , home_velocity ):
@@ -1002,17 +1004,17 @@ def get_home_parameters(self):
1002
1004
"""
1003
1005
1004
1006
get_msg = self .send_request (MGMSG .MOT_REQ_HOMEPARAMS ,
1005
- MGMSG .MOT_GET_HOMEPARAMS , 1 )
1007
+ [ MGMSG .MOT_GET_HOMEPARAMS ] , 1 )
1006
1008
return st .unpack ("<L" , get_msg .data [6 :10 ])[0 ]
1007
1009
1008
1010
def move_home (self ):
1009
1011
"""Start a home move sequence.
1010
1012
1011
- This call is blocking until device is homed.
1013
+ This call is blocking until device is homed or move is stopped .
1012
1014
"""
1013
1015
1014
1016
self .send_request (MGMSG .MOT_MOVE_HOME ,
1015
- MGMSG .MOT_MOVE_HOMED , 1 )
1017
+ [ MGMSG .MOT_MOVE_HOMED , MGMSG . MOT_MOVE_STOPPED ] , 1 )
1016
1018
1017
1019
def set_limit_switch_parameters (self , cw_hw_limit , ccw_hw_limit ):
1018
1020
"""Set the limit switch parameters.
@@ -1057,7 +1059,7 @@ def get_limit_switch_parameters(self):
1057
1059
"""
1058
1060
1059
1061
get_msg = self .send_request (MGMSG .MOT_REQ_LIMSWITCHPARAMS ,
1060
- MGMSG .MOT_GET_LIMSWITCHPARAMS , 1 )
1062
+ [ MGMSG .MOT_GET_LIMSWITCHPARAMS ] , 1 )
1061
1063
return st .unpack ("<HH" , get_msg .data [2 :6 ])
1062
1064
1063
1065
def move_relative_memory (self ):
@@ -1069,7 +1071,8 @@ def move_relative_memory(self):
1069
1071
command.
1070
1072
"""
1071
1073
1072
- self .send (Message (MGMSG .MOT_MOVE_RELATIVE , param1 = 1 ))
1074
+ self .send_request (MGMSG .MOT_MOVE_RELATIVE ,
1075
+ [MGMSG .MOT_MOVE_COMPLETED , MGMSG .MOT_MOVE_STOPPED ], 1 )
1073
1076
1074
1077
def move_relative (self , relative_distance ):
1075
1078
"""Start a relative move
@@ -1079,7 +1082,9 @@ def move_relative(self, relative_distance):
1079
1082
"""
1080
1083
1081
1084
payload = st .pack ("<Hl" , 1 , relative_distance )
1082
- self .send (Message (MGMSG .MOT_MOVE_RELATIVE , data = payload ))
1085
+ self .send_request (MGMSG .MOT_MOVE_RELATIVE ,
1086
+ [MGMSG .MOT_MOVE_COMPLETED , MGMSG .MOT_MOVE_STOPPED ],
1087
+ data = payload )
1083
1088
1084
1089
def move_absolute_memory (self ):
1085
1090
"""Start an absolute move of distance in the controller's memory.
@@ -1090,7 +1095,9 @@ def move_absolute_memory(self):
1090
1095
command.
1091
1096
"""
1092
1097
1093
- self .send (Message (MGMSG .MOT_MOVE_ABSOLUTE , param1 = 1 ))
1098
+ self .send_request (MGMSG .MOT_MOVE_ABSOLUTE ,
1099
+ [MGMSG .MOT_MOVE_COMPLETED , MGMSG .MOT_MOVE_STOPPED ],
1100
+ param1 = 1 )
1094
1101
1095
1102
def move_absolute (self , absolute_distance ):
1096
1103
"""Start an absolute move.
@@ -1101,21 +1108,19 @@ def move_absolute(self, absolute_distance):
1101
1108
"""
1102
1109
1103
1110
payload = st .pack ("<Hl" , 1 , absolute_distance )
1104
- self .send (Message (MGMSG .MOT_MOVE_ABSOLUTE , data = payload ))
1111
+ self .send_request (MGMSG .MOT_MOVE_ABSOLUTE ,
1112
+ [MGMSG .MOT_MOVE_COMPLETED , MGMSG .MOT_MOVE_STOPPED ],
1113
+ data = payload )
1105
1114
1106
- def move_jog (self , direction , async = False ):
1115
+ def move_jog (self , direction ):
1107
1116
"""Start a job move.
1108
1117
1109
1118
:param direction: The direction to jog. 1 is forward, 2 is backward.
1110
- :param async: If True then the command does not wait for the move to
1111
- finish. If False the command only returns when move is finished.
1112
1119
"""
1113
1120
1114
- if async :
1115
- self .send_request (MGMSG .MOT_MOVE_JOG ,
1116
- MGMSG .MOT_MOVE_COMPLETED , 1 , direction )
1117
- else :
1118
- self .send (Message (MGMSG .MOT_MOVE_JOG , param1 = 1 , param2 = direction ))
1121
+ self .send_request (MGMSG .MOT_MOVE_JOG ,
1122
+ [MGMSG .MOT_MOVE_COMPLETED , MGMSG .MOT_MOVE_STOPPED ],
1123
+ param1 = 1 , param2 = direction )
1119
1124
1120
1125
def move_velocity (self , direction ):
1121
1126
"""Start a move.
@@ -1134,7 +1139,7 @@ def move_velocity(self, direction):
1134
1139
1135
1140
self .send (Message (MGMSG .MOT_MOVE_VELOCITY , param1 = 1 , param2 = direction ))
1136
1141
1137
- def move_stop (self , stop_mode , async = False ):
1142
+ def move_stop (self , stop_mode ):
1138
1143
"""Stop any type of motor move.
1139
1144
1140
1145
Stops any of those motor move: relative, absolute, homing or move at
@@ -1143,15 +1148,13 @@ def move_stop(self, stop_mode, async=False):
1143
1148
:param stop_mode: The stop mode defines either an immediate (abrupt)
1144
1149
or profiled stop. Set this byte to 1 to stop immediately, or to 2
1145
1150
to stop in a controlled (profiled) manner.
1146
- :param async: If set to False, this method will block until motor
1147
- is really stopped. Returns immediately if set to True.
1148
1151
"""
1149
1152
1150
- if async :
1151
- self .send (Message (MGMSG .MOT_MOVE_STOP , param1 = 1 , param2 = stop_mode ))
1152
- else :
1153
+ if self .is_moving ():
1153
1154
self .send_request (MGMSG .MOT_MOVE_STOP ,
1154
- MGMSG .MOT_MOVE_STOPPED , 1 , stop_mode )
1155
+ [MGMSG .MOT_MOVE_STOPPED ,
1156
+ MGMSG .MOT_MOVE_COMPLETED ],
1157
+ 1 , stop_mode )
1155
1158
1156
1159
def set_dc_pid_parameters (self , proportional , integral , differential ,
1157
1160
integral_limit , filter_control = 0x0F ):
@@ -1185,7 +1188,7 @@ def get_dc_pid_parameters(self):
1185
1188
"""
1186
1189
1187
1190
get_msg = self .send_request (MGMSG .MOT_REQ_DCPIDPARAMS ,
1188
- MGMSG .MOT_GET_DCPIDPARAMS , 1 )
1191
+ [ MGMSG .MOT_GET_DCPIDPARAMS ] , 1 )
1189
1192
return st .unpack ("<LLLLH" , get_msg .data [2 :])
1190
1193
1191
1194
def set_av_modes (self , mode_bits ):
@@ -1212,7 +1215,7 @@ def get_av_modes(self):
1212
1215
"""
1213
1216
1214
1217
get_msg = self .send_request (MGMSG .MOT_REQ_AVMODES ,
1215
- MGMSG .MOT_GET_AVMODES , 1 )
1218
+ [ MGMSG .MOT_GET_AVMODES ] , 1 )
1216
1219
return st .unpack ("<H" , get_msg .data [2 :])[0 ]
1217
1220
1218
1221
def set_button_parameters (self , mode , position1 , position2 ):
@@ -1250,7 +1253,7 @@ def get_button_parameters(self):
1250
1253
"""
1251
1254
1252
1255
get_msg = self .send_request (MGMSG .MOT_REQ_BUTTONPARAMS ,
1253
- MGMSG .MOT_GET_BUTTONPARAMS , 1 )
1256
+ [ MGMSG .MOT_GET_BUTTONPARAMS ] , 1 )
1254
1257
return st .unpack ("<Hll" , get_msg .data [2 :12 ])
1255
1258
1256
1259
def set_eeprom_parameters (self , msg_id ):
@@ -1274,7 +1277,7 @@ def get_dc_status_update(self):
1274
1277
"""
1275
1278
1276
1279
get_msg = self .send_request (MGMSG .MOT_REQ_DCSTATUSUPDATE ,
1277
- MGMSG .MOT_GET_DCSTATUSUPDATE , 1 )
1280
+ [ MGMSG .MOT_GET_DCSTATUSUPDATE ] , 1 )
1278
1281
pos , vel , _ , stat = st .unpack ("<LHHL" , get_msg .data [2 :])
1279
1282
return pos , vel , stat
1280
1283
@@ -1286,7 +1289,7 @@ def get_status_bits(self):
1286
1289
"""
1287
1290
1288
1291
get_msg = self .send_request (MGMSG .MOT_REQ_STATUSBITS ,
1289
- MGMSG .MOT_GET_STATUSBITS , 1 )
1292
+ [ MGMSG .MOT_GET_STATUSBITS ] , 1 )
1290
1293
return st .unpack ("<L" , get_msg .data [2 :])[0 ]
1291
1294
1292
1295
def suspend_end_of_move_messages (self ):
1 commit comments
sbourdeauducq commentedon Jun 19, 2015
Documentation update needed.