Network and communication programming

Source: Internet
Author: User
Tags nameserver
Open a dial-up connection
Call the dialup program in the dial-up network to connect: the name of the dialup program created by 'connect Internet'
Winexec('rundll32.exe rnaui. dll, rnadial '+ 'connect to Internet', 9 );
A serial communication problem?
Serial Port Communications?
Question
I want to build a simple electrical controller which has es input from
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.
Answer:
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
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
Communication.
There is a 'But'. In D1 the port function was available but not supported ented. 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. cocould somebody indicate
Whether the port function still exist or what the alternative cocould be?
Regards,
Hans Brekelmans
Procedure setiicline (terminal: iicterminaltypes; high: Boolean );
VaR count: word;
Ctrladdress: word;
Begin {set IIC line}
Ctrladdress: = baseaddress + 2;
Case terminal
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
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;
Get the local IP address?
How about using winsockets?
This code is untested and uugly.
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.
Any dynamic change/Add the DNS address of TCP/IP in network settings
For example, you can add the DNS server address as 192.0.0.1 and 192.1.1.0:
Settcpipdnsaddresses ('2017. 0.0.1 192.1.1.0 ');
// Separate addresses with a space
1. settcpipdnsaddresses is defined as follows:
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. The savestringtoregistry_local_machine definition is as follows:
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;
In a program, how does one dynamically obtain the Working Group and computer names in Win95/98 network neighbors?
The following code may be helpful:
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}
The following Unit defines a component. tnetworkbrowser, which can enumerate all
In fact, it takes a long time to browse network resources.
Open "entire network" to compare. If you set the scope attribute to nscontext, you can see
The same machine list as that in the network neighbor.
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, nd1_admin, 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
Nsconnected: dwscope: = resource_connected;
Nsglobal: dwscope: = resource_globalnet;
Nsremembered: dwscope: = resource_remembered;
Nscontext: dwscope: = resource_context;
Else
Dwscope: = resource_globalnet;
End;
Case fresourcetype
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
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
Resourcetype_any: newitem. fresourcetype: = nrany;
Resourcetype_disk: newitem. fresourcetype: = nrdisk;
Resourcetype_print: newitem. fresourcetype: = nrprint;
Else
Newitem. fresourcetype: = nrany;
End;
Case nrarray [I]. dwdisplaytype
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_policadmin: newitem. fdisplay: =
Nd1_admin;
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.