UniNE-CHYN / thorpy

Python library implementing Thorlabs APT communication protocol
43 stars 22 forks source link

Issues with BSC201 and stepper DRV013 #17

Closed CidrolinF closed 5 years ago

CidrolinF commented 5 years ago

Hello, I have had several problems trying to control a BSC201 connected to a stepper motor DRV013 from a Raspberry Pi (the objective is to construct a web app), some of which I managed to solve.

First I have had to fix USB permission to access infos like Manufacturer and so. For that I followed this procedure : https://stackoverflow.com/questions/3738173/why-does-pyusb-libusb-require-root-sudo-permissions-on-linux

Then during the Port init, I noticed that the first message received after MGMSG_HW_REQ_INFO() is not of GMSG_HW_GET_INFO type, but this one :

(dest=0x0, src=0x0, chan_ident=1, position=0, status_bits=0) This happens everytime when connecting (and I don't understand why ?), so I added a condition to match the expected type : ``` while self._info_message is None: self.send_message(MGMSG_HW_REQ_INFO()) try: message = self._recv_message(blocking = True) print("type :", type(message)) if isinstance(message,thorpy.message.systemcontrol.MGMSG_HW_GET_INFO) : self._info_message = message ``` The second message is the good one and this is the infos I get back from the BSC201. (The dialog seems a bit laggy though, and I often have to reboot the unit and launch the code again to get a response): ``` controller_type 40 stage_type 114 hw_version 3 model_number SCC201 ``` The stage was not recognized by the code, so I had to add this bit of code inside the function stage_name_from_get_hw_info() (I'm not quite sure about it though) : ``` elif controller_type in (40, ): if stage_type == 114: return '17DRV013 Enc LNR 25mm' ``` It took me a very long time to get there, and now I can't get the stage to go to home position with s.home(), nor get its state with s.print_state() The message (dest=0x50, src=0x1, chan_ident=1) is sent but I don't receive any response from the unit, so after a timeout, _wait_for_properties() does not return anything, what yields to an error. Is there something I could have missed ? Thank you and good day !
CidrolinF commented 5 years ago

Allright, I solved the communication issue by inverting the RTS state at the serial port initialization. It works fine now. I don't know if it is specific to my controller BSC201.

In port.py :

self._serial.setRTS(0) time.sleep(0.05) self._serial.reset_input_buffer() self._serial.reset_output_buffer() self._serial.setRTS(1) time.sleep(0.05)

It works fine now. I just had to tinker the rest of the code a bit to make it work with a stepper motor. Thank you for this project, I learned a lot !