手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>程序设计>delphi>列表

网络和通讯编程

来源:互联网 作者:西部数码 时间:2008-04-09
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!
打开拨号连接   调用拨号网络里的拨号程序来连接:其中''''连接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;

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!