MSCOMM怎么发送16进制的数据啊??

yuechuan 2005-09-22 11:26:44
设有如下数据:
02 03 00 0A 00 01 A4 3B

如果使用下面的方法
Var S:string;
S:=#2+#3+#0+#$0A+#0+#1+#$A4+#$3B;
MSComm1.Output := S;

则MSCOMM在发送的时候会将数据按照widestring的来处理,导致最后 A4 3B 这2个字节被合并成3F

请问怎么样才能按原样发送呢?

在线等~
...全文
880 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
daidai_____DD 2005-10-17
  • 打赏
  • 举报
回复
晕倒,串口发送数据为什么不用数组来发?
yuechuan 2005-09-22
  • 打赏
  • 举报
回复
自己搞定了。。累啊。。用了一上午。。不过接受的问题还是不行。。

var
temp:Variant;

begin
temp := VarArrayCreate([0, 7], varbyte);

temp[0]:=2;
temp[1]:=3;
temp[2]:=0;
temp[3]:=$0D;
temp[4]:=0;
temp[5]:=1;
temp[6]:=$15;
temp[7]:=$FA ;

MSComm1.Output := temp;
abc3000 2005-09-22
  • 打赏
  • 举报
回复
setlenth(mByteAry,8); 写错了
abc3000 2005-09-22
  • 打赏
  • 举报
回复
var
mByteAry: array of byte;
begin
setlenth(mByteAry,7);
mByteAry[0]:=$02;
mByteAry[1]:=$03;
mByteAry[2]:=$00;
mByteAry[3]:=$0a;
mByteAry[4]:=$00;
mByteAry[5]:=$01;
mByteAry[6]:=$a4;
mByteAry[7]:=$3b;

mscomm.output:=mByteAry;
yuechuan 2005-09-22
  • 打赏
  • 举报
回复
加上chr以后呢?
MSCOMM的Output 是OLEVariant 类型
Delphi的帮助中写道
When you assign a Variant that contains custom data (such as a Delphi string, or a one of the new custom variant types) to an OleVariant, the runtime library tries to convert the Variant into one of the OleVariant standard data types (such as a Delphi string converts to an OLE BSTR string). For example, if a variant containing an AnsiString is assigned to an OleVariant, the AnsiString becomes a WideString.

所以我原来的办法是不对的,但是想不出其他的办法
yuechuan 2005-09-22
  • 打赏
  • 举报
回复
怎么试?参数类型,数量都不一样的
winstonbonaparte 2005-09-22
  • 打赏
  • 举报
回复
02 03 00 0A 00 01 A4 3B
加个CHR,
如chr(02)
abc3000 2005-09-22
  • 打赏
  • 举报
回复
试过没?试过再说
yuechuan 2005-09-22
  • 打赏
  • 举报
回复
不对的,那个帖子是SPCOMM的~和MSCOMM不一样
abc3000 2005-09-22
  • 打赏
  • 举报
回复
试试看,行不行
abc3000 2005-09-22
  • 打赏
  • 举报
回复
http://community.csdn.net/Expert/topic/4279/4279030.xml?temp=.6661646

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧