delphi mscomm串口通讯485乱码

下面是我发送命令的button代码。在232通讯时不会乱码,而485,只接收来自下位机的数据,不发送命令时,也不会乱码。只要一点发送 发送某个命令时,上位机接收的数据就会产生一些乱码,比如?等,是咋回事?
varlen:integer;i,count,maxcount,tmpint:integer;tmpvar:variant;tmpstr,output:string;beginif not mscomm1.PortOpen thenbeginshowmessage('串口没有打开!');exit;endelsebeginif length(memo2.Text)=0 then //输入内容是空时begincheckbox4.Checked:=false;ShowMessage('请输入要发送的内容!');end //发送二进制数,需要使用variant变量矩阵,矩阵大小自动调节else if hexsend thenbeginlen:=0;count:=1;maxcount:=1;output:=memo2.Text;len:=length(output);if len>0 thenbegini:=1;//创建一个variant数组tmpvar:=vararraycreate([1,1],varbyte);while (i<len) dobegin//每3个字符串中截取2个字符,转换为十六进制tmpstr:=copy(output,i,2);tmpstr:=Trimall(tmpstr);tmpstr:=lowercase(tmpstr);tmpint:=hextoint(tmpstr);if tmpint=-1 thenbeginshowmessage('发送的数据格式有问题!');break;endelsebeginif count=maxcount+1 thenbegin Inc(MaxCount); //增大Variant数组VarArrayRedim(tmpvar, MaxCount); //Resizes a Variant Arrayend;tmpvar[count]:=tmpint;inc(count);end;i:=i+2;end;mscomm1.Output:=tmpvar;end;endelsebeginoutput:=memo2.Text;MSComm1.Output:=Output;end;len:=length(memo2.Text);end;txnum:=txnum+len;StatusBar1.Panels[2].Text:='发送(TX):'+ inttostr(txnum)+' '+'bytes';end;//
你发送的时候要选择内容发送格式为二进制,你现在这种写法是错误的,
首先确保硬件连接没有问题,用 串口调试工具验证

再测试程序