Thanks for your help Kale.
Actually, I already have some experience of writing code to use the serial
Comms using the Windows API, although in another language.
That's why I'd like to see simple PureBasic commands.
IMO the forté of a high level language should be to separate the programmer
from the complexities of the OS. Thus programs are easier to write and test,
less dependant on OS foibles and hence more portable. If I wanted to do
everything using the API I might as well use a low level language like C.
Compare my example above with this code extracted from the PureFrog
example. I hate to ask what
des tampons d'E/S are 8O
In any case, the commands used are unofficial so will they
be supported in future versions of PureBasic?
Structure DCB2
DCBlength.l ; sizeof(DCB)
BaudRate.l ; current baud rate
Flags.l
wReserved.w ; not currently used
XonLim.w ; transmit XON threshold
XoffLim.w ; transmit XOFF threshold
ByteSize.b ; number of bits/byte, 4-8
Parity.b ; 0-4=no,odd,even,mark,space
StopBits.b ; 0,1,2 = 1, 1.5, 2
XonChar.b ; Tx and Rx XON character
XoffChar.b ; Tx and Rx XOFF character
ErrorChar.b ; error replacement character
EofChar.b ; end of input character
EvtChar.b ; received event character
wReserved1.w ; reserved; do not use
EndStructure
StartFrog:
*File = OpenComPort(0, SelectedPort$+':')
If *File
If EnableLog
If OpenFile(1, 'PureFrog.log')
FileSeek(Lof())
EndIf
EndIf
If GetCommState_(*File, @PortConfig.DCB2)
; Allocation des tampons d'E/S
;
HandleError( SetupComm_(*File, 4096, 4096), 'SetupComm()' )
ct.COMMTIMEOUTS
ctReadIntervalTimeout = #MAXDWORD
ctReadTotalTimeoutMultiplier = 0
ctReadTotalTimeoutConstant = 0
ctWriteTotalTimeoutMultiplier = 0
ctWriteTotalTimeoutConstant = 0
HandleError( SetCommTimeouts_(*File, ct), 'SetCommTimeouts()' )
; construction des donnees d'initialisation du port
dcb.DCB2;
HandleError( GetCommState_(*File, @dcb), 'GetCommState()' )
dcbBaudRate = #CBR_300;
dcbParity = #NOPARITY;
dcbStopBits = #TWOSTOPBITS;
dcbByteSize = 8;
dcbFlags = 4227 ; Combined flags values got from the C.. PureBasic doesn't support flags in structures
HandleError( SetCommState_(*File, @dcb), 'SetCommState()' )
CreateThread(@FrogThread(), 0)
EndIf
Else
MessageRequester('PureFrog','Can't open the following port: '+SelectedPort$+Chr(10)+'This port is may be in use', #MB_ICONERROR)
EndIf
Return