我在使用这个控件时发现,当发送的字符少于8个字节时,它能一次接收,当超过
8个字节时,他会分成几次接收[事件RxChar()],每次8个字节。
我现在想问的问题是:怎样才能一次收完所有的数据,不要这样一次8个字节的
接收。第2个问题:有什么加密算法可以加密/解密Char(0)这种空字符?我的数据中包含
           有空字符。第3个问题:delphi编写dll怎样才能传送包含有空字符的串给pb程序,和pb怎样传
           这样的数据给dll

解决方案 »

  1.   

    这个控件不是可以自定义Packet吗?你自己定义一下,就很容易控制了,当然你的数据包需要有一定的规范,要能够定义,这个控件可以定义定长和不定长的包。2、3没有经验。
      

  2.   

    >>第3个问题:delphi编写dll怎样才能传送包含有空字符的串给pb程序,和pb怎样传
    >>           这样的数据给dll
    用 byte 數組, 不要用字符串
      

  3.   

    但是在pb中函数的参数不能是数组
    这样写会报错
    function Integer getdata(ref char buf[100])
    或者
    function Integer getdata(ref char buf[])
    function Integer getdata(char buf[100])
    function Integer getdata(char buf[])
    都会报错,不知道该怎么做?
      

  4.   

    第一个问题我是这样处理的,参考一下!
    var
      sRxStr, {卡机接收的字符串}procedure TfrmMain.ComPortRxChar(Sender: TObject; Count: Integer);
    var
      sTempStr: string;
      iRxStrLen: integer;
    begin
      iRxStrLen := 12; //每次发送的字符长度
      Application.ProcessMessages;
      ComPort.ReadStr(sTempStr, Count);
      sRxStr := sRxStr + sTempStr;
      //卡机的长度符合才抓进来
      if (Length(sRxStr)) = (iRxStrLen) then
      begin
      
      end
      else
        //每次撷取的长度会不一样,所以要判断 sRxStr (全域变量)的长度一但超过总长度,就要将sRxStr清空
        //否则将永远不会进入到 if (Length(sRxStr)) = (iRxStrLen) then 这个判断式内
        if (Length(sRxStr)) > (iRxStrLen) then
          sRxStr := '';
    end;