Login  
Search All Forums
Dart Home | PowerTCP Emulation for .NET | Custom Development Reply | PowerTCP Emulation for .NET Topics | Forums   
AuthorForum: PowerTCP Emulation for .NET
Topic: Breaking up Data into parts
sbowyer

From: Exeter, RI USA
Posts: 4
Member Since: 11/07/11
posted November 11, 2011 11:48 AM

For the .NET Emulator package, I need to be able to read in data, send all or part of it to the vt component, and also act on it.
So itís a combination of automated and interactive client.

If I do a read:

data = Telnet.Read(buffer, 0, 1024);

and then discover I only really needed 500 bytes of it, I seem to only be able to send the whole thing to the emulator:

Telnet.Marshal(data, string.Empty, null);
(telnet1_Data part:) vt1.Write(e.Data.Buffer, e.Data.Offset, e.Data.Count);

Is there a way I can break up the data to send only the part I want the user to see:

Part1 = data.Substr(0,500);
Part2 = data.Substr(500, 524);

Telnet.Marshal(part1, Ö);

I donít see anything in the manual page for Data for this
Jason Farrar (Admin)

From: USA
Posts: 223
Member Since: 07/24/07

Extra Support Options
Custom Application Development

posted November 11, 2011 1:02 PM

The e.Data.Buffer is just a byte array so you can use vt1.Write method like this:

vt1.Write(e.Data.Buffer,0,500); //Will write the first 500 bytes.

vt1.Write(e.Data.Buffer, 500, 564)l //Will write bytes 500-564.
sbowyer

From: Exeter, RI USA
Posts: 4
Member Since: 11/07/11
posted November 11, 2011 1:25 PM

Thanks very much for the quick response. Unfortunately, the vt1.Write part is too late. The problem is the telnet marshal:

Telnet.Marshal(data, string.Empty, null);

That's not byte[], it's Data. That's the one I need to split. By the time it gets over to the other side (foreground thread), it's not going to know where to split it.
Jason Farrar (Admin)

From: USA
Posts: 223
Member Since: 07/24/07

Extra Support Options
Custom Application Development

posted November 11, 2011 3:14 PM

Where you are sending in null in the Marshall method you can send the parameters as an int array and cast it in the event like this:

Telnet.Marshal(data, string.Empty, new int[]{500,524});

Event:

    void telnet1_Data(object sender, DataEventArgs e)
    {
      int[] writepositions = { e.Data.Offset, e.Data.Count };
      //try catch just for safety.
      try
      {
         writepositions = e.UserState as int[];
      }
      catch{}

      //Received data is marshaled to this function
      vt1.Write(e.Data.Buffer, writepositions[0], writepositions[1]);
      vt1.Focus();
    }

Note that this is just a quick example of how to do this, if I were going to do something like this for a production application I would create a class object to hold the positions instead of just using a raw int array. You could also just pass the bytes you actually want to write as a byte array for the state object and just use that instead of the data object's buffer property.
sbowyer

From: Exeter, RI USA
Posts: 4
Member Since: 11/07/11
posted November 15, 2011 11:43 AM

Interesting. So if you want to send the whole Data packet, you do:

Telnet.Marshal(data, string.Empty, null);

If you want to pass only part of the packet, you do:

Telnet.Marshal(data, string.Empty, new int[]{500,524});

The telnet1_Data() routine stays the same in both cases because the DataEvent argument is always filled out with the offset and count.

This still involves remembering what portion of the Data packet I sent already between calls. I suppose there is nothing like:

Data d = Partof(oldData)

to create a new Data object to Marshal?
Jason Farrar (Admin)

From: USA
Posts: 223
Member Since: 07/24/07

Extra Support Options
Custom Application Development

posted November 16, 2011 4:42 PM

Thank you for bringing this up. Currently there is not a way to create a new Data object to marshal, we expect to provide this functionality in the next release of PowerTCP Emulation for .NET.
Reply | PowerTCP Emulation for .NET Topics | Forums   
This site is powered by PowerTCP WebServer Tool PowerTCP WebServer for ActiveX