Program hangs on ReadString

HARRY

Active Member
Licensed User
Longtime User
Hi,

I am working on a small program which acts as a network client to a micro controller as server.

For some reason the program hangs on the s=stream.ReadString statement.

The Network library version is 1.0.3678.39641.


The complete program looks as follows:

Sub App_Start

Form1.Show
Client.New1
Client.Connect("192.168.2.2",50000) 'the ip address of the micro controller and the port number, where the server listens.
stream.New1(Client.GetStream,True)
Msgbox("Connected")
Timer1.Interval=1000
Timer1.Enabled=True
End Sub

Sub Timer1_Tick
If Client.DataAvailable = True Then
s=stream.ReadString
TBSR.Text=TBSR.Text & CRLF & s
End If
End Sub

Sub CBSend_Click
stream.WriteString(TBS.Text)
TBSR.Text=TBSR.Text & CRLF & TBS.Text
End Sub

Sub CBDisconnect_Click
Client.Close
Msgbox("Disconnected.")
End Sub

The connection succeeds.

The micro controller works fine with a terminal emulator like MobileVT

Does somebody have an idea on the cause of this problem?

Harry
 

Zenerdiode

Active Member
Licensed User
A BinaryFile.ReadString is expecting the string to be preceded with the length of the string in bytes. Are you sure your microcontroller transmits the string in that way [format]?

Try using BinaryFile.ReadBytes instead - converting each byte of the array into a character and then adding to your TBSR.text
 

HARRY

Active Member
Licensed User
Longtime User
Hi Zenerdiode,

Thanks, your solution works very well. I should have read the documentation more carefully.

The direction from microcontroller to PDA is now OK; but I think that I have a similar problem with the other direction. Does Basic4PPC sends a string with the string length heading the text?

If that is true and the string length contains a NULL character than the microcontroller stops reading, I think. How can I send just the characters without header from Basic4PPC?

I don't see how to convert the text to send into a buffer, in order to be able to use WriteBytes2. Any suggestion?

Harry
 
Top