lwbe / ThorlabsApt

1 stars 2 forks source link

Error when running `test_device.py` with BSC203 and NRT150 #1

Open mxochicale opened 4 years ago

mxochicale commented 4 years ago

Hi @lwbe

First of all, thanks for the nice development of your apt. I realise that your work is very active these days compare to others ones such as https://github.com/freespace/pyAPT. I am wondering if you have tested your application under Ubuntu 18.04x6x with Controller BSC203 and linear stages NRT150/M?

After installing pip install -r requirements.txtin my virtual environment and using this from six.moves import configparser for python3, I have run python test_device.py under Ubuntu 18.04x6x with Controller [BSC203] and linear stages [NRT150/M] but I am not sure what I am missing perhaps you have some hints for the following bug:

Traceback (most recent call last):
  File "test_xn.py", line 5, in <module>
    from thorlabs_device import Thorlabs_device
  File "$HOME/repositories/ThorlabsApt/thorlabs_device.py", line 271
    print self.thor_msg.msg_id_to_keyword[msg_id]
             ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(self.thor_msg.msg_id_to_keyword[msg_id])?
lwbe commented 4 years ago

Hello,

I have corrected the bug you mentionned. I'll be glad to help you as much as I can but as you can see the code is not very well written ( I mean there is no setup.py and unit test stuff). The motivation of this code is to implement the communication protocol to be able to drive some thorlabs units we have in my lab. The communication layer is done through serial port only . I have the BSC203 controller but not the NRT150/M stage but please let me know if I can help you.

sincerely

L.

mxochicale commented 4 years ago

Hi @lwbe

Thanks for your message! It does sort out the previous issue. Then, following the example of test_device.py, I realise that the variables of port, baudrate and timeout needs to be defined which are added as shown below:

#!/usr/bin/env python
"""
Simple code to show how to use the library
Usage: "python test_BSC203_NRT150.py"
"""
from thorlabs_device import Thorlabs_device
from thorlabs_apt_comm import Thorlabs_apt_communication
import serial
import os,sys

port="/dev/ttyUSB0"
baudrate=115200
timeout=0
serial_device = serial.Serial(port,baudrate=baudrate,timeout=timeout)
#tac = Thorlabs_apt_communication()

However, when running the same script with the uncommented tac = Thorlabs_apt_communication() I got two different bugs which are depented on the python version:

$ python2 test_BSC203_NRT150.py
Traceback (most recent call last):
  File "test_BSC203_NRT150.py", line 6, in <module>
    from thorlabs_device import Thorlabs_device
  File "/home/pyapt/LS/repositories/ThorlabsApt/thorlabs_device.py", line 1, in <module>
    import serial
ImportError: No module named serial
$ python3 test_BSC203_NRT150.py
Traceback (most recent call last):
  File "test_BSC203_NRT150.py", line 16, in <module>
    tac = Thorlabs_apt_communication()
  File "/home/pyapt/LS/repositories/ThorlabsApt/thorlabs_apt_comm.py", line 104, in __init__
    apt_keys.remove("header")
AttributeError: 'dict_keys' object has no attribute 'remove'

Questions:

  1. How (or where) do you set up the serial port parameters?
  2. Which is the version of your python and the Operating System where you are testing this code.

Regards Miguel

lwbe commented 4 years ago

Hello

thanks for the report. I have changed the readme.md to add a few more information.

Essentially the code will run with python2.7 only. I can work on python 3 but for now it is only 2.7.

You need pyserial to use this code. I've tried to implement the code in such a way that if you supply a write and read function on your own. In the readme I indicate how to use virtualenv to install packages without touching the system modules.

To answer your questions 1) The serial ports parameters are in thorlabs_device.py in the init function of the Thorlabs_device.

2) I'm using python2.7 on centos 7.

I realise test_device.py is not correct. If you want to use the library please try someting like

   from thorlabs_device import Thorlabs_device
  d1 = Thorlabs_device("serial_number_of_bsc203","BSC20x","NRT150E Enc Stage 150mm",1)

The stages name are in the MG17APTServer.ini file and for NRT150 you can find

NRT150E Enc Stage 150mm NRT150 Enc Stage 150mm HS NRT150 Enc Stage 150mm

The serial number can be found using

lsusb -v | grep iSerial

and for BSC20x series it should start by 70xxx beware that the serial number should be given as a string.

Hope this helps and let me know.

lwbe commented 4 years ago

Hello again

I updated the codes and made a small doc in the readme on the first page. Let me know if it is understandable.

L.

mxochicale commented 4 years ago

Hi @lwbe

Many thanks for your helpful explanations. Following your comments, the following script test_BSC203_NRT150.py" runs well.

#!/usr/bin/env python
"""
Simple code to show how to use the library
Usage: "python test_BSC203_NRT150.py"
"""
from thorlabs_device import Thorlabs_device
from thorlabs_apt_comm import Thorlabs_apt_communication
import serial
import os,sys

d1 = Thorlabs_device("70112214", "BSC20x", "NRT150E Enc Stage 150mm", 1)
d1.get_info()
d1.get_position()

However, I am afraid of not getting the right outputs when calling get_info() or get_position() as shown below

python test_BSC203_NRT150.py 
keyword MGMSG_HW_STOP_UPDATEMSGS params: 1, 0, 17, 1
msg sent:  (0x12 00 01 00 11 01) params : [18, 1, 0, 17, 1]
keyword MGMSG_HW_REQ_INFO params: 0, 0, 17, 1
msg sent:  (0x05 00 00 00 11 01) params : [5, 0, 0, 17, 1]
keyword MGMSG_MOT_REQ_POSCOUNTER params: 1, 0, 33, 1
msg sent: ! (0x11 04 01 00 21 01) params : [1041, 1, 0, 33, 1]

Do you have any suggestions?

lwbe commented 4 years ago

Hello,

the two lines like

keyword MGMSG_HW_STOP_UPDATEMSGS params: 1, 0, 17, 1 msg sent: (0x12 00 01 00 11 01) params : [18, 1, 0, 17, 1]

are debug info. I will have to turn them off or at least that should be an option.

get_info() and get_position() return a variable and if you want to see them you need to print them. So print(d1.get_info()) and print(d1.get_position()) will return the content that you can check. get_info() return a dict() and is perhaps not very easy to read.

mxochicale commented 4 years ago

Thanks @lwbe

When trying your recommendation

d1 = Thorlabs_device("70112214", "BSC20x", "NRT150E Enc Stage 150mm", 1)
print(d1.get_info())
print(d1.get_position())

The following bug appears.

t$ python test_BSC203_NRT150.py 
keyword MGMSG_HW_STOP_UPDATEMSGS params: 1, 0, 17, 1
msg sent:  (0x12 00 01 00 11 01) params : [18, 1, 0, 17, 1]
keyword MGMSG_HW_REQ_INFO params: 0, 0, 17, 1
msg sent:  (0x05 00 00 00 11 01) params : [5, 0, 0, 17, 1]
Error: nothing to analyse, is there a communication problem!!
Traceback (most recent call last):
  File "test_BSC203_NRT150.py", line 12, in <module>
    print(d1.get_info())
  File "/home/pyapt/LS/repositories/ThorlabsApt/thorlabs_device.py", line 308, in wrapper
    return  self.send_command(*p)
  File "/home/pyapt/LS/repositories/ThorlabsApt/thorlabs_device.py", line 222, in send_command
    return self.read_response()
  File "/home/pyapt/LS/repositories/ThorlabsApt/thorlabs_device.py", line 229, in read_response
    length_to_read,keyword = self.thor_msg.read_header(raw_recv_msg)
TypeError: 'NoneType' object is not iterable

I think the bug is related to the reading the response of the controller. For which I have added ftdi.rules and changed the permissions and its group of the USB port of the controller as shown below.

$ ls -la /dev/ttyUSB0
crw-rw-rw- 1 root dialout 188, 0 Dec  3 08:09 /dev/ttyUSB0
$ groups
pyapt tty dialout sudo

Do you have any idea what would it be?

lwbe commented 4 years ago

Hello,

unfortunately I don't remember how I have treated this case. But since I didn't change the code I suspect it is a communication problem. So I have update the code to perform a flush of the serial bus but you need to add the configure() method before doing anything with the device. So please checkout the code from github and in you have to change your code from

   d1 = Thorlabs_device("70112214", "BSC20x", "NRT150E Enc Stage 150mm", 1)
   print(d1.get_info())
   print(d1.get_position())

to d1 = Thorlabs_device("70112214", "BSC20x", "NRT150E Enc Stage 150mm", 1)

for now you need to configure the device by hand

   d1.configure()
   print(d1.get_info())
   print(d1.get_position())

Let me know if this work otherwise I'll write so code to investigate the problem more in depth.

sincerely

L.

mxochicale commented 4 years ago

Thanks Lorenzo

I have updated my local repo with your nice updates and tried this

d1 = Thorlabs_device("70112214", "BSC20x", "NRT150E Enc Stage 150mm", 1)
d1.configure()
print(d1.get_info())
print(d1.get_position())

which create this bug

$ python test_BSC203_NRT150.py 
keyword MGMSG_HW_STOP_UPDATEMSGS params: 1, 0, 17, 1
msg sent:  (0x12 00 01 00 11 01) params : [18, 1, 0, 17, 1]
keyword MGMSG_HW_NO_FLASH_PROGRAMMING params: 0, 0, 17, 1
msg sent:  (0x18 00 00 00 11 01) params : [24, 0, 0, 17, 1]
keyword MGMSG_HW_STOP_UPDATEMSGS params: 1, 0, 17, 1
msg sent:  (0x12 00 01 00 11 01) params : [18, 1, 0, 17, 1]
keyword MGMSG_HW_REQ_INFO params: 0, 0, 17, 1
msg sent:  (0x05 00 00 00 11 01) params : [5, 0, 0, 17, 1]
Error: nothing to analyse, is there a communication problem!!
Traceback (most recent call last):
  File "test_BSC203_NRT150.py", line 12, in <module>
    d1.configure()
  File "/home/pyapt/LS/repositories/ThorlabsApt/thorlabs_device.py", line 178, in configure
    self.get_info()
  File "/home/pyapt/LS/repositories/ThorlabsApt/thorlabs_device.py", line 311, in wrapper
    return  self.send_command(*p)
  File "/home/pyapt/LS/repositories/ThorlabsApt/thorlabs_device.py", line 225, in send_command
    return self.read_response()
  File "/home/pyapt/LS/repositories/ThorlabsApt/thorlabs_device.py", line 232, in read_response
    length_to_read,keyword = self.thor_msg.read_header(raw_recv_msg)
TypeError: 'NoneType' object is not iterable

My guess your code is fine but there is something wrong with how the USB port in my Ubuntu18x64bit is configured as it did not received any answer after sending a command. Any ideas on how you configured the USB port on your machine with centos?

lwbe commented 4 years ago

Hello,

i will try to send you a piece of code tomorrow to check but I don't have access right now to the computer to check. Did you try as root? Don't forget to use the venv when you are root.

Does

lsusb -v | grep 70112214

return something.

Sincerely

L.

lwbe commented 4 years ago

Hello,

I could find a BSC203 and try to see if I could reproduce your problem but I couldn't. I discovered that the code doesn't work well with BSC203 and so you'll have to checkout the new code.

To test I'll propose you to do the configuration one step at a time so after

     d1 = Thorlabs_device("70112214", "BSC20x", "NRT150E Enc Stage 150mm", 1)

please type in a python interpreter (or best ipython since it should be installed by the requirements)

      d1.no_flash_programming()
      d1.stop_update_msg()
      d1.enable()
      d1.get_status_update()

Normally the 3 first commands are only write commands and it should work the last one might give you problem since it waits for a return. But if it works please do

       d1.get_info()

Note that since BSC20x is a multi channel that the first channel is connected (it is the 1 at the end of the d1 = Thorlabs_device("70112214", "BSC20x", "NRT150E Enc Stage 150mm", 1) command. And if you get the info I would be interested in the values of

       'firmware_version_interim_rev ': 3,
       'firmware_version_major_rev ': 2,
       'firmware_version_minor_rev ': 1,

sincerely

L.

mxochicale commented 4 years ago

Thanks for your comments for using the root account. To be honest I am not sure if this is a good hardware software practice but I will have a go later following your advice for the configuration of the venv. For the lsusb command, see below the output:

$ lsusb -v | grep 70112214
Couldn't open device, some information will be missing
Couldn't open device, some information will be missing
Couldn't open device, some information will be missing
  iSerial                 3 70112214

Is that what you expect to see?

mxochicale commented 4 years ago

Thanks L for your advice on using the python interprete. That said, the following output is generated:

$ python
Python 2.7.15+ (default, Jul  9 2019, 16:51:35) 
[GCC 7.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from thorlabs_device import Thorlabs_device
>>> from thorlabs_apt_comm import Thorlabs_apt_communication
>>> import serial
>>> import os,sys
>>> d1 = Thorlabs_device("70112214", "BSC20x", "NRT150E Enc Stage 150mm", 1)
keyword MGMSG_HW_STOP_UPDATEMSGS params: 1, 0, 17, 1
msg sent:  (0x12 00 01 00 11 01) params : [18, 1, 0, 17, 1]
>>> d1.no_flash_programming()
keyword MGMSG_HW_NO_FLASH_PROGRAMMING params: 0, 0, 17, 1
msg sent:  (0x18 00 00 00 11 01) params : [24, 0, 0, 17, 1]
'None'
>>> d1.stop_update_msg()
keyword MGMSG_HW_STOP_UPDATEMSGS params: 1, 0, 17, 1
msg sent:  (0x12 00 01 00 11 01) params : [18, 1, 0, 17, 1]
'None'
>>> d1.enable()
keyword MGMSG_MOD_SET_CHANENABLESTATE params: 1, 1, 33, 1
msg sent: ! (0x10 02 01 01 21 01) params : [528, 1, 1, 33, 1]
'None'
>>> d1.get_status_update()
keyword MGMSG_MOT_REQ_STATUSUPDATE params: 1, 0, 33, 1
msg sent: �! (0x80 04 01 00 21 01) params : [1152, 1, 0, 33, 1]
Error: nothing to analyse, is there a communication problem!!
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "thorlabs_device.py", line 316, in wrapper
    return  self.send_command(*p)
  File "thorlabs_device.py", line 225, in send_command
    return self.read_response()
  File "thorlabs_device.py", line 232, in read_response
    length_to_read,keyword = self.thor_msg.read_header(raw_recv_msg)
TypeError: 'NoneType' object is not iterable
>>> 

This makes me think that using root access will sort out this issue which I will test later.

Also thanks for pointed out the muli-channel version of the BSC203 controller which I hope to confirm the output once I can read the info.

lwbe commented 4 years ago

Hello,

i finally found a way to get the same TypeError: 'NoneType' and it seems that it happens when the device receive a wrong message. Did you switch off switch on the controller? If I restart the controller and type

    from thorlabs_device import Thorlabs_device
    d1 = Thorlabs_device("70112214", "BSC20x", "NRT150E Enc Stage 150mm", 1)
    d1.configure()

then

    d1.get_info() 

return some values and not a TypeError. At least after the d1.configure() the light of the channel should switch on. Let me know if this helps. In anycase I would look if all the hardware is well plugged and start the code.

Let me know before we try to dive into pure serial and binary variable.

sincerely

L.

mxochicale commented 4 years ago

Thanks L for your kind help. I have just tried your previous advice and this is the output:

$ python
Python 2.7.15+ (default, Jul  9 2019, 16:51:35) 
[GCC 7.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from thorlabs_device import Thorlabs_device
>>> d1 = Thorlabs_device("70112214", "BSC20x", "NRT150E Enc Stage 150mm", 1)
keyword MGMSG_HW_STOP_UPDATEMSGS params: 1, 0, 17, 1
msg sent:  (0x12 00 01 00 11 01) params : [18, 1, 0, 17, 1]
>>> d1.configure()
keyword MGMSG_HW_NO_FLASH_PROGRAMMING params: 0, 0, 17, 1
msg sent:  (0x18 00 00 00 11 01) params : [24, 0, 0, 17, 1]
keyword MGMSG_HW_STOP_UPDATEMSGS params: 1, 0, 17, 1
msg sent:  (0x12 00 01 00 11 01) params : [18, 1, 0, 17, 1]
keyword MGMSG_HW_REQ_INFO params: 0, 0, 17, 1
msg sent:  (0x05 00 00 00 11 01) params : [5, 0, 0, 17, 1]
Error: nothing to analyse, is there a communication problem!!
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "thorlabs_device.py", line 178, in configure
    self.get_info()
  File "thorlabs_device.py", line 316, in wrapper
    return  self.send_command(*p)
  File "thorlabs_device.py", line 225, in send_command
    return self.read_response()
  File "thorlabs_device.py", line 232, in read_response
    length_to_read,keyword = self.thor_msg.read_header(raw_recv_msg)
TypeError: 'NoneType' object is not iterable

What is remaining to test is the use of root access which I will put it in the next comment and then let's see what follows.

Regards Miguel

mxochicale commented 4 years ago

Testing ThorlabsApt with root permisions

I have tried ThorlabsApt with root permission following this commands:

cd $HOME/LS/repositories/
mkdir ThorlabsAptRoot/
git clone https://github.com/lwbe/ThorlabsApt
cd $HOME/LS/repositories/ThorlabsAptRoot/ThorlabsApt

sudo su
apt install python-pip
pip install virtualenv
virtualenv venv
source $HOME/LS/repositories/ThorlabsAptRoot/ThorlabsApt/venv/bin/activate
pip install -r doc/requirements.txt

Then running the following three commands in the python interpreter which output is still buggy:

(venv) root@labmachine:$HOME/ThorlabsAptRoot/ThorlabsApt# python
Python 2.7.15+ (default, Jul  9 2019, 16:51:35) 
[GCC 7.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from thorlabs_device import Thorlabs_device
>>> d1 = Thorlabs_device("70112214", "BSC20x", "NRT150E Enc Stage 150mm", 1)
keyword MGMSG_HW_STOP_UPDATEMSGS params: 1, 0, 17, 1
msg sent:  (0x12 00 01 00 11 01) params : [18, 1, 0, 17, 1]
>>> d1.configure()
keyword MGMSG_HW_NO_FLASH_PROGRAMMING params: 0, 0, 17, 1
msg sent:  (0x18 00 00 00 11 01) params : [24, 0, 0, 17, 1]
keyword MGMSG_HW_STOP_UPDATEMSGS params: 1, 0, 17, 1
msg sent:  (0x12 00 01 00 11 01) params : [18, 1, 0, 17, 1]
keyword MGMSG_HW_REQ_INFO params: 0, 0, 17, 1
msg sent:  (0x05 00 00 00 11 01) params : [5, 0, 0, 17, 1]
Error: nothing to analyse, is there a communication problem!!
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "thorlabs_device.py", line 178, in configure
    self.get_info()
  File "thorlabs_device.py", line 316, in wrapper
    return  self.send_command(*p)
  File "thorlabs_device.py", line 225, in send_command
    return self.read_response()
  File "thorlabs_device.py", line 232, in read_response
    length_to_read,keyword = self.thor_msg.read_header(raw_recv_msg)
TypeError: 'NoneType' object is not iterable

See below some outputs related to the USB port

# lsusb -v | grep 70112214
FIXME: alloc bigger buffer for device capability descriptors
  iSerial                 3 70112214
# ls -la /dev/ttyUSB0
crw-rw-rw- 1 root dialout 188, 0 Dec  6 07:56 /dev/ttyUSB0
# groups 
root

The above test means that it should be related to the firmware of the controller and maybe the commands to read and write are not the right ones. Any ideas?

lwbe commented 4 years ago

Hello,

it seems that the controller is not responding. I mean writing to it won't show any problems but it seems that this controller is not ready.

For now I would restart the controller by switching it on and off (and I also switch several time while the controller is unplugged from wall socket to discharge capacitors) and do the following sequence

    from thorlabs_device import Thorlabs_device
    d1 = Thorlabs_device("70112214", "BSC20x", "NRT150E Enc Stage 150mm", 1)
    d1.no_flash_programming()
    d1.stop_update_msg()
    d1.enable()

and then

    print(d1.get_info())
    print(d1.get_position())

If you receive the same error (if the first print(d1.get_info()) fails try to send it a second time I might have to find a correct way to empty the bus)). If it fails again I would try to use the thorlabs apt software or kinetic to check that the device is working. If it is working with apt or kinetics and not with my code could you send me the firmware version of your controller that I can try to find a way to solve this problem with thorlabs. Maybe I'm missing a mandatory step for older (or newer?) hardware.

Sorry for not being more helpful.

L.

mxochicale commented 4 years ago

Thanks L. your replies are indeed very helpful. I have some good news, following this

For now I would restart the controller by switching it on and off (and I also switch several time while the controller is unplugged from wall socket to discharge capacitors). Also code has been tested with only turning the controller on/off.

See below the terminal output for the previous commands

(venv) root@$MACHINE: $HOME/ThorlabsAptRoot/ThorlabsApt# python
Python 2.7.15+ (default, Jul  9 2019, 16:51:35) 
[GCC 7.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from thorlabs_device import Thorlabs_device
>>> d1 = Thorlabs_device("70112214", "BSC20x", "NRT150E Enc Stage 150mm", 1)
keyword MGMSG_HW_STOP_UPDATEMSGS params: 1, 0, 17, 1
msg sent:  (0x12 00 01 00 11 01) params : [18, 1, 0, 17, 1]
>>> d1.no_flash_programming()
keyword MGMSG_HW_NO_FLASH_PROGRAMMING params: 0, 0, 17, 1
msg sent:  (0x18 00 00 00 11 01) params : [24, 0, 0, 17, 1]
'None'
>>> d1.stop_update_msg()
keyword MGMSG_HW_STOP_UPDATEMSGS params: 1, 0, 17, 1
msg sent:  (0x12 00 01 00 11 01) params : [18, 1, 0, 17, 1]
'None'
>>> d1.enable()
keyword MGMSG_MOD_SET_CHANENABLESTATE params: 1, 1, 33, 1
msg sent: ! (0x10 02 01 01 21 01) params : [528, 1, 1, 33, 1]
'None'
>>> print(d1.get_info())
keyword MGMSG_HW_REQ_INFO params: 0, 0, 17, 1
msg sent:  (0x05 00 00 00 11 01) params : [5, 0, 0, 17, 1]
{u'nb_channels': 3, u'dest': 129, u'HW Version': 2, u'msg_id': 6, u'model_number': 'BSC203 \x00', u'firmware_version_interim_rev ': 3, u'Mod_state': 0, u'source': 17, u'internal_data': 'APT Stepper Motor Controller\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', u'firmware_version_unused ': 0, u'param2': 0, u'param1': 84, u'firmware_version_major_rev ': 2, u'serial_number': 70000000, u'type': 32, u'firmware_version_minor_rev ': 3}
>>> print(d1.get_position())
keyword MGMSG_MOT_REQ_POSCOUNTER params: 1, 0, 33, 1
msg sent: ! (0x11 04 01 00 21 01) params : [1041, 1, 0, 33, 1]
0.0
>>> 

Here the output for d1.get_info() in case that tell you anything.

print(d1.get_info()) keyword MGMSG_HW_REQ_INFO params: 0, 0, 17, 1 msg sent:  (0x05 00 00 00 11 01) params : [5, 0, 0, 17, 1] {u'nb_channels': 3, u'dest': 129, u'HW Version': 2, u'msg_id': 6, u'model_number': 'BSC203 \x00', u'firmware_version_interim_rev ': 3, u'Mod_state': 0, u'source': 17, u'internal_data': 'APT Stepper Motor Controller\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', u'firmware_version_unused ': 0, u'param2': 0, u'param1': 84, u'firmware_version_major_rev ': 2, u'serial_number': 70000000, u'type': 32, u'firmware_version_minor_rev ': 3}

Questions:

  1. The capacitors can be discharged when you switch the controller on and off, can you elaborate more on what is exactly happening in the communication?

  2. I have tried d1.home() but there is no movement of the stages and the output goes into a loop increasing the position

>>> d1.home()
msg sent: C! (0x43 04 01 00 21 01) params : [1091, 1, 0, 33, 1]
keyword MGMSG_MOT_REQ_STATUSBITS params: 1, 0, 33, 1
msg sent: )! (0x29 04 01 00 21 01) params : [1065, 1, 0, 33, 1]
('status bits :', {u'dest': 129, u'msg_id': 1066, u'source': 33, u'param2': 0, u'param1': 6, u'Chan_id': 1, u'Status Bits': 2148536864})
status bits (2148536864): {'jogging reverse': 0, 'CCW reverse soft limit switch active': 0, 'CW forward soft limit switch active': 0, 'homed': 0, 'homing': 1, 'CCW reverse hw limit switch active': 0, 'jogging forward': 0, 'moving reverse': 1, 'moving forward': 0, 'CW forward hw limit switch active': 0}
('------> ', 1066, {u'dest': 129, u'msg_id': 1066, u'source': 33, u'param2': 0, u'param1': 6, u'Chan_id': 1, u'Status Bits': 2148536864})
keyword MGMSG_MOT_REQ_POSCOUNTER params: 1, 0, 33, 1
msg sent: ! (0x11 04 01 00 21 01) params : [1041, 1, 0, 33, 1]
('pos counter ', {u'dest': 129, u'msg_id': 1042, u'source': 33, u'param2': 0, u'param1': 6, u'chan_id': 1, u'Position': -3703})
Position -0.009041 mm

Regards Miguel

lwbe commented 4 years ago

Hello,

good news that you could make it work. The output of the get_info indicates that your BSC203 as a firmware version 2.3.3 while mine is 2.3.1 but it should make no difference I guess. For your questions

1) In my naive approach the capacitors keep some current in the circuit and memories can still keep their content. Unplugging th wall plug an switch the device on will take the current and the memory would then lost their content. But as I said it is a rather naive approach. Or it might be black magic going on ;).

2) For the home part, you says that the position is increasing but you send me only one output and the position is negative and the output indicates that the stage is moving reverse. So the position should be decreasing.

Can you try to

I have added some debug info to the code and add a test to check if the movement should end so please pull the code and copy paste the begining of the output.

a typical output is

we send the command to get the status bit

  keyword MGMSG_MOT_REQ_STATUSBITS params: 1, 0, 33, 1 msg sent: )! (0x29 04 01 00 21 01) params : [1065, 1, 0, 33, 1]

this the return value the expected value of this should contain a msg_id of 1066but if the stage reaches the end it can return a msg_id value of 1092

  get_statusbit return value (expected msgid=1066):  {u'dest': 129, u'msg_id': 1066, u'source': 33, u'param2': 0, u'param1': 6, u'Chan_id': 1, u'Status Bits': 2147488272} 

some stage (or controller doesn't seem to send the information that the end has been reached and so I look for the value of 'moving reverse' and 'moving forward' if they are both 0 the stage doesn't move.

  status bits (2147488272): {'jogging reverse': 0, 'CCW reverse soft limit switch active': 0, 'CW forward soft limit switch active': 0, 'homed': 0, 'homing': 1, 'CCW reverse hw limit switch active': 0, 'jogging forward': 0, 'moving reverse': 0, 'moving forward': 1, 'CW forward hw limit switch active': 0}

in the code if I didn't reach the end of movement I ask for the position of the stage

  keyword MGMSG_MOT_REQ_POSCOUNTER params: 1, 0, 33, 1 msg sent: ! (0x11 04 01 00 21 01) params : [1041, 1, 0, 33, 1]

here is the output. This might contain the msg_id of 1092 since it we read the message from the stage

  get_poscounter return value (expected msgid=1042):  {u'dest': 129, u'msg_id': 1042, u'source': 33, u'param2': 0, u'param1': 6, u'chan_id': 1, u'Position': 24} 

  Position 0.000937 mm

So can you look for the output and see if you have an unexpected msg_id or if you have a move forward or reverse equal both to zero.

This doesn't explain why the stage doesn't move. I had the same probleme with a stage and in fact the parameters where so wrong that the stage was indeed moving but very slowly around 100 time slower so can you check it is not really moving.

Sincerely

L.

mxochicale commented 4 years ago

Hi L. I am afraid I will have no access to the linear stages until I come back to the lab on 13 of January 2020 I will then reply back to the above comments. In the meantime, I would like to reiterate my gratitude for your help which is indeed very valuable and I am sure the linear stages will be working soon.

lwbe commented 4 years ago

Hello,

OK I'll wait for your response when you'll come back and I would also thank you for using and testing my code. I would probably not have worked on it while the fact that it may be useful makes me want to improve it.

Sincerely

L.