所以,我試圖使用我的條碼掃描器作爲'串行'設備,而不是鍵盤模擬器,但它不創建com端口。我掃描了手冊中的設置代碼,將其設置爲串行設備,似乎正確配置掃描儀(它停止將掃描代碼發送到文本框\文本編輯器),但由於沒有COM端口,我無法當我掃描條形碼時捕獲數據......條碼掃描器 - 串行端口
Windows第一次插入時安裝了驅動程序,沒有提供磁盤\驅動程序......想知道是否有其他人遇到過相同的問題.....
這裏是我的代碼....
class Program
{
// Create the serial port with basic settings
private SerialPort port = new SerialPort("com1", 9600, Parity.None, 8, StopBits.One);
[STAThread]
static void Main(string[] args)
{
new Program();
}
private Program()
{
string[] ports = System.IO.Ports.SerialPort.GetPortNames();
Console.WriteLine("Incoming Data:");
// Attach a method to be called when there
// is data waiting in the port's buffer
port.DataReceived += new
SerialDataReceivedEventHandler(port_DataReceived);
// Begin communications
port.Open();
// Enter an application loop to keep this thread alive
Application.Run();
}
private void port_DataReceived(object sender,
SerialDataReceivedEventArgs e)
{
// Show all the incoming data in the port's buffer
Console.WriteLine(port.ReadExisting());
}
}
我得到錯誤信息...... '端口 'COM1' 不存在' ......當我嘗試打開P ORT。
當我創建了一個虛擬端口(使用第三方應用程序)代碼運行,但我仍然沒有從掃描儀獲取數據....
您必須編寫一段代碼才能連接到COM端口,如果沒有通過指定端口,波特率,數據位和其他幾個參數顯式連接到掃描器,掃描器將無法工作。它與捕捉數據不同,而不是鍵盤模式。 – lucas
@ mauro21pl是的,這樣做,是否已經添加了我的代碼,我收到錯誤信息.....'端口'com1'不存在'.....當我嘗試打開端口時。也許我做錯了什麼.... – User45362
這將是「COM1」,而不是「COM1」?無法記住它是否在DOS時間區分大小寫......只需在您的'ports'中調試值即可。 –