Rpi - 不能在我的C#程序中使用我的/ dev / hidraw0作为序列号

时间:2014-11-30 10:45:57

标签: c# usb raspberry-pi barcode-scanner hid

我想使用我的USB条码扫描器,它使用C#代码在我的Raspi B +设备上/dev/hidraw0下。

这是我目前的计划:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO.Ports;

namespace USBSupp5
{
    class Program
    {
        static void Main(string[] args)
        {
           SerialPort sp = new SerialPort("/dev/hidraw0", 115200, Parity.None, 20);
           sp.Open();
        }
    }
}

以下是例外:

Unhandled Exception: System.IO.IOException: No such file or directory
at System.IO.Ports.SerialPortStream.ThrowIOException () [0x00000] in <filename unknown>:0
at System.IO.Ports.SerialPortStream..ctor (System.String portName, Int32 baudRate, Int32 dataBits, Parity parity, StopBits stopBits, Boolean dtrEnable, Boolean rtsEnable, Handshake handshake, Int32 readTimeout, Int32 writeTimeout, Int32 readBufferSize, Int32 writeBufferSize) [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPortStream:.ctor (string,int,int,System.IO.Ports.Parity,System.IO.Ports.StopBits,bool,bool,System.IO.Ports.Handshake,int,int,int,int) at System.IO.Ports.SerialPort.Open () [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPort:Open ()
at USBSupp5.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0

[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.IOException: No such file or directory
at System.IO.Ports.SerialPortStream.ThrowIOException () [0x00000] in <filename unknown>:0
at System.IO.Ports.SerialPortStream..ctor (System.String portName, Int32 baudRate, Int32 dataBits, Parity parity, StopBits stopBits, Boolean dtrEnable, Boolean rtsEnable, Handshake handshake, Int32 readTimeout, Int32 writeTimeout, Int32 readBufferSize, Int32 writeBufferSize) [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPortStream:.ctor (string,int,int,System.IO.Ports.Parity,System.IO.Ports.StopBits,bool,bool,System.IO.Ports.Handshake,int,int,int,int) at System.IO.Ports.SerialPort.Open () [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPort:Open ()
at USBSupp5.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0

1 个答案:

答案 0 :(得分:0)

好吧没关系。通过进一步的研究,我发现我的条形码扫描器被视为标准输入设备(键盘),我的Raspi已经支持驱动程序。因此,无需使用程序,因为条形码扫描仪的输入已被正确解释。

我通过笔记本电脑通过SSH编程我的Raspi,条形码扫描仪连接到我的Raspi。我没看到条形码扫描仪输入的原因是因为通过SSH标准输入(STDIN)是我的笔记本电脑,而不是Raspi pheripherial设备(IE.USB端口)