使用串口控件sax.net
http://www.sax.net/framework/communications/
我已经用它成功地应用于串口数据采集.

解决方案 »

  1.   

    up 学习!!
    不知道调用API函数有没有用!
      

  2.   

    hongchao(love) 
    使用串口控件sax.net
    有没有注册版的!
    有的话!给一个!
    [email protected]
    谢了!!
      

  3.   

    看看天极上的这篇文章会大有帮助的:http://www.yesky.com/SoftChannel/72342380468109312/20040523/1800310.shtml范例中 JustinIO.cs 操作串口一点问题都没有。
      

  4.   

    用mscomm,然后在他的 on_comm事件中就收到上传的数据了.
    这就是那个接收的代码
    private void axMSComm_OnComm(object sender, System.EventArgs e)
    {
    switch( this.axMSComm.CommEvent)
         {
    case (int)CommEvent.MSCommEvReceive:
    {
       if(this.axMSComm.InBufferCount>0)
          Byte[] newByte = (Byte[])this.axMSComm.Input;
       //这里就写的你的分析代码就可以了 AnalyseData();
    }

    break;
         }
    case (int)CommEvent.MSCommEvSend:
    {
    break;
    } case (int)CommError.MSCommErBreak:
    {
    StrLastError = "接收到中断信号!";
    TestErrorList.Add(StrLastError);
    Console.WriteLine(StrLastError);
    break;
    } case (int)CommError.MSCommErCTSTO:
    {
    StrLastError = "Clear To Send 超时!";
    TestErrorList.Add(StrLastError);
    Console.WriteLine(StrLastError);
    break;
    } case (int)CommError.MSCommErDSRTO:
    {
    StrLastError = "Data Set Ready 线为低电平!";
    TestErrorList.Add(StrLastError);
    Console.WriteLine(StrLastError);
    break;
    } case (int)CommError.MSCommErFrame:
    {
    StrLastError = "帧错误!";
    TestErrorList.Add(StrLastError);
    Console.WriteLine(StrLastError);
    break;
    } case (int)CommError.MSCommErOverrun:
    {
    StrLastError = "端口超速!";
    TestErrorList.Add(StrLastError);
    Console.WriteLine(StrLastError);
    break;
    } case (int)CommError.MSCommErCDTO:
    {
    StrLastError = "载波检测超时!";
    TestErrorList.Add(StrLastError);
    Console.WriteLine(StrLastError);
    break;
    }

    case (int)CommError.MSCommErRxOver:
    {
    this.ClearReceiveBuf();
    StrLastError = "接受缓冲区溢出!";
    TestErrorList.Add(StrLastError);
    Console.WriteLine(StrLastError);
    break;
    } case (int)CommError.MSCommErRxParity:
    {
    StrLastError = "奇偶校验!";
    TestErrorList.Add(StrLastError);
    Console.WriteLine(StrLastError);
    break;
    } case (int)CommError.MSCommErTxFull:
    {
    this.ClearSendBuf();
    StrLastError = "传输缓冲区已满!";
    TestErrorList.Add(StrLastError);
    Console.WriteLine(StrLastError);
    break;
    } case (int)CommError.MSCommErDCB:
    {
    StrLastError = "载波检测超时!";
    TestErrorList.Add(StrLastError);
    Console.WriteLine(StrLastError);
    break;
    }

    default:
    {
    StrLastError = "硬件意外错误!";
    TestErrorList.Add(StrLastError);
    Console.WriteLine(StrLastError);
    break;
    }
    }
    }
    }
      

  5.   

    如果要发送,就这么写就行了.
    public void SendData(Byte sendData)
    {
    try 
    {
    Byte[] sendChar = new Byte[1];
    sendChar[0] = sendData;
    this.axMSComm.Output = sendChar;
    Thread.Sleep(6);
    }
    catch(Exception e)
    {
    MessageBox.Show(e.ToString());
    }
    }
      

  6.   

    yangzhenhai(叉子) 的方法可行,这以前也是这样用的.
      

  7.   

    个人感觉mscomm不太好用。
    我用的是:http://www.codeproject.com/dotnet/DotNetComPorts.asp
      

  8.   

    好贴,顶,有大哥知道怎样用vc开发的.dll在.net上使用?找了很久没找到,help!!!
      

  9.   

    在VB.Net资源包中有Sax的Free版本。