Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在C中使用VSPE tcpclient/tcpserver_C#_Serial Port - Fatal编程技术网

C# 在C中使用VSPE tcpclient/tcpserver

C# 在C中使用VSPE tcpclient/tcpserver,c#,serial-port,C#,Serial Port,我尝试使用VSPE COM服务在我的C程序中创建TCP客户端和TCP服务器。除了创建的TcpServer/TcpClient在运行时占用了太多的CPU时间外,其他一切似乎都正常—其中2个可能占用我100%的CPU时间。有人能帮忙吗 服务器创建: string comName = "COM2"; string tcpPortNum = "5555"; string ipAddr = LocalServerIpAddress.ToString(); string initString = tcpPo

我尝试使用VSPE COM服务在我的C程序中创建TCP客户端和TCP服务器。除了创建的TcpServer/TcpClient在运行时占用了太多的CPU时间外,其他一切似乎都正常—其中2个可能占用我100%的CPU时间。有人能帮忙吗

服务器创建:

string comName = "COM2";
string tcpPortNum = "5555";
string ipAddr = LocalServerIpAddress.ToString();
string initString = tcpPortNum + ";" + comName.Remove(0, 3) + ";19200,0,8,1,0,0;" + ipAddr + ";0;0";

// Create
int result = vspe.vspe_createDevice("TcpServer", initString);
客户端创建:

string comName = "COM3";
string tcpPortNum = "5555";
string ipAddr = remoteServerIpAddr.ToString();
string initString = ipAddr + ";" + tcpPortNum + ";" + comName.Remove(0, 3) + ";19200,0,8,1,0,0;0;30;;0;0";

// Create
int result = vspe.vspe_createDevice("TcpClient", initString);

代码确实使用了VSPE提供的[com]服务,这是微软的组件对象模型。我最终放弃了使用VSPE创建com端口——tcpserver和tcpclient。并且从零开始完全编程了我自己的com tcp服务器/客户端。并将通信量从com端口转发到tcpserver/客户端,类似地,将数据从tcp转发到com端口。不过,欢迎评论。