RS232仿真问题 [英] Problem with RS232 emulation

查看:74
本文介绍了RS232仿真问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

与仿真的RS232 COM端口的连接存在一些问题.

我使用以下代码:

Hello,

I've some problems with the connection to a emulated RS232 COM port.  

I use the following code:

<身体>
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Text;
使用System.IO.Ports;
命名空间ConsoleApplication1
{
类课程
{
静态SerialPort m_SerialPort;
静态void Main(string [] args)
{
Console.WriteLine(尝试打开COM8....");
m_SerialPort = SerialPort();
尝试
{
m_SerialPort.PortName =" " COM8" ;
m_SerialPort.Open();
渔获(Exeption ex)
.{
Console.WriteLine(convert.tostring(ex));
如果是(m_SerialPort.IsOpen)
.{
Console.WriteLine(端口已打开!");
m_SerialPort.Close();
否则
{
Console.WriteLine(打开时出现问题!");
Console.Read();
}
}
using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
using System.IO.Ports;  
 
namespace ConsoleApplication1  
{  
    class Program  
    {  
        static SerialPort m_SerialPort;  
 
        static void Main(string[] args)  
        {  
            Console.WriteLine("try to open COM8....");  
            m_SerialPort = new SerialPort();  
            try  
            {  
                m_SerialPort.PortName = "COM8";  
                m_SerialPort.Open();  
            }  
            catch(Exeption ex)
            {  
                Console.WriteLine(convert.tostring(ex));  
            }  
            if (m_SerialPort.IsOpen)  
            {  
                Console.WriteLine("port is open!");  
                m_SerialPort.Close();  
            }  
            else  
            {  
                Console.WriteLine("Problem while opening!");  
            }  
            Console.Read();  
        }  
    }  
}  
 

推荐答案

将PortName更改为"COM8:"工作更好吗?

Hyperterm是否仍打开COM8?如果是这样,您将收到访问被拒绝"的异常消息.详细信息.

否则,请发布异常的详细信息,以便他人提供有用的指导.
Does changing the PortName to "COM8:" work any better?

Is COM8 still opened by Hyperterm?  If so you'll get an exception with "access denied" detail.

Otherwise, please post the detail of the exception for someone to provide useful guidance.


这篇关于RS232仿真问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆