Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.pascal.delphi.misc > #572 > unrolled thread
| Started by | "P E Schoen" <paul@peschoen.com> |
|---|---|
| First post | 2013-12-29 08:03 -0500 |
| Last post | 2013-12-29 13:24 -0500 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.pascal.delphi.misc
Detecting Bluetooth COM port(s) in Delphi 4 "P E Schoen" <paul@peschoen.com> - 2013-12-29 08:03 -0500
Re: Detecting Bluetooth COM port(s) in Delphi 4 Hans-Peter Diettrich <DrDiettrich1@aol.com> - 2013-12-29 16:45 +0100
Re: Detecting Bluetooth COM port(s) in Delphi 4 "P E Schoen" <paul@peschoen.com> - 2013-12-29 13:24 -0500
| From | "P E Schoen" <paul@peschoen.com> |
|---|---|
| Date | 2013-12-29 08:03 -0500 |
| Subject | Detecting Bluetooth COM port(s) in Delphi 4 |
| Message-ID | <l9p6jb$k53$1@dont-email.me> |
I haven't been around much lately as my efforts have been elsewhere, but
recently one of my customers had problems with the USB connection from his
computer to my Ortmaster device, where he has a 13 kV AC supply operating a
closing coil on a recloser, and it causes communication to stop, requiring a
reset of the device and removal/reinsertion of the USB connector. I tried a
USB isolator but no joy.
So, I thought maybe a direct serial connection would be more robust, and
since he is using a desktop computer it should be possible, whereas for
laptops the serial port is a rarity except in the Panasonic "Toughbooks". I
bought one of the cheap ($8 or so) Bluetooth modules on eBay and I used it
at its default 9600 baud rate to collect some data, and it seemed to work
very well, even as far as 30 feet away through two doors, and with the
device inside a metal enclosure.
For my Ortmaster, I need to use 57.6 kB, and I was able to set the baud rate
by using a USB-Serial emulator in the form of a Microchip PICdem FSUSB
board.
I was able to hard code the port number (COM14) into the software and it
worked OK, but I needed to have it check for the proper port number, as it
does now for the USB serial ports using the registry. But the Bluetooth
enumeration is a bit different, and the USB Bluetooth adapter shows up as
COM13 and COM14. However, only COM14 can be opened and used for
communication with the remote device. I found a way to do this, and although
it may not be elegant, it seems to work just fine. It's been a long time
since I programmed in Delphi so I'm a bit rusty, and there may be better
ways to do this. But here it is, and hopefully someone may find it useful. I
still don't know if this will work with my customer's setup, and he is a
utility in Maine and very busy now dealing with the widespread power outages
and cold weather problems.
Paul
===================================================================================
function GetBlutoothComPort: String;
var S, S1: String;
Item: Integer;
Reg: TRegistry;
KeyList1, KeyList2: TStringList;
begin
Reg := TRegistry.Create;
if Reg = nil then begin
fmDebug.AddDebugItem( 'Error creating Reg ' );
exit; end;
KeyList1 := TStringList.Create;
if KeyList1 = nil then begin
fmDebug.AddDebugItem( 'Error creating KeyList1 ' );
exit; end;
KeyList2 := TStringList.Create;
if KeyList2 = nil then begin
fmDebug.AddDebugItem( 'Error creating KeyList2 ' );
exit; end;
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
S := '\SYSTEM\CurrentControlSet\Enum\BTHENUM\';
fmDebug.AddDebugItem( 'Key: ' + S );
try
Reg.OpenKeyReadOnly(S);
Reg.GetKeyNames(KeyList1);
For Item := 0 to KeyList1.Count-1 do begin
S1 := KeyList1.Strings[Item];
Reg.OpenKeyReadOnly(S + S1);
Reg.GetKeyNames(KeyList2);
S1 := S + KeyList1.Strings[Item] + '\' + KeyList2.Strings[0] +
'\Device Parameters';
fmDebug.AddDebugItem( 'Key: ' + S1 );
Reg.OpenKeyReadOnly(S1);
If Reg.ValueExists('RxFIFO') then begin
S1 := Reg.ReadString('PortName');
result := S1;
fmDebug.AddDebugItem( 'Working Bluetooth Port determined: ' +
S1 );
break; end;
fmDebug.AddDebugItem( 'Bluetooth Port detected: ' +
Reg.ReadString('PortName') );
end;
except
fmDebug.AddDebugItem( 'Error Bluetooth' );
end;
finally
Reg.Free;
KeyList1.Free;
KeyList2.Free;
end;
end;
[toc] | [next] | [standalone]
| From | Hans-Peter Diettrich <DrDiettrich1@aol.com> |
|---|---|
| Date | 2013-12-29 16:45 +0100 |
| Message-ID | <biauepFo108U1@mid.individual.net> |
| In reply to | #572 |
P E Schoen schrieb: > I haven't been around much lately as my efforts have been elsewhere, but > recently one of my customers had problems with the USB connection from > his computer to my Ortmaster device, where he has a 13 kV AC supply > operating a closing coil on a recloser, and it causes communication to > stop, requiring a reset of the device and removal/reinsertion of the USB > connector. I tried a USB isolator but no joy. > > So, I thought maybe a direct serial connection would be more robust, and > since he is using a desktop computer it should be possible, whereas for > laptops the serial port is a rarity except in the Panasonic > "Toughbooks". I bought one of the cheap ($8 or so) Bluetooth modules on > eBay and I used it at its default 9600 baud rate to collect some data, > and it seemed to work very well, even as far as 30 feet away through two > doors, and with the device inside a metal enclosure. In the early 80s we used an 16 channgel RS-232 multiplexer in a very noisy environment, of thyristor-switched supplies in the MW range. Several km of lines installed, no transmission problems ever :-) I cannot help with your software problems, though :-( Happy New Year DoDi
[toc] | [prev] | [next] | [standalone]
| From | "P E Schoen" <paul@peschoen.com> |
|---|---|
| Date | 2013-12-29 13:24 -0500 |
| Message-ID | <l9ppcd$sdo$1@dont-email.me> |
| In reply to | #573 |
"Hans-Peter Diettrich" wrote in message news:biauepFo108U1@mid.individual.net... > P E Schoen schrieb: >> I haven't been around much lately as my efforts have been elsewhere, but >> recently one of my customers had problems with the USB connection from >> his computer to my Ortmaster device, where he has a 13 kV AC supply >> operating a closing coil on a recloser, and it causes communication to >> stop, requiring a reset of the device and removal/reinsertion of the USB >> connector. I tried a USB isolator but no joy. > >> So, I thought maybe a direct serial connection would be more robust, and >> since he is using a desktop computer it should be possible, whereas for >> laptops the serial port is a rarity except in the Panasonic "Toughbooks". >> I bought one of the cheap ($8 or so) Bluetooth modules on eBay and I used >> it at its default 9600 baud rate to collect some data, and it seemed to >> work very well, even as far as 30 feet away through two doors, and with >> the device inside a metal enclosure. > In the early 80s we used an 16 channgel RS-232 multiplexer in a very noisy > environment, of thyristor-switched supplies in the MW range. Several km of > lines installed, no transmission problems ever :-) > I cannot help with your software problems, though :-( I posted this on a MS forum and received a response: http://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/ad5fe4a6-9be8-4780-a8e7-7742533a2b4d/determining-bluetooth-com-port-assignments-in-windows-7?forum=wdk "you don't need to parse the ENUM key (the ENUM key is in fact private and should not be parsed). Rather you can use setupapi to enumerate the com port device interface and restrict the enumeration to the BTHENUM enumerator. for each instance, setupapi can give you the HKEY that represents Device Parameters (without knowing the full parent path) key and you can query these values from there" I am not familiar with the setupapi, but I found some information. I assume I might be able to access it from Delphi? http://msdn.microsoft.com/en-us/library/windows/hardware/ff550855(v=vs.85).aspx Thanks for the reply. And Happy "Gnu" Year to you as well! Paul www.ortmaster.com
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.pascal.delphi.misc
csiph-web