delphi7.0 spcomm3.0 向串口‘发送’和‘接收’字符串

来源:百度知道 编辑:UC知道 时间:2024/05/31 11:44:45
下面是我程序的所有代码 希望大家帮我看看
我现在进行程序调试是 我的电脑和另一天电脑的串口相连
我们两个通过‘超级终端’可以相互连接收发数据都能正常实现

然后用我的程序只能接受另一天电脑发送出来的数据 ,不能像另一台电脑发送数据

希望大家帮我找出 不能发送的原因!
private
{ Private declarations }
public
{ Public declarations }
end;

var
main_from : Tmain_from;
viewstring : string;
i : integer;
rbuf,sbuf : array of byte;

implementation

{$R *.dfm}

procedure Tmain_from.Button17Click(Sender: TObject);

begin

if length(combobox4.text)=0 then exit;
if length(combobox5.text)=0 then exit;
if length(combobox6.text)=0 then exit;
if length(combobox7.text)=0 then exit;

if (button17.Caption='连 接') then
begin
//串口号
comm.CommName:=ComboBox4.Text;
//波特率
comm.BaudRate:=strtoint(ComboBox5.Text);

你的spcomm3.0控件问题!
你重新换下载一个spcomm控件
就可以了!

有时候牵涉到硬件部分的编程,时序很重要.这种情况多半sleep一下就可以了.
可以理解为"给点时间让硬件思考一下"

sleep(1000)
if Comm.WriteCommData(str, Count) then
memo1.Lines.Add(str)
else
memo1.Lines.Add('数据发送错误!')