+ -
当前位置:首页 → 问答吧 → 用delphi7写的程序 要使用串口 软件打开不报错但是在软件里面串口显示无法打开

用delphi7写的程序 要使用串口 软件打开不报错但是在软件里面串口显示无法打开

时间:2011-09-23

来源:互联网

用delphi7写的程序 要使用串口 软件打开不报错但是在软件里面串口显示无法打开 自己用串口调试工具调试串口没有问题需求解决方法,谢谢!

作者: kuby6275   发布时间: 2011-09-23

贴原码。。。

作者: babydog01   发布时间: 2011-09-23

参数设正确没有,还有是不是串口给占用了。

作者: jyb_9   发布时间: 2011-09-23

引用 1 楼 babydog01 的回复:

贴原码。。。


{初始化串口}
procedure TDataGatherForm.InitComm(Comm: TComm; CommName:String; iBaudRate:Integer;
  asByteSize:String; asParity:String; asStopBits:String);
begin
  Comm.CommName := CommName;
  Comm.BaudRate := iBaudRate;

  if asByteSize='8' then
  Comm.ByteSize := TByteSize(_8)
  else if asByteSize='7' then
  Comm.ByteSize := TByteSize(_7)
  else if asByteSize='6' then
  Comm.ByteSize := TByteSize(_6)
  else if asByteSize='5' then
  Comm.ByteSize := TByteSize(_5);

  if asParity='N' then
  Comm.Parity := TParity(None)
  else if asParity='O' then
  Comm.Parity := TParity(Odd)
  else if asParity='E' then
  Comm.Parity := TParity(Even);

if asParity='N' then
  Comm.Parity := TParity(None)
  else if asParity='O' then
  Comm.Parity := TParity(Odd)
  else if asParity='E' then
  Comm.Parity := TParity(Even);

  if asStopBits='1' then
  Comm.StopBits := TStopBits(_1)
  else if asStopBits='1.5' then
  Comm.StopBits := TStopBits(_1_5)
  else if asStopBits='2' then
  Comm.StopBits := TStopBits(_2);
end;
这是源码

作者: kuby6275   发布时间: 2011-09-23

这个波特率不对吧,我记得CPORT的波特率不是Integer,是自定义的枚举型

这个只是设置参数,程序里还得判断有没这个串口,串口有没被占用

作者: jankercsdn   发布时间: 2011-09-23

TBaudRate = (brCustom, br110, br300, br600, br1200, br2400, br4800, br9600, br14400,
  br19200, br38400, br56000, br57600, br115200, br128000, br256000);
  TStopBits = (sbOneStopBit, sbOne5StopBits, sbTwoStopBits);
  TDataBits = (dbFive, dbSix, dbSeven, dbEight);
  TParityBits = (prNone, prOdd, prEven, prMark, prSpace);

这是CPORT的参数类型,你确定你的对?

作者: jankercsdn   发布时间: 2011-09-23

CPORT还提供了几个方便的参数转换函数,

// conversion functions
function StrToBaudRate(Str: string): TBaudRate;
function StrToStopBits(Str: string): TStopBits;
function StrToDataBits(Str: string): TDataBits;
function StrToParity(Str: string): TParityBits;
function StrToFlowControl(Str: string): TFlowControl;
function BaudRateToStr(BaudRate: TBaudRate): string;
function StopBitsToStr(StopBits: TStopBits): string;
function DataBitsToStr(DataBits: TDataBits): string;
function ParityToStr(Parity: TParityBits): string;
function FlowControlToStr(FlowControl: TFlowControl): string;

作者: jankercsdn   发布时间: 2011-09-23

作者: Veron_04   发布时间: 2011-09-23

其实这个软件是前人编写的 现在老板要我们改动以适应新的机器 他的代码看着蛋疼 我都不知道该从哪下手 主要是该 通信方式这块有网络连接和电话拨号连接 有经验的前辈可以给个方向不?看代码什么地方?是否数据库也需要修改?

作者: kuby6275   发布时间: 2011-09-23

引用 7 楼 veron_04 的回复:

http://download.csdn.net/detail/veron_04/1523158


7楼你的资料很不错 正在看 谢谢你哦!

作者: kuby6275   发布时间: 2011-09-23