使用wcf服务的串行comport通信 [英] Serial comport communication using wcf services

查看:72
本文介绍了使用wcf服务的串行comport通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在wcf seervice中编写用于在comport上写入数据的方法: - COM1



  if (!(comPort.IsOpen ==  true ))comPort.Open(); 
// 将消息转换为字节数组
byte [] newMsg = StingToAscii(msg);
// 将消息发送到端口
comPort.Write(newMsg, 0 ,newMsg.Length);





当我调用方法然后首先时间在端口上写入数据,但第二次得到错误: - 端口COM1的访问被拒绝。



当我评论此行时

  //   if(!(comPort.IsOpen == true))comPort.Open();  



然后得到错误: - Comport关闭



请建议我。它非常有用。



在此先感谢



Chandrashekhar

解决方案

我想我需要更多的代码来试图提供帮助。这段代码是如何使用的?在一个物体里面?在您的服务?你有这个对象的多个实例吗? (不止一个连接?)



也许(只是一个想法,这就是为什么我把它从评论转移到解决方案)你必须使这个方法静态

Writing method in wcf seervice for write data on comport:- COM1

if (!(comPort.IsOpen == true)) comPort.Open();
                       //convert the message to byte array
                       byte[] newMsg = StingToAscii(msg);
                       //send the message to the port
                       comPort.Write(newMsg, 0, newMsg.Length);



when i call method then first time write data on port but second time get error:-Access to the port 'COM1' is denied.

when I comment this line

//if (!(comPort.IsOpen == true)) comPort.Open();


then get error :- Comport is Closed

please Suggest me. Its very ugent.

Thanks In Advance

Chandrashekhar

解决方案

I think I need some more of your code to try to help. How is this code used? Inside an object? In your Service? Do you have more than one instances of this object? (more than one connection?)

Maybe (just an idea, and thats why i moved this from Comment to solution) you have to make this method static?


这篇关于使用wcf服务的串行comport通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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