VB.NET做上位机 serialport控件问题要用委托的形式(界面上拖一个txt_Rect文本框)
Delegate Sub SetTextCallback(ByVal InputString As String)
Private Sub ShowString(ByVal comData As String)
txt_Rect.Text= comData'将收到的数据入接收文字框中
txt_Rect.SelectionStart = txt_Rect.Text.Length
txt_Rect.ScrollToCaret()
End Sub
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
Dim inData As String = SerialPort1.ReadExisting
Dim d As New SetTextCallback(AddressOf ShowString)
BeginInvoke(d, inData)
End Sub
能给我发个VB与三菱PLC通讯的源代码实例吗,非常感谢啊得说明是什么型号的PLC啊vb.net上位机实例,串口还是网口vb.net上位机实例,VB6还是VB.NET?
算了vb.net上位机实例,写段代码vb.net上位机实例 , VB.NET与Q系列以太网通讯的:
Imports System.Net
Imports System.Runtime.InteropServices
Public Class Form1
Dim Handle1 As Int32
Dim EntLink1 As Boolean
Dim ScanCount1 As Long
Dim PLC As New EntQsPlc_Asc.PlcClient'EntQsPlc_ASC.DLL是Q系列以太网通讯组件
Public Declare Function timeGetTime Lib "winmm.dll" () As UInt32
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.CenterToScreen()
cmbReadMry.Items.Clear()
cmbReadMry.Items.Add("X")
cmbReadMry.Items.Add("Y")
cmbReadMry.Items.Add("M")
cmbReadMry.Items.Add("D")
cmbReadMry.Items.Add("R")
cmbReadMry.Items.Add("Z")
'
cmbWriteMry.Items.Clear()
cmbWriteMry.Items.Add("X")
cmbWriteMry.Items.Add("Y")
cmbWriteMry.Items.Add("M")
cmbWriteMry.Items.Add("D")
cmbWriteMry.Items.Add("R")
cmbWriteMry.Items.Add("Z")
'
cmbBitMry.Items.Clear()
cmbBitMry.Items.Add("X")
cmbBitMry.Items.Add("Y")
cmbBitMry.Items.Add("M")
'
cmbReadType.Items.Clear()
cmbReadType.Items.Add("INT16")
cmbReadType.Items.Add("UINT16")
cmbReadType.Items.Add("DINT32")
cmbReadType.Items.Add("HEX32")
cmbReadType.Items.Add("REAL32")
cmbReadType.Items.Add("BIN16")
'
cmbWriteType.Items.Clear()
cmbWriteType.Items.Add("INT16")
cmbWriteType.Items.Add("UINT16")
cmbWriteType.Items.Add("DINT32")
cmbWriteType.Items.Add("HEX32")
cmbWriteType.Items.Add("REAL32")
cmbWriteType.Items.Add("BIN16")
cmbReadMry.SelectedIndex = 3
cmbWriteMry.SelectedIndex = 3
cmbBitMry.SelectedIndex = 2
cmbReadType.SelectedIndex = 0
cmbWriteType.SelectedIndex = 0
lstRead.Items.Clear()
txtWrite.Text = ""
'
cmbCmdType.SelectedIndex = 0
End Sub
Private Sub butLink_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butLink.Click
Dim re As Short
Dim restr As String = ""
re = PLC.EntLink(Trim(txtLocalIP.Text), Val(txtLocalPort.Text), Trim(txtRemoteIP.Text), Val(txtRemotePort.Text), "DEMO", Handle1, 1000, CBool(cmbCmdType.SelectedIndex))
txtReLink.Text = re.ToString
If re = 0 Then
EntLink1 = True
MsgBox("PLC联接成功! ")
Else
EntLink1 = False
MsgBox("PLC联接失败: "restr)
End If
End Sub
Private Sub butClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butClose.Click
Dim re As Short
If Not EntLink1 Then
MsgBox("还未与PLC建立联接!")
Exit Sub
End If
re = PLC.DeLink(Handle1)
txtReClose.Text = re.ToString
End Sub
Private Sub butRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butRead.Click
Dim re As Short
Dim i As Short
Dim RD() As Object
ReDim RD(Val(txtReadCnt.Text - 1))
If Not EntLink1 Then
MsgBox("还未与PLC建立联接!")
' Exit Sub
End If
Dim mry As EntQsPlc_Asc.PlcClient.PlcMemory = cmbReadMry.SelectedIndex1
Dim typ As EntQsPlc_Asc.PlcClient.DataType = cmbReadType.SelectedIndex1
re = PLC.CmdRead(Handle1, mry, typ, CInt(txtReadAdd.Text), CUShort(txtReadCnt.Text), RD)
txtReRead.Text = re.ToString
lstRead.Items.Clear()
For i = 0 To UBound(RD) Step 1
If Not IsNothing(RD(i)) Then lstRead.Items.Add(RD(i))
Next i
If re0 Then
Timer1.Enabled = False
butScan.Text = "Cycle R/W"
End If
End Sub
Private Sub butWrite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butWrite.Click
Dim re As Short
Dim i As Short
Dim temp() As String
Dim WD() As Object
If Not EntLink1 Then
MsgBox("还未与PLC建立联接!")
Exit Sub
End If
ReDim WD(Val(txtWriteCnt.Text) - 1)
temp = Split(txtWrite.Text, vbCrLf)
For i = 0 To UBound(WD) Step 1
If iUBound(temp) Then
WD(i) = 0
Else
WD(i) = Trim(temp(i))
End If
Next i
Dim mry As EntQsPlc_Asc.PlcClient.PlcMemory = cmbWriteMry.SelectedIndex1
Dim typ As EntQsPlc_Asc.PlcClient.DataType = cmbWriteType.SelectedIndex1
re = PLC.CmdWrite(Handle1, mry, typ, CInt(txtWriteAdd.Text), CUShort(txtWriteCnt.Text), WD)
txtReWrite.Text = re.ToString
If re0 Then
Timer1.Enabled = False
butScan.Text = "Cycle R/W"
End If
End Sub
Private Sub butScan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butScan.Click
If Not EntLink1 Then
MsgBox("还未与PLC建立联接!")
Exit Sub
End If
Timer1.Enabled = Not Timer1.Enabled
If Timer1.Enabled Then
ScanCount1 = 0
butScan.Text = "Stop R/W"
Else
butScan.Text = "Cycle R/W"
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Enabled = False
Dim tim As Integer = timeGetTime
If Not EntLink1 Then
MsgBox("还未与PLC建立联接!")
Exit Sub
End If
'
Call butRead_Click(Nothing, Nothing)
Call butWrite_Click(Nothing, Nothing)
'
If (Val(txtReRead.Text)0) Or (Val(txtReWrite.Text)0) Then
butScan.Text = "Cycle R/W"
Exit Sub
Else
ScanCount1= 1
txtScanCnt.Text = ScanCount1
txtScanPrd.Text = (timeGetTime - tim)"ms"
End If
Timer1.Enabled = True
End Sub
Private Sub butBitTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butBitTest.Click
If Not EntLink1 Then
MsgBox("还未与PLC建立联接!")
Exit Sub
End If
Dim rd As Boolean
Dim re As Short
Dim mry As EntQsPlc_Asc.PlcClient.PlcMemory = cmbBitMry.SelectedIndex1
re = PLC.Bit_Test(Handle1, mry, CUShort(txtBitAdd.Text), rd)
txtBitTest.Text = rd
txtReBit.Text = re
End Sub
Private Sub butBitSet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butBitSet.Click
If Not EntLink1 Then
MsgBox("还未与PLC建立联接!")
Exit Sub
End If
Dim re As Short
re = PLC.Bit_Set(Handle1, cmbBitMry.SelectedIndex1, Val(txtBitAdd.Text))
txtReBit.Text = re
End Sub
Private Sub butBitRst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butBitRst.Click
If Not EntLink1 Then
MsgBox("还未与PLC建立联接!")
Exit Sub
End If
Dim re As Short
re = PLC.Bit_Reset(Handle1, cmbBitMry.SelectedIndex1, Val(txtBitAdd.Text))
txtReBit.Text = re
End Sub
End Class
现在在开发一个上位机应用程序,使用vs2008中的vb.net开发基于wince的应用程序,实现对串口采集过来的数据这是我配置vs2005的模拟器,你参考一下吧 。
1.在VS2005里新建项目中时,选择创建Platform builder for CE 6.0的OS Design,新项目可以自
命名,这里命名为“MyEmulator” 。
2.创建MyEmulator的向导中 , BSP一定要选择“Device Emulator: ARMV4I”,下一步;
3.模板(Design Templates)选择“PDA Device”,下一步;
4.选择“Mobile Handheld”,下一步;
5.应用程序(ApplicationMedia)就随自己的需要选择,下一步;
6.网络和通信(NetworkingCommunications)在此只选择“Local Area Network(LAN)”,下一步;
7.选择完成;
8.选择Acknowledge;
到此工程建完;
四.添加组件(可以根据需要添加,这里主要添加汉字相关的组件)
(1) 添加汉字字库(这里要记得加入 , 很多人这里没有加入,就出现汉字只看到方框的现象):
1.在Catalog View添加“Core OS”--“CEBASE”--“International”--“Locale Specific support”--“Chinese (Simplified)”--“Fonts”--“SimSunNSimSum(choose 1)”--“SimSunNSimSun”或者“SimSumNSimSun (Subset 2_50)”;
2.在Catalog View添加“Core OS”--“CEBASE”--“International”--“Locale Specific support”--“Chinese (Simplified)”--“GB18030 Data Vonverter”和“Monotype Imaging AC3 Font Compression”;
(2)添加中文输入法:
在Catalog View添加“Core OS”--“CEBASE”--“International”--“Locale Specific support”--“Chinese (Simplified)”--“Input Method Editor”--“MSPY 3.0 for Windows Embedded CE”;
(3) VS2005中菜单“项目”--“MyEmulator(项目名)属性”,配置选择“所有配置”,配置属性--“Build Options”,在“Build Options”中去掉“Enable KITL (no IMGNOKITL=1)” (这里如果加入了KITL功能的话,可能在模拟器运行的时候,会一直是黑屏的);
(4) “Locale”中,Locales先Clear All,然后选择“中文(中国)”,Default local选择“中文(中国)”;
(5) 运行VS2005菜单“生成”--“生成MyEmulator”;
五.构建SDK:
1.运行VS2005菜单“项目”--“Add New SDK…”,在SDK属性页中填写必要的信息 , 属性“Emulation”中Configuration 选择Debug,可以设置模拟器的显示屏大小及色深,还有内存大小 , 在此设置为240 x 320,16色深,128M内存,然后“应用”,“确定” 。。
2. 然后运行VS2005菜单“生成”--“Build All SDK…” , 顺利的话,就会在%WINCEROOT\OSDesigns\ \MyEmulator\MyEmulator\SDKs\SDK1\MSI\下会有MyEmulator.msi;
六.配置VS2005:
1、先安装生成好的MyEmulator.msi 。运行Visual Studio 2005,选择菜单“工具->选项”,打开选项设置对话框,从左边的树型列表中选择“设备工具->设备”,右边的下拉列表框拉到底可以看到 “MyEmulator”,这就是刚刚生成的那个模拟器 。下面的设备列表里有两项 , 双击MyEmulator,设定传输为DMA传输,再点击“仿真器选 项”,在“显示”选项卡里设定好模拟器屏幕尺寸,颜色深度等 , 全部保存 。
2、用VS2005新建一个智能设备项目,向导选择平台时 , 先删除Pocket PC 2003 , 选择MyEmulator,完成 。然后按F5运行程序,顺利的话定制的模拟器就会出来了(不过这个过程比较慢,需要等待一段时间) 。
【包含vb.net上位机实例的词条】关于vb.net上位机实例和的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息 , 记得收藏关注本站 。
推荐阅读
- 钱的电脑符号怎么打,钱的电脑符号怎么打的
- asp.netlistbox选择时间的简单介绍
- mysql表下级表,mysql表与表之间怎么连接
- 明天怎么安装mysql 怎么安装mysql5717
- 联想win10怎么u盘启动设置,联想windows10怎么设置u盘启动
- phpcms无法添加栏目,无法添加此网站的应用
- 如何用移动互联网推广产品,移动互联网app推广
- oracle行数怎么加行 oracle加行锁
- python字典语句,python 字典