扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
LZ:你的想法是行的通的。1字节BYTE其值在0-255间,写成2进制的字符串形式为00000000-11111111
10年的万源网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都营销网站建设的优势是能够根据用户设备显示端的尺寸不同,自动调整万源建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联公司从事“万源网站设计”,“万源网站推广”以来,每个客户项目都认真落实执行。
事实上每BIT可代表1个项目的signal状态,开或关。
你可进行BIT运算,来判断某BIT是0或1从而发送控制信号。
具体的进制转换可参阅下列链接:
得说明是什么型号的PLC啊,串口还是网口,VB6还是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.SelectedIndex + 1
Dim typ As EntQsPlc_Asc.PlcClient.DataType = cmbReadType.SelectedIndex + 1
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 re 0 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 i UBound(temp) Then
WD(i) = 0
Else
WD(i) = Trim(temp(i))
End If
Next i
Dim mry As EntQsPlc_Asc.PlcClient.PlcMemory = cmbWriteMry.SelectedIndex + 1
Dim typ As EntQsPlc_Asc.PlcClient.DataType = cmbWriteType.SelectedIndex + 1
re = PLC.CmdWrite(Handle1, mry, typ, CInt(txtWriteAdd.Text), CUShort(txtWriteCnt.Text), WD)
txtReWrite.Text = re.ToString
If re 0 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.SelectedIndex + 1
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.SelectedIndex + 1, 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.SelectedIndex + 1, Val(txtBitAdd.Text))
txtReBit.Text = re
End Sub
End Class
你可以预先约定一个截止附,读取的字节统统放到缓存区里,直到读到截止附再处理、显示。
这是我配置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. 应用程序(Application Media)就随自己的需要选择,下一步;
6. 网络和通信(Networking Communications)在此只选择“Local Area Network(LAN)”,下一步;
7. 选择完成;
8. 选择Acknowledge;
到此工程建完;
四.添加组件(可以根据需要添加,这里主要添加汉字相关的组件)
(1) 添加汉字字库(这里要记得加入,很多人这里没有加入,就出现汉字只看到方框的现象):
1. 在Catalog View添加“Core OS”--“CEBASE”--“International”--“Locale Specific support”--“Chinese (Simplified)”--“Fonts”--“SimSun NSimSum(choose 1)”--“SimSun NSimSun”或者“SimSum NSimSun (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运行程序,顺利的话定制的模拟器就会出来了(不过这个过程比较慢,需要等待一段时间)。
下位机是谁写的?让他帮你就好了。
上位机和下位机从来都是一块儿调的,离了谁都不行。
要用委托的形式(界面上拖一个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
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流