How to do robust SerialPort programming with .NET / C#?

前端 未结 9 1398
心在旅途
心在旅途 2020-12-23 10:22

I\'m writing a Windows Service for communication with a Serial Mag-stripe reader and a relay board (access control system).

I run into problems where the code stops

9条回答
  •  时光说笑
    2020-12-23 10:48

    I think I have come to the conclusion that HyperTerminal does not play well. I've run the following test:

    1. Start my service in "console mode", it starts switching the device on/off (i can tell by it's LED).

    2. Start HyperTerminal and connect to the port. The device stays on (HyperTerminal raises DTR) My service writes to the event log, that it cannot open the port

    3. Stop HyperTerminal, I verify it is properly closed using task manager

    4. The device stays off (HyperTerminal has lowered DTR), my app keeps on writing to the event log, saying it cannot open the port.

    5. I start a third application (the one I need to coexist with), and tell it to connect to the port. I does so. No errors here.

    6. I stop the above mentioned application.

    7. VOILA, my service kicks in again, the port opens successfully, and the LED goes ON/OFF.

提交回复
热议问题