Магда Ю.С. Компьютер в Домашней Лаборатории (2008)

198
КОМПЬЮТЕР В ДОМАШНЕЙ ЛАБОРАТОРИИ Москва, 2008 Магда Ю. С.

Upload: belyi2014

Post on 16-Oct-2015

247 views

Category:

Documents


8 download

TRANSCRIPT

  • , 2008

    . .

  • 621.396.6 32.872

    M12

    M12 . . . .: , 2008. 200 .: .

    ISBN 9785940744207

    , , % Windows, . % % , %, . USB Bluetooth, . % , . % % , , % . .

    , .

    621.396.6 32.872

    . .

    , , . % , . % , .

    . ., 2008ISBN 978%5%94074%420%7 , , , 2008

  • 3 ......................................................................................................... 5

    ............................................................................................ 5

    1. .......................................... 7

    2. * ....................................................................11

    3. ..........................21

    3.1. ................................................................25

    3.2. .........................................................................27

    3.3. .................................................34

    3.4. .................................................57

    3.5. .............................................................................61

    4. ....................................................................69

    4.1. RS232 ................................................................................72

    4.2. ................................75

    5. .......................................................93

    5.1. .......................................................94

    5.2. .....................................96

    5.3. ........ 105

    6. USB Bluetooth ....................................................... 117

    6.1. USB Windows ............................................. 123

  • 6.2. USB.............................................. 126

    6.3. Bluetooth ........................... 136

    6.4. Bluetooth ...................................................... 142

    C Bluetooth .............................................................. 143

    Bluetooth .......................................................................... 144

    Bluetooth Java ................................................................................................... 145

    .................................................................... 147

    .............................................................................. 147

    ................................................................................. 147

    ..................................................................... 148

    ...................................................... 149

    7. Windows ..................................................................................... 151

    7.1. ................................................................ 154

    7.2. Windows ............................................. 157

    ....................................... 158

    7.3. ........................... 160

    7.4. ................................................................... 172

    7.5. ....................... 185

    ................................................................................................ 198

  • 5

    , , , . , , . , , , . , , .

    , Windows , .

    , , , USB Bluetooth. .

    .

    .

    , , , . , .

    6 ; :

    1 . ;

    2 . .

  • , ;

    3 . . Windows;

    4 . , . ;

    5 . . DirectSound DirectX;

    6 USB Bluetooth. , USB Bluetooth, .

    . .

  • , : , , , , . , , , , , , . , , .

    , , , , . , , , . , . , :

    ; ; ; USB Bluetooth.

    , , , , , . , , . , USB, , Bluetooth.

    , Microsoft, , , , . , , , Microsoft Robotics Studio,

    1

    8

  • , . Phidgets USB, Robotics Studio, . .

    . , , , Phidgets. , . , , . , , . , . .

    , , , , ( , ) . , .

  • *

  • 12

    2* ,

    , PCI x86, . . , , .

    , , . , . 2.1.

    . 2.1

    , , (, PCI PCI Express . .) .

  • 13

    , , .

    . . , . .

    . , , .

    ( ), PCI PCI Express. , . , , , PCI, .

    , , , . . , Intel PCI PCI Express (. 2.2).

    . 2.2

    , . PCI , , . , PCI USB, , , USB USB.

    ,

  • 14

    /. . PCI , . , (CANBUS, I2C, SPI . .), .

    ? :

    / , . , , ( , / / . .);

    . , ;

    , , ;

    , .

    , . , . . , () 8 8 (. 2.3).

    . 2.3

  • 15

    8 , 8 .

    . (. . 2.3) A0A7, . . , ( , ). .

    , , D0D7 , . , , , , , .

    . , ( ) .

    . 2.3 (. 2.4):

    . 2.4

    . , A2 A3. ( 8 ), A3. , , . : ?

    , , , A3.

    () , ( ) (. 2.5).

  • 16

    , , .

    , . . 2.6.

    . 2.5

    . 2.6

    , , , , .

    , . 2.6, A3. , PCI . , . , ( ).

  • 17

    , , , , . . 32 , 32 . , 8 , / 40 . , . , .

    , , , / , . . (), .

    , , PCI. , , , PCI(. 2.7).

    . 2.7 PCI

    PCI . , . , PCI CLK. CLK , , , .

    FRAME# , . . FRAME#

  • 18

    AD[0:31] , . C/BE# , ( , 0011, ).

    DEVSEL# ( )., IRDY# . (target) TRDY#, , , TRDY# ( ).

    , 3 CLK , ( TRDY#). , , 4 CLK. FRAME# .

    PCI, , , , . , , , , .

    , ( , Intel, in/out ). , , mov. , , 1 , 2 () 4 ( ).

    , . in, :

    mov DX, 0x379in AL, DX

    DX , 1 AL .

    (00xFFFF) 0xF8 0xFF.

    PCI PCI Express. , PCI PCI Express. , USB USB PCI, USB ( , , ).

    . RS232, , PCI UART ( ). ( , Bluetooth, WiFi . .).

  • 19

    Windows 98/Me in out, . Windows 2000/XP/2003, ( ), , .

    :

    IOPL (I/O Provilege level) (1213 EFLAGS);

    , TSS (Task StateSegment).

    IOPL . . , 0 1. , . WinAPI.

    , (CPL, Current Privilege Level) IOPL: in, ins, out, outs, cli, sti.

    , , (GeneralProtection Exceptin). , IOPL.

    , . : , (, ), , , .

    in ( ) out ( ) EAX (32 ), AX (16 ) AL ( ). DX.

    ,

    in AL, 0x378mov DX, 0x379out DX, AL

    ins outs . DX, DS:ESI ( ) ES:EDI ( ).

  • (, rep) ins outs . ESI EDI ( DF), , .

    , ( ) . , , , , (, , , . .). API., UNIX .

    , , : . ( , . .) . , .

    0x379 , . , Windows WinAPI, Win32.

    , , , USB Bluetooth.

  • 3.1. ...................................................................25

    3.2. ...........................................................................27

    3.3. ....................................................34

    3.4. ...................................................57

    3.5. ...............................................................................61

  • 22

    , (). , , , .

    9 12 . 4 , 5 8 , 25 DB25, .

    , Centronics. , . , Centronics : , , .

    3.1 , DB25 .

    , Centronics, SPP (Standard Parallel Port). EPP (Enhanced ParallelPort) ECP (Extended Capabilities Port), IEEE 1284, SPP.

    , SPP , , Centronics. , () , .

    SPP , ,, , . SPP . 3.1.

    . :

    BUSY: 0, , D0D7 ,

    3

  • 23

    STROBE , , D0D7 ;

    D0D7, BUSY . ACK , , BUSY. ( , 5 ) ACK , , . .

    3.1 Centronics

    1 Strobe 0 ,

    2 Data0 0 3 Data1 1 4 Data2 2 5 Data3 3 6 Data4 4 7 Data5 5 8 Data6 6 9 Data7 7

    10 Ack 6 11 Busy 7 12 PaperOut 5

    PaperEnd13 Select / 4 14 AutoLineFeed 1 15 Error/Fault 3 16 Initialize 2 17 SelectPrinter

    SelectIn 3 1825 Gnd

    . 3.1 SPP

  • 24

    , , BUSY .

    , . , : , .

    , .

    , Base, Base, Base+1 Base+2.

    ( ) 0x3BC, 0x378, 0x278, BIOS . , , , BIOS.

    ; , IRQ7 IRQ9 . 0x3BC , . Windows Linux LPTn, n (1, 2 . .), LPT1 0x378, LPT2 0x278h, 3.2.

    3.2

    0x3BC 0x3BE ECP0x378 0x37F LPT10x278 0x27F LPT2

    BIOS 0x3BC, , , LPT1. 0x378 0x278; , LPT2 LPT3. 0x3BC , LPT1 0x378, LPT2 0x278.

    , BIOS :

    Printer ( Default Normal); Standard & Bidirectional (SPP); EPP1.7 SPP; EPP1.9 SPP; ECP; ECP EPP1.7; ECP EPP1.9.

  • 25

    :

    Printer , SPP. , 5 ;

    Standard & Bidirectional . 5 , ;

    EPP1.7 SPP EPP 1.7 SPP. SPP (, ), EPP. , 5 . EPP 1.7 EPP, ;

    EPP1.9 and SPP , , EPP 1.9.

    Centronics .

    , Windows 98/Me, Windows 2000/XP/2003. , , PortTalk ( , ,www.beyondlogic.org). , .

    :

    , ;

    , , , !

    BIOS, 0x378, , , !

    3.1. *

    , ,

  • 26

    , .

    , Windows 2000/XP/2003 (, , ), , ,, .

    Windows 95/98/Millenium , , in out. Windows , Win API CreateFile, ReadFile WriteFile, .

    WINAPI CreateFile, LPTn, n , . n 1,. . LPT1. CreateFile . WINAPI :

    #include #include . . .HANDLE hLPT;char *buf = "Any string";DWORD bytes;. . .hLPT = CreateFile("LPT1", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);if (hLPT == INVALID_HANDLE_VALUE){ printf("Could not open file (error %d)\n", GetLastError()); return 0;}bool fSuccess = WriteFile(hLPT, buf, strlen(buf), &bytes, NULL);. . .

    , , , . .

  • 27

    Windows2000/XP/2003/Vista PortTalk, . , , , Windows, . , , , . , , , Windows 98/Me. .

    3.2. *

    . , . . TTL, .

    0x378 ( ) 0x278 ( LPT2).

    , Delphi 2007 ( Delphi 7, Delphi 2005 Turbo Delphi) , , , 0x378 . (. 3.2):

    . 3.2

  • 28

    , :

    unit Unit1;

    interface

    uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,Forms, Dialogs, StdCtrls;

    type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;

    var Form1: TForm1;

    implementation

    {$R *.dfm}

    procedure TForm1.Button1Click(Sender: TObject);begin asm mov DX, 378h in AL, DX not AL out DX, AL end;end;

    end.

    asm end, . DX , AL in AL, DX , .

    porttalk.sys, allowio.exe start.bat. start.bat :

    @echo offAllowIo 0x378 test_LPToutput.exe

  • 29

    allowio.exe , , . , 25 LPT , , 2 9. .

    . , . (, ) 0x379. .

    , , , . , (. 3.3).

    . 3.3

    D1 If, R1, DA1, VOUT = If x R1. , , , VOUT (, ). C1 , , . , R1.

    DA1 DA2, UOP. VOUT UOP , 6 ( 0x379). ( , , ).

  • 30

    . Delphi 2007 (. 3.4).

    . 3.4

    : . 5 6 0x379 , 0 ( ), . SystemON , SystemOFF . , . :

    unit Unit1;

    interface

    uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,Forms, Dialogs, StdCtrls, ExtCtrls;

    type TForm1 = class(TForm) SystemON: TButton; Timer1: TTimer; SystemOFF: TButton; procedure SystemONClick(Sender: TObject);

  • 31

    procedure SystemOFFClick(Sender: TObject); procedure Timer1Timer(Sender: TObject); private { Private declarations } public { Public declarations } end;

    var Form1: TForm1;

    implementation

    {$R *.dfm}

    procedure TForm1.SystemONClick(Sender: TObject);begin timer1.Enabled:= true;end;

    procedure TForm1.SystemOFFClick(Sender: TObject);begin timer1.Enabled:= false;end;

    procedure TForm1.Timer1Timer(Sender: TObject);var LightON: Byte;begin asm mov DX, 379h in AL, DX and AL, 01000000b shr AL, 6 mov byte ptr LightON, AL end; if LightOn = 0 then ShowMessage('Light is ON!');end;

    end.

    asm end . 0x379 AL. AL 6 , , . AL LightON, 0, ShowMessage.

    (. 3.5).

  • 32

    , , porttalk.sys, allowio.exe start.bat, start.bat .

    , , . : (, ) , 6 0, , , . , , .

    . 3.3 . (. 3.6).

    : VD1 DA1.

    . 3.5

    . 3.6

  • 33

    U, , .0. , 6 0x379, 0 0x378. Q1, RL1. L1 . . LN. , , VD1 , .1. , 6, , .0 0 .

    VD2 , . , .

    , , :

    unit Unit1;

    interface

    uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,Forms, Dialogs, StdCtrls, ExtCtrls;

    type TForm1 = class(TForm) SystemON: TButton; Timer1: TTimer; SystemOFF: TButton; procedure SystemONClick(Sender: TObject); procedure SystemOFFClick(Sender: TObject); procedure Timer1Timer(Sender: TObject); private { Private declarations } public { Public declarations } end;

    var Form1: TForm1;

    implementation

    {$R *.dfm}

    procedure TForm1.SystemONClick(Sender: TObject);begin timer1.Enabled:= true;

  • 34

    end;

    procedure TForm1.SystemOFFClick(Sender: TObject);begin timer1.Enabled:= false;end;

    procedure TForm1.Timer1Timer(Sender: TObject);begin asm mov DX, 379h in AL, DX and AL, 01000000b shr AL, 6 dec DX cmp AL, 0 sete BL mov AL, BL out DX, AL end;end;

    end.

    , ( ), . . 6 0x379 0 ( ), 0 0x378 .1, Q1, . 6 .1 ( ), 0 0x378 0, .

    3.3.

    , . . , . . , . . , , Windows.

    , LTC1286 Linear Technology. 12 , (. 3.7):

  • 35

    LTC1286 12 , . LTC1286 12.5 . , 250 . 1 . . 5 9 , .

    SPI. , SPI 3 , , , . .

    05.

    LTC1286 :

    Vref (.1) , . +5, 0 5;

    +IN (.2) ;

    -IN (.3) ( , );

    Vss (.4) ( );

    CS/SHDN (.5) (Chip Select, CS). 0 LTC1286. 1 , ;

    Dout (.6) . , ;

    CLK (.7) . , Dout. , ;

    Vdd (.8) . ,

    . 3.7

  • 36

    . 7805, 9 . , , . , , , .

    . 30 . , / . , .

    , , Delphi 2007.

    . 3.8.

    . 3.8

    : get Data , . 3.9.

    . 3.9

  • 37

    :

    unit Unit1;

    interface

    uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,Forms, Dialogs, StdCtrls;

    type TForm1 = class(TForm) Edit1: TEdit; Button1: TButton; Label1: TLabel; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;

    var Form1: TForm1; binResult: Word; total: Real;

    implementation

    {$R *.dfm}

    procedure TForm1.Button1Click(Sender: TObject);const DATA = #$378; STATUS = #$379;begin asm push ebx

    mov dx, DATA xor ax, ax bts ax, 7 out dx, al

    btr ax, 7 out dx, al

    mov bx, 15 @next:

  • 38

    xor ax, ax mov dx, DATA btr ax, 6 out dx, al

    mov dx, STATUS in al, dx bt ax, 3 rcl cx, 1

    mov dx, DATA bts ax, 6 out dx, al

    dec bx jnz @next

    mov dx, DATA bts ax, 7 out dx, al

    pop ebx and cx, 0FFFh mov word ptr binResult, cx end; total:= binResult*5.0 / 4096; Edit1.Text:= FloatToStr(total);end;

    end.

    . , , , Microsoft Excel Microsoft Access. , Excel.

    , Excel. :

    unit Unit1;

    interface

    uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,Forms, Dialogs, StdCtrls, ComObj;

    type

  • 39

    TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end;

    var Form1: TForm1; binResult: Word; total: Real; XLApp: variant; i1: Integer;

    implementation

    {$R *.dfm}

    procedure TForm1.Button1Click(Sender: TObject);const DATA = #$378; STATUS = #$379;begin asm push ebx

    mov dx, DATA xor ax, ax bts ax, 7 out dx, al

    btr ax, 7 out dx, al

    mov bx, 15 @next:

    xor ax, ax mov dx, DATA btr ax, 6 out dx, al

    mov dx, STATUS in al, dx bt ax, 3

  • 40

    rcl cx, 1

    mov dx, DATA bts ax, 6 out dx, al

    dec bx jnz @next

    mov dx, DATA bts ax, 7 out dx, al

    pop ebx and cx, 0FFFh mov word ptr binResult, cx end; total:= binResult*5.0 / 4096; XLApp.ActiveSheet.cells.item[i1, 1].value:= total; Inc(i1);

    end;

    procedure TForm1.FormCreate(Sender: TObject);begin XLApp := CreateOleObject(Excel.Application); XLApp.Workbooks.Add; XLApp.Visible := True; i1:= 1;end;

    procedure TForm1.FormDestroy(Sender: TObject);begin if not VarIsEmpty(XLApp) then begin XLApp.DisplayAlerts := False; // Discard unsaved files.... XLApp.Quit; end;end;end.

    , , , Excel Delphi. ( FormCreate) Microsoft Excel. , (FormDestroy) Microsoft Excel .

    Excel get Data, .

    (. 3.10).

  • 41

    : Excel. (. 3.11).

    . 3.10

    . 3.11

    . , , . .

    . . .

  • 42

    , . , , Delphi 2007.

    , (. 3.12).

    . 3.12

    , , , . , . ( , ), TCP/IP. , .

    , . , TCP. , , .

    , , Delphi 2007. .

    TTcpClient Internet. , TCP, TTimer ( System). , . . 3.13 .

    10 , TcpClient.

  • 43

    getData. :

    function TForm1.getData: Real;const DATA = #$378; STATUS = #$379;begin asm push ebx

    mov dx, DATA xor ax, ax bts ax, 7 out dx, al

    btr ax, 7 out dx, al

    mov bx, 15 @next:

    xor ax, ax mov dx, DATA btr ax, 6 out dx, al

    mov dx, STATUS

    . 3.13

  • 44

    in al, dx bt ax, 3 rcl cx, 1

    mov dx, DATA bts ax, 6 out dx, al

    dec bx jnz @next

    mov dx, DATA bts ax, 7 out dx, al

    pop ebx and cx, 0FFFh mov word ptr binResult, cx end; total:= binResult*5.0 / 4096; Result:= total;end;

    , . , , , . TCP (). /, . , , IP, 32 , , , 192.163.10.45. , , , www.microsoft.com. 32 , IP, .

    IP. , , , 127.0.0.1. IP, , . 065535. , , , . 13000. 127.0.0.1 13000, (listening) . , 13000.

  • 45

    , TcpClient1 TcpClient. : (. 3.14).

    . 3.14

    127.0.0.1 RemoteHost, 13000 RemotePort. , , . , TCP ( , ).

    , Winsock, . , , TcpClient1 , , , , .

    , TcpClient1: , Active True, , False. , Active True.

    , :

    procedure TForm1.Timer1Timer(Sender: TObject);var s1: String;

  • 46

    fres: Real;begin if TcpClient1.Active = false then TcpClient1.Active:= True; if TcpClient1.Connected = False then TcpClient1.Connect(); fres:= getData();

    s1:= 'A-D Conversion result: ' + FloatToStr(fres) + 'V'; TcpClient1.Sendln (s1); if TcpClient1.Connected = True then TcpClient1.Disconnect();end;

    getData fres, TcpClient1.SendLn(s1).

    :

    unit Unit1;

    interface

    uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,Forms, Dialogs, Sockets, StdCtrls, ExtCtrls;

    type TForm1 = class(TForm) TcpClient1: TTcpClient; Timer1: TTimer; procedure FormCreate(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure Timer1Timer(Sender: TObject); function getData: Real; private { Private declarations } public { Public declarations } end;

    var Form1: TForm1; binResult: Word; total: Real;

    implementation

    {$R *.dfm}

  • 47

    procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);begin timer1.Enabled:= false; TcpClient1.Active:= False;

    end;

    procedure TForm1.FormCreate(Sender: TObject);begin timer1.Enabled:= true; TcpClient1.Active:= true;end;

    procedure TForm1.Timer1Timer(Sender: TObject);var s1: String; fres: Real;begin if TcpClient1.Active = false then TcpClient1.Active:= True; if TcpClient1.Connected = False then TcpClient1.Connect(); fres:= getData();

    s1:= 'A-D Conversion result: ' + FloatToStr(fres) + 'V'; TcpClient1.Sendln (s1); if TcpClient1.Connected = True then TcpClient1.Disconnect();end;

    function TForm1.getData: Real;const DATA = #$378; STATUS = #$379;begin asm push ebx

    mov dx, DATA xor ax, ax bts ax, 7 out dx, al

    btr ax, 7 out dx, al

    mov bx, 15 @next:

    xor ax, ax

  • 48

    mov dx, DATA btr ax, 6 out dx, al

    mov dx, STATUS in al, dx bt ax, 3 rcl cx, 1

    mov dx, DATA bts ax, 6 out dx, al

    dec bx jnz @next

    mov dx, DATA bts ax, 7 out dx, al

    pop ebx and cx, 0FFFh mov word ptr binResult, cx end; total:= binResult*5.0 / 4096; Result:= total;end;

    end.

    , . TTcpServer ( Internet ) TMemo. 10 . . 3.15 , .

    TcpServer1 LocalHost 127.0.0.1, LocalPort 13000. BlockMode bmThreadBlocking (. 3.16).

    OnAccept. :

    procedure TForm1.TcpServer1Accept(Sender: TObject; ClientSocket: TCustomIpClient);var s1: String;begin s1:= ClientSocket.Receiveln(); Memo1.Lines.Add (s1); ClientSocket.Close();end;

  • 49

    . 3.15

    . 3.16 TcpServer1

  • 50

    :

    unit Unit1;

    interface

    uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,Forms, Dialogs, StdCtrls, Sockets;

    type TForm1 = class(TForm) TcpServer1: TTcpServer; Memo1: TMemo; procedure TcpServer1Accept(Sender: TObject; ClientSocket:TCustomIpClient); procedure FormCreate(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); private { Private declarations } public { Public declarations } end;

    var Form1: TForm1; ClientSocket: TCustomIpClient;implementation

    {$R *.dfm}

    procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);begin TcpServer1.Active:= False;end;

    procedure TForm1.FormCreate(Sender: TObject);begin TcpServer1.Active:= True; Memo1.Clear();end;

    procedure TForm1.TcpServer1Accept(Sender: TObject; ClientSocket: TCustomIpClient);var s1: String;begin s1:= ClientSocket.Receiveln(); Memo1.Lines.Add (s1);

  • 51

    ClientSocket.Close();end;

    end.

    .

    3.17 .

    . 3.17

    , , IP , , .

    , , , 8. (. 3.18).

    8 CD4051. 8 AC , 02 .

    8 Delphi 2007, Excel.

    (. 3.19). ,

    (Select channel), UpDown1 ( TUpDown), Edit1 ( TEdit). , Label1 Edit2, .

    UpDown1 Edit1 ( Associate) 07 ( ). Select channel pos, .

    get Data, .

    :

  • 52

    . 3.18 8

  • 53

    unit Unit1;

    interface

    uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,Forms, Dialogs, StdCtrls, ComObj, ComCtrls;

    type TForm1 = class(TForm) Button1: TButton; Edit1: TEdit; Button2: TButton; UpDown1: TUpDown; Label1: TLabel; Edit2: TEdit; procedure Button1Click(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Button2Click(Sender: TObject);

    . 3.19

  • 54

    private { Private declarations } public { Public declarations } end;

    var Form1: TForm1; binResult: Word; total: Real; XLApp: variant; i1: Integer; pos: Byte;implementation

    {$R *.dfm}

    procedure TForm1.Button1Click(Sender: TObject);const

    DATA = #$378; STATUS = #$379;begin asm push ebx

    mov dx, DATA xor ax, ax or al, pos bts ax, 7 out dx, al

    btr ax, 7 out dx, al

    mov bx, 15 @next:

    xor ax, ax or al, pos mov dx, DATA btr ax, 6 out dx, al

    mov dx, STATUS in al, dx bt ax, 3 rcl cx, 1

    mov dx, DATA

  • 55

    bts ax, 6 out dx, al

    dec bx jnz @next

    mov dx, DATA bts ax, 7 out dx, al

    pop ebx and cx, 0FFFh mov word ptr binResult, cx

    end; total:= binResult*5.0 / 4096.0;

    XLApp.ActiveSheet.cells.item[i1, 1].value:= total; Inc(i1);

    end;

    procedure TForm1.Button2Click(Sender: TObject);begin Edit2.Text:= IntToStr(UpDown1.Position); pos:= UpDown1.Position;end;

    procedure TForm1.FormCreate(Sender: TObject);begin XLApp := CreateOleObject(Excel.Application); XLApp.Workbooks.Add; XLApp.Visible := True; i1:= 1;end;

    procedure TForm1.FormDestroy(Sender: TObject);begin if not VarIsEmpty(XLApp) then begin XLApp.DisplayAlerts := False; XLApp.Quit; end;end;end.

    . 8 , .

  • 56

    , . ,

    LM335. , 10 /. , .

    . 3.20.

    U , +5. , . Rf , , , 273 (0).

    , , 1 , +5 , Rf (5 2.73) / 1 = 2.27 , . . , 2.2 . , 0 LM335 , 10 273 = 2.73 .

    , , , .

    , , . , LM335 , . . 3.21 .

    . .

    . 3.20

    LM335

    . 3.21

  • 57

    , .

    3.4. *

    , . , . , , , 74HC4051. 8 (. . 3.18).

    8 (. 3.22).

    , X DD1. , 3 0x378 . , , .

    Delphi 2007. (. 3.23).

    : , GetData, Data 0 1 .

    :

    unit Unit1;

    interface

    uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,Forms, Dialogs, StdCtrls, ComCtrls;

    type TForm1 = class(TForm) UpDown1: TUpDown; Edit1: TEdit; Button1: TButton; Edit2: TEdit; Label1: TLabel; Label2: TLabel;

    procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations }

  • 58

    . 3.22 8

  • 59

    . 3.23

    end;

    var Form1: TForm1;

    implementation

    {$R *.dfm}

    procedure TForm1.Button1Click(Sender: TObject);var pos, dataBit: Byte;begin

    pos:= UpDown1.Position; asm mov dx, 378h xor al, al or al, pos out dx, al // inc dx in al, dx shr al, 3 mov dataBit, al end; Edit2.Text:= IntToStr(dataBit);end;

    end.

  • 60

    . 3.24 16

  • 61

    16, 74HC4069(. 3.24).

    16 , 8 , , Max UpDown1 7 15.

    3.5.

    , . , , . . , . , , , , TTL . , TTL , .

    , . , , Windows, 50 , , , , .

    , .

    . , , . , (. 3.25).

    . 3.25

    6 0x379. , , , 1 , 10 ( 01) , (. 3.26).

    , . , , Delphi 2007. (. 3.27).

  • 62

    , OnStart, Edit1 Label1 Label2. , 1 . 10 6 . 1 .

    , , , TTimer 1 .

    , . , , , .

    :

    unit Unit1;

    interface

    uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,Forms,

    . 3.26

    . 3.27

  • 63

    Dialogs, StdCtrls, ExtCtrls;

    type TForm1 = class(TForm) OnStart: TButton; Edit1: TEdit; Label1: TLabel; Label2: TLabel; procedure OnStartClick(Sender: TObject); private { Private declarations } public { Public declarations } end;type TThread1 = class(TThread) public procedure Execute; override; end;

    var Form1: TForm1; Thread1: TThread1; Done: Byte; cnt: Integer; freq: Real;

    implementation

    {$R *.dfm}

    procedure TThread1.Execute;begin Sleep(1000); Done:= 1;end;

    procedure TForm1.OnStartClick(Sender: TObject);begin cnt:= 0; Done:= 0; Thread1:= TThread1.Create(False); asm clc mov dx, 379h @wait_1: in al, dx bt ax, 6 jnc @wait_1 //

  • 64

    @wait_0: in al, dx bt ax, 6 jc @wait_0 inc dword ptr cnt cmp byte ptr Done, 1 jne @wait_1 end; Thread1.Terminate(); freq:= cnt / 1000; Edit1.Text:= FloatToStr(freq);end;end.

    Thread1, 1 , Execute Sleep. 1 Done, asm end. 1 , cnt , 1 , . , : porttalk.sys, allowio.exe start.bat. .

    , , . , . , , Delphi 1 33000 , . . 500 ( 10 01 ).

    , . , . . , (. 3.28).

    , , .

    unit Unit1;

    interface

    uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,Forms, Dialogs, StdCtrls, ComCtrls, ExtCtrls;

    type TForm1 = class(TForm)

  • 65

    Edit1: TEdit; OnStart: TButton; Timer1: TTimer; UpDown1: TUpDown; Label1: TLabel; OnStop: TButton; procedure Timer1Timer(Sender: TObject); procedure OnStartClick(Sender: TObject); procedure OnStopClick(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end;

    var Form1: TForm1; period: Integer;

    Implementation

    {$R *.dfm}

    procedure TForm1.FormCreate(Sender: TObject);begin timer1.Enabled:= False; OnStart.Enabled:= true; OnStop.Enabled:= false;

    . 3.28

  • 66

    end;

    procedure TForm1.OnStartClick(Sender: TObject);begin OnStart.Enabled:= false; OnStop.Enabled:= true; period:= UpDown1.Position; timer1.Interval:= period; timer1.Enabled:= true;end;

    procedure TForm1.OnStopClick(Sender: TObject);begin OnStart.Enabled:= true; OnStop.Enabled:= false; timer1.Enabled:= false;end;

    procedure TForm1.Timer1Timer(Sender: TObject);begin asm mov dx, 378h in al, dx not al out dx, al end;end;

    end.

    . 3.29

    : ( 1 32000), Start. Stop. . 3.29.

    ,

    , . 555.

    , , Windows 2000/XP/2003/Vista.

    MCP41100 Microchip Technology Inc. , 100 K. . 3.30.

  • 67

    CS, SCK SI MCP41100 SPI. CS , SI MCP41100 SCK. CS .

    MCP41100 (. 3.31):

    , PA0 PB0 . MCP41100 (. 3.32).

    PW0 PA0, , PB0. 8, 256 . , , :

    RAB = Dn RLSB,

    RAB PA0 PB0, Dn , RLSB ( ), . MCP41100 , 100 K, 100000/256 = 390.625 . , , 10 K, Dn, 10000/390.625.

    F 555 . 3.30 :

    . 3.30

    . 3.31

    . 3.32

  • F = 1.44/Cx (R1 + RAB + R2).

    :

    F = 1.44/Cx (R1 + R2 + Dn RLSB).

    , Cx, R1, R2 RAB Dn, MCP41100.

    : 8 , 8 . MCP41100 Microchip Corp.

    Cx: 1000 pF, 10000 pF 100000 pF. R1 R2, , Cx (. . 3.30), . , 0x378 ( BIOS ). , .

    . 3.33.

    . 3.33, Cx .

    . 555 . R1 R2 ,

    Cx . 30 . , / . , .

    MCP41100 www.microchip.com Microchip Technology Inc.

    . 3.33

  • 4.1. RS232 ..................................................................................72

    4.2. ..................................75

  • 70

    , , , RS232. , RS232, 9 , 25 . , , , , .

    COM. , UART (Universal Asynchronous Receiver Transmitter, ), 115 / ( kbps), 460 /.

    , , (. 4.1).

    4 4.1

    COM1 IRQ4 0x3f8COM2 IRQ3 0x2f8COM3 IRQ4 0x3e8COM4 IRQ3 0x2e8

    , , , . , , , , USB, Bluetooth, Fireware , , .

    . , .

  • 71

    . , , , , , , , . , , .

    , , () , , , . . 4.1.

    . 4.1

    :

    ____

    , 8N1 , 8 , .

    8E2

    , 8 .

    ASCII. , 5, 6, 7 8 , 1, 1.5, 2, .

    : 50, 75, 110,150, 300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600 115200 /. , , .

    RS232, COM , .

  • 72

    4.1. RS*232

    RS232 , ( ). RS232 ( , ).

    3 12 ( 1) 3 12 ( 0). 3+3 ( ).

    , RS232 (, , ), () , () .

    RS232 . , , TD RD, / , , . 4.2.

    . 4.2

    , . 4.2, ASCII A : 7 , . , 7 .

    ( , 0), , .

  • 73

    , . . 1, 0.

    , .

    F (. 4.2). , .

    RS232 UART. , . , 8250, 16450, 16550, 16650, 16750.

    , (. 4.2). , , .

    RS232 :

    SG (Signal Ground) ( );

    TD (Transmit Data) (TXD); RD (Receive Data) (RXD); RTS (RequestToSend) ,

    UART ; CTS (ClearToSend)

    ; DTR (Data Terminal Ready) ,

    ; DSR (Data Set Ready) UART

    , ; DCD (Data Carrier Detect)

    . , ;

    RI (Ring Indicator) .

    RD TD, / , / . , , RTS, CTS, DCD, DSR, DTR, RTS RI .

    , , 9 , , . 4.2.

    COM , , , .

    RS232

  • 74

    , , . , , , , .

    . 4.3.

    4.2 RS232

    9

    3 TD2 RD7 RTS8 CTS6 DSR5 SG1 CD4 DTR9 RI

    . 4.3

    ( ) , .

    (loopback interface), . 4.4.

    RS232 , . , , , / , . , , , , .

    . 4.4

  • 75

    , . :

    RTS/CTS ( );

    DTR/DSR RTS/CTS, ;

    XON/XOFF . . , XOFF, , XON.

    ACK . ACK, .

    , , .

    4.2.

    Windows , .

    , . , , .

    . Windows WINAPI . , , COM Win API CreateFile, CloseHandle, ReadFile WriteFile, . , , , , COM1 , LPT1 . , COM1 CreateFile, , , COM1. (handle) ReadFile,WriteFile CloseHandle.

  • 76

    COM Windows .

    8 . , C++ Microsoft Visual Studio .NET.

    #include #include

    void main(void){ HANDLE hCom; char *pcComPort = "COM1"; DCB dcb;

    DWORD bytesWritten; __int8 i1;

    hCom = CreateFile(pcComPort, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);

    if (hCom == INVALID_HANDLE_VALUE){ printf("COM1 opening error!\n"); return;}

    GetCommState(hCom, &dcb);printf("COM1 baud rate is %d\n", dcb.BaudRate);

    {while (true) { printf("\nEnter value to be outputted at COM1 port:"); scanf("%du", &i1); WriteFile(hCom,

    &i1, sizeof(i1), &bytesWritten, NULL);

    }}CloseHandle(hCom);return;}

  • 77

    , C++ Windows, . COM1 WINAPI CreateFile. Windows , CreateFile 0 OPEN_EXISTING.

    CreateFile hCom , . GetCommState , , . . dcb DCB. dcb.BaudRate. , , , , , .

    , while , scanf. WINAPI WriteFile.

    , , . Windows, .

    #include #include

    void main(void){ HANDLE hCom; char *pcComPort = "COM1"; DCB dcb;

    DWORD bytesRead; char buf[128];

    hCom = CreateFile(pcComPort, GENERIC_READ | GENERIC_WRITE,

    0, NULL, OPEN_EXISTING, 0, NULL);

    if (hCom == INVALID_HANDLE_VALUE) { printf("COM1 opening error!\n"); return; }

    GetCommState(hCom, &dcb);

  • 78

    printf("COM1 baud rate is %d\n", dcb.BaudRate);printf("Waiting for data from COM1...\n");do { ReadFile(hCom, buf,

    sizeof(buf), &bytesRead, NULL);

    if (bytesRead > 0) {

    buf[bytesRead] = '\0';printf(buf);printf("\n");

    } }while (true);CloseHandle(hCom);return;}

    , Windows, COM1 (WINAPI CreateFile), buf ReadFile. bytesRead 0, printf .

    Visual Studio. NET SerialPort, ().

    , . 4.5.

    . 4.5

    COM

    . 4.5 TxD RxD . , , TxD RxD . ,

  • 79

    , TxD RxD . , , , , ,, .

    , , RC, 1/2RC. , COM . , .

    , . Microsoft Visual Studio .NET 2005.

    Visual Basic .NET, Visual Basic Windows Application (. 4.6).

    . 4.6

    COM1_Alarm OK . SerialPort Timer Toolbox (. 4.7).

    , , . , 5 , , , , . . .

    , . .

  • 80

    , , SerialPort. SerialPort1. COM, . SerialPort1 , . 4.8.

    (, 9600 , ( , COM1), , . .). COM Windows, SerialNet, .

    SerialPort1 . , SerialNet; , , , , . SerialPort DataReceived. , DataReceived , .

    ( SerialPort1_DataReceived) DataReceived, . 4.9.

    :

    Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVale As System.IO.Ports.SerialDataReceivedEventArgs) HandlesSerialPort1.DataReceived Dim readMes As String = SerialPort1.ReadLine()

    . 4.7

  • 81

    . 4.8 SerialPort1

    . 4.9 DataReceived

  • 82

    Beep()End Sub

    SerialPort1_DataReceived . , SerialPort1.ReadLine(), ReadLine() . , COM . , Beep(), , RxD , . . . TxD RxD , DataReceived , .

    , COM. Timer Timer1. , (. 4.10).

    . 4.10

    Timer1

    (. . ) Timer1 , Enabled False. 5000 (5 ). Timer1_Tick Tick, 5 (. 4.11).

    Timer1_Tick:

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Timer1.Tick SerialPort1.WriteLine(Cnt.ToString()) Cnt = Cnt + 1End Sub

  • 83

    COM , .

    , . Windows , (, , ) , , . , . , ( , , , , ). Alarm ON :

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button1.Click If SerialPort1.IsOpen = False Then SerialPort1.Open() End If Cnt = 0 Timer1.Enabled = True Button2.Enabled = True Button1.Enabled = False End Sub

    . :

    Public Class Form1 Dim Cnt As Integer

    . 4.11 Tick

  • 84

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button1.Click If SerialPort1.IsOpen = False Then SerialPort1.Open() End If Cnt = 0 Timer1.Enabled = True Button2.Enabled = True Button1.Enabled = False End Sub

    Private Sub SerialPort1_DataReceived(ByVal sender As System.Object,ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) HandlesSerialPort1.DataReceived Dim readMes As String = SerialPort1.ReadLine() Beep() End Sub

    Private Sub Form1_Activated(ByVal sender As Object, ByVal e AsSystem.EventArgs) Handles Me.Activated Button1.Enabled = True Button2.Enabled = False End Sub

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e AsSystem.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing SerialPort1.Close() Timer1.Enabled = False End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Timer1.Tick SerialPort1.WriteLine(Cnt.ToString()) Cnt = Cnt + 1 End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button2.Click Timer1.Enabled = False Button2.Enabled = False Button1.Enabled = True End SubEnd Class

    . COM , . 4.5 ( , , TxD RxD), . Alarm ON , .

  • 85

    , , . (PIR) . , / , TxD RxD . ( 1 ), . , , . , ( ), , . . . 4.12.

    , , , . PIR , , TTL. PIR, (U) .1 . ( DD1.1 DD1.2) RS, / Q1. TxD, RxD . PIR Q1 , TxD RxD. , .

    , , , Internet Explorer, . , .4.12. TCP, (127.0.0.1), 8080, ( 80 , , ,Microsoft IIS). Visual Basic .NET, Windows. NET (ExpressEditions 2005 2008).

    Visual Studio .NET 2005 . (. 4.13). , Visual Basic .NET.

    .vb ( , Module1.vb), (. 4.14).

    :

    Imports SystemImports System.IO.Ports

  • 86

    . 4.12

  • 87

    . 4.13 Visual Studio .NET

    . 4.14

  • 88

    Imports System.Net.Sockets

    Module Module1 Dim recvMsg As String Dim SerialPort1 As SerialPort Sub Main() Try 'Configuring the serial port SerialPort1 = New SerialPort

    'setting the Serial port parameters SerialPort1.BaudRate = 9600 SerialPort1.DtrEnable = False SerialPort1.DiscardNull = False SerialPort1.Handshake = Handshake.None SerialPort1.Parity = Parity.None SerialPort1.ParityReplace = 63 SerialPort1.PortName = "COM1" SerialPort1.ReadBufferSize = 4096 SerialPort1.ReadTimeout = -1 SerialPort1.RtsEnable = False SerialPort1.StopBits = StopBits.One SerialPort1.WriteBufferSize = 2048 SerialPort1.WriteTimeout = -1 SerialPort1.ReceivedBytesThreshold = 1

    'Adding the Serial port Event Handler AddHandler SerialPort1.DataReceived, NewIO.Ports.SerialDataReceivedEventHandler(AddressOfSerialPort1_DataReceived)

    'Opening the serial port If SerialPort1.IsOpen = False Then SerialPort1.Open() End If

    ' Configuring the TCP/IP Server ' Set the TcpListener on port 8080. Dim port As Int32 = 8080 Dim addr As Net.IPAddress = Net.IPAddress.Parse("127.0.0.1") Dim server As New TcpListener(addr, port)

    ' Start listening for client requests. server.Start()

    ' Buffer for reading data Dim bytes(1024) As [Byte] Dim data As [String] = Nothing

    ' Enter the listening loop.

  • 89

    While True Console.Write("Waiting for a connection on port 8080... ")

    ' Perform a blocking call to accept requests.

    Dim client As TcpClient = server.AcceptTcpClient() Console.WriteLine("Connected!")

    data = Nothing

    ' Get a stream object for reading and writing Dim stream As NetworkStream = client.GetStream()

    Dim i As Int32

    ' Receive all the data sent by the client. i = stream.Read(bytes, 0, bytes.Length) If (i > 0) Then ' Translate data bytes to a ASCII string. data = System.Text.Encoding.ASCII.GetString(bytes, 0, i) Console.WriteLine([String].Format("Received: {0}", data)) End If ' Serial Port sends message data = Checking room. Please, wait... Dim msg As Byte() = System.Text.Encoding.ASCII.GetBytes(data) stream.Write(msg, 0, msg.Length)

    recvMsg = "Nobody presents" SerialPort1.WriteLine("ALARM! Invasion!") System.Threading.Thread.Sleep(1000)

    data = " " & recvMsg & " " msg = System.Text.Encoding.ASCII.GetBytes(data) stream.Write(msg, 0, msg.Length)

    stream.Close()

    ' Shutdown and end connection client.Close() End While Catch e As SocketException Console.WriteLine("SocketException: {0}", e)End TrySerialPort1.Close()End Sub Sub SerialPort1_DataReceived(ByVal obj As Object, ByVal e AsSystem.IO.Ports.SerialDataReceivedEventArgs) recvMsg = SerialPort1.ReadLine() End SubEnd Module

  • 90

    . server, ( 127.0.0.1) 8080 while. client

    Dim client As TcpClient = server.AcceptTcpClient()

    / stream:

    Dim stream As NetworkStream = client.GetStream()

    stream /, recv send C.

    SerialPort . , TxD RxD SerialPort1_DataReceived.

    TxD RxD:

    SerialPort1.WriteLine("ALARM! Invasion!")

    , recvMsg ( SerialPort1_DataReceived):

    recvMsg = SerialPort1.ReadLine()

    , 1 recvMsg :

    Nobody presents ; ALARM! Invasion! , . . ,

    .

    , . , . , , , . webserver1.exe.

    , . 4.15. ( , Internet Explorer

    6) . , IP 127.0.0.1 , . , , .

  • 91

    , . , (. 4.16).

    . 4.15

    . 4.16

    http://127.0.0.1:8080

    , . , (. 4.17).

  • , , . 4.18.

    , , , , . , .

    . 4.17

    . 4.18

  • 5.1. ..........................................................94

    5.2. .......................................96

    5.3. .......... 105

  • 94

    () , , , . . , , , .

    , , . , ( 20 ), .

    , . , , , (, . Pulse Code Modulation, PCM), .

    5.1. *

    () . 5.1. FS FSAMPLE,

    , (), . 8 , 256, , , 12 , 212 4096. , , .

    , , FSAMPLE. , , .

    :

    5

  • 95

    , , , , (FSAMPLE ) FS.

    , 4 , 8 . : , . .

    , , . , , 12 , 4000 12000, . 22 , 44 .

    .

    .

    (. 5.2).

    . 5.1

    . 5.2

  • 96

    , , , . , .

    , ( ) ( ) . , . .

    , . () , (, ).

    5.2.

    , , , . , , , .

    , , , ( API Windows , , DirecSound DirectX SDK).

    , . , .

    (, , . .). , , .

    , , , , NCH Tone Generator, . , .

  • 97

    . 5.3 1000 .

    , () 1000 1000 (1 ). . 1 1000 .

    (. 5.4).

    , , , ( , , ), . , .

    (, WAV) . WAV. meandr.wav (. 5.5).

    , , . , , () , .

    , , Windows. .

    . 5.3

    . 5.4

    . 5.5

  • 98

    WAV, , DirectSound DirectX SDK Microsoft. DirectSound . , , . , DirectSound , Visual Basic. NET C# .NET. DirectX SDK ( www.microsoft.com).

    , DirectSound, Visual Basic .NET, meandr.wav.

    Visual Studio .NET 2005 ( Express Editions). Visual Basic .NET, Play WAVfile!, meandr.wav (. 5.6).

    . 5.6

    Microsoft.DirectX Microsoft.DirectX.DirectSound (. 5.7, 5.8).

    NET Add Reference, DirectX SDK , , .

    DirectX DirectSound Imports, :

    Imports Microsoft.DirectXImports Microsoft.DirectX.DirectSound

  • 99

    . 5.7

    . 5.8

    (device), , , , .

    :

  • 100

    Imports Microsoft.DirectXImports Microsoft.DirectX.DirectSoundImports System.Windows.Forms

    Public Class Form1 Public device As Device Public buf As Microsoft.DirectX.DirectSound.Buffer

    Private Sub Button1_Click(ByVal sender As Object, ByVal e AsSystem.EventArgs) Handles Button1.Click device = New Microsoft.DirectX.DirectSound.Device device.SetCooperativeLevel(Me, CooperativeLevel.Priority) buf = New Microsoft.DirectX.DirectSound.Buffer("i:\meandr.wav",device) buf.Play(0, BufferPlayFlags.Default) End SubEnd Class

    , . , :

    1. (device).2. (SetCooperativeLevel).3. , ,

    .4. Play.

    , , ( ). , Visual Basic .NET (. 5.9).

    . 5.9

  • 101

    : CheckBox ( ), OpenFileDialog ( ) , . Stop Playing.

    : . Loop, , .

    , :

    Imports Microsoft.DirectXImports Microsoft.DirectX.DirectSound

    Public Class Form1 Public device As Microsoft.DirectX.DirectSound.Device Public buf As Microsoft.DirectX.DirectSound.Buffer

    Public _loop As Boolean

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button1.Click device = New Microsoft.DirectX.DirectSound.Device device.SetCooperativeLevel(Me, CooperativeLevel.Priority) If ofd.ShowDialog() Then buf = New Microsoft.DirectX.DirectSound.Buffer(ofd.FileName, device) TextBox1.Text = ofd.FileName buf.Play(0, IIf(_loop, BufferPlayFlags.Looping,BufferPlayFlags.Default)) End If End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e AsSystem.EventArgs) Handles Me.Load _loop = FalseEnd Sub

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVale As System.EventArgs) Handles CheckBox1.CheckedChanged _loop = CheckBox1.CheckedEnd Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button2.Click buf.Stop()End SubEnd Class

    _loop , Checked CheckBox1 CheckBox1_Che-

  • 102

    ckedChanged. Play .

    IIf(_loop, BufferPlayFlags.Looping, BufferPlayFlags.Default)

    , _loop, buf. _loop false, ( BufferPlayFlags.Default), true, ( BufferPlayFlags.Looping).

    , OpenFileDialog, , .

    , , , , . , , 10 1000 , , , 1, , , , . .

    ToolBox, , .

    . 5.10 .

    . 5.10

    NumericUpDown, . 1, 32000. Value

  • 103

    132000 .

    :

    Imports Microsoft.DirectXImports Microsoft.DirectX.DirectSoundImports System.Threading

    Public Class Form1 Public device As Microsoft.DirectX.DirectSound.Device Public buf As Microsoft.DirectX.DirectSound.Buffer Public sthread As Thread Public tStart As Threading.ThreadStart Public delay As Integer

    Sub ThreadProc() While (True) buf.Play(0, BufferPlayFlags.Default) Thread.Sleep(delay) End While End Sub

    Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e AsSystem.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed sthread.Abort()End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e AsSystem.EventArgs) Handles Me.Load delay = 0 device = New Microsoft.DirectX.DirectSound.Device device.SetCooperativeLevel(Me, CooperativeLevel.Priority) tStart = New ThreadStart(AddressOf Me.ThreadProc) sthread = New Thread(tStart)End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button1.Click If ofd.ShowDialog Then TextBox1.Text = ofd.FileName buf = New Microsoft.DirectX.DirectSound.Buffer(ofd.FileName, device) delay = UpDown1.Value sthread.Start() End IfEnd SubEnd Class

    ( Form1_Load) sthread, ThreadProc , delay, UpDown1.Value.

  • 104

    , Form1_FormClosed Abort sthread.

    (. 5.11).

    ,

    DirectSound . ,

    Windows. Beep. Microsoft Visual Studio , Visual C++ .NET, Beep 1000 , .

    Beep Visual C++ .NET. : , .

    , , , , Beep, , , . , , , , , TTL.

    , Visual C++ .NET, , . :

    #include #include

    void main(int argc, char *argv[]){ int freq = 1000; int duration = 1000;

    if (argc != 3) { printf("Usage: %s freq duration\n", argv[0]); Beep(freq, duration); return; }

    freq = atoi(argv[1]); duration = atoi(argv[2]); Beep(freq, duration); return;}

    . 5.11

  • 105

    . , 1000 1 .

    . , , , / . , . .

    5.3.

    . 2 . , (. 5.12).

    . 5.12

    .

    , , , . , , .

    , TTL, , , . (. 5.13).

    , , 0 10 LM331

  • 106

    National Semiconductor. :

    VOUT = 0.001FIN.

    , 10 1 .

    C1 , . (. 5.14).

    R1 (

    ). , . , .

    . 10 0.1 1 . 1000 10000 1000 . , 0.1 (. 5.14)

    . 5.13

    . 5.14

  • 107

    1000 , 0.5 5000 . .

    10 1000 10000 meandr1000.wav, meandr2000.wav . . Visual Basic .NET , , . 5.15.

    . 5.15

    (Set Voltage Stop), TextBox ListBox. : , Set Voltage, . . , Stop, .

    :

    Imports Microsoft.DirectXImports Microsoft.DirectX.DirectSoundImports System.Threading.Thread

    Public Class Form1 Public device As Microsoft.DirectX.DirectSound.Device Public buf As Microsoft.DirectX.DirectSound.Buffer Public threadStart As Threading.ThreadStart

  • 108

    Public thread1 As Threading.Thread

    ' Public file0 As String = "i:\meandr1000.wav" Public file1 As String = "i:\meandr2000.wav" Public file2 As String = "i:\meandr3000.wav" Public file3 As String = "i:\meandr4000.wav" Public file4 As String = "i:\meandr5000.wav" Public file5 As String = "i:\meandr6000.wav" Public file6 As String = "i:\meandr7000.wav" Public file7 As String = "i:\meandr8000.wav" Public file8 As String = "i:\meandr9000.wav" Public file9 As String = "i:\meandr10000.wav"

    Private Sub OnPlay_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles OnPlay.Click

    Dim listIndex As Integer = ListBox1.SelectedIndex TextBox1.Text = ListBox1.SelectedItem.ToString threadStart = New Threading.ThreadStart(AddressOf threadProc) thread1 = New Threading.Thread(threadStart)

    Select Case listIndex Case 0 buf = New Microsoft.DirectX.DirectSound.Buffer(file0, device) Case 1 buf = New Microsoft.DirectX.DirectSound.Buffer(file1, device) Case 2 buf = New Microsoft.DirectX.DirectSound.Buffer(file2, device) Case 3 buf = New Microsoft.DirectX.DirectSound.Buffer(file3, device) Case 4 buf = New Microsoft.DirectX.DirectSound.Buffer(file4, device) Case 5 buf = New Microsoft.DirectX.DirectSound.Buffer(file5, device) Case 6 buf = New Microsoft.DirectX.DirectSound.Buffer(file6, device) Case 7 buf = New Microsoft.DirectX.DirectSound.Buffer(file7, device) Case 8 buf = New Microsoft.DirectX.DirectSound.Buffer(file8, device) Case 9 buf = New Microsoft.DirectX.DirectSound.Buffer(file9, device) End Select OnPlay.Enabled = False OnStop.Enabled = True thread1.Start() End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As

  • 109

    System.EventArgs) Handles Me.Load device = New Microsoft.DirectX.DirectSound.Device() device.SetCooperativeLevel(Me, CooperativeLevel.Priority) OnStop.Enabled = False End Sub

    Private Sub OnStop_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles OnStop.Click thread1.Abort() OnPlay.Enabled = True OnStop.Enabled = False End Sub

    Public Sub threadProc() While (True) buf.Play(0, BufferPlayFlags.Default) End While End Sub

    Private Sub Form1_FormClosed(ByVal sender As System.Object, ByVal eAs System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed thread1.Abort() End SubEnd Class

    , Microsoft.DirecX Microsoft.DirectX.DirectSound. , Imports.

    , buf ( !) .

    Beep, .

    , , LM3915 . , 10 , .

    . 5.16. Q1 D1 .

    . DA2 .

    U, DA1 12 . DA1 R, DA2

    U = U (1 + nRF/R) (U1 + U2 + + Un) (RF/R), n DA1.

  • 110

    . 5.16

    , DA2 U. R RF .

    , , .

    (. 5.17).

    . 5.17

    . RX Rt DA1.2,

  • 111

    , (, ).

    RX Rt, LM3915 . , , , .

    LM3915 , , LM324, ( ) , . , , , LM358, LF451 . .

    , . 5.13 ( LM131/LM231/LM331). , . (. 5.18).

    . 5.18

    DA2 , . ( ) . , , LM331 , RXRt, . ,

  • 112

    , .

    , . , , . . , 4 .

    , . , , . . . , , . , : , .

    , , , 1000 , , , , 1000 . , f(x)

    4/ [sin(x)/1 + sin(3x)/3 + sin(5x)/5 + . . . ] , , 4/,

    , ( , 3 ) 3 . .

    , , 1000 , , 1000 , , , . , 1000 ,, , . 1000 . 5.19.

    . , 1000 , ( 10, , ). (Texas Instrument, Microchip . .), , , .

    , , / . . 5.20.

  • 113

    1000 100 DA1 200 . 1000 D1. DA2, , U , .1. Q1 , M1.

    , , 1200 , DA2. , Q1 , M1. U , , , , , Windows.

    , , 2000, 3000, 4000 , .

    , . , , 3000 , , 3000 , . , 4 (. 5.21):

    , , . 1000 4000 , . , , , , 5000, 6000 . .

    . 5.19 1000

  • 114

    . 5.20

  • 115

    ( ) .

    , , , , 300 .

    , , . , , , , . , .

    ,, . , ; .

    . 5.21

  • USB Bluetooth

    6.1. USB Windows ............................................... 123

    6.2. USB ................................................ 126

    6.3. Bluetooth ............................. 136

    6.4. Bluetooth ......................................................... 142

  • 118

    USB Bluetooth . USB. (Universal Serial Bus,USB) . USB , . , Wireless USB.

    USB , , . USB :

    USB ? :

    ;

    , . . ;

    , ;

    12 / , ;

    127 . USB ;

    , ;

    : USB , ;

    . , , , USB ;

    6 USB Bluetooth

  • 119

    , USB ;

    , .

    USB , / .

    USB (,) , . USB, 5 .

    USB . 6.1:

    . 6.1 USB

    USB USB. () USB, ( . 6.1 USB ).

    USB. . USB ( ) .

    , , , . , . USB (, , , . .) USB .

    . 6.2. PCI ,

    . , . , USB, . 6.2.

    USB BLUETOOTH

  • 120

    USB BLUETOOTH

    USB, , Windows? , . . USB, USB , . . 6.3.

    , USB . , . USB, , * * (. 6.4).

    USB, , , USB, USB. USB (. 6.5).

    , USB: , USB Intel82801EB24D2.

    USB, , , , .

    . 6.2

    USB

  • 121

    USB , , . 6.6.

    USB , . , USB . , . 6.7.

    . 6.3 USB

    . 6.4 USB

    USB BLUETOOTH

  • 122

    USB BLUETOOTH

    . 6.5

    USB

    . 6.6USB

    . 6.7, USB , (. . , ,

  • 123

    ). , , , USB , . USB . (Windows, Linux . .) , , .

    USB , Windows 2000/XP/2003/Vista.

    6.1. USB Windows

    USB : . USB , . , . , PnP , . , .

    Windows USB , . , .

    . 6.7 USB

    USB

  • 124

    USB BLUETOOTH

    USB USB . . USB Windows, , . 6.8.

    . 6.8

    USB Windows

    . 6.8 USB. class () , . . , , . , . USB, , . , , , , USB .

    , PCI, USB. , ., , .

    ,

  • 125

    , .

    Windows . ( usbuhci.sys), (usbhub.sys) usbui.dll, (usbd.sys). , .

    USB :

    Control ( ). , 8, 16, 32 64 ;

    Bulk . , 8, 16, 32 64 . ;

    Interrupt , (, ), . , 64 ;

    Isochronous , . , 1023 . .

    .

    USB, Win API, . (I/O Request Packet, IRP) . USB, , , .

    (microframes) 125 USB 2.0 ( USB 1.1). , , ( ). :

    (token) . , , . , , ;

    (data) ( ) ( );

    USB

  • 126

    USB BLUETOOTH

    (handshake) , ( ) USB , . , ACK. , NAK. , , STALL.

    , . 6.9.

    . 6.9

    , , . USB , , .

    USB , USB.

    6.2. USB*

    , Windows , USB. USB , USB .

    USB, , :

    , , , . ;

  • 127

    , , . , USB, , , ;

    USB.

    USB , . , USB , . , . , GNU , LibUsb, Windows Linux. , . , .

    , , , . LibUsb (wrappers) VisualBasic .NET C# .NET, LibUsbDotNet, . USB, , . , USB, LibUsb. , www.sourceforge.net .

    USB LibUsb? , , USB:

    , , (enumeration). , USB, libusb;

    ( , ), ;

    , , , . USB, , , , .

    libusb, , ; ,

    USB

  • 128

    USB BLUETOOTH

    . . , libusb Windows.

    libusb Windows libusb0.sys. , , , USB (. 6.10).

    , libusb0.dll, .

    , , USB , . Visual Basic .NET , libusb (libusb ).

    USB 3 (. 6.11).

    . 6.10

    libusb0.sys

    . 6.11

    USB

  • 129

    Visual Basic .NET, (. 6.12):

    . 6.12

    :

    Public Class Form1 Declare Sub usb_init Lib "libusb0.dll" () Declare Function usb_find_busses Lib "libusb0.dll" () As Integer Declare Function usb_find_devices Lib "libusb0.dll" () As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button1.Click Dim nBusses As Integer Dim nDevices As Integer

    usb_init() nBusses = usb_find_busses() nDevices = usb_find_devices() Label1.Text = "Devices " & nDevices Label2.Text = "Busses " & nBusses

    End SubEnd Class

    Declare usb_init,usb_find_busses usb_find_devices libusb0.dll. usb_init , usb_find_busses

    USB

  • 130

    USB BLUETOOTH

    USB, usb_find_devices USB.

    label1 label2 . , . 6.13.

    , # .NET, :

    . 6.13

    using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Runtime.InteropServices;

    namespace CSharp_USB{ public partial class Form1 : Form { public int nDevices; public int nBusses;

    [DllImport("libusb0.dll")] public static extern void usb_init(); [DllImport("libusb0.dll")] public static extern int usb_find_busses(); [DllImport("libusb0.dll")] public static extern int usb_find_devices();

    public Form1() { InitializeComponent(); }

    private void button1_Click(object sender, EventArgs e) { usb_init(); nBusses = usb_find_busses(); nDevices = usb_find_devices(); label1.Text = "Busses: " + nBusses; label2.Text = "Devices: " + nDevices; } }}

  • 131

    C# .NET System.Runtime.InteropServices, DllImport.

    , Visual C++ .NET, USB. :

    #include #include #include

    #define DEBUG_LEVEL 0#define PROTOCOL_MOUSE 2#define PROTOCOL_KEYBOARD 1

    struct usb_bus *busses,*bus,*dbus;

    int findDevice(int PROTOCOL,struct usb_device *device){ bool found = false; struct usb_device *dev;

    usb_find_busses(); usb_find_devices(); busses = usb_get_busses();

    for (bus = busses;bus && !found;bus=bus->next) { for (dev=bus->devices;dev; dev = dev->next) { if (dev->config->interface->altsetting->bInterfaceProtocol==PROTOCOL) {

    dbus=bus;found=true;

    break; } } }if (!found) return -1;device = dev;return 1;}

    void main(void){

    struct usb_device *dev; char *buf;

    USB

  • 132

    USB BLUETOOTH

    int n,x,r; char string[50]; bool found = false;

    usb_dev_handle *fdev; usb_set_debug(DEBUG_LEVEL); usb_init();

    if (findDevice(PROTOCOL_MOUSE,dev)descriptor.bDeviceProtocol);

    printf("Report Length : %dn",dev->descriptor.bLength); printf("Decriptor Type : %dn",dev->descriptor.bDescriptorType);

    printf("End Points :%dn",dev->config->interface->altsetting->bNumEndpoints); printf("Interface Class :%dn",dev->config->interface->altsetting->bInterfaceClass);

    printf("Protocol :%dn",dev->config->interface->altsetting->bInterfaceProtocol); printf("Interface Number:%dn",dev->config->interface->altsetting->bInterfaceNumber);

    printf("Device Filename : %sn",dev->filename); printf("Bus Dir Name : %sn",dbus->dirname);

    usb_get_string_simple(fdev,dev->descriptor.iManufacturer,string,sizeof(string));

    printf("Device Manfucaturer : %sn",string);

  • 133

    usb_get_string_simple(fdev,dev->descriptor.iProduct,string,sizeof(string));

    printf("Product Name : %sn",string);

    usb_get_string_simple(fdev,dev->descriptor.iSerialNumber,string,sizeof(string));

    printf("Device Serial Number: %sn",string); printf("End point addresses : 0x%xn",dev->config->interface->altsetting->endpoint->bEndpointAddress);

    printf("Closing Device.n");

    usb_release_interface(fdev,0); usb_close(fdev); return;}

    libusb , libusb.lib. , libusb

    USB. , Visual Basic C# .NET . GNU LibUsbDotNet (www.sourceforge.net), libusb NET. USB LibUsbDotNet.

    LibUsbDotNet . , Visual C# .NET, / USB . TextBox Toolbox Dock Fill, . , (. 6.14).

    LibUsbDotNet , ( NET , , dll), AddReference Browse LibUsbDotNet (. 6.15).

    , using. :

    using System;using System.Collections.Generic;using System.Diagnostics;using System.Windows.Forms;using LibUsbDotNet.DeviceNotify;using LibUsbDotNet.Usb;using LibUsbDotNet.Usb.Main;

    namespace Test_DeviceNotify{

    USB

  • 134

    USB BLUETOOTH

    public partial class Form1 : Form { private DeviceNotifier mDevNotifier;

    public Form1() { InitializeComponent(); mDevNotifier = new DeviceNotifier();

    . 6.14

    . 6.15 LibUsbDotNet

  • 135

    mDevNotifier.OnDeviceNotify += newEventHandler(mDevNotifier_OnDeviceNotify); }

    #region PRIVATE METHODS

    private void mDevNotifier_OnDeviceNotify(object sender,DeviceNotifyEventArgs e) { Invoke(new DeviceNotifyEventDelegate(OnDevNotify), new object[]{sender, e}); Debug.Print(e.Object.ToString()); }

    private void OnDevNotify(object sender, DeviceNotifyEventArgs e) { object[] o = new object[] {e.EventType.ToString(),DateTime.Now.ToString(), e.DeviceType.ToString(), e.Object.ToString()}; string s = String.Format("{0} - Time: {1} - {2}\r\n{3}", o);

    if (e.DeviceType == DeviceType.DEVICEINTERFACE && e.EventType ==EventType.DEVICEARRIVAL) s += "\r\n" + e.Device.SymbolicName.FullName; tNotify.Text += s; }

    #endregion

    #region Nested type: DeviceNotifyEventDelegate

    private delegate void DeviceNotifyEventDelegate(object sender,DeviceNotifyEventArgs e);

    #endregion }}

    / USB DeviceNotify, / .

    USB, , CDRW, (. 6.16).

    USB , (. 6.17).

    LibUsbDotNet . , , .

    , , , . , libusb .

    USB

  • 136

    USB BLUETOOTH

    6.3. Bluetooth

    Bluetooth , . , Bluetooth. , , . , USB ( , dongle (), USB).

    Bluetooth, , Java, Bluetooth JSR82.

    Bluetooth? , Bluetooth ,

    . 6.16

    USB

    . 6.17

    USB

  • 137

    Bluetooth . (HTTP, FTP, SMTP . .), . Bluetooth : , , , , , . Bluetooth , 1 / 100 , , , WiFi.

    Bluetooth , , , , . .

    Bluetooth 100 , . Bluetooth (64 /), , (721 / 57,6 / ), (432,6 / ). Bluetooth 2.4 10100 . , , 10 . , 0.3 30 .

    Bluetooth ( FHSS, FrequencyHopping Spread Spectrum) , (1600 ) , 79 . , , .

    Bluetooth? , USB Bluetooth

    USB . (. 6.18).

    Bluetooth USB, , ( ), . , Bluetooth, (. 6.19).

    Bluetooth. , , ( ), (. 6.20).

    Bluetooth. , (. 6.21).

    . 6.18 Bluetooth

    . 6.19Bluetooth

    BLUETOOTH

  • 138

    USB BLUETOOTH

    Bluetooth ( , 10) (. 6.22).

    , , (. 6.23).

    Bluetooth . Bluetooth . , My Bluetooth Places. ,

    . 6.20

    Bluetooth

    . 6.21

  • 139

    Bluetooth, / (. 6.24).

    Bluetooth :

    Bluetooth Serial Port Bluetooth ;

    DialUp Networking Bluetooth, , dialup .

    . 6.22 Bluetooth

    . 6.23,

    BLUETOOTH

  • 140

    USB BLUETOOTH

    , Bluetooth , , ;

    Fax , Bluetooth;

    File Transfer Bluetooth(. 6.25);

    . 6.24

    Bluetooth

    . 6.25

    Bluetooth

    Information Exchange ();

    Information Synchronization (. 6.26);

    Network Access , (. 6.27).

    Bluetooth, , . , Windows XP , .

  • 141

    . 6.26 Bluetooth

    . 6.27

    . Bluetooth LAN Access Server Driver , (. 6.28).

    . . Bluetooth . 6.29 6.30.

    IP, . 6.30, ( ). TCP/IP , , . 3Com 3C996B (. 6.28, Local Area Connection). , . 6.31.

    . . , TCP/IP , , IP. BluetoothNullConnection. 921600 (~1Mb) (. 6.32).

    BLUETOOTH

  • 142

    USB BLUETOOTH

    . 6.28

    . 6.29

    Bluetooth LANAccess Server Driver

    , , BluetoothNullConnection. , .

    , Bluetooth .

    6.4. Bluetooth

    Bluetooth , Bluetooth.

  • 143

    . 6.30 IP

    Bluetooth, , , Bluetooth, , . Bluetooth www.bluetooth.com. , . .

    C Bluetooth

    , Bluetooth. , , , . , Bluetooth. Bluetooth, , .

    Bluetooth:

    HCI (Host Controller Interface) ;

    L2CAP (Logical Link Controller Adaptation Protocol) , ( , HCI, );

    BLUETOOTH

  • 144

    USB BLUETOOTH

    . 6.31

    SDP (Service Discovery Protocol) Bluetooth;

    RFCOMM .

    Bluetooth

    Bluetooth , Bluetooth . , Bluetooth Bluetooth, Bluetooth. , ? , ? , , , , ?

    Bluetooth . , , , Synchronization Profile , . , , vcf , Object Push Profile. , Dialup Networking Profile, . ,

  • 145

    . 6.32 Bluetooth

    Bluetooth , .

    : Bluetooth J2ME. J2ME Java, J2ME. , MID Java, CLDC (Connected Limited Device Configuration). , Bluetooth , Bluetooth. , Object Push Profile Palm PDA C++, Bluetooth .

    Bluetooth Java

    Bluetooth Java. , Java . Atinav Java Bluetooth SDK ( , Bluetooth , , ).

    Bluetooth Java (, ) :

    BLUETOOTH

  • 146

    USB BLUETOOTH

    ; ; ; ; .

    , , . , , Bluetooth. , . , Bluetooth:

    import javax.bluetooth.*;import javax.microedition.io.*;import com.atinav.BCC;public class WirelessDevice implements DiscoveryListener {

    LocalDevice localDevice = null; public WirelessDevice (){

    //

    BCC.setPortName("COM1");

    // COM

    BCC.setBaudRate(57600);

    //

    BCC.setConnectable(true);

    //

    BCC.setDiscoverable(DiscoveryAgent.GIAC); try { localDevice = LocalDevice.getLoalDevice(); } catch (BluetoothStateException exp) { }

    // DiscoveryListener class }}

  • 147

    LocalDevice RemoteDevice Java Bluetooth Specification, . Bluetooth (LocalDevice), (RemoteDevice). LocalDevice.getLocalDevice() LocalDevice . , getBluetoothAddress() LocalDevice. Bluetooth , MAC , Bluetooth . , setDiscoverable() LocalDevice.

    , , Bluetooth Java Bluetooth Specification APIs.

    , Bluetooth.

    Bluetooth , Bluetooth . , Bluetooth , Java Bluetooth API. Bluetooth. DiscoveryAgent DiscoveryListener.

    LocalDevice, DiscoveryAgent, LocalDevice.getDiscoveryAgent():

    LocalDevice localdevice = LocalDevice.getLocalDevice();DiscoveryAgent discoveryagent = localdevice.getDiscoveryAgent();

    , Bluetooth, . , DiscoveryListener. (, , TCP/IP ). , , , .

    , startInquiry() DiscoveryAgent. , , Bluetooth. , Java deviceDiscovered(), DiscoveryListener. RemoteDevice, .

    Bluetooth, , () . searchServices() DiscoveryAgent, , RemoteDevice. , Java servicesDiscovered() ( ,

    BLUETOOTH

  • 148

    USB BLUETOOTH

    DiscoveryListener). ServiceRecord, . , , , ServiceRecord.

    getConnectionURL ServiceRecord. , servRecord[i], :

    String connectionURL = servRecord[i].getConnectionURL(0, false);

    Bluetooth, Bluetooth SDDB(Service Discovery DataBase). . , , , ftp, telnet ., , . , (, ), ( ).

    SDDB:

    Connector.open() StreamConnectionNotifier ( Connector.open() ServiceRecord );

    LocalDevice StreamConnectionNotifier ServiceRecord, ;

    , ServiceRecord; StreamConnectionNotifier acceptAndOpen(), ,

    Bluetooth ;

    , close() StreamConnectionNotifier.

    StreamConnectionNotifier Connector javax.microedition.io J2ME platform. , :

    //

    StreamConnectionNotifier notifier = null;StreamConnection sconn = null;LocalDevice localdevice = null;ServiceRecord servicerecord = null;

    // 1// String URL

    notifier = (StreamConnectionNotifier)Connector.open(url);

  • 149

    // 2// LocalDevice,

    localdevice = LocalDevice.getLocalDevice();servicerecord = localdevice.getRecord(notifier);

    // 3 ()// 4// , // . ,// SDDB

    notifier.acceptAndOpen();

    // 5// // , , // 6// SDDBnotifier.close();

    , Bluetooth. .

    Java Bluetooth API , , RFCOMM. , RFCOMM , Serial Port Profile . , , Bluetooth, :

    //

    StreamConnectionNotifier notifier = null;StreamConnection con = null;LocalDevice localdevice = null;ServiceRecord servicerecord = null;InputStream input;OutputStream output;

    // URL, (UUID),//

    String url ="btspp://localhost:00112233445566778899AABBCCDDEEFF;name=serialconn";

    // URL // StreamConnectionNotifier

    BLUETOOTH

  • notifier = (StreamConnectionNotifier)Connector.open(url);

    // ,

    con = notifier.acceptAndOpen();

    // ,

    input = con.openInputStream();output = con.openOutputStream();

    // . . .

    , . String url btspp://localhost: Serial Port Profile. UUID, 00112233445566778899AABBCCDDEEFF. ( ), , URL ( ). , SDDB :

    ServiceName = serialconn

    , .

    Serial Port Profile J2ME :

    Connector.open().StreamConnection con =(StreamConnection)Connector.open(url);

    URL, Bluetooth , ServiceRecord . , Serial Port Profile :

    String connectionURL = serviceRecord.getConnectionURL(0, false);StreamConnection con =(StreamConnection)Connector.open(connectionURL);

    URL Serial Port Profile? , , 0001234567AB, URL , , :

    btspp://0001234567AB:3

    3 , , SDDB.

    JSR82 Development Kit Atinav, J2ME WirelessToolkit Sun Microsystems. Bluetooth, , .

    USB BLUETOOTH

  • 7.1. ................................................................... 154

    7.2. Windows ............................................... 157

    7.3. .............................. 160

    7.4. ...................................................................... 172

    7.5. ......................... 185

    Windows

  • 152

    , PortTalk.sys allowio.exe. Windows, , .

    Windows (, , ) . , . , , , .

    , , C ( C) Windows. , ( ).

    , , . , , .

    , Microsoft Windows DDK (Driver Development Kit). Microsoft. .

    , , , . , , , , , . Windows2000/XP/2003/Vista.

    7 Windows

  • 153

    , , , . (. 7.1):

    . 7.1 Windows.

    Windows 2000/XP/2003/Vista (, . .) . , , , Windows, . , . , .

    Windows , , . , () , , , , , . . , , . . , Delphi, 0x378 Windows XP, :

    program Project1;{$APPTYPE CONSOLE}uses SysUtils;begin try { TODO -oUser -cConsole Main : Insert code here } asm

    WINDOWS

  • 154

    WINDOWS

    mov DX, 378h mov AL, 1h out DX, AL end; except on E:Exception do Writeln(E.Classname, ': ', E.Message); end;end.

    (. 7.2):

    . 7.2

    in out Intel , , .

    . , , . PortTalk.sys allowio.exe.

    . . :

    1) ;2) ,

    .

    , , .

    7.1.

    , Windows, , , (

  • 155

    WINAPI), , , kernel32.dll. : , , , , ., , Windows LPT1, COM1 . . , , , LPT1.

    . , . . 7.3:

    . 7.3

    () . , , , CreateFile() (1). , . ( , LPT1) . ( WINAPI), . WINAPI , , , .

    , WINAPI CreateFile() ,

  • 156

    WINDOWS

    / (). , , , , . , (IRP) , .

    CreateFile() () . , ( , ).

    . WINAPI WriteFile() (2). CreateFile(), . , .

    , , WINAPI CloseHandle(3), , .

    , . , WINAPI CreateFile(), WriteFile(),ReadFile() CloseHandle() . :

    1) CreateFile() ( ). , ( );

    2) ReadFile() WriteFile() (/). (ReadFile()) (WriteFile()) ;

    3) CloseHandle(). , , .

    ReadFile() WriteFile() WINAPI DeviceIoControl(). , , , . , , . DeviceIoControl().

  • 157

    , WINAPI , . , , .

    7.2. Windows

    , Windows : PnP . , , PnP, WDM, , NT. , . , WDM , PnP ( , . .). , WDM Windows, (. 7.4):

    . 7.4 WDM

    / WDM INF, ( , , . .).

    NT INF , , WINAPI . , , , . PnP, , . , NT , , . , .

    WINDOWS