千家论坛_智能建筑与智能家居技术交流社区

标题: 开发西门子计费软件遇到的通讯问题 [打印本页]

作者: honva    时间: 2005-5-27 09:06
标题: 开发西门子计费软件遇到的通讯问题
西门子HIPATH4000,串口设置为"4800,e,7,1",用系统自带的超级终端通讯时,系统能自动将通话记录传上来,但我用自己的软件与它通讯时,串口设置好并打开后,根本就不会触发中断事件,这是什么原来?大家遇到过吗?谢谢
作者: honva    时间: 2005-5-27 13:39
没人遇到过吗
作者: pabxman    时间: 2005-5-27 18:09

程序是你自己写的吗?用什么语言?

一般来说,中断未决没有清除,这是程序员对 RS232 编程时常犯的错误。


作者: xhlmjh    时间: 2005-5-29 17:10
顶上去!
作者: honva    时间: 2005-5-29 18:48
是自己写的,delphi写的
作者: pabxman    时间: 2005-5-29 22:43
Com 模块是自己写的?还是调用第三方的?
作者: honva    时间: 2005-5-30 13:26
第三方的
作者: pabxman    时间: 2005-5-30 16:43

一个例子:

{****************************************************************************} {* *} {* Procedure ComParams(ComPort:Byte; Baud:Longint; *} {* WordSize:Byte; Parity:Char; StopBits:Byte); *} {* *} {* ComPort:Byte -> Port # to initialize. Must be (1 - C_MaxCom) *} {* Procedure aborted if port # invalid or unopened. *} {* Baud:Longint -> Desired baud rate. Should be (C_MinBaud - C_MaxBaud)*} {* C_MinBaud or C_MaxBaud used if out of range. *} {* WordSize:Byte -> Word size, in bits. Must be 5 - 8 bits. *} {* 8-bit word used if out of range. *} {* Parity:Char -> Parity classification. *} {* May be N)one, E)ven, O)dd, M)ark or S)pace. *} {* N)one selected if classification unknown. *} {* StopBits:Byte -> # of stop bits to pad character with. Range (1-2) *} {* 1 stop bit used if out of range. *} {* *} {* ComParams is used to configure an OPEN'ed port for the desired comm- *} {* unications parameters, namely baud rate, word size, parity form and *} {* # of stop bits. A call to this procedure will set up the port approp- *} {* riately, as well as assert the DTR, RTS and OUT2 control lines and *} {* clear all buffers. *} {* *} {****************************************************************************}

Procedure ComParams(ComPort:Byte; Baud:LongInt; WordSize:Byte; Parity:Char; StopBits:Byte);

Const C_Stopbit1 = $00; { Bit masks for parity, stopbits } C_Stopbit2 = $04; C_NoParity = $00; C_OddParity = $08; C_EvenParity = $18; C_MarkParity = $28; C_SpaceParity = $38; Const C_IER = 1; { 8250 register offsets } C_IIR = 2; C_LCR = 3; C_MCR = 4; C_LSR = 5; C_MSR = 6; C_SCR = 7;

Var X : Real; Y,P : Word; DivMSB,DivLSB : Byte; WS,SB,PTY : Byte;

Begin If (ComPort<1) Or (ComPort>C_MaxPort) Or (Not C_PortOpen[ComPort]) Then Exit;

Inline($FA); P := C_PortAddr[ComPort];

{ Calculate baud rate divisors }

X := Baud; If X < C_MinBaud Then X := C_MinBaud; If X > C_MaxBaud Then X := C_MaxBaud; Y := Round($900/(X/50)); DivMSB := Hi(Y); DivLSB := Lo(Y);

{ Determine parity mask } { Default if unknown: No parity }

Case UpCase(Parity) Of 'N' : PTY := C_NoParity; 'E' : PTY := C_EvenParity; 'O' : PTY := C_OddParity; 'M' : PTY := C_MarkParity; 'S' : PTY := C_SpaceParity; Else PTY := C_NoParity; End;

{ Determine stop-bit mask } { Default if out of range: 1 Stop bit }

Case StopBits Of 1 : SB := C_StopBit1; 2 : SB := C_StopBit2; Else SB := C_StopBit1; End;

{ Determine word-size mask } { Default if out of range: 8 bit word size }

If (WordSize >= 5) And (WordSize <= 8) Then WS := WordSize - 5 Else WS := 3;

{ Initialize line-control register }

Y := Port+ Port[P+C_LSR]; Port[P+C_LCR] := WS + SB + PTY;

{ Initialize baud rate divisor latches }

Port[P+C_LCR] := Port[P+C_LCR] Or $80; Port:= DivLSB; Port[P+1] := DivMSB; Port[P+C_LCR] := Port[P+C_LCR] And $7F; X := Port + Port[P+C_LSR] + Port[P+C_MSR] + Port[P+C_IIR];

{ Assert RS323 control lines (DTR,RTS,OUT2) & exit }

Port[P+C_MCR] := $0B; ClearCom(ComPort,'B'); Inline($FB); End;

[此贴子已经被作者于2005-5-30 16:46:00编辑过]

作者: pabxman    时间: 2005-5-30 16:48

X := Port + Port[P+C_LSR] + Port[P+C_MSR] + Port[P+C_IIR];

这行很重要,一定要有,否则就会造成中断未决。


作者: philips-pbx    时间: 2005-6-6 23:31


作者: jason_wan    时间: 2005-6-21 16:24
那行X=port+的代码是不是正确啊,用port的地址和其数组值进行运算.让人无法理解
作者: pabxman    时间: 2005-6-21 19:08
这是标准的 Pascal 语法,与 delphi 相兼容




欢迎光临 千家论坛_智能建筑与智能家居技术交流社区 (http://bbs.qianjia.com:8020/) Powered by Discuz! X3.2