未知设备的串行端口连接

时间:2011-01-01 16:21:39

标签: c# .net hardware serial-port

我有投币机接受器设置,我想使用serialport连接这台机器。我的主要问题是,我几乎尝试了连接该机器的所有设置。引脚编号在电缆上写为第3和第7。所以我试试

    private void Form1_Load(object sender, EventArgs e)
    {   
        // SerialPort paraPort defined at designer's generated code        
        paraport = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);


        //I wanna access to windows controls from the thread
        System.Windows.Forms.Form.CheckForIllegalCrossThreadCalls = false;
    }


    private void button2_Click(object sender, EventArgs e)
    {
        //paraPort is the name of serialport class
        paraPort.ReadBufferSize = 1024;
        paraPort.WriteBufferSize = 1024;
        paraPort.ReadTimeout = 1000;
        paraPort.WriteTimeout = 1000;
        paraPort.NewLine = "\n";

        //Because 7th pin is for RTS which means request 2 send
        paraPort.Handshake = Handshake.RequestToSend;


        //Data Terminal Ready Enable
        paraPort.DtrEnable = true;
        paraPort.RtsEnable = true;
        paraPort.Open();

        //Then Thread check the procedure inside of try - catch block

     try{
        // Thread money defined at designer's generated code
        money = new Thread(new ThreadStart(CheckTheMachineState));
        money.Start();
     }catch(Exception e){
        MessageBox.Show("thread cannot be created"+e.Message);
     }

     }


        private void CheckTheMachineState()
        {
            richTextBox1.AppendText("Thread is running\n");


            //I wanna get the value of IOCTL_SERIAL_WAIT_ON_MASK
            //But I still don't know how

        }
    }

机器运转良好。但是当我使用paraPort.ReadBufferSize属性时,它在硬币接受时给出0:S。当我使用paraPort.Read方法时,它会抛出一个超时异常:\

那么我能为这些东西做些什么呢?我正在使用portmon工具来捕获投币机信号。

当我放硬币时,

IOCTL_SERIAL_WAIT_ON_MASK值变为SUCESS。我怎样才能抓住这个价值?

1 个答案:

答案 0 :(得分:0)

经过几天的工作,我已经想出如何使用VB6通过串口将硬币接收器/验证器机器连接到PC,这样插入插槽的每个硬币都会触发一个信号将被PC捕获