发送一个文件从pc端到mcu端,文件要按块发送。发送时,pc先发送一个握手指令,然后等待mcu端发送一个应答指令。不知道应该怎么做,谢谢!
解决方案 »
- DBChart所绑定的TClientDataset类型数据集变化后,DBChart如何更新
- 在delphi2007上装 EhLib 时出错:E2202 Required package 'rtl' not found,如何解决???
- 如何修改某个主键字段里面的值???
- 高手!这是不是不好办呀!
- actionmanager控件不会用,谁可提供一个实例教材?
- 请进来聊聊,关于第三方控件的安装方法。。。
- 关于flash控件,怎么样来封装这个控件到exe里面呢?
- 《Delphi技巧精选实例集》这书好不好?
- Directive Static, Register, abstract, virtual
- 怎样返回指定隐藏文件的句柄?
- 动态创建Tchart控件问题,高手请进!
- 怎样将TMemoryStream 每64个字节读入到byte数组里面 ,然后按包传输。
我用的是spcomm,但是不知道应该怎么做。你能否放个例子上来阿?非常感谢!
TRecData=record
comm:byte;
len:integer;
data:array[0..255]of byte;
end;
然后定义两个全局变量
recData:TRecData; //收到的数据
sendData:TRecData;//待发送的数据比如说发送握手命令的过程commSendStatus是这样写的:
procedure tform1.commSendStatus;
begin
sendData.comm:=$60;
sendData.len:=0;
self.commSend;
end;然后就是commSend过程了,这样写的:
procedure tform1.commSend;
var
CRC:byte;
i:integer;
s:string;
begin
comm1.SendByte($ff);
comm1.SendByte($ff);
comm1.SendByte($ff);
CRC:=$81;
comm1.SendByte($81);
CRC:=CRC+sendData.comm;
comm1.SendByte(sendData.comm);
CRC:=CRC+sendData.len;
comm1.SendByte(sendData.len);
comm1.SendData(@sendData.data[0],sendData.len);
for i:=0 to sendData.len-1 do
CRC:=CRC+sendData.data[i];
comm1.SendByte(-CRC);
RichEdit1.SelAttributes.Color:=clBlue;
if sendData.Len=0 then
RichEdit1.Lines.Add(trans(msgIndex)+': Send: Command='+intToHexFormat(sendData.comm)+' Len='+intToStr(sendData.Len)+'('+FormatDateTime('tt', now)+')')
else
begin
s:='';
for i:=0 to sendData.len-1 do
if (sendData.comm=2) or (sendData.comm=4) or (sendData.comm=10) then
s:=s+intToHex(sendData.data[i],2)
else
s:=s+intToStr(sendData.data[i]);
RichEdit1.Lines.Add(trans(msgIndex)+': Send: Command='+intToHexFormat(sendData.comm)+' Data='+s+' Len='+intToStr(sendData.Len)+'('+FormatDateTime('tt', now)+')');
end;
end;仅供参考吧,commSend过程是自定义的协议,所以比较乱,发送一个字节是用comm1.SendByte