急需delphi关于plc串口通讯的程序!!(200分)

  • 主题发起人 主题发起人 dreamsea
  • 开始时间 开始时间
D

dreamsea

Unregistered / Unconfirmed
GUEST, unregistred user!
由于编程需要,急需串口通讯的读写信息程序!!
请个为大虾指导!!
谢谢!!
 
我也需要,请mail to
sheepish@china.com
thanx
 
我也正在做关于PLC编程的,当PLC接受信息成功后,怎么取得返回信息呢?
请各位大虾指点啊,问题相当的急!
 
使用时只要将PORT95.PAS加到工程文件中,并在users中加上Port
95,就可以在应用程序中直接对I/O端口进行操作。
具体的实现方法及PORT95.PAS的源代码如下:
unit Port95;
interface
function PortReadByte(Addr:Word) : Byte;
function PortReadWord(Addr:Word) : Word;
function PortReadWordLS(Addr:Word) : Word;
procedure PortWriteByte(Addr:Word; Value:Byte);
procedure PortWriteWord(Addr:Word; Value:Word);
procedure PortWriteWordLS(Addr:Word; Value:Word);
implementation
{*
* Port Read byte function
*Parameter:port address
*Return: byte value from given port
*}
function PortReadByte(Addr:Word) : Byte; assembler; regi
ster;
asm
MOV DX,AX
IN AL,DX
end;
{*
* HIGH SPEED Port Read Word function
* Parameter: port address
* Return: word value from given port
* Comment:may problem with some cards and computers that
can't to access whole word, usualy it works.
*}
function PortReadWord(Addr:Word) : Word; assembler; regi
ster;
asm
MOV DX,AX
IN AX,DX
end;
{*
* LOW SPEED Port Read Word function
* Parameter: port address
*Return:word value from given port
*Comment:work in cases,only to adjust DELAY if need
*}
function PortReadWordLS(Addr:Word) : Word; assembler; re
gister;
const
Delay = 150;
// depending of CPU speed and cards speed
asm
MOV DX,AX
IN AL,DX
//read LSB port
MOV ECX,Delay
@1:
LOOP @1 //delay between two reads
XCHG AH,AL
INC DX
//port+1
IN AL,DX //read MSB port
XCHG AH,AL //restore bytes order
end;
{* Port Write byte function*}
procedure PortWriteByte(Addr:Word; Value:Byte); assemble
r; register;
asm
XCHG AX,DX
OUT DX,AL
end;
{*
* HIGH SPEED Port Write word procedure
* Comment:may problem with some cards and computers that
can't to access whole word, usualy it works.
*}
procedure PortWriteWord(Addr:word; Value:word); assemble
r; register;
asm
XCHG AX,DX
OUT DX,AX
end;
{*
* LOW SPEED Port Write Word procedure
*}
procedure PortWriteWordLS(Addr:word; Value:word); assemb
ler; register;
const
Delay = 150;
// depending of CPU speed and cards speed
asm
XCHG AX,DX
OUT DX,AL
MOV ECX,Delay
@1:
LOOP@1
XCHG AH,AL
INC DX
OUT DX,AL
end;
end. //单元结束
 

to sw

能否详细解析一下你举出的 port95.

现须通过串口项一单板机发送数据,2400k 波特率,8个数据位,

1个起始位,1个停止位,1个效验位,用port95如何实现 ?

 
spcomm32完全可以实现这些功能!
http://vcl.vclxx.com/DELPHI/D32FREE/SPCOMM.ZIP
delphi中最好的串口控件
 
PLC支持netDDE的
你当然也可以用串口直接操作,不过要注意通信协议
 
给我一份
ao.li2000@263.net
 
多人接受答案了。
 
后退
顶部