AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Ayuda / WLanguage / Funciones WLanguage / Funciones estándar / Funciones de Windows / Funciones de puertos serie y paralelo
  • Example: Opening a port with a timeout
Example: Opening a port with a timeout
WINDEVWEBDEV - Código ServidorCódigo de Usuario (UMC)Ajax This example opens a serial port and sets the timeout.
PortNum is int = 1 // Port number
// String to write onto the port
StringToWrite is string = "String to write"
SizeWritten is int // Size of the string that was written
SizeEntryBuffer is int = 5000 // Size of buffer for the read operations
SizeOutputBuffer is int = 5000 // Size of buffer for the write operations
// Timeout of sRead/sWrite between two characters (in ms)
PortTimeout is int = 100
 
// Open the port
IF sOpen(PortNum, SizeEntryBuffer, SizeOutputBuffer, PortTimeout) = False THEN
// Process the opening error
Error("Error while opening COM" + PortNum)
ELSE
  // Configure the port
IF sParameter(PortNum, 9600, 0, 8, 0, True, True, True) = False THEN
// Process the configuration error
Error("Error while configuring COM" + PortNum)
ELSE
LOOP
  // Write onto the port
  SizeWritten = sWrite(PortNum, StringToWrite)
  // Check the write operation
IF SizeWritten = 0 AND StringToWrite <> "" THEN
// Nothing was written while the string to write is not empty
// Check the output buffer
IF sInExitQueue(PortNum) < SizeOutputBuffer THEN
// The output buffer is not full: device problem
IF YesNo("Unable to write onto the port" + ...
 "COM" + PortNum,...
 "Check whether a device is ready" + ...
 "and properly connected.", ...
 "Do you want to retry?") = False THEN
BREAK // Cancel the write operation
END
ELSE
// The output buffer is full
// Timeout in order for the output buffer to be cleared
Multitask(200)
// Check the output buffer again
IF sInExitQueue(PortNum) >= SizeOutputBuffer THEN
// The output buffer is full
IF YesNo("Unable to write onto the port" + ...
  "COM" + PortNum, ...
  "Check whether a device is ready" + ...
  "and properly connected.", ...
  "Do you want to retry?") = False THEN
  BREAK // Cancel the write operation
END
END
  END
ELSE
IF SizeWritten = Length(StringToWrite) THEN
// Everything was written
BREAK
// Otherwise, only a part was written
// But we wrote something, so let's try again
END
END
END
END
  // Close COM1
  sClose(PortNum)
END
Versión mínima requerida
  • Versión 9
Esta página también está disponible para…
Comentarios
Haga clic en [Agregar] para publicar un comentario

Última modificación: 27/05/2022

Señalar un error o enviar una sugerencia | Ayuda local