百分大赠送!在NT里做串口通信(100分)

  • 主题发起人 主题发起人 redzhong
  • 开始时间 开始时间
R

redzhong

Unregistered / Unconfirmed
GUEST, unregistred user!
兄弟我近日来在NT里做串口通信,可是怎么也调不通,WriteFile老是返回FALSE
而我把程序放到WIN98里就可以。我猜想是NT里头还要设置权限,但却不知如何做,
请各位大哥教教小第。
 
是不是嫌分少?
如果今天能解决它,我还可以再加100分,不能的话我只能delete了
 
用 Tserversocket ,TClientsocket
相当好用
unit serv;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ScktComp;

type
TForm1 = class(TForm)
ServerSocket1: TServerSocket;
Memo_receive: TMemo;
procedure ServerSocket1ClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
st : TMemoryStream;
implementation

{$R *.DFM}

procedure TForm1.ServerSocket1ClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
memo_receive.Lines.Add(socket.RemoteHost+':'+ socket.RemoteAddress );
end;

procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
Fullscreen : Tbitmap;
FullscreenCanvas : TCanvas;
dc : HDC;

begin
{ Fullscreen := TBitmap.Create; // create a bimap to save picture
Fullscreen.Width := 100;
Fullscreen.Height := 100;

DC := GetDC (0); // get screen dc

FullscreenCanvas := TCanvas.Create; //create screen canvas
FullscreenCanvas.Handle := DC;

Fullscreen.Canvas.CopyRect (Rect (0, 0, 100,100), fullscreenCanvas,
Rect (0, 0, Screen.Width, Screen.Height));
FullscreenCanvas.Free; //free screen canvasReleaseDC (0, DC);
Fullscreen.SaveToStream(st);
socket.SendStreamthendrop(st);}
memo_receive.Lines.Add(socket.ReceiveText);
socket.SendText('heofdjs');

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
st := TMemoryStream.create;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
st.Destroy;
end;

end.

unit serv;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ScktComp;

type
TForm1 = class(TForm)
ServerSocket1: TServerSocket;
Memo_receive: TMemo;
procedure ServerSocket1ClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
st : TMemoryStream;
implementation

{$R *.DFM}

procedure TForm1.ServerSocket1ClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
memo_receive.Lines.Add(socket.RemoteHost+':'+ socket.RemoteAddress );
end;

procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
Fullscreen : Tbitmap;
FullscreenCanvas : TCanvas;
dc : HDC;

begin
{ Fullscreen := TBitmap.Create; // create a bimap to save picture
Fullscreen.Width := 100;
Fullscreen.Height := 100;

DC := GetDC (0); // get screen dc

FullscreenCanvas := TCanvas.Create; //create screen canvas
FullscreenCanvas.Handle := DC;

Fullscreen.Canvas.CopyRect (Rect (0, 0, 100,100), fullscreenCanvas,
Rect (0, 0, Screen.Width, Screen.Height));
FullscreenCanvas.Free; //free screen canvasReleaseDC (0, DC);
Fullscreen.SaveToStream(st);
socket.SendStreamthendrop(st);}
memo_receive.Lines.Add(socket.ReceiveText);
socket.SendText('heofdjs');

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
st := TMemoryStream.create;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
st.Destroy;
end;

end.
可以传输图像
做的深一点,可以远程控制
 
有没搞错,人家是要做串口通讯。
建议用spcomm控件试试,我用它做过NT下的串口通讯程序,没碰到什么问题。
 
to urus : 用API
to 小黄鱼 :我这有一个完整的远程抓屏程序,你要不要
 
Redzhong: 在NT下读写串口没问题,与权限关系不大。
把你包含CreateFile 和ReadFile、WriteFile函数的代码贴出来。
 
我想可能NT里不能用同步I/O方式读写串口,异步大概可以.jianyiquan大哥,其实我真的很
希望您说错了,因为................我的硬盘刚第N+1次分区!!!
以下是程序
......
outbuffer:Array[0..128] of char Absolute outstr;
.......
hcom:=CreateFile('com1',generic_read or generic_write,0,nil,open_existing,
file_flag_overlapped,0);// 试 打 开 串 行 口 1
.......
function WriteOrder(OrderStr:String):Boolean;
begin
outstr:=OrderStr;
TimeOut.WriteTotalTimeoutMultiplier:=5;
TimeOut.WriteTotalTimeoutConstant:=10;
SetCommTimeOuts(hcom,TimeOut);
//就是这一行在NT里不通,98里可以
//改成异步I/O方式不知行不行
if WriteFile(hcom,outbuffer,strlen(Pchar(outstr)),nBytesWrite,NIL) then
begin
PurgeComm(hcom,PURGE_TXCLEAR);
WriteOrder:=True;
end
else
Result:=False;
end;
 
有那位大虾能提供一份在NT里调通的程序,100分立马送上。
 
请到<a href=http://avsuper.126.com>http://avsuper.126.com</a>下载MyComm,我编写的,在98/NT/2000下都没有问题.
有演示程序! 程序极其简单!!!!
 
to caowei
老兄,你的网站上不了呀,
 
http://avsuper.126.com/ 上不了的。。。。
为什么 redzhong 老兄昨晚看了没有反映?还“谢谢”的?。。。。。
难道是你能上去?!!!%#^%@%@
 
上去了,先看了,是不是只能过8:30才能上?
 
去用ComPort这个控件吧,我用它跟底层单片机通讯。很好用
,可以发各种数据类型。
在www.inprises.com上有这个控件.
 
后退
顶部