I need to query a modem for signal strength using an AT command.
Testing using "AT". Hyperterminal gives "OK". Program gives nothing (0 bytes returned).
I thought to begin communicating with the modem using the MSComm control, but it only returns echoed characters. I switched to direct serial reading and writing (using CreateFile, ReadFile, WriteFile), but am getting -1 for my pointer (that's not right is it?).
(This is mostly from MSDN, but I've lost the link)
Testing using "AT". Hyperterminal gives "OK". Program gives nothing (0 bytes returned).
I thought to begin communicating with the modem using the MSComm control, but it only returns echoed characters. I switched to direct serial reading and writing (using CreateFile, ReadFile, WriteFile), but am getting -1 for my pointer (that's not right is it?).
(This is mostly from MSDN, but I've lost the link)
Code:
' Obtain a handle to the COM1 serial port.
hSerialPort = CreateFile("COM1", GENERIC_READ Or GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0)
' Verify that the obtained handle is valid.
If hSerialPort = -1 Then
'PROBLEM
debug.print "PROBLEM"
End If
' Write data to COM1.
Success = WriteFile(hSerialPort, Buffer, UBound(Buffer) - 1, BytesWritten, 0)
If Success = False Then
'PROBLEM
debug.print "PROBLEM"
End If
' Read data from COM1.
Buffer(LBound(Buffer)) = 0
Success = ReadFile(hSerialPort, Buffer, BytesWritten, BytesRead, 0)
If Success Then
Form1.text = ("BytesRead: " & BytesRead)
For i = LBound(Buffer) To LBound(Buffer) + BytesRead - 1
Form1.text = (i & " | " & Buffer(i)) '& " | " & chr(Buffer(i)))
Next
Else
'PROBLEM
End If
Success = CloseHandle(hSerialPort)
If (not Success) Then
Form1.text = ("Unable to release handle to " & port)
End If