110,500
社区成员
发帖
与我相关
我的任务
分享
private bool OpenCL2018Com(int iCom, string sBTl)
{
string sTmp;
System.Net.Sockets.Socket wskCL2018 = null;
wskCL2018 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Udp);
wskCL2018.Connect("193.168.18.1", 10003);
System.Net.IPEndPoint endpoint = new System.Net.IPEndPoint(0, 20000 + (iCom - 1) * 2);
wskCL2018.Bind(endpoint);
System.Net.Sockets.Socket wskCl2018BTL = null;
wskCl2018BTL = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Udp);
wskCl2018BTL.Connect("193.168.18.1", 10003);
System.Net.IPEndPoint endpoint1 = new System.Net.IPEndPoint(0, 20001 + (iCom - 1) * 2);
wskCl2018BTL.Bind(endpoint1);
if (sBTl.IndexOf(",") > -1) sTmp = "init " + sBTl.Replace(",", " ");
if (sBTl.IndexOf("-") > -1) sTmp = "init " + sBTl.Replace("-", " ");
"Init 19200 8 1 0 ";
wskCl2018BTL.Send(Encoding.ASCII.GetBytes(sTmp));
}
private bool OpenCL2018Com(int iCom, string sBTl)
{
string sTmp;
wskCL2018.Close();
wskCL2018.RemoteHost = "193.168.18.1";
wskCL2018.RemotePort = 10003;
wskCL2018.Bind(20000 + (iCom - 1) * 2);
wskCl2018BTL.Close(); //(wskCl2018BTL是winsock控件)
wskCl2018BTL.RemoteHost = "193.168.18.1";
wskCl2018BTL.RemotePort = 10003;
wskCl2018BTL.Bind(20001 + (iCom - 1) * 2);
if ( InStr(sBTl, ",") ) { sTmp = "init " + Replace(sBTl, ",", " ")
if ( InStr(sBTl, "-") ) { sTmp = "init " + Replace(sBTl, "-", " ")
“Init 19200 8 1 0 “;
wskCl2018BTL.SendData(sTmp); //(初始化端口波特率)
txtMsg.Text = Time + "-->打开端口COM" + CStr(iCom) + "成功,初始化波特率:" + sBTl + vbCrLf + txtMsg.Text;
bOpenCom = true;
return true;
}
private bool OpenCL2018Com(int iCom, string sBTl)
{
string sTmp;
wskCL2018.Close ;
wskCL2018.RemoteHost = "193.168.18.1" ;
wskCL2018.RemotePort = 10003 ;
wskCL2018.Bind 20000 + (iCom - 1) * 2 ;
wskCl2018BTL.Close (wskCl2018BTL是winsock控件);
wskCl2018BTL.RemoteHost = "193.168.18.1";
wskCl2018BTL.RemotePort = 10003;
wskCl2018BTL.Bind 20001 + (iCom - 1) * 2 ;
if ( InStr(sBTl, ",") ) { sTmp = "init " + Replace(sBTl, ",", " ")
if ( InStr(sBTl, "-") ) { sTmp = "init " + Replace(sBTl, "-", " ")
“Init 19200 8 1 0 “;
Call wskCl2018BTL.SendData(sTmp) (初始化端口波特率);
txtMsg.Text = Time + "-->打开端口COM" + CStr(iCom) + "成功,初始化波特率:" + sBTl + vbCrLf + txtMsg.Text;
OpenCL2018Com = true;
bOpenCom = true;
}