说三道四技术文摘-感悟人生的经典句子
说三道四 > 文档快照

网络和通讯编程-Delphi资料

HTML文档下载 WORD文档下载 PDF文档下载
网络和通讯编程-Delphi资料

一个串口通讯的问题?

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;

destructor Destroy; override;

procedure Open;

procedure Close;

property Items: TNetworkItems read FItems;

published

property Scope: TNetScope read FScope write SetScope default nsGlobal;

property ResourceType: TNetResourceType read FResourceType

write SetResourceType default nrAny;

property Usage: TNetUsage read FUsage write SetUsage default [];

property Active: Boolean read FActive write SetActive default False;

end;

implementation

type

PNetResourceArray = ^TNetResourceArray;

TNetResourceArray = array[0..0] of TNetResource;

{ TNetworkItem }

constructor TNetworkItem.Create;

begin

inherited;

FSubItems := TNetworkItems.Create;

end;

destructor TNetworkItem.Destroy;

begin

if FSubItems <> nil then

FSubItems.Free;

inherited;

end;

{ TNetworkItems }

constructor TNetworkItems.Create;

begin

inherited;

FList := TList.Create;

end;

destructor TNetworkItems.Destroy;

begin

Clear;

if FList <> nil then

FList.Free;

inherited;

end;

procedure TNetworkItems.SetItem(Index: Integer; Value: TNetworkItem);

begin

if (FList.Items[Index] <> nil) and (FList.Items[Index] <> Value) then

TNetworkItem(FList.Items[Index]).Free;

FList.Items[Index] := Value;

end;

function TNetworkItems.GetItem(Index: Integer): TNetworkItem;

begin

Result := TNetworkItem(FList.Items[Index]);

end;

procedure TNetworkItems.Clear;

begin

while Count > 0 do

Delete(0);

end;

procedure TNetworkItems.Add(Item: TNetworkItem);

begin

FList.Add(Item);

end;

procedure TNetworkItems.Delete(Index: Integer);

begin

if FList.Items[Index] <> nil then

TNetworkItem(FList.Items[Index]).Free;

FList.Delete(Index);

end;

function TNetworkItems.GetCount: Integer;

begin

if FList <> nil then

Result := FList.Count

else

Result := 0;

end;

{ TNetworkBrowser }

constructor TNetworkBrowser.Create(AOwner: TComponent);

begin

inherited Create(AOwner);

FItems := TNetworkItems.Create;

FScope := nsGlobal;

FResourceType := nrAny;

FUsage := [];

end;

destructor TNetworkBrowser.Destroy;

begin

if FItems <> nil then

FItems.Free;

inherited;

end;

procedure TNetworkBrowser.EnumerateNet(NetItems: TNetworkItems; lpnr:

PNetResource);

var

dwResult

dwResultEnum: Integer;

hEnum: THandle;

cbBuffer

cEntries

i: Integer;

nrArray: PNetResourceArray;

NewItem: TNetworkItem;

dwScope

dwType

dwUsage: Integer;

begin

cbBuffer := 16384;

cEntries := $FFFFFFFF;

case FScope of

nsConnected: dwScope := RESOURCE_CONNECTED;

nsGlobal: dwScope := RESOURCE_GLOBALNET;

nsRemembered: dwScope := RESOURCE_REMEMBERED;

nsContext: dwScope := RESOURCE_CONTEXT;

else

dwScope := RESOURCE_GLOBALNET;

end;

case FResourceType of

nrAny: dwType := RESOURCETYPE_ANY;

nrDisk: dwType := RESOURCETYPE_DISK;

nrPrint: dwType := RESOURCETYPE_PRINT;

else

dwType := RESOURCETYPE_ANY;

end;

dwUsage := 0;

if nuConnectable in FUsage then

dwUsage := dwUsage or RESOURCEUSAGE_CONNECTABLE;

if nuContainer in FUsage then

dwUsage := dwUsage or RESOURCEUSAGE_CONTAINER;

dwResult := WNetOpenEnum(dwScope

dwType

dwUsage

lpnr

hEnum);

if dwResult <> NO_ERROR then Exit;

GetMem(nrArray

cbBuffer);

repeat

dwResultEnum := WNetEnumResource(hEnum

cEntries

nrArray

cbBuffer);

if dwResultEnum = NO_ERROR then

for i := 0 to cEntries-1 do

begin

NewItem := TNetworkItem.Create;

case nrArray[i].dwScope of

RESOURCE_CONNECTED: NewItem.FScope := nsConnected;

RESOURCE_GLOBALNET: NewItem.FScope := nsGlobal;

RESOURCE_REMEMBERED: NewItem.FScope := nsRemembered;

RESOURCE_CONTEXT: NewItem.FScope := nsContext;

else

NewItem.FScope := nsGlobal;

end;

case nrArray[i].dwType of

RESOURCETYPE_ANY: NewItem.FResourceType := nrAny;

RESOURCETYPE_DISK: NewItem.FResourceType := nrDisk;

RESOURCETYPE_PRINT: NewItem.FResourceType := nrPrint;

else

NewItem.FResourceType := nrAny;

end;

case nrArray[i].dwDisplayType of

RESOURCEDISPLAYTYPE_GENERIC: NewItem.FDisplay := ndGeneric;

RESOURCEDISPLAYTYPE_DOMAIN: NewItem.FDisplay := ndDomain;

RESOURCEDISPLAYTYPE_SERVER: NewItem.FDisplay := ndServer;

RESOURCEDISPLAYTYPE_SHARE: NewItem.FDisplay := ndShare;

RESOURCEDISPLAYTYPE_FILE: NewItem.FDisplay := ndFile;

RESOURCEDISPLAYTYPE_GROUP: NewItem.FDisplay := ndGroup;

RESOURCEDISPLAYTYPE_NETWORK: NewItem.FDisplay := ndNetwork;

RESOURCEDISPLAYTYPE_ROOT: NewItem.FDisplay := ndRoot;

RESOURCEDISPLAYTYPE_SHAREADMIN: NewItem.FDisplay :=

ndShareAdmin;

RESOURCEDISPLAYTYPE_DIRECTORY: NewItem.FDisplay :=

ndDirectory;

RESOURCEDISPLAYTYPE_TREE: NewItem.FDisplay := ndTree;

RESOURCEDISPLAYTYPE_NDSCONTAINER: NewItem.FDisplay :=

ndNDSContainer;

else

NewItem.FDisplay := ndGeneric;

end;

NewItem.FUsage := [];

if nrArray[i].dwUsage and RESOURCEUSAGE_CONNECTABLE <> 0 then

Include(NewItem.FUsage

nuConnectable);

if nrArray[i].dwUsage and RESOURCEUSAGE_CONTAINER <> 0 then

Include(NewItem.FUsage

nuContainer);

NewItem.FLocalName := StrPas(nrArray[i].lpLocalName);

NewItem.FRemoteName := StrPas(nrArray[i].lpRemoteName);

NewItem.FComment := StrPas(nrArray[i].lpComment);

NewItem.FProvider := StrPas(nrArray[i].lpProvider);

NetItems.Add(NewItem);

// if container

call recursively

if (nuContainer in NewItem.FUsage) and (FScope <> nsContext) then

EnumerateNet(NewItem.FSubItems

@nrArray[i])

end;

until dwResultEnum = ERROR_NO_MORE_ITEMS;

FreeMem(nrArray);

WNetCloseEnum(hEnum);

end;

procedure TNetworkBrowser.Refresh;

begin

FItems.Clear;

if FActive then

EnumerateNet(FItems

nil);

end;

procedure TNetworkBrowser.SetActive(Value: Boolean);

begin

if Value <> FActive then

begin

FActive := Value;

Refresh;

end;

end;

procedure TNetworkBrowser.SetScope(Value: TNetScope);

begin

if Value <> FScope then

begin

FScope := Value;

Refresh;

end;

end;

procedure TNetworkBrowser.SetResourceType(Value: TNetResourceType);

begin

if Value <> FResourceType then

begin

FResourceType := Value;

Refresh;

end;

end;

procedure TNetworkBrowser.SetUsage(Value: TNetUsage);

begin

if Value <> FUsage then

begin

FUsage := Value;

Refresh;

end;

end;

procedure TNetworkBrowser.Open;

begin

Active := True;

end;

procedure TNetworkBrowser.Close;

begin

Active := False;

end;

end.

英特尔硬享公社启动“创意原型拍卖” 对接创意与商机 详解Swift 2.0(一):苹果做的25项改变 2015甲骨文数据库大会:回顾、感恩、展望,欲续写辉煌 Nokia进军VR领域:让人欢喜让人忧 2015中国人工智能大会在京成功召开 成为糟糕游戏设计师的五种打开方式 Stripe使用指南:Swift开发中的信用卡支付 将安全延伸至云端以及更远的地方 专访FreeWheel北京研发中心:一流技术型人才应具有国际化视野 iOS UIView动画实践(五):Keyframe Animation 【CTO讲堂】简说创业公司的技术选型,从BearyChat的开发说起 《近匠》Webix,跨浏览器的JavaScript UI组件库 微软正式推送Windows 10,你会升级最后一款Windows产品? Cinatra:高性能现代C++ Web框架 《移动App测试实战》作者邱鹏:我在测试过程中遇到的那些坑 Rust一周精彩回顾:《高级Rust编程语言》、新增13名贡献者 来自Sony Morpheus的开发灵感: 如何打造逼真的VR游戏? 如何像巫师那样隔空操作——聊聊迷你雷达的原理和应用 等你来战——IBM Cloudant数据库开发大赛火热开启! 《近匠》360加固保,应用安全攻防的核心实现 DEFCON黑客大会抢鲜看:你所不知道的黑客大对决 MDCC2015中国移动开发者大会启动 七场专题技术论坛公布 【CTO讲堂】如何构建高性能网络服务平台及生态系统? mysql备份数据库批处理 《近匠》Remix周哲,让Android运行在“电脑”上! TIOBE 2015年8月编程语言排行榜:Java第一,Objective-C跌出前五 Oculus PC SDK 0.7版即将发布,含新Direct Driver Mode 【CTO讲堂】NoSQL对未来大数据发展的意义何在? 从Java转向Go——AeroFS的一段奇妙之旅 谷歌重组建母公司Alphabet,新来的CEO Sandar Pichai是什么来头? 《近匠》专访AllSeen联盟主席薛国栋:从通讯层为物联网去中心化 关于电子论坛的设计!!!(回答有意义的高分美人相送,灌水的大炮伺候) jdk1.4大量认证资料奉送 请教对话框的创建 几个小问题,请大家多多帮忙!在线等待 请大家仔细看看,不知道我有没有写清楚,不知道算不算难还算容易....... win2000 sever怎样安装borland c++builder?(高分100) 请大家帮个忙,举手之劳而已 使用MSComm,在关闭窗口的时候,出现“端口已打开”的错误。怎么解决? 请问这几段C#语句怎么办? applet问题,期待高手出现 如何使用OpenDialog啊? 高分组网,斑竹不要删~~~~~~~~~~~~~~~ win2000 sever怎样安装borland c++builder?(高分100) 如何按分组条件,给一个字段乘以不同的值 求电子书!!! win2000问题,很急.在线等 求教,用delphi编的drm程序,急!~~~~~~~~ 请教对话框的创建 倒粪1 win2k中tts问题 XML+XSL+HTML运行出错(书上的例子) 倒粪2 高手帮我看一下这个奇怪的问题 倒粪3 ServerSocket的疑问 倒粪4 电脑配件 请问如何在JBuilder中调用我自己编写的JavaBean? 文件1可以Imports文件2的Namespace么? 我需要一个汉字的字库和词库,请问在什么地方能够得到?或者怎么可以从一个输入法程序中导出词库或词库?多谢。 调查:有多少人用的支持Java的手机? 关于注册表重命名操作? redhat的lilo问题 急!!!!!!计算机启动后,能检测到新的硬件并安装驱动,之后出现错误按任一键继续按三键重启任一键后,屏幕上一无所有,出现蓝屏,多次启动依然 常用工具栏不见了?怎么加上啊? 哪里有windows2000的资源工具包下载? win2000启动问题!!! 请问如何取得客户端(浏览网页的用户)的ip地址????????????? 学过数据结构的不妨来看一看! 好心人,进来看看!小弟我也快沉了,帮帮忙,谢谢了! 如何实现计算器的屏幕从右端开始显示? 交叉表FILTER 关注Tcl/Tk语言的朋友请进 df 遇到麻烦——通过winio取bios密码的程序 关于图片显示 今年再考一次。 SQL语句中[]的问题 请教一个关于派生新视图类的小问题 Delphi7适合编程盲学使用吗? 我想用Linux+mySql+jave做一套专用系统,越小越好大家给点建议 复音词中复合复音词举例?古代汉语 这道关于复音词的问题该怎么分析呢?全国2012年1月高等教育自学考试古代汉语试题第6题 下列句中加着重号的部分属于复音词的是A.大音希声,大象无形,道隐无名.(大象) B.文章千古事,得失 什么是复音词? 复音词和复合词有什么区别? 复音词和同义词有什么样的关系 毛泽东军事思想的科学含义是什么?它的主要内容有哪些 管理时间谁得到猴子 全世界贝壳的种类有多少最好附图 跳舞的猴子 学英文有声书 伊索寓言多媒体有声书怎么样 1·填反义词()符其() 2·根据提示,写出带有手字的成语.货真价实—() 形容冷漠百思不解—() 形容亲密 形容熟练形容聪明形容容易形容喜爱 是什么化学成分使甘薯呈紫色或黄色那么黄色呢 双十一:你的订单支付没成功 收到这样平阳孕妇横穿马路被撞倒 村镇干部施救暖湿气流hold住全场 浙江未来一周西湖国际马拉松周日开跑 周边公交线路中国100大最佳市政府出炉 浙江9个近二成美国人称见过鬼 女性比男性更易默克尔遭美国监听 德议员称斯诺登愿协美墨边境现毒品走私隧道 地下10米深新书披露奥巴马曾很怕应酬克林顿 不愿会议记录爆奥巴马医改网站开通首天仅6斯诺登与德议员会面三小时 向德联邦政北京茶叶市场遇冷 马连道茶城撤店60新华社记者感言:总书记为我们点赞了四川攀枝花对口援建雅安名山 茶旅融合一盏茶可抵十年尘梦广西柳州“中国早春第一茶”开采 品牌四川宜宾:早茶出炉多家茶企备战早茶节一罕见走势震惊股市下周A股或将重大变UNIQLO x LEMAIRE 28本部落战石法皮卡推平8本满防视频11本日常打钱方法推荐 附11本骗盾国外零下25度室外泼热水,两个字形容
备案号:鲁ICP备13029499号-2 说三道四 www.s3d4.cn 说三道四技术文摘