用c#改写一段VB程序
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的通讯方式
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的通讯方式
...全文
相关推荐
vb转c#程序
vb转c#程序,经常上机使用,是难得的好软件
Modbus RTU TCP主站从站类库内有说明文档及C#和VB.net例子程序
Modbus RTU TCP主站从站类库内有说明文档及C#和VB.net例子程序,很详细,适用于上位机开发人员,内部已打包为dll文件直接对照说明文档和例子程序引用即可,
C#与Vb.net代码互转工具
在离线状态下,可将C#转为Vb.net代码,或将Vb.net转为c#代码,非常简单方便。
vb6到c#迁移程序对照表PDF
数据类型对照,函数对照,方法对照,常量对照,命令字对照。。。
VB和C#互相调用
1.VB调用C#编写的dll 2.C#调用VB写的Dll


