I have a USB modem connected and it is working fine at port COM1 with putty.
The modem is able to response to commands like
AT
OK
ATZ
OK
I tried to do the same thing under .NET 2.0 framework using SerialPort class but no "OK" is ever received.
Code is updated for further testing
Initialize port
Dim ModemPort As SerialPort
ModemPort.DtrEnable = True
ModemPort.Handshake = Handshake.XOnXOff
ModemPort.NewLine = "\r\n" '(Added but the problem still exist)
'ModemPort.ReadTimeout = 3000 (Removed for testing)
SendSerialData(ModemPort, "ATZ")
Method SendSerialData
Function SendSerialData(ByRef modemPort As SerialPort, ByVal data As String)
Dim returnStr As String = ""
If modemPort.IsOpen = False Then
modemPort.Open()
End If
'Updated
modemPort.WriteLine(data) 'ATZ
System.Threading.Thread.Sleep(1000)
Try
Do
Dim Incoming As String = modemPort.ReadExisting()
If Incoming = "OK" Then
Exit Do
End If
If Incoming = "" Then
modemPort.WriteLine(data)
System.Threading.Thread.Sleep(1000) 'Modem will send "Error" sometime
Else
returnStr &= Incoming
End If
Loop
Catch ex As Exception
End Try
Return returnStr
End Function
However, all I revived is echo
Dim Incoming As String = modemPort.ReadExisting()
is
ATZ ATZ ATZ ATZ ATZ ATZ ATZ ATZ ATZ ATZ ATZ ATZ ATZ ATZ ATZ ATZ ATZ ATZ ATZ ATZ AT ERROR Z ATZ
(Split by newlines)
w̶h̶i̶c̶h̶ ̶i̶s̶ ̶j̶u̶s̶t̶ ̶w̶h̶a̶t̶ ̶I̶ ̶s̶e̶n̶t̶ ̶t̶h̶r̶o̶u̶g̶h̶ ̶W̶r̶i̶t̶e̶L̶i̶n̶e̶ (This is actually an echo)
The modem is able to echo my commands but the modem will not send an "OK" but sometime "ERROR".
This is the modemPort variable at runtime just before ReadLine()
A local test done by PassMark shows the modem is functional
M̶a̶y̶b̶e̶ ̶t̶h̶e̶ ̶m̶o̶d̶e̶m̶ ̶n̶o̶t̶ ̶r̶e̶a̶d̶i̶n̶g̶ ̶t̶h̶e̶ ̶s̶t̶r̶e̶a̶m̶?̶
Is there any configuration needed to be done?
I did some digging online but it seems that no one has similar problems.
Thanks in advance.