Unexpected data from TCPClient

B

b.pruitt

Hello All,

Need a little help with a TCPClient. I am converting a VB6 app to VB
2005 and can't get the same data back from the device I am connected
to.

A little background. I have an Intermec 3400e printer that I want to
upload the label formats from.

My VB6 code is as follows ....

Private Sub ws_DataArrival(ByVal bytesTotal As Long)
Dim vtData As String
ws.GetData vtData, vbString
Dim IPL As New IPLCommandReference 'Just a class I created to
convert ascii control characters.
txtReceive.Text = txtReceive.Text & IPL.Interpreter.Decode(vtData)
End Sub

I get the following results....

<STX>R;<ESC>C<ESC>P;<ETX>
<STX>E2;A2, ;<ETX>
<STX>L39;D0;<ETX>
<STX>W000, ;o00010,00006;f0;h0342;l0142;w0001;<ETX>
<STX>D39;H001, ;o00139,00027;f3;k010;c25,0;b000;r0;d3,Duff
Beer Rules;<ETX>
<STX>R<ETX>


Now with VB 2005

Public Sub ReceiveMessage(ByVal ar As IAsyncResult)
Try
Dim bytesRead As Integer

bytesRead = client.GetStream.EndRead(ar)

If bytesRead < 1 Then
Exit Sub
Else
Dim para() As Object = _
{System.Text.Encoding.ASCII.GetString( _
data, 0, bytesRead)}
Me.Invoke(New delUpdateHistory( _
AddressOf Me.UpdateHistory), para)
End If

client.GetStream.BeginRead( _
data, 0, CInt(client.ReceiveBufferSize), _
AddressOf ReceiveMessage, Nothing)
Catch ex As Exception
End Try
End Sub

I get the following...

<STX>R;<ESC>C<ESC>P;<ETX>
<STX>E2;A2, ;<ETX>
<STX>L39;D0;<ETX>
<STX>W000, ;o00010,00006;f0;h0342;l0142;w0001;<ETX>
<STX>D39;H001, ;o00139,000006;f0;h0342;l0142;w0001;<ETX>
<STX>D39;H001, ;o00139,00027;f342;l0142;w0001;<ETX>
<STX>D39;H001, ;o00139,00027;f3;k010;c25,39;H001, ;o00139,00027;f3;k010;c25,0;b000;r0;d3,Duff
Be01;<ETX>
<STX>D39;H001, ;o00139,00027;f3;k010;c25,0;b000;r0;d39,00027;f3;k010;c25,0;b000;r0;d3,Duff
Beer, oops, Rules;<ETX>
<STX>R<ETX>

I can not figure out why I get the extra lines of data. The Intermec
printer sends the data in 64 byte chunks, don't know if that helps.

I have connected to the same printer using HyperTerminal(Winsock) and
get the same results as in VB 2005.

This is my first attempt at network programming in .Net, so be gentle.

All of my testing has been done on Windows XP.
HyperTerminal, VB6, and VB2005 all running on my PC using the same
network adapter and printer connection.

Any help would be greatly appreciated.
 
T

Tom Shelton

Hello All,

Need a little help with a TCPClient. I am converting a VB6 app to VB
2005 and can't get the same data back from the device I am connected
to.

A little background. I have an Intermec 3400e printer that I want to
upload the label formats from.

My VB6 code is as follows ....

Private Sub ws_DataArrival(ByVal bytesTotal As Long)
Dim vtData As String
ws.GetData vtData, vbString
Dim IPL As New IPLCommandReference 'Just a class I created to
convert ascii control characters.
txtReceive.Text = txtReceive.Text & IPL.Interpreter.Decode(vtData)
End Sub

I get the following results....

<STX>R;<ESC>C<ESC>P;<ETX>
<STX>E2;A2, ;<ETX>
<STX>L39;D0;<ETX>
<STX>W000, ;o00010,00006;f0;h0342;l0142;w0001;<ETX>
<STX>D39;H001, ;o00139,00027;f3;k010;c25,0;b000;r0;d3,Duff
Beer Rules;<ETX>
<STX>R<ETX>


Now with VB 2005

Public Sub ReceiveMessage(ByVal ar As IAsyncResult)
Try
Dim bytesRead As Integer

bytesRead = client.GetStream.EndRead(ar)

If bytesRead < 1 Then
Exit Sub
Else
Dim para() As Object = _
{System.Text.Encoding.ASCII.GetString( _
data, 0, bytesRead)}
Me.Invoke(New delUpdateHistory( _
AddressOf Me.UpdateHistory), para)
End If

client.GetStream.BeginRead( _
data, 0, CInt(client.ReceiveBufferSize), _
AddressOf ReceiveMessage, Nothing)
Catch ex As Exception
End Try
End Sub

I get the following...

<STX>R;<ESC>C<ESC>P;<ETX>
<STX>E2;A2, ;<ETX>
<STX>L39;D0;<ETX>
<STX>W000, ;o00010,00006;f0;h0342;l0142;w0001;<ETX>
<STX>D39;H001, ;o00139,000006;f0;h0342;l0142;w0001;<ETX>
<STX>D39;H001, ;o00139,00027;f342;l0142;w0001;<ETX>
<STX>D39;H001, ;o00139,00027;f3;k010;c25,39;H001, ;o00139,00027;f3;k010;c25,0;b000;r0;d3,Duff
Be01;<ETX>
<STX>D39;H001, ;o00139,00027;f3;k010;c25,0;b000;r0;d39,00027;f3;k010;c25,0;b000;r0;d3,Duff
Beer, oops, Rules;<ETX>
<STX>R<ETX>

I can not figure out why I get the extra lines of data. The Intermec
printer sends the data in 64 byte chunks, don't know if that helps.

I have connected to the same printer using HyperTerminal(Winsock) and
get the same results as in VB 2005.

This is my first attempt at network programming in .Net, so be gentle.

All of my testing has been done on Windows XP.
HyperTerminal, VB6, and VB2005 all running on my PC using the same
network adapter and printer connection.

Any help would be greatly appreciated.

Just a question... Are you sending something to the printer to get your
response? And is it possible, that maybe that it is encoded improperly?
 
L

LineSupport

Just a question...  Are you sending something to the printer to get your
response?  And is it possible, that maybe that it is encoded improperly?

Yes, I send the following string to the printer. <STX><ESC>x2<ETX>
This is the Intermec IPL format. (Intermec Printer Language)

I send the string with the following ....

Private Sub buttonSend_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles buttonSend.Click
SendMessage(textCommand.Text)
End Sub

Public Sub SendMessage(ByVal message As String)
Try
'---send a message to the server
Dim ns As NetworkStream = client.GetStream
Dim data As Byte() = _
System.Text.Encoding.ASCII.GetBytes(message)
'---send the text---
ns.Write(data, 0, data.Length)
ns.Flush()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub

Just so you have all of the details, here is the Connect and Begin
Read code.

Private Sub buttonConnect_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles buttonConnect.Click
If buttonConnect.Text = "Connect" Then
Try
'---connect to server
client = New TcpClient

client.Connect("192.168.0.200", IntermecPort)

'---read from server
client.GetStream.BeginRead( _
data, 0, CInt(client.ReceiveBufferSize), _
AddressOf ReceiveMessage, Nothing)
buttonConnect.Text = "Sign Out"
buttonSend.Enabled = True
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Else
'---disconnect from server
Disconnect()
buttonConnect.Text = "Connect"
buttonSend.Enabled = False
End If
End Sub

Here is the delegate routines....
'---delegate and subroutine to update the TextBox control
Public Delegate Sub delUpdateHistory(ByVal str As String)
Public Sub UpdateHistory(ByVal str As String)
rtbReceive.AppendText(IPL.Interp.Decode(str))
If rtbReceive.Text.Length > 0 Then
Try
Dim CursorPos As Int32
CursorPos = rtbReceive.SelectionStart
TestExpression("[<]...[>]")
'TestExpression("[<]CR[>]")
'TestExpression("[<]LF[>]")
rtbReceive.SelectionStart = CursorPos
Catch ex As Exception

End Try
End If
End Sub

I have gone as far as debug.print in the ReceiveMessage sub to see the
data before it was passed to the delegate with the same results.

If memory serves me, and this is the way back machine, VB4 or was it
5, had a bug where winsock would fire data receive before the data was
actually available. Read that somewhere. Anyway, I don't know how the
TCPClient knows when to fire the callback. Just checking the bytes
read, I can see that the data is coming in 64 byte chunks which still
doesn't tell me how the client knows when to fire the callback.

Thanks
 
T

Tom Shelton

Just a question...  Are you sending something to the printer to get your
response?  And is it possible, that maybe that it is encoded improperly?
- Show quoted text -

Yes, I send the following string to the printer.   <STX><ESC>x2<ETX>
This is the Intermec IPL format. (Intermec Printer Language)

I send the string with the following ....

    Private Sub buttonSend_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles buttonSend.Click
        SendMessage(textCommand.Text)
    End Sub

    Public Sub SendMessage(ByVal message As String)
        Try
            '---send a message to the server
            Dim ns As NetworkStream = client.GetStream
            Dim data As Byte() = _
            System.Text.Encoding.ASCII.GetBytes(message)
            '---send the text---
            ns.Write(data, 0, data.Length)
            ns.Flush()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

Just so you have all of the details, here is the Connect and Begin
Read code.

    Private Sub buttonConnect_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles buttonConnect.Click
        If buttonConnect.Text = "Connect" Then
            Try
                '---connect to server
                client = New TcpClient

                client.Connect("192.168.0.200", IntermecPort)

                '---read from server
                client.GetStream.BeginRead( _
                   data, 0, CInt(client.ReceiveBufferSize), _
                   AddressOf ReceiveMessage, Nothing)
                buttonConnect.Text = "Sign Out"
                buttonSend.Enabled = True
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        Else
            '---disconnect from server
            Disconnect()
            buttonConnect.Text = "Connect"
            buttonSend.Enabled = False
        End If
    End Sub

Here is the delegate routines....
    '---delegate and subroutine to update the TextBox control
    Public Delegate Sub delUpdateHistory(ByVal str As String)
    Public Sub UpdateHistory(ByVal str As String)
        rtbReceive.AppendText(IPL.Interp.Decode(str))
        If rtbReceive.Text.Length > 0 Then
            Try
                Dim CursorPos As Int32
                CursorPos = rtbReceive.SelectionStart
                TestExpression("[<]...[>]")
                'TestExpression("[<]CR[>]")
                'TestExpression("[<]LF[>]")
                rtbReceive.SelectionStart = CursorPos
            Catch ex As Exception

            End Try
        End If
    End Sub

I have gone as far as debug.print in the ReceiveMessage sub to see the
data before it was passed to the delegate with the same results.

If memory serves me, and this is the way back machine, VB4 or was it
5, had a bug where winsock would fire data receive before the data was
actually available. Read that somewhere. Anyway, I don't know how the
TCPClient knows when to fire the callback. Just checking the bytes
read, I can see that the data is coming in 64 byte chunks which still
doesn't tell me how the client knows when to fire the callback.


Boy, this is a really hard one - especially without the printer to
test it on :) But, you say you get the same result when you connect
to the printer with hyperterminal? Have you tried using telnet? You
can telnet to an address and port from the command prompt - unless
your using special emulation...
 
L

LineSupport

Yes, I send the following string to the printer.   <STX><ESC>x2<ETX>
This is the Intermec IPL format. (Intermec Printer Language)
I send the string with the following ....
    Private Sub buttonSend_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles buttonSend.Click
        SendMessage(textCommand.Text)
    End Sub
    Public Sub SendMessage(ByVal message As String)
        Try
            '---send a message to the server
            Dim ns As NetworkStream = client.GetStream
            Dim data As Byte() = _
            System.Text.Encoding.ASCII.GetBytes(message)
            '---send the text---
            ns.Write(data, 0, data.Length)
            ns.Flush()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
Just so you have all of the details, here is the Connect and Begin
Read code.
    Private Sub buttonConnect_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles buttonConnect.Click
        If buttonConnect.Text = "Connect" Then
            Try
                '---connect to server
                client = New TcpClient
                client.Connect("192.168.0.200", IntermecPort)
                '---read from server
                client.GetStream.BeginRead( _
                   data, 0, CInt(client.ReceiveBufferSize), _
                   AddressOf ReceiveMessage, Nothing)
                buttonConnect.Text = "Sign Out"
                buttonSend.Enabled = True
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        Else
            '---disconnect from server
            Disconnect()
            buttonConnect.Text = "Connect"
            buttonSend.Enabled = False
        End If
    End Sub
Here is the delegate routines....
    '---delegate and subroutine to update the TextBox control
    Public Delegate Sub delUpdateHistory(ByVal str As String)
    Public Sub UpdateHistory(ByVal str As String)
        rtbReceive.AppendText(IPL.Interp.Decode(str))
        If rtbReceive.Text.Length > 0 Then
            Try
                Dim CursorPos As Int32
                CursorPos = rtbReceive.SelectionStart
                TestExpression("[<]...[>]")
                'TestExpression("[<]CR[>]")
                'TestExpression("[<]LF[>]")
                rtbReceive.SelectionStart = CursorPos
            Catch ex As Exception
            End Try
        End If
    End Sub
I have gone as far as debug.print in the ReceiveMessage sub to see the
data before it was passed to the delegate with the same results.
If memory serves me, and this is the way back machine, VB4 or was it
5, had a bug where winsock would fire data receive before the data was
actually available. Read that somewhere. Anyway, I don't know how the
TCPClient knows when to fire the callback. Just checking the bytes
read, I can see that the data is coming in 64 byte chunks which still
doesn't tell me how the client knows when to fire the callback.

Boy, this is a really hard one - especially without the printer to
test it on :)  But, you say you get the same result when you connect
to the printer with hyperterminal?  Have you tried using telnet?  You
can telnet to an address and port from the command prompt - unless
your using special emulation...

I tried telnet this morning, same results. I still get the extra data.
I took another look at the VB6 code to see if I was doing something
different. I don't see anything that would make a difference.

Thanks
 
L

LineSupport

On Feb 20, 4:55 pm, (e-mail address removed) wrote:
On Feb 20, 6:12 pm, Tom Shelton
Hello All,
Need a little help with a TCPClient. I am converting a VB6 app to VB
2005 and can't get the same data back from the device I am connected
to.
A little background. I have an Intermec 3400e printer that I want to
upload the label formats from.
My VB6 code is as follows ....
Private Sub ws_DataArrival(ByVal bytesTotal As Long)
    Dim vtData As String
    ws.GetData vtData, vbString
    Dim IPL As New IPLCommandReference 'Just a class I createdto
convert ascii control characters.
    txtReceive.Text = txtReceive.Text & IPL.Interpreter.Decode(vtData)
End Sub
I get the following results....
<STX>R;<ESC>C<ESC>P;<ETX>
<STX>E2;A2,          ;<ETX>
<STX>L39;D0;<ETX>
<STX>W000,          ;o00010,00006;f0;h0342;l0142;w0001;<ETX>
<STX>D39;H001,          ;o00139,00027;f3;k010;c25,0;b000;r0;d3,Duff
Beer Rules;<ETX>
<STX>R<ETX>
Now with VB 2005
    Public Sub ReceiveMessage(ByVal ar As IAsyncResult)
        Try
            Dim bytesRead As Integer
            bytesRead = client.GetStream.EndRead(ar)
            If bytesRead < 1 Then
                Exit Sub
            Else
                Dim para() As Object = _
                   {System.Text.Encoding.ASCII..GetString( _
                   data, 0, bytesRead)}
                Me.Invoke(New delUpdateHistory( _
                   AddressOf Me.UpdateHistory), para)
            End If
            client.GetStream.BeginRead( _
               data, 0, CInt(client.ReceiveBufferSize), _
               AddressOf ReceiveMessage, Nothing)
        Catch ex As Exception
        End Try
    End Sub
I get the following...
<STX>R;<ESC>C<ESC>P;<ETX>
<STX>E2;A2,          ;<ETX>
<STX>L39;D0;<ETX>
<STX>W000,          ;o00010,00006;f0;h0342;l0142;w0001;<ETX>
<STX>D39;H001,          ;o00139,000006;f0;h0342;l0142;w0001;<ETX>
<STX>D39;H001,          ;o00139,00027;f342;l0142;w0001;<ETX>
<STX>D39;H001,          ;o00139,00027;f3;k010;c25,39;H001,          ;o00139,00027;f3;k010;c25,0;b000;r0;d3,Duff
Be01;<ETX>
<STX>D39;H001,          ;o00139,00027;f3;k010;c25,0;b000;r0;d39,00027;f3;k010;c25,0;b000;r0;d3,Duff
Beer, oops, Rules;<ETX>
<STX>R<ETX>
I can not figure out why I get the extra lines of data. The Intermec
printer sends the data in 64 byte chunks, don't know if that helps..
I have connected to the same printer using HyperTerminal(Winsock) and
get the same results as in VB 2005.
This is my first attempt at network programming in .Net, so be gentle.
All of my testing has been done on Windows XP.
HyperTerminal, VB6, and VB2005 all running on my PC using the same
network adapter and printer connection.
Any help would be greatly appreciated.
Just a question...  Are you sending something to the printer to get your
response?  And is it possible, that maybe that it is encoded improperly?
--
Tom Shelton- Hide quoted text -
- Show quoted text -
Yes, I send the following string to the printer.   <STX><ESC>x2<ETX>
This is the Intermec IPL format. (Intermec Printer Language)
I send the string with the following ....
    Private Sub buttonSend_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles buttonSend.Click
        SendMessage(textCommand.Text)
    End Sub
    Public Sub SendMessage(ByVal message As String)
        Try
            '---send a message to the server
            Dim ns As NetworkStream = client.GetStream
            Dim data As Byte() = _
            System.Text.Encoding.ASCII.GetBytes(message)
            '---send the text---
            ns.Write(data, 0, data.Length)
            ns.Flush()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
Just so you have all of the details, here is the Connect and Begin
Read code.
    Private Sub buttonConnect_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles buttonConnect.Click
        If buttonConnect.Text = "Connect" Then
            Try
                '---connect to server
                client = New TcpClient
                client.Connect("192.168.0.200", IntermecPort)
                '---read from server
                client.GetStream.BeginRead( _
                   data, 0, CInt(client.ReceiveBufferSize), _
                   AddressOf ReceiveMessage, Nothing)
                buttonConnect.Text = "Sign Out"
                buttonSend.Enabled = True
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        Else
            '---disconnect from server
            Disconnect()
            buttonConnect.Text = "Connect"
            buttonSend.Enabled = False
        End If
    End Sub
Here is the delegate routines....
    '---delegate and subroutine to update the TextBox control
    Public Delegate Sub delUpdateHistory(ByVal str As String)
    Public Sub UpdateHistory(ByVal str As String)
        rtbReceive.AppendText(IPL.Interp.Decode(str))
        If rtbReceive.Text.Length > 0 Then
            Try
                Dim CursorPos As Int32
                CursorPos = rtbReceive.SelectionStart
                TestExpression("[<]...[>]")
                'TestExpression("[<]CR[>]")
                'TestExpression("[<]LF[>]")
                rtbReceive.SelectionStart = CursorPos
            Catch ex As Exception
            End Try
        End If
    End Sub
I have gone as far as debug.print in the ReceiveMessage sub to see the
data before it was passed to the delegate with the same results.
If memory serves me, and this is the way back machine, VB4 or was it
5, had a bug where winsock would fire data receive before the data was
actually available. Read that somewhere. Anyway, I don't know how the
TCPClient knows when to fire the callback. Just checking the bytes
read, I can see that the data is coming in 64 byte chunks which still
doesn't tell me how the client knows when to fire the callback.
Boy, this is a really hard one - especially without the printer to
test it on :)  But, you say you get the same result when you connect
to the printer with hyperterminal?  Have you tried using telnet?  You
can telnet to an address and port from the command prompt - unless
your using special emulation...
- Show quoted text -

I tried telnet this morning, same results. I still get the extra data.
I took another look at the VB6 code to see if I was doing something
different. I don't see anything that would make a difference.

Thanks- Hide quoted text -

- Show quoted text -

Tom, I went back to your comment about the encoding and found a
difference.

This is the command string that I was sending with the VB6 app.
<STX><ESC>x2<ETX><ENQ>

This is all I was sending with VB2005.
<STX><ESC>x2<ETX>
... Missing the <ENQ>

Not sure why it would make a difference. But having the <ENQ> made all
the difference in telnet, Hyperterminal, and VB2005.
I modified the VB6 app to exclude the ENQ and got the same results as
2005.

I think this is a difference between using the Serial versus Enet on
the printer side. When I sent the command string without the ENQ via
the serial port in HyperTerminal, the data came back as expected.
Tried again with the ENQ, got good results also.

But, when using Enet, no ENQ means the data will be incorrect. The
Intermec IPL Programmers Reference Manual was written based on Serial
port communications. The optional Enet interface is not covered in the
manual. Infact, it has a separate booklet that covers physical install
and how to set the IP address, and that's it. No mention of IPL or the
protocol used on the Enet interface.

Hopefully, I will not run into anymore undocumented features using the
Enet interface. I guess the next step is to contact Intermec tech
support, who has been trying to help, and see if they can explain the
difference.

Thanks Tom
 
T

Tom Shelton

On Feb 20, 4:55 pm, (e-mail address removed) wrote:
On Feb 20, 6:12 pm, Tom Shelton
On 2008-02-20, (e-mail address removed) <[email protected]> wrote:
Hello All,
Need a little help with a TCPClient. I am converting a VB6 app to VB
2005 and can't get the same data back from the device I am connected
to.
A little background. I have an Intermec 3400e printer that I want to
upload the label formats from.
My VB6 code is as follows ....
Private Sub ws_DataArrival(ByVal bytesTotal As Long)
    Dim vtData As String
    ws.GetData vtData, vbString
    Dim IPL As New IPLCommandReference 'Just a class I created to
convert ascii control characters.
    txtReceive.Text = txtReceive.Text & IPL.Interpreter.Decode(vtData)
End Sub
I get the following results....
<STX>R;<ESC>C<ESC>P;<ETX>
<STX>E2;A2,          ;<ETX>
<STX>L39;D0;<ETX>
<STX>W000,          ;o00010,00006;f0;h0342;l0142;w0001;<ETX>
<STX>D39;H001,          ;o00139,00027;f3;k010;c25,0;b000;r0;d3,Duff
Beer Rules;<ETX>
<STX>R<ETX>
Now with VB 2005
    Public Sub ReceiveMessage(ByVal ar As IAsyncResult)
        Try
            Dim bytesRead As Integer
            bytesRead = client.GetStream.EndRead(ar)
            If bytesRead < 1 Then
                Exit Sub
            Else
                Dim para() As Object = _
                   {System.Text.Encoding.ASCII.GetString( _
                   data, 0, bytesRead)}
                Me.Invoke(New delUpdateHistory( _
                   AddressOf Me.UpdateHistory), para)
            End If
            client.GetStream.BeginRead( _
               data, 0, CInt(client.ReceiveBufferSize), _
               AddressOf ReceiveMessage, Nothing)
        Catch ex As Exception
        End Try
    End Sub
I get the following...
<STX>R;<ESC>C<ESC>P;<ETX>
<STX>E2;A2,          ;<ETX>
<STX>L39;D0;<ETX>
<STX>W000,          ;o00010,00006;f0;h0342;l0142;w0001;<ETX>
<STX>D39;H001,          ;o00139,000006;f0;h0342;l0142;w0001;<ETX>
<STX>D39;H001,          ;o00139,00027;f342;l0142;w0001;<ETX>
<STX>D39;H001,          ;o00139,00027;f3;k010;c25,39;H001,          ;o00139,00027;f3;k010;c25,0;b000;r0;d3,Duff
Be01;<ETX>
<STX>D39;H001,          ;o00139,00027;f3;k010;c25,0;b000;r0;d39,00027;f3;k010;c25,0;b000;r0;d3,Duff
Beer, oops, Rules;<ETX>
<STX>R<ETX>
I can not figure out why I get the extra lines of data. The Intermec
printer sends the data in 64 byte chunks, don't know if that helps.
I have connected to the same printer using HyperTerminal(Winsock) and
get the same results as in VB 2005.
This is my first attempt at network programming in .Net, so be gentle.
All of my testing has been done on Windows XP.
HyperTerminal, VB6, and VB2005 all running on my PC using the same
network adapter and printer connection.
Any help would be greatly appreciated.
Just a question...  Are you sending something to the printer to get your
response?  And is it possible, that maybe that it is encoded improperly?
- Show quoted text -
Yes, I send the following string to the printer.   <STX><ESC>x2<ETX>
This is the Intermec IPL format. (Intermec Printer Language)
I send the string with the following ....
    Private Sub buttonSend_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles buttonSend.Click
        SendMessage(textCommand.Text)
    End Sub
    Public Sub SendMessage(ByVal message As String)
        Try
            '---send a message to the server
            Dim ns As NetworkStream = client.GetStream
            Dim data As Byte() = _
            System.Text.Encoding.ASCII.GetBytes(message)
            '---send the text---
            ns.Write(data, 0, data.Length)
            ns.Flush()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
Just so you have all of the details, here is the Connect and Begin
Read code.
    Private Sub buttonConnect_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles buttonConnect.Click
        If buttonConnect.Text = "Connect" Then
            Try
                '---connect to server
                client = New TcpClient
                client.Connect("192.168.0.200", IntermecPort)
                '---read from server
                client.GetStream.BeginRead( _
                   data, 0, CInt(client.ReceiveBufferSize), _
                   AddressOf ReceiveMessage, Nothing)
                buttonConnect.Text = "Sign Out"
                buttonSend.Enabled = True
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        Else
            '---disconnect from server
            Disconnect()
            buttonConnect.Text = "Connect"
            buttonSend.Enabled = False
        End If
    End Sub
Here is the delegate routines....
    '---delegate and subroutine to update the TextBox control
    Public Delegate Sub delUpdateHistory(ByVal str As String)
    Public Sub UpdateHistory(ByVal str As String)
        rtbReceive.AppendText(IPL.Interp.Decode(str))
        If rtbReceive.Text.Length > 0 Then
            Try
                Dim CursorPos As Int32
                CursorPos = rtbReceive.SelectionStart
                TestExpression("[<]...[>]")
                'TestExpression("[<]CR[>]")
                'TestExpression("[<]LF[>]")
                rtbReceive.SelectionStart = CursorPos
            Catch ex As Exception
            End Try
        End If
    End Sub
I have gone as far as debug.print in the ReceiveMessage sub to see the
data before it was passed to the delegate with the same results.
If memory serves me, and this is the way back machine, VB4 or was it
5, had a bug where winsock would fire data receive before the data was
actually available. Read that somewhere. Anyway, I don't know how the
TCPClient knows when to fire the callback. Just checking the bytes
read, I can see that the data is coming in 64 byte chunks which still
doesn't tell me how the client knows when to fire the callback.
Boy, this is a really hard one - especially without the printer to
test it on :)  But, you say you get the same result when you connect
to the printer with hyperterminal?  Have you tried using telnet?  You
can telnet to an address and port from the command prompt - unless
your using special emulation...
- Show quoted text -

I tried telnet this morning, same results. I still get the extra data.
I took another look at the VB6 code to see if I was doing something
different. I don't see anything that would make a difference.

Thanks- Hide quoted text -

- Show quoted text -

Tom, I went back to your comment about the encoding and found a
difference.

This is the command string that I was sending with the VB6 app.
<STX><ESC>x2<ETX><ENQ>

This is all I was sending with VB2005.
<STX><ESC>x2<ETX>
... Missing the <ENQ>

Not sure why it would make a difference. But having the <ENQ> made all
the difference in telnet, Hyperterminal, and VB2005.
I modified the VB6 app to exclude the ENQ and got the same results as
2005.

I think this is a difference between using the Serial versus Enet on
the printer side. When I sent the command string without the ENQ via
the serial port in HyperTerminal, the data came back as expected.
Tried again with the ENQ, got good results also.

But, when using Enet, no ENQ means the data will be incorrect. The
Intermec IPL Programmers Reference Manual was written based on Serial
port communications. The optional Enet interface is not covered in the
manual. Infact, it has a separate booklet that covers physical install
and how to set the IP address, and that's it. No mention of IPL or the
protocol used on the Enet interface.

Hopefully, I will not run into anymore undocumented features using the
Enet interface. I guess the next step is to contact Intermec tech
support, who has been trying to help, and see if they can explain the
difference.

Thanks Tom

Well, I'm glad to here you figured it out :) I was wondering if it was
something like that - since you were getting the same result using
hyperterminal, telnet, and vb.net. That was telling me that it wasn't
necessarily a tcp/ip problem :) I guess I can stop reading that Intemec
command reference now :)
 
Top