富翁们能否提供有关串口通讯和位操作的资料呢?(100分)

  • 主题发起人 主题发起人 Zhejiang_Knight
  • 开始时间 开始时间
Z

Zhejiang_Knight

Unregistered / Unconfirmed
GUEST, unregistred user!
俺的E文不行,不要给我E文资料.大家帮帮忙.
 
Operator Operation Operand types Result type 中文
not bitwise negation integer integer not X 按位取反
and bitwise and integer integer X and Y 按位与
or bitwise or integer integer X or Y 按位或
xor bitwise xor integer integer X xor Y 按位异或
shl bitwise shift left integer integer X shl 2 左移
shr bitwise shift right integer integer Y shl I 右移

串口可用控件
 
就这么点?
我希望再多一点,指点一下哪里有电子书可以下?
不过还是要谢你
 
》位操作
const
bits:array[0..7] of integer=(1,2,4,8,16,32,64,128);
implementation
function testbit(abit:integer;abyte:byte):boolean;
BEGIN
result:=((bits[abit] and abyte)=bits[abit]);
END;
function setbit_1(abit:integer;abyte:byte):byte;
BEGIN
result:=abyte or bits[abit];
END;
function setbit_0(abit:integer;abyte:byte):byte;
BEGIN
result:=abyte;
if testbit(abit,abyte) then result:=abyte-bits[abit];
END;
。。。。。。


FOR EXAMPLE:
procedure TForm1.Button1Click(Sender: TObject);
var
abyte:byte;
begin
abyte:=0;
abyte:=setbit_1(0,abyte); //bit0置1
showmessage(inttohex(abyte,2));
if testbit(0,abyte) then showmessage('true');
abyte:=setbit_0(0,abyte); //bit0置0
showmessage(inttohex(abyte,2));
if not testbit(0,abyte) then showmessage('false');
end;

》串口通讯
串口用mscomm,spcomm,comport.....,推荐用comport,个人认为最好,google搜索下载有例子
 
的到当前可使用的端口
procedure TJeffsForm.GetAvailableComPorts();
var
i : Integer;
S : String;
ComName: array[0..9] of Char;
TheComHandle: Integer;

begin

(*
** Okay, Clear everything in the PortsComboBox because
** we want to start off fresh.
*)

PortsComboBox.Clear();

(*
** Windows 95/98 can only handle up to 50 COM ports.
** All we are doing here is checking to see if Windows
** "can" open up the COM port. If so, then we know it's
** available. And so we add it to our ComboBox list
** and of course close the COM port each time we check it.
*)

for i := 1 to 50 do begin

StrFmt( ComName, '//./COM%d', );

TheComHandle := CreateFile
(
ComName, // name
GENERIC_READ or GENERIC_WRITE, // access attributes
0, // no sharing
nil, // no security
OPEN_EXISTING, // creation action
FILE_ATTRIBUTE_NORMAL or
FILE_FLAG_OVERLAPPED, // attributes
0 // no template
);

if ( TheComHandle <> INVALID_HANDLE_VALUE ) then begin

S := Format('COM%d', );
PortsComboBox.Items.Add(S);

end;

CloseHandle( TheComHandle );

end; {end of for loop}

end;

 
多人接受答案了。
 

Similar threads

回复
0
查看
1K
不得闲
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
647
import
I
后退
顶部