I'm having issues communicating with the Anritsu MG69377B microwave generators.
I have no problem going into a remote mode and identifying the instrument, but any other command which returns a value is timed out and the instrument does seem to respond to any write command. I'm using PyVISA to communicate to the instrument.
>>>import visa
>>> x = visa.connect('GPIB::5') #Address the instrument
>>> x.ask('*IDN?') # Works Fine
>>>'ANRITSU,69377B,010918,2.35'
>>>
>>> x.ask('*STB?')
Traceback (most recent call last):
File "<pyshell#37>", line 1, in <module>
x.ask('*STB?')
File "C:\Python27\lib\site-packages\pyvisa\visa.py", line 502, in ask
return self.read()
File "C:\Python27\lib\site-packages\pyvisa\visa.py", line 433, in read
return self._strip_term_chars(self.read_raw())
File "C:\Python27\lib\site-packages\pyvisa\visa.py", line 407, in read_raw
chunk = vpp43.read(self.vi, self.chunk_size)
File "C:\Python27\lib\site-packages\pyvisa\vpp43.py", line 840, in read
visa_library().viRead(vi, buffer, count, byref(return_count))
File "C:\Python27\lib\site-packages\pyvisa\vpp43.py", line 398, in check_status
raise visa_exceptions.VisaIOError, status
VisaIOError: VI_ERROR_TMO: Timeout expired before operation completed.
*STB? is a standard IEEE command and should work across any instrument which follows the standard (which is basically all). I've looked in the manual and I can't seem to find anything wrong with syntax for other code as well. The instrument just does not seem to work when connected to remotely with PyVISA. (Unsure if this is a PyVISA problem or an issue with my instrument).
The 693xxB supports two languages, referred to as Native and SCPI. In that instrument the SCPI language was an option (option 19). In a 693xxB with option 19 the language is an instrument setting.
Native mode only supports the common command *IDN?.
SCPI mode supports more common commands, like *STB? for example.
Your syntax and VISA connection seem fine. It's on the instrument setting/support side.
Related
This is my first post here. I'm building a Python window application with PyQt5 that implements interactions with the OpenAI completions endpoint. So far, any code that I've written myself has performed fine, and I was reaching the point where I wanted to start implementing long-term memory for conversational interactions. I started by just running my own chain of prompts for categorizing and writing topical subjects and summaries to text files, but I decided it best to try exploring open source options to see how the programming community is managing things. This led me to LangChain, which seems to have some popular support behind it and already implements many features that I intend.
However, I have not had even the tiniest bit of success with it yet. Even the most simple examples don't perform, regardless of what context I'm implementing it in (within a class, outside a class, in an asynchronous loop, to the console, to my text browsers within the main window, whatever) I always get the same error message.
The simplest possible example:
import os
from langchain.llms import OpenAI
from local import constants #For API key
os.environ["OPENAI_API_KEY"] = constants.OPENAI_API_KEY
davinci = OpenAI(model_name= 'text-davinci-003', verbose=True, temperature=0.6)
text = "Write me a story about a guy who is frustrated with Python."
print("Prompt: " + text)
print(davinci(text))
It capably instantiates the wrapper and prints the prompt to the console, but at any point a command is sent through the wrapper's functions to receive generated text, it encounters this AttributeError.
Here is the traceback:
Traceback (most recent call last):
File "D:\Dropbox\Pycharm Projects\workspace\main.py", line 16, in <module>
print(davinci(text))
File "D:\Dropbox\Pycharm Projects\workspace\venv\lib\site-packages\langchain\llms\base.py", line 255, in __call__
return self.generate([prompt], stop=stop).generations[0][0].text
File "D:\Dropbox\Pycharm Projects\workspace\venv\lib\site-packages\langchain\llms\base.py", line 128, in generate
raise e
File "D:\Dropbox\Pycharm Projects\workspace\venv\lib\site-packages\langchain\llms\base.py", line 125, in generate
output = self._generate(prompts, stop=stop)
File "D:\Dropbox\Pycharm Projects\workspace\venv\lib\site-packages\langchain\llms\openai.py", line 259, in _generate
response = self.completion_with_retry(prompt=_prompts, **params)
File "D:\Dropbox\Pycharm Projects\workspace\venv\lib\site-packages\langchain\llms\openai.py", line 200, in completion_with_retry
retry_decorator = self._create_retry_decorator()
File "D:\Dropbox\Pycharm Projects\workspace\venv\lib\site-packages\langchain\llms\openai.py", line 189, in _create_retry_decorator
retry_if_exception_type(openai.error.Timeout)
AttributeError: module 'openai.error' has no attribute 'Timeout'
I don't expect that there is a fault in the LangChain library, because it seems like nobody else has experienced this problem. I imagine I may have some dependency issue? Or I do notice that others using the LangChain library are doing so in a notebook development environment, and my lack of familiarity in that regard is making me overlook some fundamental expectation of the library's use?
Any advice is welcome! Thanks!
What I tried: I initially just replaced my own function for managing calls to the completion endpoint with one that issued the calls through LangChain's llm wrapper. I expected it to work as easily as my own code had, but I received that error. I then stripped everything apart layer by layer attempting to instantiate the wrapper at every scope of the program, then I attempted to make the calls in an asynchronous function through a loop that waited to completion, and no matter what, I always get that same error message.
I think it might be something about your current installed versions of Python, OpenAI, and/or LangChain. Maybe try using a newer version of Python and OpenAI. I'm new to Python and these things but hopefully I could help.
I am trying to open a device file in windows using python. I heard I needed to use win32 API. So I am using that, to open my file I need to perform the following this stackoverflow question : Opening a handle to a device in Python on Windows
import win32file as w32
self.receiver_handle = w32.CreateFile("\\\\.\\xillybus_read_32", # file to open
w32.GENERIC_READ, # desired access
w32.FILE_ATTRIBUTE_READONLY, # shared mode
None, # security attribute
w32.OPEN_EXISTING, # creation distribution
w32.FILE_ATTRIBUTE_READONLY, #flags and attributes
None) # no template file
This results in the handle always returning 0.
Here is the API reference: http://winapi.freetechsecrets.com/win32/WIN32CreateFile.htm
The driver came with a barebones C program to test it and it works flawlessly, so it can't be the driver itself that is not properly working.
What am I doing wrong?
The API should not return zero. It should return a PyHANDLE object. I don't have your device, but opening an existing file works. The 3rd parameter should be w32.FILE_SHARE_READ (or similar share mode value), however:
>>> import win32file as w32
>>> w32.CreateFile('blah.txt',w32.GENERIC_READ,w32.FILE_SHARE_READ,None,w32.OPEN_EXISTING,w32.FILE_ATTRIBUTE_READONLY,None)
<PyHANDLE:280>
If the file does not exist (or any other error), Python should raise an exception based on the GetLastError() code returned by the Win32 API called:
>>> w32.CreateFile('blah.txt',w32.GENERIC_READ,w32.FILE_SHARE_READ,None,w32.OPEN_EXISTING,w32.FILE_ATTRIBUTE_READONLY,None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
pywintypes.error: (2, 'CreateFile', 'The system cannot find the file specified.')
If this doesn't help, edit your question to show the exact code you are running and the exact results of running the code.
I installed the MATLAB Engine according to this solution and it also start, but by executing it, the following error occurs:
Traceback (most recent call last):
File "<ipython-input-1-7f0848dd34ed>", line 1, in <module>
runfile('/media/geodasie/dat/Dennis/Python/PythonProgram/CryoSat2_main_Test.py', wdir='/media/geodasie/dat/Dennis/Python/PythonProgram')
File "/home/geodasie/anaconda3/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", line 705, in runfile
execfile(filename, namespace)
File "/home/geodasie/anaconda3/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "/media/geodasie/dat/Dennis/Python/PythonProgram/CryoSat2_main_Test.py", line 288, in <module>
eng = matlab.engine.start_matlab() # start Matlab
File "/home/geodasie/anaconda3/lib/python3.6/site-packages/matlab/engine/__init__.py", line 115, in start_matlab
eng = future.result()
File "/home/geodasie/anaconda3/lib/python3.6/site-packages/matlab/engine/futureresult.py", line 67, in result
return self.__future.result(timeout)
File "/home/geodasie/anaconda3/lib/python3.6/site-packages/matlab/engine/matlabfuture.py", line 87, in result
handle = pythonengine.getMATLAB(self._future)
EngineError: Transport stopped.
The code sequence, in which the error occurs is this one:
Path_year = fileName[19:23] + '/'
Path_month = fileName[23:25] + '/'
# read DBL file with the help of the Matlab function provided by ESA
eng = matlab.engine.start_matlab() # start Matlab
DATA = eng.main_read(path_saveFilefromFTP + Path_year + Path_month + fileName) # run matlab script
eng.quit() # end Matlab
This code was already running on another pc, but sadly on this one the error occurs.
I installed the MATLAB Engine several times but the result is the same. According to the futureresult.py function which is called, the timeout is the number of seconds it waits before returning a result. But per default the function waits, until a result is available. Because there the error occurs it seems, that the function can't provide a result.
The future result is explained as followed:
An instance of FutureResult is returned from each asynchronous invocation of a
function call: start_matlab, connect_matlab, or MatlabEngine.. The
future result serves as a placeholder of the actual result, so the future
result can be returned immediately. The actual result is placed into the
placeholder when the function finishes its evaluation.
But the program already stops by calling the engine, the MATLAB Engine, so there should be a problem in the connection between MATLAB and Python.
I use Python 3.6.5 with Anaconda 5.2 in Ubuntu 16.04 LTS and have MATLAB 2018a installed.
Update: Now I tested it at another pc and the same error occurs. It seems that it always happen after I had to activate MATLAB at this pc. Therefore I changed the title.
Does someone has an idea how to solve this?
Thanks in advance!
After many tests the only solution was to delete MATLAB and then install it again. Maybe there are better solutions but because MATLAB needed the activation beside it was already activated, I guess there was a problem with the MATLAB license and thus MATLAB didn't respond to the MATLAB Engine.
I read in the howto documentation to install Trigger, but when I test in python environment, I get the error below:
>>> from trigger.netdevices import NetDevices
>>> nd = NetDevices()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/trigger/netdevices/__init__.py", line 913, in __init__
with_acls=with_acls)
File "/usr/local/lib/python2.7/dist-packages/trigger/netdevices/__init__.py", line 767, in __init__
production_only=production_only, with_acls=with_acls)
File "/usr/local/lib/python2.7/dist-packages/trigger/netdevices/__init__.py", line 83, in _populate
# device_data = _munge_source_data(data_source=data_source)
File "/usr/local/lib/python2.7/dist-packages/trigger/netdevices/__init__.py", line 73, in _munge_source_data
# return loader.load_metadata(path, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/trigger/netdevices/loader.py", line 163, in load_metadata
raise RuntimeError('No data loaders succeeded. Tried: %r' % tried)
RuntimeError: No data loaders succeeded. Tried: [<trigger.netdevices.loaders.filesystem.XMLLoader object at 0x7f550a1ed350>, <trigger.netdevices.loaders.filesystem.JSONLoader object at 0x7f550a1ed210>, <trigger.netdevices.loaders.filesystem.SQLiteLoader object at 0x7f550a1ed250>, <trigger.netdevices.loaders.filesystem.CSVLoader object at 0x7f550a1ed290>, <trigger.netdevices.loaders.filesystem.RancidLoader object at 0x7f550a1ed550>]
Does anyone have some idea how to fix it?
The NetDevices constructor is apparently trying to find a "metadata source" that isn't there.
Firstly, you need to define the metadata. Second, your code should handle the exception where none is found.
I'm the lead developer of Trigger. Check out the the doc Working with NetDevices. It is probably what you were missing. We've done some work recently to improve the quality of the setup/install docs, and I hope that this is more clear now!
If you want to get started super quickly, you can feed Trigger a CSV-formatted NetDevices file, like so:
test1-abc.net.example.com,juniper
test2-abc.net.example.com,cisco
Just put that in a file, e.g. /tmp/netdevices.csv and then set the NETDEVICES_SOURCE environment variable:
export NETDEVICES_SOURCE=/tmp/netdevices.csv
And then fire up python and continue on with your examples and you should be good to go!
I found that the default of /etc/trigger/netdevices.xml wasn't listed in the setup instructions. It did indicate to copy from the trigger source folder:
cp conf/netdevices.json /etc/trigger/netdevices.json
But, I didn't see how to specify this instead of the default NETDEVICES_SOURCE on the installation page. But, as soon as I had a file that NETDEVICES_SOURCE pointed to in my /etc/trigger folder, it worked.
I recommend this to get the verifying functionality examples to work right away with minimal fuss:
cp conf/netdevices.xml /etc/trigger/netdevices.xml
Using Ubuntu 14.04 with Python 2.7.3
Basically, I want to read the CPU temperature with Python. Please explain in layman's terms as I have never done this on Windows before nor have I had to work with wmi.
This is what I have at the moment:
import wmi
w = wmi.WMI(namespace="root\wmi")
temperature_info = w.MSAcpi_ThermalZoneTemperature()[0]
print temperature_info.CurrentTemperature
(I got this code from this thread: Accessing CPU temperature in python)
However, on running the script, I get this error:
Traceback (most recent call last):
File "C:\Users\Ryan\Desktop\SerialSystemMonitor", line 4, in <module>
temperature_info = w.MSAcpi_ThermalZoneTemperature()[0]
File "C:\Python27\lib\site-packages\wmi.py", line 819, in query
handle_com_error ()
File "C:\Python27\lib\site-packages\wmi.py", line 241, in handle_com_error
raise klass (com_error=err)
x_wmi: <x_wmi: Unexpected COM Error (-2147217396, 'OLE error 0x8004100c', None, None)>
What can I do to get this to work?
According to the MSDN page on WMI Error Constants, the error you have received is:
WBEM_E_NOT_SUPPORTED
2147749900 (0x8004100C)
Feature or operation is not supported.
Presumably, then, your CPU does not provide temperature information through WMI. If your CPU doesn't expose this information, you're probably out of luck, at least as far as a straightforward solution in Python goes.
I assume you've tried the other option given in the answer you linked, using Win32_TemperatureProbe(); if you haven't, try it.
Just execute as Admin. It's work for me.