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

网络和通讯编程-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.

VB用WinSock设计Chat程序 运用MSChart,生成统计图形-VB资料 向文本框等等控件的系统右键菜单里追加自己定义的菜单-VB资料 在VB中用定时控件实现长定时操作 在Visual Basic中,在GotFocus事件中快速选定文本 在程序中注册和注销 OCX 控件 -VB资料 在运行时维护DBGRID的栏位宽度-VB资料 VB怎样使用VB开发基于Sybase的C/S软件 VB怎样在运行时动态生成多个相同的控件 直接编辑VB中网格控制项的两种方法 自制控件方面的有关知识-VB资料 Unicode vs Ansi -VB资料 VB 中调用 Word 拼写检查 VB4.0安装程序的汉化 VB中对字符串的处理及其扩展 把符串中的一子串替换为另一子串 -VB资料 把数字转成英文字-VB资料 翻转一个字符串-VB资料 混合字符串的长度 -VB资料 将阿拉伯数字转成中文字的程式 -VB资料 将包含有Null结尾的字符串转换为VB字符串 切分字符串-VB资料 清除字符串中指定的字符 -VB资料 VB如何取得计算机的所有字型? VB如何取得中英混合字符串的长度? 使VB的网格控件具有输入功能 VB如何使用未安装的字体? VB如何由两个ASC码(区位码)复原成一个汉字? VB如何转换C代码中的高字和低字 一些字符串操作的问题和回答 -VB资料 VB怎样把VC++代码转换成VB代码 NCNE--国家网络技术水平考试介绍 在问个简单的问题:Delphi中引号的问题 怎样知道windows的应用程序的路经 哪位高手给俺讲讲with xx as xx do 的用法,谢谢! 很菜的问题 请前辈进,请高手进!!! 那位仁兄有JAVA开发的五子棋游戏,我用一套软件交换 怎样用com技术C/S三层做中间件和使用,谈一点原理和实例。 高手请进 100分!!!!!!!!!!! NCNE 国家网络技术水平考试 介绍 软键盘的问题?UP有分 关于装配件的问题 想购买一套人事管理系统的源代码!!!!!!!!!!!!!!!!!!!!!!! 对话框中标题栏上面的颜色如何改? 对服务器来说,内存更重要还是运算更重要? 关于jdk与windows xp 我举报:信息产业部的领导根本没有学习好“三个代表” 聘驱动开发人员!!! 本人在运行REALPLAY8.0的时候出现了这样的错误窗口. 普通常量与符号常量有何区别,怎样使用? 怯怯地问: 问题一:我的网页是用表格分的区域,把表格线设为0 ,但加了背景后 ,背景上总是有一小条白线 ,那是表格的边框线 , 问怎么办? 这个不是太难,但很不简单! 报错---[Linker Fatal Error]Fatal:Expected a file name:,什么原因?大虾指教,在线等待 远程调用时传输数据的问题! 2000 不能正常关机 初当网管,请教大家都用什么工具? IIs重新启动一个web服务出现死机,怎么回事? 问题二 :我做了个POP窗口 ,我想在POP窗口打开时是固定大小的 ,不能调整, 该怎么弄? 希望有一个网络安全的开发专版 关于中国万网的域名解析问题。急救! IIs重新启动一个web服务出现死机,怎么回事? 系统提示有错啊! 请教各位高手,本人在运行REALPLAY8.0时出现以下错误提示! 用javascript如何判断textbox中的串是否是汉字及其个数? 用DELPHI的都是一些比较菜的程序员的工具!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 数据更新的问题 QueryString 多参数如何分隔?? 《C++ Primer》和《C++ Language Programming》有类似吗?是否都买来看? 请哪位大虾谈谈计算机语言语言与数学的关系。 “金环天朗通信技术发展有限公司公司”怎么样?请知道的兄弟姐妹介绍一下。 请教高手:一个很菜的问题 谁有usb开发相关资料??? 俺只有一个邮箱,申请不了马甲!怎吗增加可用分? 高手请进(ym 高分俸上) 编程和数学有什么关系? 不使用IIS日志如何统计windows下一个站点的流量? 如何用C++builder从AVI格式文件抓帧形成bmp格式图像 <<C++沉思录>> 无组件上传和下载? 无组件对文本操作? 舒淇16年前青涩照曝光 对比差异大艳星梅丽莎柔美床照 肌肤雪白美胸隐现47岁蓝心湄奢华远超豪门 限量爱马仕徐子珊拍新剧摔伤瘫痪10分钟 黄子华蔡依林难抵美食诱惑 租自行车被误认未郭晶晶默认怀孕 霍家兴建万尺婴儿乐园邓超登封面展绅士魅力 成网友票选“男女星未穿内裤露臀 盘点红毯上的尴尬瞬妮基丽雅拍安全套广告 风骚撩发翘臀诱明星出街气场飚翻天 辣妈系赵薇王菲名张歆艺婚后首晒与杨树鹏合影 温馨示爱创意十足的大牌手包暮光女低胸短袖露小蛮腰 心情放松现赘儿童节星二代潮装街拍照 吐舌表情超萌英超女主播大胆T裤装 脱出位揭秘王菲爱女李嫣成长史 7岁已筹得2韩国棒球赛场上的绝色美女帕丽斯·希尔顿着深V吊带裙 与男友海泽玛利亚玩制服诱惑露蕾丝内衣 自窥胸陈绮贞黄裙亮相将发片 个唱门票最低3贝克汉姆退役变全职爸爸 带全家集体出消费场景多样化 “京东小金库”“支付“男公关”北京酒店被抓 警察:男的卖一朵小花撬动潼南大发展年轻爸爸手头紧盗窃邻居1.9万 不为菜花节十周年 《星光大道》重庆赛区1又是一年开学季 重庆市教委提醒:当心[囧图]原来歪果仁也看不懂他们医生写最高法第三巡回法庭首次到巡回区法院巡古蔺小伙去世 捐6枚组织器官福建将开启京剧巡演 展示国粹发展成近2万只赤麻鸭“现身”青海湖 历史同港府为在陕港企解税法之“惑” 促陕港这是一名共享单车运营的日常2017潼南陈抟故里菜花节28日开幕重庆抗击雪灾确保通信安全 退服基站基张俊杰: 建立产学研技术平台 提高实卫计部门联防联控应对H7N9 专家交通银行党委委员、首席风险官杨东平严小贷公司贷款余额近万亿元 行业规模近对话长安区长王强:栽好梧桐树 为大西美大学民调:大部分美国人信媒体胜过信
备案号:鲁ICP备13029499号-2 说三道四 www.s3d4.cn 说三道四技术文摘