Setting up communication via USB device with instrument

16 visualizaciones (últimos 30 días)
SnooptheEngineer
SnooptheEngineer el 8 de Ag. de 2024
Editada: dpb el 9 de Ag. de 2024
I am trying to communicate with a device via usb. When I connect the usb cable, it doesnt fall under the COM port section in my device manager but under the Universial Serial Bus Devices. How do I go about openning the port with serial command?
  4 comentarios
dpb
dpb el 8 de Ag. de 2024
Editada: dpb el 9 de Ag. de 2024
At 38.4k, if you're not wasting cycles by pauses or the like, it shouldn't be terribly slow. How much data does the device typically transmit?
The serial communication across USB is undoubtedly faster, but whether it will make a really noticeable difference in the response of the instrument will depend upon whether the latency is mostly data transfer or whether it is the speed of the onboard processor in interpreting and acting upon the commands. Of course, only testing will tell you that, but don't be too surprised if the speedup isn't nearly what you expect (presuming you can get it working, of course). You might be able to judge somewhat by using the packaged application that apparently is shipped with the instrument to see if it seems markedly quicker or not.
From the instrument documentation I find the following...
...
7.4.3 Setting the USB Address
The USB Address can be set remotely with the “ADDRess” command.
7.5 USB Communication
The instrument is designed to communicate with standard USB interfaces. When the instrument is first connected to a PC(*), the user will be prompted by the computer to install software drivers. These drivers are included in the software CD that accompanies the power meter. Communication can be done through this interface by using the application contained in the CD or by developing software in the user’s preferred programming language. The software CD contains drivers and example programs in the following programming languages: LabVIEW, Visual Basic, and Visual C++. (emphasis added--dpb)
MATLAB is notably absent in the list so I'm pretty sure you're going to be writing code as a DLL if you're going to be calling it from MATLAB.
(*) My addition. Up at the very top there's also the following--
viii Preface
IMPORTANT NOTE
Before plugging the instrument into a PC via a USB communication port, please make sure that the USB Drivers are installed. Run Setup.exe from the Software CD that came with your product. The installation program will configure the PC with the 1931/2931 Series USB drivers.
Whether doing that first will make any difference or not, but...
dpb
dpb el 8 de Ag. de 2024
Editada: dpb el 9 de Ag. de 2024
"... more and more likely a newport problem ..."
I don't think it's a problem in the sense of there being something wrong, only that Newport doesn't support MATLAB directly; you'll have to write code in a supported language and package it as either a DLL or mex functions.
Looking on the Newport web site, I found a legacy MATLAB example; but it dates from 2006. Whether there are more recent libraries with your software distribution I've no idea, but here's their sample m-file...
function powermeter_USB
%This file represents a basic example of how to interface a Newport 1900
%or 2900 series power meters via a USB using the Matlab genric dll
%interface. It is assumed that you have loaded the appropriate
%drivers, plugged a USB cable into the power meter, and followed the
%new hardware found promt.
%Reed Farrar, Newport Corporation, 11 October 2006
warning off %optional
clc %optional
%Load the library and header file. Include the path estblished when
%you loaded the drivers from the Newport CD.
headerFile = ('C:\Program Files\Newport\Newport Power Meter Application - v 2.0.3\USB_Drivers\PM_USB.h');
loadlibrary('usbdll', headerFile)
%Verify that the library loaded. optional.
if libisloaded('usbdll') == 0
disp('library did not load')
end
%The following three functions can be used to view the dll functions
%and their respective signatures. Uncomment whichever is desired.
%libfunctionsview usbdll
%libfunctions usbdll
%libfunctions usbdll -full
%initialize the power meter
calllib('usbdll', 'newp_usb_init_system');
%Check to see which USB address has been set for your instrument. This
%can be done from the front panel by pressing the setup key, then the
%system key at the bottom of the display.
deviceAddress = int32(2);
for n=1:1:10 %acquire 10 power values
%send the command to the meter to acquire a power reading
%The last parameter sent by the 'newp_usb_send_ascii' function
%represents the length of the command character string; in this
%case: 9.
[K, L] = calllib('usbdll', 'newp_usb_send_ascii',...
deviceAddress, 'pm:power?', 9);
%read value from the meter. Note that the returned parameter
%'data'is a cell array.
d=0;
dataString = blanks(256); %define data string
[A, data{n}, D] = calllib('usbdll', 'newp_usb_get_ascii',...
deviceAddress, dataString, 256, d);
end
str2double(data)' %display the acquired values
%unload library
unloadlibrary usbdll
%varify that the library unloaded. optional
if libisloaded('usbdll') == 1
disp('Library did not unload')
end
%clear all variable
clear all
Unfortunately, your instrument is also now considered to be a "legacy" model, so what you have is what you're going to get; there will be no additional updates or new drivers.

Iniciar sesión para comentar.

Respuestas (2)

Garmit Pant
Garmit Pant el 8 de Ag. de 2024
Editada: Garmit Pant el 8 de Ag. de 2024
Hi OmartheEngineer
To connect your Newport device to MATLAB through a COM port, you can leverage the "Serial Explorer" tool. This tool can help you discover compatible devices connected to your computer. To launch the tool, enter the following command in MATLAB:
serialExplorer
If your device does not appear in the tool window, ensure that the correct drivers are installed for your device. You can explore the latest Newport device drivers at the following link: Newport Device Drivers.
For further understanding, please refer to the following MathWorks Documentation:
I hope you find the above explanation and suggestions useful!
  1 comentario
SnooptheEngineer
SnooptheEngineer el 8 de Ag. de 2024
Hi Garmit. I did check the drivers and still no success. I see the device listed under the bus devices and not bus controller....

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 8 de Ag. de 2024
USB devices respond to hardware queries by listing a series of "endpoints". Each "endpoint" corresponds to a different behaviour. One of the endpoints is a control interface. Another of the endpoints is potentially a serial interface. Other endpoints are potentially audio bulk transport or video bulk transport or "disk drive". There are standard codes for the most common types of endpoints.
If the USB device exposes a serial endpoint, then it will do so with a standard serial endpoint number, and that standard endpoint number will be detected by the host, leading the host to list the device in the COM port section. If the USB device does not expose a serial endpoint, then the device will not be listed in the COM port section.
We must conclude that your device does not expose a serial endpoint, and so cannot be communicated with using serial protocols.
At the moment, we do not know if the device exposes endpoints for any other common protocols such as bulk data transport. It is possible that the device exposes only a control endpoint and a private endpoint number, so potentially it needs a custom USB driver.
  1 comentario
SnooptheEngineer
SnooptheEngineer el 8 de Ag. de 2024
That all sounds good. So does that mean matlab can only communite with a device if its listed under the com port section. This does require a customer driver, which I have installed. However, my device is listed under the Universial Serial Bus Device and not com port. So that means it is serial in nature but no com port

Iniciar sesión para comentar.

Categorías

Más información sobre Troubleshooting in Instrument Control Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by