|
| | UsbConnection () |
| | 根據 vendorId 和 productId 初始化新類實例。此實例的目標是與 vendorId 和 productId 匹配的第一個印表機。 更多...
|
| |
|
| UsbConnection (short vendorId) |
| |
|
| UsbConnection (short vendorId, short productId) |
| |
| | UsbConnection (string descriptor) |
| | 根據 descriptor 字符串初始化新類實例。 更多...
|
| |
|
override void | Close () |
| | Closes a connection.
|
| |
|
override void | Open () |
| | Opens a connection.
|
| |
|
override byte[] | Read () |
| | Read all bytes available.
|
| |
|
virtual void | Read (BinaryWriter binDataIn) |
| | Reads all bytes available into the stream passed in.
|
| |
| virtual void | WaitForData (int msTimeOut) |
| | 等待數據可用 BytesAvailable 在當前線程。當前線程休眠直到接收到數據或超時。阻塞調用。 更多...
|
| |
| virtual void | Write (BinaryReader binReader) |
| | 從輸入流寫入輸出流 更多...
|
| |
|
override void | Write (byte[] dataOut) |
| | Writes all bytes from the array passed in.
|
| |
| virtual void | WriteAndWaitForResponse (BinaryWriter binDataIn, BinaryReader binDataOut, int responseStartTimeOut, int responseEndTimeOut, string completetionToken) |
| | 將 binDataOut 流數據寫入輸出流,並將接收到的數據返回到 binDataIn 流中。返回的數據是接收到的任何數據或達到接收的完成令牌。如果沒有回應則在返回前等待超時。 更多...
|
| |
| virtual byte[] | WriteAndWaitForResponse (byte[] dataOut, int responseStartTimeOut, int responseEndTimeOut, string completetionToken) |
| | 將字節數據寫入輸出流並返回接收到的數據。返回的數據是接收到的任何數據或達到接收的完成令牌。在返回前等待回應超時。 更多...
|
| |
實現USB特定通信並擴展AComm類的類別。
範例
using System;
using System.IO;
using System.Text;
namespace Snippets
{
class MyComm
{
public static void MainComm(string[] args)
{
SendPrintFile();
SendPrintString();
}
public static void SendPrintFile()
{
if (devices.Count > 0)
{
string fileName = @"C:\testFiles\Hello.pgl";
try
{
PtrUsbComm.Open();
if (File.Exists(fileName))
{
using (BinaryReader binReader = new BinaryReader(File.Open(fileName, FileMode.Open)))
{
Console.WriteLine($"Sending \"{fileName}\" to printer");
PtrUsbComm.Write(binReader);
}
}
else
{
Console.WriteLine($"File \"{fileName}\" not found");
}
}
catch (Exception e)
{
Console.WriteLine($"Exception Msg: {e.Message}");
}
finally
{
PtrUsbComm.Close();
}
}
}
public static void SendPrintString()
{
string dataToPrint =
@"~CREATE;C39;72
SCALE;DOT
PAGE;30;40
ALPHA
C10;1;33;0;0;@HELLO@
C16;54;37;0;0;@*World*@
STOP
BARCODE
C128C;XRD3:3:6:6:9:9:12:12;H6;10;32
@World@
STOP
END
~EXECUTE;C39
~NORMAL
";
if (devices.Count > 0)
{
try
{
PtrUsbComm.Open();
if (PtrUsbComm.Connected)
{
byte[] outBytes = Encoding.ASCII.GetBytes(dataToPrint);
PtrUsbComm.Write(outBytes);
}
else
{
Console.WriteLine($"Not connected to printer");
}
}
catch (Exception e)
{
Console.WriteLine($"Exception Msg: {e.Message}");
}
finally
{
PtrUsbComm.Close();
}
}
}
}
}