转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 软件开发 >> Delphi程序 >> 正文
网络和通讯编程         ★★★★

网络和通讯编程

作者:闵涛 文章来源:闵涛的学习笔记 点击数:1719 更新时间:2009/4/23 18:42:41
打开拨号连接   调用拨号网络里的拨号程序来连接:其中''''连接Internet''''为你创建的拨号程序名称
winexec(''''rundll32.exe rnaui.dll,RnaDial ''''+''''连接Internet'''',9);
一个串口通讯的问题? Serial Port Communications?

I want to build a simple electrical controller which receives input from a
sensor through a comm port and either turns a power source(s) on or off
based upon this signal. I want this controller to be software in nature.
How do I communicate through the port and is it possible to discern changes
in voltage.
If not, what kind of signal must be input.

When you want to write and read only binary signals you can use the printer
parallel port. For that purpose the Port command is useful. In the below an
example of some D1 code used for bidirectional 2 wire bus communication (I2C).
BaseAddress is $278, $378 or $3BC, depending on the LPT port used for
communication.
There is a ''''but''''. In D1 the port function was available but not documented. In
D2 and D3 it seems to have disappeared entirely (Please somebody correct me if
this is wrong).
We are using the parallel printer port with attached a small interface card
with some I/O buffering for control of RF modules. Could somebody indicate
whether the Port function still exist or what the alternative could be ?
regards,
Hans Brekelmans
PROCEDURE SetIICline(Terminal: IICterminalTypes; High: Boolean);
Var Count : Word;
      CtrlAddress: word;
Begin { set iic line }
  CtrlAddress:=BaseAddress+2;
  Case Terminal of
    SCL : if High then Port[CtrlAddress]:=$08 else Port[CtrlAddress]:=$00;
    SDA : if NOT High then Port[BaseAddress]:=$80 else Port[BaseAddress]:=$00;
  END;
  For Count := 1 to ClockDelay do;
End; {SetIICline}
FUNCTION GetIICline(Terminal: IICterminalTypes): Boolean;
const SDA_IN=$80; { SDA: 25 pin #11, status, NOT BUSY, bit 7 }
         SCL_IN=$08; { SCL: 25 pin #15, status, NOT Error, bit 3 }
var Count : Word;
    ReadAddress: word;
Begin
   ReadAddress:=BaseAddress+1;
   CASE Terminal OF
     SCL: GetIICline:=((Port[ReadAddress] AND SCL_IN) = SCL_IN);
     SDA: GetIICline:=((Port[ReadAddress] AND SDA_IN) = SDA_IN); { read sda
pin }
   END;
   For Count := 1 to ClockDelay do;
End;
得到本机IP地址? How about using winsockets?
This code is untested and ugly.
program get_ip;
uses
  winsock,sysutils;
VAR
  ch : ARRAY[1..32] OF Char;
  i : Integer;
  WSData: TWSAData;
  MyHost: PHostEnt;
begin
  IF WSAstartup(2,wsdata)<>0 THEN
    BEGIN
      Writeln(''''can''''''''t start Winsock: Error '''',WSAGetLastError);
      Halt(2);
    END;
  try
    IF getHostName(@ch[1],32)<>0 THEN
      BEGIN
        Writeln(''''getHostName failed'''');
        Halt(3);
      END;
  except
    Writeln(''''getHostName failed'''');
    halt(3);
  end;
  MyHost:=GetHostByName(@ch[1]);
  IF MyHost=NIL THEN
    BEGIN
      Writeln(GetHostName(''''+StrPas(@ch[1])+'''') failed : Error
''''+IntToStr(WSAGetLastError));
      Halt(4);
    END
  ELSE
    BEGIN
        Write(''''address '''');
         FOR i:=1 TO 4 DO
            BEGIN
              Write(Ord(MyHost.h_addr^[i-1]));
              IF i<4 THEN
                write(''''.'''')
              ELSE
                writeln;
            END;
   END;
end.
任何动态改变/添加网络设置中的 TCP/IP 的 DNS 地址 例如,把 DNS Server的地址添加为192.0.0.1和192.1.1.0,可调用:
SetTCPIPDNSAddresses(''''192.0.0.1 192.1.1.0'''') ;
// 各地址之间用一个空格隔开
1. SetTCPIPDNSAddresses 定义如下:
procedure SetTCPIPDNSAddresses( sIPs : string );
begin
//
// if using Windows NT
//
SaveStringToRegistry_LOCAL_MACHINE(
''''SYSTEM\CurrentControlSet'''' +
''''\Services\Tcpip\Parameters'''',
''''NameServer'''',
sIPs );
//
// if using Windows 95
//
SaveStringToRegistry_LOCAL_MACHINE(
''''SYSTEM\CurrentControlSet'''' +
''''\Services\VxD\MSTCP'''',
''''NameServer'''',
sIPs );
end;
2. 其中 SaveStringToRegistry_LOCAL_MACHINE 定义:
uses Registry;
procedure SaveStringToRegistry_LOCAL_MACHINE(
sKey, sItem, sVal : string );
var
reg : TRegIniFile;
begin
reg := TRegIniFile.Create( '''''''' );
reg.RootKey := HKEY_LOCAL_MACHINE;
reg.WriteString( sKey, sItem, sVal + #0 );
reg.Free;
end;
如何在程序中动态取得Win95/98的网络邻居中的工作组及计算机名? 可参考下面代码,或许有所帮助:
procedure GetDomainList(TV:TTreeView);
var
a : Integer;
ErrCode : Integer;
NetRes : Array[0..1023] of TNetResource;
EnumHandle : THandle;
EnumEntries : DWord;
BufferSize : DWord;
s : string;
itm : TTreeNode;
begin
{ Start here }
try
With NetRes[0] do begin
dwScope :=RESOURCE_GLOBALNET;
dwType :=RESOURCETYPE_ANY;
dwDisplayType :=RESOURCEDISPLAYTYPE_DOMAIN;
dwUsage :=RESOURCEUSAGE_CONTAINER;
lpLocalName :=NIL;
lpRemoteName :=NIL;
lpComment :=NIL;
lpProvider :=NIL;
end;
{ get net root }
ErrCode:=WNetOpenEnum(
RESOURCE_GLOBALNET,
RESOURCETYPE_ANY,
RESOURCEUSAGE_CONTAINER,
@NetRes[0],
EnumHandle
);
If ErrCode=NO_ERROR then begin
EnumEntries:=1;
BufferSize:=SizeOf(NetRes);
ErrCode:=WNetEnumResource(
EnumHandle,
EnumEntries,
@NetRes[0],
BufferSize
);
WNetCloseEnum(EnumHandle);
ErrCode:=WNetOpenEnum(
RESOURCE_GLOBALNET,
RESOURCETYPE_ANY,
RESOURCEUSAGE_CONTAINER,
@NetRes[0],
EnumHandle
);
EnumEntries:=1024;
BufferSize:=SizeOf(NetRes);
ErrCode:=WNetEnumResource(
EnumHandle,
EnumEntries,
@NetRes[0],
BufferSize
);
IF ErrCode=No_Error then with TV do try
a:=0;
Items.BeginUpDate;
Items.Clear;
Itm:=Items.Add(TV.Selected,string(NetRes[0].lpProvider));
Itm.ImageIndex:=0;
Itm.SelectedIndex:=0;
{ get domains }
下面的一个单元定义了一个组件. TNetworkBrowser, 可以枚举hierachical树上所有
的网络资源. 实际上浏览是要花费很长时间的,这您可以通过在WINDOWS资源管理器
中打开"整个网络" 来比较一下. 如果你设置SCOPE属性 为nsContext , 你就可以看到
和网络邻居中一样的机器列表.
unit NetBrwsr;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TNetScope = (nsConnected, nsGlobal, nsRemembered, nsContext);
TNetResourceType = (nrAny, nrDisk, nrPrint);
TNetDisplay = (ndDomain, ndGeneric, ndServer, ndShare, ndFile, ndGroup,
ndNetwork, ndRoot, ndShareAdmin, ndDirectory, ndTree, ndNDSContainer);
TNetUsage = set of (nuConnectable, nuContainer);
TNetworkItems = class;
TNetworkItem = class
private
FScope: TNetScope;
FResourceType: TNetResourceType;
FDisplay: TNetDisplay;
FUsage: TNetUsage;
FLocalName: string;
FRemoteName: string;
FComment: string;
FProvider: string;
FSubItems: TNetworkItems;
public
constructor Create;
destructor Destroy; override;
property Scope: TNetScope read FScope;
property ResourceType: TNetResourceType read FResourceType;
property Display: TNetDisplay read FDisplay;
property Usage: TNetUsage read FUsage;
property LocalName: string read FLocalName;
property RemoteName: string read FRemoteName;
property Comment: string read FComment;
property Provider: string read FProvider;
property SubItems: TNetworkItems read FSubItems;
end;
TNetworkItems = class
private
FList: TList;
procedure SetItem(Index: Integer; Value: TNetworkItem);
function GetItem(Index: Integer): TNetworkItem;
function GetCount: Integer;
public
constructor Create;
destructor Destroy; override;
procedure Clear;
procedure Add(Item: TNetworkItem);
procedure Delete(Index: Integer);
property Items[Index: Integer]: TNetworkItem read GetItem write
SetItem; default;
property Count: Integer read GetCount;
end;
TNetworkBrowser = class(TComponent)
private
FItems: TNetworkItems;
FScope: TNetScope;
FResourceType: TNetResourceType;
FUsage: TNetUsage;
FActive: Boolean;
procedure Refresh;
procedure SetActive(Value: Boolean);
procedure SetScope(Value: TNetScope);
procedure SetResourceType(Value: TNetResourceType);
procedure SetUsage(Value: TNetUsage);
procedure EnumerateNet(NetItems: TNetworkItems; lpnr: PNetResource);
protected
public
constructor Create(AOwner: TComponent); override;
d

[1] [2]  下一页


没有相关教程
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · C语言系列  · VB.NET程序
    · JAVA开发  · Delphi程序
    · 脚本语言
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台