本文整理汇总了C#中Frame.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Frame.ToString方法的具体用法?C# Frame.ToString怎么用?C# Frame.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Frame
的用法示例。
在下文中一共展示了Frame.ToString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendAsync
/// <summary>
/// Sends a Frame to the PLC
/// </summary>
/// <param name="frame">The <see cref="Omron.Core.Frames.Frame">Frame</see> to be sent to the PLC</param>
/// <returns></returns>
public async Task SendAsync(Frame frame)
{
byte[] bytes = frame.BuildFrame();
Trace.WriteLine("Sending: " + Environment.NewLine + frame.ToString());
await stream.WriteAsync(bytes, 0, bytes.Length - 1);
}
示例2: ReceiveAsync
public async Task<Frame> ReceiveAsync()
{
byte[] buffer;
int read = 0;
const int READ_SIZE = 512;
buffer = new byte[client.ReceiveBufferSize];
int chunk;
while ((chunk = await stream.ReadAsync(buffer, read, buffer.Length - read)) > 0)
{
read += chunk;
if (read == buffer.Length)
{
int nextByte = stream.ReadByte();
if (nextByte == -1)
{
break;
}
byte[] newBuffer = new byte[buffer.Length * 2];
Array.Copy(buffer, newBuffer, buffer.Length);
newBuffer[read] = (byte)nextByte;
buffer = newBuffer;
read++;
}
}
// Buffer is now too big. Shrink it.
byte[] ret = new byte[read];
Array.Copy(buffer, ret, read);
var frame = new Frame(ret);
Trace.WriteLine("Received: " + Environment.NewLine + frame.ToString());
return frame;
}