我要发送0xaa+0x55+'O'+'N'+0xff+0xff+后四项求和取反
请问要怎么些代码啊?
mscomm1.output:=0xaa+0x55+'O'+'N'+0xff+0xff+('O'+'N'+0xff+0xff xor $FFFFFFFF)不对啊 怎么修改 谢谢
怎么发送16进制数据呢?只能转化为10进制再发吗?
delphi中用串口发送16进制数据问题
答案:2 悬赏:80 手机版
解决时间 2021-03-11 08:53
- 提问者网友:咪咪
- 2021-03-10 19:01
最佳答案
- 五星知识达人网友:往事隔山水
- 2021-03-10 19:36
明确告诉你 取反 用 not
procedure TForm4.btn1Click(Sender: TObject);
var
a:Byte;
begin
a:=255;//a 11111111
ShowMessageFmt('%D',[not a]);//0
end;
not (ord('N')+ord('O')+255+255)应该这样吧
procedure TForm4.btn1Click(Sender: TObject);
var
a:Byte;
begin
a:=255;//a 11111111
ShowMessageFmt('%D',[not a]);//0
end;
not (ord('N')+ord('O')+255+255)应该这样吧
全部回答
- 1楼网友:思契十里
- 2021-03-10 20:22
实例:apddatapacket的onpacket(16进制收发)或onstringpacket(字符串收发)过程 pc和数据采集器通信,收发数据为16进制实例代码:(里面的steam没有用到,没有删除而已)
unit rs485_hex;
interface
uses
winapi.windows, winapi.messages, system.sysutils, system.variants,
system.classes, vcl.graphics,
vcl.controls, vcl.forms, vcl.dialogs, oomisc, adport, vcl.stdctrls, adpacket,
spcomm;
type
tform1 = class(tform)
memo1: tmemo;
button1: tbutton;
button2: tbutton;
edit1: tedit;
apdcomport1: tapdcomport;
apddatapacket1: tapddatapacket;
procedure button1click(sender: tobject);
procedure formcreate(sender: tobject);
procedure onreceivedata(sender: tobject; buffer: pointer;
bufferlength: word);
procedure senddata(myarray: array of byte);
procedure comm1modemstatechange(sender: tobject; modemevent: cardinal);
procedure formdestroy(sender: tobject);
procedure apddatapacket1packet(sender: tobject; data: pointer;
size: integer);
private
{ private declarations }
public
{ public declarations }
end;
var
form1: tform1;
senstream: tstream; // 一个流对象
revstream: tstream;
msg: array of byte; // 发送
rbuf: array of byte;
viewstring: string;
implementation
{$r *.dfm}
procedure tform1.apddatapacket1packet(sender: tobject; data: pointer;
size: integer);
var
i,k:integer;
pointtodata:pbyte;
str:string;
begin
memo1.lines.add('apddatapacket1packet '+ '数据大小为:'+ inttostr(size));
pointtodata:=pbyte(data);
for k := 0 to size-1 do
str := str + inttohex(pointtodata[k], 2) + ' ';
memo1.lines.add(str) ;
end;
procedure tform1.button1click(sender: tobject);
var
msg1: array of byte;
revmsg: array [0 .. 7] of byte;
mymsg, sendmsg: string;
i,j: integer;
begin
setlength(msg1, 8);
msg1[0] := $01;
msg1[1] := $04;
msg1[2] := $00;
msg1[3] := $42;
msg1[4] := $00;
msg1[5] := $01;
msg1[6] := $91;
msg1[7] := $de;
revmsg[0]:=$01; //接收到的数据的帧头
revmsg[1]:=$04;
revmsg[2]:=$02;
apddatapacket1.startstring:= strpas(pansichar(@revmsg[0])); //收到数据的帧头
apddatapacket1.packetsize:=7; //数据的大小
apddatapacket1.enabled:=true;
for i := 0 to 7 do
begin
apdcomport1.putchar(ansichar(msg1[i]));
end;
//apdcomport1.open:=false;
/// memo1.lines.add(inttostr(comm1.getmodemstate));
// 01 04 00 42 00 01 91 de
// self.senddata(msg);
end;
procedure tform1.onreceivedata(sender: tobject; buffer: pointer;
bufferlength: word);
var
k: integer;
begin
showmessage('收到数据');
viewstring := '';
setlength(rbuf, bufferlength);
move(buffer^, pchar(rbuf)^, bufferlength);
for k := 0 to bufferlength do
viewstring := viewstring + inttohex(rbuf[k], 2) + ' ';
viewstring := '接收' + viewstring;
memo1.lines.add(viewstring);
memo1.lines.add(' ');
end;
procedure tform1.comm1modemstatechange(sender: tobject; modemevent: cardinal);
begin
memo1.lines.add(inttostr(modemevent));
end;
procedure tform1.formcreate(sender: tobject);
begin
// comm1.startcomm;
apdcomport1.open:=true;
end;
procedure tform1.formdestroy(sender: tobject);
begin
apdcomport1.open:=false;
end;
procedure tform1.senddata(myarray: array of byte);
var
j: integer;
commflag: boolean;
begin
viewstring := '';
commflag := true;
viewstring := '发送' + viewstring;
form1.memo1.lines.add(viewstring);
form1.memo1.lines.add(' ');
if not commflag then
messagedlg('发送失败', mterror, [mbyes], 0);
end;
end.
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯