Not able to communicate with usb daq device.

hi all, i am not able to communicate with my usb daq device. i am using the windows' COM port in my coding. please help me out. thx
ERROR MESSAGE
Error using serialport
Unable to connect to the serialport device at port 'COM4'. Verify that a device is connected to the port, the port is not in use, and all serialport input
arguments and parameter values are supported by the device.
See related documentation for troubleshooting steps.
Error in testcode2 (line 2)
serialPort = serialport("COM4", 115200); % Replace "COM1" with the appropriate port name
>>

Réponses (1)

Sarthak
Sarthak le 21 Avr 2023

0 votes

Hi Kulbir,
As per my understanding it is difficult to pinpoint the exact reason for the error you are facing however there can be multiple reasons
  • Make sure the specified COM port matches the port of your USB.
  • Ensure that the specified port is not already in use.
If you have made sure that you have the required drivers and inputs, you may need to refer to the documentation provided by the manufacturer of your DAQ device or raise a support request for the same.
Here is the link for your reference

8 commentaires

Kulbir
Kulbir le 24 Avr 2023
@Sarthak hi, i have tried everything, but could not be succeded yet. thanks.
What does windows Device Manager say is connected to COM4 ?
@Walter Roberson hi, am getting non binary o/p
device = serialport("COM4",9600)
write(device,1:5,"uint8");
first_5 = read(device,5,"uint8");
% first_5= readbinblock(device);
fprintf('Not sure why we are reading 5 bytes, but the values received were:\n');
disp(first_5);
h = animatedline('MaximumNumPoints', 10000);
start = tic;
while isvalid(h) && toc(start) < 30 %FOR TESTING
currentline = readline(device);
data = str2double(currentline);
if isnan(data)
fprintf('data nan, line as text was: "%s"\n', currentline);
continue;
end
now = toc(start);
if isvalid(h)
addpoints(h, now, data);
drawnow limitrate
end
end
clear device
% clear;clc;
Walter Roberson
Walter Roberson le 24 Avr 2023
Déplacé(e) : Walter Roberson le 24 Avr 2023
As discussed in https://www.mathworks.com/matlabcentral/answers/1943519-real-time-audio-data-plot-from-com-serial-port#comment_2704823 you need to find out what binary format your device is sending. Your device is not sending text. As I discussed in the above link you need to be using read(), but I do not know what binary format it is. You have never posted the exact kind of device, brand or model.
@Walter Roberson, thank you for the reply,
as i mentioned previousely it's self made device. it is a DAQ(digital to anlog converter circut). so to me i think i am getting analog signal plot in the commant window when i run the code.
device = serialport("COM4",9600)
write(device,1:5,"uint8");
first_5 = read(device,5,"uint8");
% first_5= readbinblock(device);
fprintf('Not sure why we are reading 5 bytes, but the values received were:\n');
disp(first_5);
h = animatedline('MaximumNumPoints', 10000);
start = tic;
while isvalid(h) && toc(start) < 30 %FOR TESTING
currentline = readline(device);
data = str2double(currentline);
if isnan(data)
fprintf('data nan, line as text was: "%s"\n', currentline);
continue;
end
now = toc(start);
if isvalid(h)
addpoints(h, now, data);
drawnow limitrate
end
end
clear device
% clear;clc;
Analog to Digital conversion circuits just drop the readings unless something else in the circuit is providing an iterface to allow the data to be read. As outside observers we have no idea what you used as an interface.
For example is this device an Arduino that is interfacing to an I2C device and has a sketch that is writing the received data to serial port?
Kulbir
Kulbir le 24 Avr 2023
it is not an Arduino device. yes DAQ(digital to analog convert is provided in the device). a button is also provided to plot the readings.
Have you created a circuit diagram for your device that you could post?

Connectez-vous pour commenter.

Question posée :

le 28 Mar 2023

Commenté :

le 24 Avr 2023

Community Treasure Hunt

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

Start Hunting!

Translated by