fargiolas/py-opc-ng

Unexpected Response Error

Opened this issue · 3 comments

I have a OPC-N3 connected to Raspberry PI via USB to SPI cabling. I have three of these setups and can successfully connect to the OPC and read data 50% of the time.

Upon reboot or at random sampling windows i receive the following error:

ERROR:opcng:Error while reading bytes from the device: Received unexpected response 0x3F for command: 0x3F 

Traceback (most recent call last): 

File "test_opc.py", line 10, in  

dev = opc.detect(spi) 

File "/usr/local/lib/python3.7/dist-packages/opcng/init.py", line 680, in detect 

info = o.info() 

File "/usr/local/lib/python3.7/dist-packages/opcng/init.py", line 381, in info 

buf = self._read_bytes(_OPC_CMD_READ_INFO_STRING, 60) 

File "/usr/local/lib/python3.7/dist-packages/opcng/init.py", line 302, in _read_bytes 

logger.error('Something failed while reading byte sequence, expected size: {}, received: {}'.format(sz, len(l))) 

NameError: name 'l' is not defined

Any suggestions as to what may be causing this issue?

Just a quick feedback, will look into this better tomorrow.
There is actually a bug there as len(l) should be len(result) but it's just a coincidence of the problem you're seeing.

If you connect the N3 to power and send no SPI command for about 65 seconds (chapter 9 of Alphasense Manual) it goes into Standalone mode and starts recording data on the on-board SD card. You can easily see it yourself as the fan powers on on its own if you connect the device and don't do anything with it for a while.

If I recall correctly when the device enters this mode it doesn't answer SPI commands as it's supposed to. The solution is to unplug the USB and plug it again and start acquiring data before it enters this automatic mode.

I have to run a few tests to see if is there a software way to reset it, stop this Standalone mode and enter the normal SPI operation mode.

I personally always used them in continous data acquisition mode so as soon as the Raspberry boots it starts a service that turns on the device and starts getting PM and histogram data and it doesn't have time to enter this mode.

Will investigate a bit more and let you know if I find anything useful.

Apparently when the device is working in this autonomous mode it still listens to SPI commands but it's probably busy most of the time so it doesn't meet the timing requirements from Alphasense SPI specs. Sometimes commands seems to work sometimes they fail.

It seems that if you manage to send an off() command it exits this mode and starts to respond properly again. But I'm just speculating, maybe it still keeps some of the state and who knows. I'd say the best is to power cycle it and use it through SPI before it enters this state.

Could be worth asking for more information to Alphasense or dig into the manuals to see if this standalone mode can be disabled.

Thank you for you quick feedback! I will implement your suggestions and let you know if it resolves the problems. I assumed it was getting stuck in a certain state but wasn't sure on the specifics.