开发者

serialport connection for unknown device

I've coin machine acceptor set and I wanna connect this machine using serialport. My main problem is, I did try almost every setting to connect that machine. The pin numbers are written on the cable as 3th and 7th. So I try

    private void Form1_Load(object sender, EventArgs e)
    {   
        // SerialPort paraPort d开发者_运维技巧efined 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

        }
    }

The machine is working well. But when I use paraPort.ReadBufferSize property, it gives me 0 when the coin accept :S. When I use the paraPort.Read method it throws an timeout exception :\

So What can I do for this stuff ? I'm using portmon tools to catch the coin machine signal.

IOCTL_SERIAL_WAIT_ON_MASK value is changed as SUCESS when I put the coin. How can I catch this value ?


After several days of work, I have figured out how to connect a coin acceptor/validator machine to a PC via serial port using VB6, such that every coin inserted in the slot will trigger a signal that will be caught by the PC.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜