Does Alpha5 V8 support read/write data from/to serial port (RS232)? If does, how?
Thanks.
Ming
Thanks.
Ming
Alpha Software Mobile Development Tools: Alpha Anywhere | Alpha TransForm |
Type OVERLAPPED Internal As Integer InternalHigh As Integer offset As Integer OffsetHigh As Integer hEvent As Integer End Type ' Declare Function WriteFile Lib "Kernel32" _ ' (ByVal hFile As Long, ByVal lpBuffer As String, _ ' ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, _ ' lpOverlapped As OVERLAPPED) As Long declarestruct _lpNumberOfBytesWritten L1Value declare kernel32 WriteFile LLCL(_lpNumberOfBytesWritten)(OVERLAPPED)
'Date Created: 18-Jul-2004 05:14:39 PM 'Last Updated: 13-Oct-2006 01:44:30 PM 'Created By : Marcel Kollenaar 'Updated By : marcel '------------------------------------------------------------------------------- ' ' CommWrite - Output data to the serial port. ' ' Parameters: ' strData - Data string ' ' Returns: ' Error Code - 0 = No Error. -1 = Error ' '-------------------------------------------------------------------------------- ' ' The next members of the gComm structure must be set before CommWrite() is called. ' ' Parameters: ' gComm.CommPort as C 'Name of the COM port: "COM1" or "COM2" ' gComm.InQueue as N 'default buffersize = 1024 bytes ' gComm.OutQueue as N 'default buffersize = 1024 bytes ' gComm.DevCntrlStr as C '"9600,N,8,1,P" of "9600,N,8,1,X" of "9600,N,8,1" ' ' The next members of the gCommTimeOuts can be set. The next values are the default ' values for CreateFile(). ' ' gCommTimeOuts.ReadIntervalTimeout = -1 ' gCommTimeOuts.ReadTotalTimeoutMultiplier = 0 ' gCommTimeOuts.ReadTotalTimeoutConstant = 1000 ' gCommTimeOuts.WriteTotalTimeoutMultiplier = 0 ' gCommTimeOuts.WriteTotalTimeoutConstant = 1000 ' ' Returns: ' gComm.Success as L 'Successfull execution = .T. ' '------------------------------------------------------------------------------- FUNCTION CommWrite AS N (strData as C) Dim i As N Dim lngStatus As N dim lngNumberOfBytesToWrite As N dim pNumberOfBytesWritten as {_lpNumberOfBytesWritten} dim lngWrStatus As N debug(1) On Error GoTo Routine_Error ' Get the length of the data. lngNumberOfBytesToWrite = Len(strData) ' Get a pointer to the lng buffer. 'lpNumberOfBytesWritten is declared in XmodINIT as 1L. 'lngWrSize.lpNumberOfBytesWritten = 0 ' Output the data. lngWrStatus = WriteFile(gComm.CommHandle, \ strData, \ lngNumberOfBytesToWrite, \ pNumberOfBytesWritten, \ gCommOverlap) XDoEvent() If lngWrStatus = 0 Then lngStatus = GetLastError() If lngStatus = 0 Then GoTo Routine_Exit ElseIf lngStatus = ERROR_IO_PENDING Then While GetOverlappedResult(gComm.CommHandle, \ gCommOverlap, \ pNumberOfBytesWritten, \ .T.) = 0 lngStatus = GetLastError() If lngStatus <> ERROR_IO_INCOMPLETE Then lngStatus = SetCommErrorEx("CommWrite (GetOverlappedResult)", gComm.CommHandle) GoTo Routine_Exit End If Wend Else ' Some other error occurred. pNumberOfBytesWritten.Value = -1 lngStatus = SetCommErrorEx("CommWrite (WriteFile)", gComm.CommHandle) GoTo Routine_Exit End If End If 'Give the system time to process messages. For i = 1 To 10 XDoEvent() Next Routine_Exit: 'Return the number of bytes that has been written to the buffer. CommWrite = pNumberOfBytesWritten.value Exit Function Routine_Error: pNumberOfBytesWritten.Value = -1 gComm.Success = SetCommError("CommWrite()") Resume Routine_Exit END FUNCTION
Comment