Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Not finding "available ports" with "instrfind" or "instrfindall"

Subject: Not finding "available ports" with "instrfind" or "instrfindall"

From: Star Strider

Date: 14 Nov, 2009 04:17:03

Message: 1 of 9

I have a USB device (fingertip pulse-oximeter) that pretends to be a serial (COMx) port. It works fine and produces really neat data, but only after I manually find the port it's assigned to. I can't get "instrfind" or "instrfindall" (neither with arguments since I want it/them to find everything) to discover what COM ports are avaliable prior to opening and assigning one to my pulse-ox. When I attempt to open COM1 and assign it, I get:

-------------------------------------------------------------------------------------
??? Error using ==> serial.fopen at 72
Port: COM1 is not available. Available ports: COM3, COM4.
Use INSTRFIND to determine if other instrument objects are connected to the requested
device.

Error in ==> PulseOx_01 at 111
fopen(s1);
------------------------------------------------------------------------------------

Obviously MATLAB understands how to do this, and even returns the available ports in the error message. (For whatever reason, Windows 7 has assigned the pulse-ox to COM4. I discovered this when I opened Device Manager.)

For the time being, I "hard-coded" the pulse-ox to COM4. The problem is that if I want to share my routine or use it on another machine, I'll have to go back into Device Manager on that machine and figure out what serial port it's assigned to. If I could at least find the available COM ports, I could query them to find out which one was connected to the pulse-ox.

Either I'm doing something wrong or I've discovered a problem with "instrfind" and "instrfindall". I've looked through all the "Help" documentation and did a search on the TMW site but couldn't find the answer. To the best of my knowledge, I'm doing everything correctly, but obvously something is wrong somewhere.

Is there a way for me to convince MATLAB to discover — and write to a variable — that my pulse-ox is on COM4, rather than my having to do this manually? Am I doing something wrong with "instrfind" or "instrfindall", or am I missing something else? (This wasn't a problem under 32-bit Vista and 32-bit MATLAB, so I can't figure out what's wrong. With those I could assign my pulse-ox to any COMx port and it'd work.)

Thanks,

Frank

Subject: Not finding "available ports" with "instrfind" or "instrfindall"

From: HeavierThanAir

Date: 9 Dec, 2009 14:32:04

Message: 2 of 9

I am having the exact same problem. I have a USB device (custom-built circuit board that takes USB input) that pretends to be a serial port. Works great if I plug the USB cable into the same port each time and hardcode the port in the Matlab code, but this shouldn't be necessary. Any thoughts or commands that Star Strider and I should try?

HTA


"Star Strider" <skystriderDELETETHIS@ieee.net> wrote in message <hdlavv$35u$1@fred.mathworks.com>...
> I have a USB device (fingertip pulse-oximeter) that pretends to be a serial (COMx) port. It works fine and produces really neat data, but only after I manually find the port it's assigned to. I can't get "instrfind" or "instrfindall" (neither with arguments since I want it/them to find everything) to discover what COM ports are avaliable prior to opening and assigning one to my pulse-ox. When I attempt to open COM1 and assign it, I get:
>
> -------------------------------------------------------------------------------------
> ??? Error using ==> serial.fopen at 72
> Port: COM1 is not available. Available ports: COM3, COM4.
> Use INSTRFIND to determine if other instrument objects are connected to the requested
> device.
>
> Error in ==> PulseOx_01 at 111
> fopen(s1);
> ------------------------------------------------------------------------------------
>
> Obviously MATLAB understands how to do this, and even returns the available ports in the error message. (For whatever reason, Windows 7 has assigned the pulse-ox to COM4. I discovered this when I opened Device Manager.)
>
> For the time being, I "hard-coded" the pulse-ox to COM4. The problem is that if I want to share my routine or use it on another machine, I'll have to go back into Device Manager on that machine and figure out what serial port it's assigned to. If I could at least find the available COM ports, I could query them to find out which one was connected to the pulse-ox.
>
> Either I'm doing something wrong or I've discovered a problem with "instrfind" and "instrfindall". I've looked through all the "Help" documentation and did a search on the TMW site but couldn't find the answer. To the best of my knowledge, I'm doing everything correctly, but obvously something is wrong somewhere.
>
> Is there a way for me to convince MATLAB to discover — and write to a variable — that my pulse-ox is on COM4, rather than my having to do this manually? Am I doing something wrong with "instrfind" or "instrfindall", or am I missing something else? (This wasn't a problem under 32-bit Vista and 32-bit MATLAB, so I can't figure out what's wrong. With those I could assign my pulse-ox to any COMx port and it'd work.)
>
> Thanks,
>
> Frank

Subject: Not finding "available ports" with "instrfind" or "instrfindall"

From: Trent Jarvi

Date: 9 Dec, 2009 14:47:25

Message: 3 of 9

Hello HTA

Currently, you can add the serial port and find it in MATLAB. The problem
is that you only get a fresh list of available ports on the first scan.
Your observations are correct in that MATLAB assumes the serial port is
soldered onto your motherboard and wont go anyplace. We are considering
adding the ability to scan for new and moved serial ports as USB virtual
ports are fairly reliable and common now.

"HeavierThanAir " <kyle.adrian.hill@gmail.com> wrote in message
news:hfocd4$1ji$1@fred.mathworks.com...
>I am having the exact same problem. I have a USB device (custom-built
>circuit board that takes USB input) that pretends to be a serial port.
>Works great if I plug the USB cable into the same port each time and
>hardcode the port in the Matlab code, but this shouldn't be necessary. Any
>thoughts or commands that Star Strider and I should try?
>
> HTA
>
>
> "Star Strider" <skystriderDELETETHIS@ieee.net> wrote in message
> <hdlavv$35u$1@fred.mathworks.com>...
>> I have a USB device (fingertip pulse-oximeter) that pretends to be a
>> serial (COMx) port. It works fine and produces really neat data, but
>> only after I manually find the port it's assigned to. I can't get
>> "instrfind" or "instrfindall" (neither with arguments since I want
>> it/them to find everything) to discover what COM ports are avaliable
>> prior to opening and assigning one to my pulse-ox. When I attempt to
>> open COM1 and assign it, I get:
>>
>> -------------------------------------------------------------------------------------
>> ??? Error using ==> serial.fopen at 72
>> Port: COM1 is not available. Available ports: COM3, COM4.
>> Use INSTRFIND to determine if other instrument objects are connected to
>> the requested
>> device.
>>
>> Error in ==> PulseOx_01 at 111
>> fopen(s1);
>> ------------------------------------------------------------------------------------
>>
>> Obviously MATLAB understands how to do this, and even returns the
>> available ports in the error message. (For whatever reason, Windows 7
>> has assigned the pulse-ox to COM4. I discovered this when I opened
>> Device Manager.)
>>
>> For the time being, I "hard-coded" the pulse-ox to COM4. The problem is
>> that if I want to share my routine or use it on another machine, I'll
>> have to go back into Device Manager on that machine and figure out what
>> serial port it's assigned to. If I could at least find the available COM
>> ports, I could query them to find out which one was connected to the
>> pulse-ox.
>>
>> Either I'm doing something wrong or I've discovered a problem with
>> "instrfind" and "instrfindall". I've looked through all the "Help"
>> documentation and did a search on the TMW site but couldn't find the
>> answer. To the best of my knowledge, I'm doing everything correctly, but
>> obvously something is wrong somewhere.
>>
>> Is there a way for me to convince MATLAB to discover — and write to
>> a variable — that my pulse-ox is on COM4, rather than my having to
>> do this manually? Am I doing something wrong with "instrfind" or
>> "instrfindall", or am I missing something else? (This wasn't a problem
>> under 32-bit Vista and 32-bit MATLAB, so I can't figure out what's wrong.
>> With those I could assign my pulse-ox to any COMx port and it'd work.)
>>
>> Thanks,
>>
>> Frank

Subject: Not finding "available ports" with "instrfind" or "instrfindall"

From: Star Strider

Date: 10 Dec, 2009 00:52:18

Message: 4 of 9

I've posted my latest results at the end ...


"Trent Jarvi" <tjarvi@mathworks.com> wrote in message <hfod9t$kb$1@fred.mathworks.com>...
> Hello HTA
>
> Currently, you can add the serial port and find it in MATLAB. The problem
> is that you only get a fresh list of available ports on the first scan.
> Your observations are correct in that MATLAB assumes the serial port is
> soldered onto your motherboard and wont go anyplace. We are considering
> adding the ability to scan for new and moved serial ports as USB virtual
> ports are fairly reliable and common now.
>
> "HeavierThanAir " <kyle.adrian.hill@gmail.com> wrote in message
> news:hfocd4$1ji$1@fred.mathworks.com...
> >I am having the exact same problem. I have a USB device (custom-built
> >circuit board that takes USB input) that pretends to be a serial port.
> >Works great if I plug the USB cable into the same port each time and
> >hardcode the port in the Matlab code, but this shouldn't be necessary. Any
> >thoughts or commands that Star Strider and I should try?
> >
> > HTA
> >
> >
> > "Star Strider" <skystriderDELETETHIS@ieee.net> wrote in message
> > <hdlavv$35u$1@fred.mathworks.com>...
> >> I have a USB device (fingertip pulse-oximeter) that pretends to be a
> >> serial (COMx) port. It works fine and produces really neat data, but
> >> only after I manually find the port it's assigned to. I can't get
> >> "instrfind" or "instrfindall" (neither with arguments since I want
> >> it/them to find everything) to discover what COM ports are avaliable
> >> prior to opening and assigning one to my pulse-ox. When I attempt to
> >> open COM1 and assign it, I get:
> >>
> >> -------------------------------------------------------------------------------------
> >> ??? Error using ==> serial.fopen at 72
> >> Port: COM1 is not available. Available ports: COM3, COM4.
> >> Use INSTRFIND to determine if other instrument objects are connected to
> >> the requested
> >> device.
> >>
> >> Error in ==> PulseOx_01 at 111
> >> fopen(s1);
> >> ------------------------------------------------------------------------------------
> >>
> >> Obviously MATLAB understands how to do this, and even returns the
> >> available ports in the error message. (For whatever reason, Windows 7
> >> has assigned the pulse-ox to COM4. I discovered this when I opened
> >> Device Manager.)
> >>
> >> For the time being, I "hard-coded" the pulse-ox to COM4. The problem is
> >> that if I want to share my routine or use it on another machine, I'll
> >> have to go back into Device Manager on that machine and figure out what
> >> serial port it's assigned to. If I could at least find the available COM
> >> ports, I could query them to find out which one was connected to the
> >> pulse-ox.
> >>
> >> Either I'm doing something wrong or I've discovered a problem with
> >> "instrfind" and "instrfindall". I've looked through all the "Help"
> >> documentation and did a search on the TMW site but couldn't find the
> >> answer. To the best of my knowledge, I'm doing everything correctly, but
> >> obvously something is wrong somewhere.
> >>
> >> Is there a way for me to convince MATLAB to discover — and write to
> >> a variable — that my pulse-ox is on COM4, rather than my having to
> >> do this manually? Am I doing something wrong with "instrfind" or
> >> "instrfindall", or am I missing something else? (This wasn't a problem
> >> under 32-bit Vista and 32-bit MATLAB, so I can't figure out what's wrong.
> >> With those I could assign my pulse-ox to any COMx port and it'd work.)
> >>
> >> Thanks,
> >>
> >> Frank
>


UPDATE
I'm still working on this problem. My device uses a Silicon Laboratories CP2102, so I e-mailed the Silabs support engineers to see if there's a way to get the port information from the Registry Entry. (According to Silabs AN197, this was possible in Vista. Silabs has updated its drivers for Windows 7 but I can't find Windows 7 documentation.)

I can get information from the Registry with MATLAB's routines. (I'm not going into detail here in case my approach is wrong.) I need to know where to look in the Registry Entry to get the COM Port assignment. When I figure out how to do this, I'll write a short MATLAB function and post it to the file exchange. I'll post the soluton here in CS-SM as well.

I found that MATLAB does strange things to the COM Ports, and that polling them to see where my hardware is invariably generates errors. To make my life even more interesting, MATLAB seems to unpredictably close open COM Ports so that subsequent attempts to open them are unsuccessful. To add complexity to this problem, each call to 'instrfind' seems to do strange things to the port status as well. (There *has* to be some magic combination of 'fopen', 'fclose', 'delete' and 'clear' that makes this work!) I still haven't figured that out, so I opted for what I hope is a more reliable approach. That led me to searching the Registry.

I decided to kludge an interim solution and finally found that my device always seems to be allocated COM4, by peeking at the Registry using the Registry Editor and searching through the tree to:

'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB' ... etc.

then searching through each USB entry until I found the 'Friendly Name' that matches the description for it in Device Manager. (This has been quite an adventure.) So for the time being I'm hard-coding the COM4 assignment in my routine.

Meanwhile, if any of you figure out a solution to this before I do, please post it to *this* thread. I have it set up to e-mail me, so I won't miss it.

Star Strider

Subject: Not finding "available ports" with "instrfind" or "instrfindall"

From: Star Strider

Date: 19 Dec, 2009 21:10:20

Message: 5 of 9

"Star Strider" <skystriderDELETETHIS@ieee.net> wrote in message <hfpgo2$4a$1@fred.mathworks.com>...
> I've posted my latest results at the end ...
>
>
> "Trent Jarvi" <tjarvi@mathworks.com> wrote in message <hfod9t$kb$1@fred.mathworks.com>...
> > Hello HTA
> >
> > Currently, you can add the serial port and find it in MATLAB. The problem
> > is that you only get a fresh list of available ports on the first scan.
> > Your observations are correct in that MATLAB assumes the serial port is
> > soldered onto your motherboard and wont go anyplace. We are considering
> > adding the ability to scan for new and moved serial ports as USB virtual
> > ports are fairly reliable and common now.
> >
> > "HeavierThanAir " <kyle.adrian.hill@gmail.com> wrote in message
> > news:hfocd4$1ji$1@fred.mathworks.com...
> > >I am having the exact same problem. I have a USB device (custom-built
> > >circuit board that takes USB input) that pretends to be a serial port.
> > >Works great if I plug the USB cable into the same port each time and
> > >hardcode the port in the Matlab code, but this shouldn't be necessary. Any
> > >thoughts or commands that Star Strider and I should try?
> > >
> > > HTA
> > >
> > >
> > > "Star Strider" <skystriderDELETETHIS@ieee.net> wrote in message
> > > <hdlavv$35u$1@fred.mathworks.com>...
> > >> I have a USB device (fingertip pulse-oximeter) that pretends to be a
> > >> serial (COMx) port. It works fine and produces really neat data, but
> > >> only after I manually find the port it's assigned to. I can't get
> > >> "instrfind" or "instrfindall" (neither with arguments since I want
> > >> it/them to find everything) to discover what COM ports are avaliable
> > >> prior to opening and assigning one to my pulse-ox. When I attempt to
> > >> open COM1 and assign it, I get:
> > >>
> > >> -------------------------------------------------------------------------------------
> > >> ??? Error using ==> serial.fopen at 72
> > >> Port: COM1 is not available. Available ports: COM3, COM4.
> > >> Use INSTRFIND to determine if other instrument objects are connected to
> > >> the requested
> > >> device.
> > >>
> > >> Error in ==> PulseOx_01 at 111
> > >> fopen(s1);
> > >> ------------------------------------------------------------------------------------
> > >>
> > >> Obviously MATLAB understands how to do this, and even returns the
> > >> available ports in the error message. (For whatever reason, Windows 7
> > >> has assigned the pulse-ox to COM4. I discovered this when I opened
> > >> Device Manager.)
> > >>
> > >> For the time being, I "hard-coded" the pulse-ox to COM4. The problem is
> > >> that if I want to share my routine or use it on another machine, I'll
> > >> have to go back into Device Manager on that machine and figure out what
> > >> serial port it's assigned to. If I could at least find the available COM
> > >> ports, I could query them to find out which one was connected to the
> > >> pulse-ox.
> > >>
> > >> Either I'm doing something wrong or I've discovered a problem with
> > >> "instrfind" and "instrfindall". I've looked through all the "Help"
> > >> documentation and did a search on the TMW site but couldn't find the
> > >> answer. To the best of my knowledge, I'm doing everything correctly, but
> > >> obvously something is wrong somewhere.
> > >>
> > >> Is there a way for me to convince MATLAB to discover — and write to
> > >> a variable — that my pulse-ox is on COM4, rather than my having to
> > >> do this manually? Am I doing something wrong with "instrfind" or
> > >> "instrfindall", or am I missing something else? (This wasn't a problem
> > >> under 32-bit Vista and 32-bit MATLAB, so I can't figure out what's wrong.
> > >> With those I could assign my pulse-ox to any COMx port and it'd work.)
> > >>
> > >> Thanks,
> > >>
> > >> Frank
> >
>
>
> UPDATE
> I'm still working on this problem. My device uses a Silicon Laboratories CP2102, so I e-mailed the Silabs support engineers to see if there's a way to get the port information from the Registry Entry. (According to Silabs AN197, this was possible in Vista. Silabs has updated its drivers for Windows 7 but I can't find Windows 7 documentation.)
>
> I can get information from the Registry with MATLAB's routines. (I'm not going into detail here in case my approach is wrong.) I need to know where to look in the Registry Entry to get the COM Port assignment. When I figure out how to do this, I'll write a short MATLAB function and post it to the file exchange. I'll post the soluton here in CS-SM as well.
>
> I found that MATLAB does strange things to the COM Ports, and that polling them to see where my hardware is invariably generates errors. To make my life even more interesting, MATLAB seems to unpredictably close open COM Ports so that subsequent attempts to open them are unsuccessful. To add complexity to this problem, each call to 'instrfind' seems to do strange things to the port status as well. (There *has* to be some magic combination of 'fopen', 'fclose', 'delete' and 'clear' that makes this work!) I still haven't figured that out, so I opted for what I hope is a more reliable approach. That led me to searching the Registry.
>
> I decided to kludge an interim solution and finally found that my device always seems to be allocated COM4, by peeking at the Registry using the Registry Editor and searching through the tree to:
>
> 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB' ... etc.
>
> then searching through each USB entry until I found the 'Friendly Name' that matches the description for it in Device Manager. (This has been quite an adventure.) So for the time being I'm hard-coding the COM4 assignment in my routine.
>
> Meanwhile, if any of you figure out a solution to this before I do, please post it to *this* thread. I have it set up to e-mail me, so I won't miss it.
>
> Star Strider



I figured out a sort of solution for this! It's inelegant, kludgy, and could likely be improved, but it works! I listed it below. I'm not posting it to the File Excange because it's not sufficiently straightforward. I invite anyone with knowledge of the Windows 7 Registry and the MATLAB commands for it to improve it. It only has to run once in any routine that needs it.

What I would like (from TMW) is a routine that tells me what's attached to the serial ports associated with each USB port. That apparently requires writing a lot of C++ code, not something I want to do anytime soon.

If anyone has problems with it, I can provide limited help through this thread.

Good luck!

Star Strider

---------------------------------------------------------------------------------------------------------------------

function PortIn = getusbserialport()
% GETUSBSERIALPORT is my (Star Strider's) kludged routine to detect the
% serial port assigned to a particular USB device. It has extensive
% internal documentation, so if necessary it should be easy to adapt to
% variations in the registry entries for each device. It requries the
% device's VID and PID values (one-time manual lookup).
%
% The returned value "PortIn" is a string variable as 'COMx' and can be
% used as returned as an argument to "serial".

% "Star Strider"
% — MATLAB® 7.9.0
% — 19 December 2009

% This routine is specifically written to detect the Windows 7 driver
% registry entry for:
% Silicon Laboratories CP210x USB to UART Bridge
% Driver Version: 5.4.24.0
% Driver Date: 2009-07-07
% See: Silicon Laboratories AN197 for full documentation

% NOTE: To find the registry entry for your device, remove the ";" from the
% "dos" command (Line 34), then run "getusbserialport" from the command
% line. Search the output in the Command Window for your device. Registry
% entry formats are different for different devices, so it may be necessary
% to tweak "getusbserialport" if the registry entry for your device is
% sufficiently different from that used by Silicon Labs for the CP210x.

% GET RELEVANT REGISTRY CONTENTS —
% Get Registry contents with DOS call.
% (Do 'REG QUERY /?' in the Command Prompt or use the MATLAB "dos"
% function with that string for details of this DOS command.)
hklm_usb_str = 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\'; % Keep this as is — likely won't change
[~, regreplyresult] = dos(['REG QUERY ' hklm_usb_str ' /t REG_SZ /s /z']);

% DEFINE TARGET STRINGS —
% It will be necessary to look though the registry to find the VID_ &
% PID_ hex values if they're not already available. (Work with them as
% strings here.) Start by looking through "regreplyresult" for the
% necessary key combination. Read the "regreplyresult" data as a
% strings. MATLAB won't care.
hklm_usb_substr = 'VID_10C4&PID_EA60\0001\Device Parameters'; % Unique to particular driver
hklm_usb_full_str = [hklm_usb_str hklm_usb_substr];

% GET STRING LOCATIONS WITHIN "regreplyresult" —
len_hklm_usb_str = length(hklm_usb_full_str); % Define offset for subsequent read
[hklm_usb_full_idx] = strfind(regreplyresult, hklm_usb_full_str); % Find specific string with VID_ & PID_
[hklm_usb_idx] = strfind(regreplyresult, hklm_usb_str); % Find all occurrences of HKLM USB entries
next_key_idx = hklm_usb_idx(find(hklm_usb_idx > hklm_usb_full_idx, 1, 'first')); % Define end of search

% GET CELL ARRAY OF REGISTRY DATA OVER DEFINED RANGE —
[vrbl, ~, ~, value] = strread(regreplyresult(hklm_usb_full_idx+len_hklm_usb_str : next_key_idx-1), '%s %s %s %s', 'delimiter',' ');

% DETERMINE WHERE "PortName" IS —
portnameidx = strmatch('PortName', vrbl);
getport = value(portnameidx); % Returns "getport" as cell array
PortIn = char(getport); % Convert from cell to string

return
% ======================== END: getusbserialport.m ========================

---------------------------------------------------------------------------------------------------------------------

Subject: Not finding "available ports" with "instrfind" or "instrfindall"

From: Mark de Jong

Date: 1 May, 2010 23:25:24

Message: 6 of 9

Hi,

Isn't it possible for you to use this file:

http://www.mathworks.com/matlabcentral/fileexchange/25593-findinstrument-find-and-connect-to-instruments-using-the-model-or-manufacturer-name

I want Matlab to find an Arduino microcontroller automatically, but no luck so far. I am using Windows XP, but I'm not quite sure how to edit your m-file so I can use it for an Arduino with XP. Could you give me some advice?

Subject: Not finding "available ports" with "instrfind" or "instrfindall"

From: Sank

Date: 14 Dec, 2011 19:00:09

Message: 7 of 9

Here is what I do: query the registry for the com device map. It gives you a list of things, such as "\Device\Serial0" (traditional com port) or something else, maybe like, "\Device\USBSER000". For your particular device, you'll get something of a unique string. It's in my cell array "devices" below. Then I query the registry for the common name of the devices, and I get a cell array of comport names ("COM1" and "COM3" for instance), in my cell array "com" below.

Cheers,

devices = winqueryreg('name', 'HKEY_LOCAL_MACHINE', 'HARDWARE\DEVICEMAP\SERIALCOMM');
if (isempty(devices))
com{1} = 'NONE';
else
com = cell(1, length(devices));
for (ii = 1:length(devices))
com{ii} = winqueryreg('HKEY_LOCAL_MACHINE', 'HARDWARE\DEVICEMAP\SERIALCOMM', devices{ii});
end
end


"Star Strider" wrote in message <hdlavv$35u$1@fred.mathworks.com>...
> I have a USB device (fingertip pulse-oximeter) that pretends to be a serial (COMx) port. It works fine and produces really neat data, but only after I manually find the port it's assigned to. I can't get "instrfind" or "instrfindall" (neither with arguments since I want it/them to find everything) to discover what COM ports are avaliable prior to opening and assigning one to my pulse-ox. When I attempt to open COM1 and assign it, I get:

Subject: Not finding "available ports" with "instrfind" or "instrfindall"

From: majkelml

Date: 2 Jan, 2012 16:55:08

Message: 8 of 9

The command which solving this problem is:

fclose(instrfind);

Subject: Not finding "available ports" with "instrfind" or "instrfindall"

From: majkelml

Date: 2 Jan, 2012 16:59:09

Message: 9 of 9

"Star Strider" wrote in message <hdlavv$35u$1@fred.mathworks.com>...
> I have a USB device (fingertip pulse-oximeter) that pretends to be a serial (COMx) port. It works fine and produces really neat data, but only after I manually find the port it's assigned to. I can't get "instrfind" or "instrfindall" (neither with arguments since I want it/them to find everything) to discover what COM ports are avaliable prior to opening and assigning one to my pulse-ox. When I attempt to open COM1 and assign it, I get:
>
> -------------------------------------------------------------------------------------
> ??? Error using ==> serial.fopen at 72
> Port: COM1 is not available. Available ports: COM3, COM4.
> Use INSTRFIND to determine if other instrument objects are connected to the requested
> device.
>
> Error in ==> PulseOx_01 at 111
> fopen(s1);
> ------------------------------------------------------------------------------------
>
> Obviously MATLAB understands how to do this, and even returns the available ports in the error message. (For whatever reason, Windows 7 has assigned the pulse-ox to COM4. I discovered this when I opened Device Manager.)
>
> For the time being, I "hard-coded" the pulse-ox to COM4. The problem is that if I want to share my routine or use it on another machine, I'll have to go back into Device Manager on that machine and figure out what serial port it's assigned to. If I could at least find the available COM ports, I could query them to find out which one was connected to the pulse-ox.
>
> Either I'm doing something wrong or I've discovered a problem with "instrfind" and "instrfindall". I've looked through all the "Help" documentation and did a search on the TMW site but couldn't find the answer. To the best of my knowledge, I'm doing everything correctly, but obvously something is wrong somewhere.
>
> Is there a way for me to convince MATLAB to discover — and write to a variable — that my pulse-ox is on COM4, rather than my having to do this manually? Am I doing something wrong with "instrfind" or "instrfindall", or am I missing something else? (This wasn't a problem under 32-bit Vista and 32-bit MATLAB, so I can't figure out what's wrong. With those I could assign my pulse-ox to any COMx port and it'd work.)
>
> Thanks,
>
> Frank
Hi,

Command which is solving this problem:

fclose(instrfind);

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us