这个问题把我愁死了,哪位不怕死的上来?(200分)

  • 主题发起人 主题发起人 110538
  • 开始时间 开始时间
1

110538

Unregistered / Unconfirmed
GUEST, unregistred user!
最近用MSCOMM控件编写一个PC机与PLC通讯的程序,这之间有个计算PLC控制电位的过程,但是程序在运行时总是跳过这一不,无法实现想要的功能,哪位高手可以解决,一定高分送上,程序的一段原代码如下:
unit againcomm;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, MSCommLib_TLB, StdCtrls;

type
TForm1 = class(TForm)
MSComm1: TMSComm;
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure MSComm1Comm(Sender: TObject);
procedure Edit5Change(Sender: TObject);
private
{ Private declarations }
NowPosition:integer;
pReadMW20To24:array [0..7]of byte;
pReadMW20To24Var:variant;
procedure ReadMW20To24(mw: Integer);
function caculatepos():integer;
public
a:integer;
caculatepos:Integer;
ReceiveData:array [0..6] of byte;
{ Public declarations }
end;

function CRC16(bData: array of Byte
bDataLen: Integer): Word
stdcall;
external 'CRC.dll' Name 'CRC16';

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
MSComm1.CommPort:=1;//串口初始化
MSComm1.Settings :='9600,n,8,2';
MSComm1.RThreshold:=1;
MSComm1.InputMode:=1;
MSComm1.PortOpen:= false
//comm口设置
MSComm1.InBufferCount:=0;
MSComm1.InputLen:=0;
MSComm1.OutBufferCount:=0;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
MSComm1.PortOpen:=true;
MSComm1.DTREnable:=true;
MSComm1.RTSEnable:=true;
Application.ProcessMessages;
ReadMW20To24(20);

Application.ProcessMessages;
//a:=caculatepos();
Edit2.Text:=IntToStr(a);
end;

procedure TForm1.ReadMW20To24(mw: Integer);
var CountCheck:Integer;
begin
pReadMW20To24[0]:=$01;
pReadMW20To24[1]:=$03;
pReadMW20To24[2]:=$00;
pReadMW20To24[3]:=mw;
pReadMW20To24[4]:=$00;
pReadMW20To24[5]:=$01;
pReadMW20To24[6]:=CRC16(pReadMW20To24,6)div 256;
pReadMW20To24[7]:=CRC16(pReadMW20To24,6)mod 256;
pReadMW20To24Var:=VarArrayCreate([0,7],varByte);
for CountCheck:=0 to 7 do
pReadMW20To24Var[CountCheck]:=pReadMW20To24[CountCheck];
MSComm1.InBufferCount:=0;
MSComm1.InputLen:=0;
MSComm1.OutBufferCount:=0;
MSComm1.Output:=pReadMW20To24Var;
end;

procedure TForm1.MSComm1Comm(Sender: TObject);
var
lengeh:integer;
ReceiveDataVar:Variant;
a:Integer;
//*DataVar:Variant;
j:integer;
begin
if MSComm1.CommEvent=ComEvReceive then
begin
//length:=MSComm1.InBufferCount
//if length=7 then begin //读PLC得到的回复,回来7个数字
ReceiveDataVar:=VarArrayCreate([0,6],varByte);
ReceiveDataVar:= MSComm1.input;
MSComm1.InBufferCount:=0;
for j:=0 to 6 do
ReceiveData[j]:=ReceiveDataVar[j];
a:=ReceiveData[3]*256+ReceiveData[4]
//Edit1.Text:=IntToStr(a);
//end;// end if 是读数据
end;
end;


function TForm1.caculatepos(data:array of byte): integer;

begin
//data:=ReceiveData;
caculatepos:=ReceiveData[3]*256+ReceiveData[4];
end;

end.
 
我是不怕死,可是我不会做,我主要做的是ERP
 
没做过,不过你分步调试看看
 
我以前做过,可是你得分给得太少
 
分步调试也不行,给200分我已经倾家荡产了!
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
683
import
I
I
回复
0
查看
679
import
I
后退
顶部