mit #PB_SerialPort_RtsCtsHandshake öffnet. Wie du bereits gesagt hast, man lernt nie aus

Code: Alles auswählen
Enumeration
#StopBits_One
#StopBits_OneAndHalf
#StopBits_Two
EndEnumeration
;Procedure von DarkDragon womit das StopBit nun als Integer gemappt wird. Dank an Daniel.
Procedure.i OpenSerialPortEx(SerialPort.i, PortName.s, Bauds.i, Parity.i, DataBits.i, StopBits.i, HandshakeMode.i, InputBufferSize.i, OutputBufferSize.i)
Protected FloatStopBits.f = PeekF(?FloatByIntStopBit + StopBits * SizeOf(Float))
ProcedureReturn OpenSerialPort(SerialPort, PortName, Bauds, Parity, DataBits, FloatStopBits, HandshakeMode, InputBufferSize, OutputBufferSize)
DataSection
FloatByIntStopBit:
Data.f 1.0
Data.f 1.5
Data.f 2.0
EndDataSection
EndProcedure
Macro OpenSerialPort(SerialPort, PortName, Bauds, Parity, DataBits, StopBits, HandshakeMode, InputBufferSize, OutputBufferSize)
OpenSerialPortEx(SerialPort, PortName, Bauds, Parity, DataBits, StopBits, HandshakeMode, InputBufferSize, OutputBufferSize)
EndMacro
Port$="COM4"
#SerialPort=0
;Handshake.l=#PB_SerialPort_NoHandshake
;Handshake.l=#PB_SerialPort_RtsCtsHandshake
Handshake.l=#PB_SerialPort_RtsHandshake
;Handshake.l=#PB_SerialPort_XonXoffHandshake
Parity.l=#PB_SerialPort_NoParity; #PB_SerialPort_EvenParity;
If OpenSerialPortEx(#SerialPort, Port$, 9600, Parity , 8, #StopBits_One , Handshake , 1024, 1024)
Schalter = 1
For i = 1 To 10
SetSerialPortStatus(#SerialPort, #PB_SerialPort_RTS, Schalter)
Delay(1000)
;Compilereinstellungen den inlineAsembler einschalten nicht vergessen!
Schalter=Schalter Not Schalter
Debug Schalter
Next i
MessageRequester("Error", "serial port is ok: "+Port$)
For i = 1 To 10
SetSerialPortStatus(#SerialPort, #PB_SerialPort_DTR, Schalter)
Delay(1000)
;Compilereinstellungen den inlineAsembler einschalten nicht vergessen!
Schalter=Schalter Not Schalter
Debug Schalter
Next i
MessageRequester("Error", "serial port is ok: "+Port$)
Else
MessageRequester("Error", "Can't open the serial port: "+Port$)
EndIf
;CloseSerialPort(#SerialPort); Der Debugger wird hiermit nur gestört, warum auch im PB-Beispiel
;dieser Befehl nicht vorhanden ist. Scheint ein Bug des Debuggers zu sein.
Code: Alles auswählen
Procedure.s DisplayComError()
ComErrorText.s = ""
If IsSerialPort(comID)
ComError.l = SerialPortError(comID)
If ComError & #PB_SerialPort_RxOver : ComErrorText + "An input buffer overflow has occurred"+#CR$ : EndIf
If ComError & #PB_SerialPort_OverRun : ComErrorText + "A character-buffer overrun has occurred"+#CR$ : EndIf
If ComError & #PB_SerialPort_RxParity : ComErrorText + "The hardware detected a parity error"+#CR$ : EndIf
If ComError & #PB_SerialPort_Frame : ComErrorText + "The hardware detected a framing error"+#CR$ : EndIf
If ComError & #PB_SerialPort_Break : ComErrorText + "The hardware detected a break condition"+#CR$ : EndIf
If ComError & #PB_SerialPort_TxFull : ComErrorText + "The output buffer was full"+#CR$ : EndIf
If ComError & #PB_SerialPort_IOE : ComErrorText + "An I/O error occurred during communications with the device"+#CR$ : EndIf
If ComError & #PB_SerialPort_WaitingCTS : ComErrorText + "Waiting CTS"+#CR$ : EndIf
If ComError & #PB_SerialPort_WaitingDSR : ComErrorText + "Waiting DSR"+#CR$ : EndIf
If ComError & #PB_SerialPort_WaitingRLSD : ComErrorText + "Waiting RLSD"+#CR$ : EndIf
If ComError & #PB_SerialPort_XoffReceived : ComErrorText + "Waiting because the XOFF character was received"+#CR$ : EndIf
If ComError & #PB_SerialPort_XoffSent : ComErrorText + "Waiting because the XOFF character was transmitted"+#CR$ : EndIf
If ComError & #PB_SerialPort_EOFSent : ComErrorText + "EOF character has been received"+#CR$ : EndIf
If Right(ComErrorText,1)=#CR$:ComErrorText=Left(ComErrorText,Len(ComErrorText)-1):EndIf
; MessageRequester("PBX Interface","Communication error occured :"+#CR$+ComErrorText)
EndIf
ProcedureReturn ComErrorText
EndProcedure
[/Edit]---------------------------
PBX Interface
---------------------------
Communication error occured :
The hardware detected a parity error
The hardware detected a framing error
The hardware detected a break condition
---------------------------
OK
---------------------------