用c#改写一段VB程序

lostowner 2009-08-18 09:20:09
Private Function OpenCL2018Com(iCom As Integer, sBTl As String) As Boolean
Dim sTmp As String

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, ",") Then sTmp = "init " & Replace(sBTl, ",", " ")
If InStr(sBTl, "-") Then 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
End Function

说明:
wskCL2018是winsock 采用的是UDP的通讯方式
...全文
121 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuyingying1986 2009-08-19
  • 打赏
  • 举报
回复

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));


}


大概就是这样吧,wskCl2018BTL.SendData(sTmp)的编码机制我不清楚,所以我就用的Ascii码,你可以自己改一下
lostowner 2009-08-19
  • 打赏
  • 举报
回复
这么个问题都2天了还没人解决 哎
Zeilone 2009-08-18
  • 打赏
  • 举报
回复
InStr和Replace这两个函数好像C#里没有,记不太清了
如果没有,可以用string类的find和replace函数替换
Zeilone 2009-08-18
  • 打赏
  • 举报
回复

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;
}

lostowner 2009-08-18
  • 打赏
  • 举报
回复
wangjun8868:
你就把函数名翻译一下啊 赚分也不是这样赚的
马老虎 2009-08-18
  • 打赏
  • 举报
回复
spices 反编译.rar
+QQ 发个你 124339316
编程有钱人了 2009-08-18
  • 打赏
  • 举报
回复
翻译完毕

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;
}
yeaicc 2009-08-18
  • 打赏
  • 举报
回复
强烈建议:

sharpdevelop代码转换



上一个好像打不开
yeaicc 2009-08-18
  • 打赏
  • 举报
回复



强烈建议:

sharpdevelop代码转换
编程有钱人了 2009-08-18
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 lostowner 的回复:]
wangjun8868:
你就把函数名翻译一下啊 赚分也不是这样赚的
[/Quote]

不好意思

翻译完了 没仔细看 也没运行

有些东西在VB有的c#没有
lostowner 2009-08-18
  • 打赏
  • 举报
回复
VB里的程序是另一个系统里的 ...
robin521 2009-08-18
  • 打赏
  • 举报
回复
有必要吗?.NET平台下运行进来都是中间语言,不转换不一样用.C#+VB一起用.
lostowner 2009-08-18
  • 打赏
  • 举报
回复
InStr和Replace 这两个函数无关紧要 关键是(wskCl2018BTL是winsock控件)
里面用到了2个port 我没明白是啥意思。。

wskCl2018BTL.RemotePort = 10003;
wskCl2018BTL.Bind 20001 + (iCom - 1) * 2 ;
谁能解释下 。。

还有就是c#中socket怎么用这两个端口。。。

110,500

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧