基本信息
源码名称:力创IO模块:EDA9061实例
源码大小:0.10M
文件格式:.rar
开发语言:ASP
更新时间:2018-02-16
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 3 元×
微信扫码支付:3 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
力创IO模块:EDA9061实例!
Public Class Frm_Main Private Structure KGLOut_Info ''' <summary> ''' 通道0的输出ON时间周期 S ''' </summary> ''' <remarks></remarks> Public CH0ON_T, CH0OFF_T As Int16 ''' <summary> ''' 通道1的输出时间周期 S ''' </summary> ''' <remarks></remarks> Public CH1ON_T, CH1OFF_T As Int16 ''' <summary> ''' 通道2的输出时间周期 S ''' </summary> ''' <remarks></remarks> Public CH2ON_T, CH2OFF_T As Int16 ''' <summary> ''' 通道3的输出时间周期 S ''' </summary> ''' <remarks></remarks> Public CH3ON_T, CH3OFF_T As Int16 ''' <summary> ''' 通道0的输出的实时时间戳 ''' </summary> ''' <remarks></remarks> Public CH0_CurrentIndex As Int16 ''' <summary> ''' 通道1的输出的实时时间戳 ''' </summary> ''' <remarks></remarks> Public CH1_CurrentIndex As Int16 ''' <summary> ''' 通道2的输出的实时时间戳 ''' </summary> ''' <remarks></remarks> Public CH2_CurrentIndex As Int16 ''' <summary> ''' 通道3的输出的实时时间戳 ''' </summary> ''' <remarks></remarks> Public CH3_CurrentIndex As Int16 ''' <summary> ''' 通道0的当前状态 0/1 ''' </summary> ''' <remarks></remarks> Public CH0_Status, CH1_Status, CH2_Status, CH3_Status As Int16 End Structure Private KGLOutInfo As KGLOut_Info Private Sub btnOpenCom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenCom.Click Try If (btnOpenCom.Text = "打开串口") Then If (SerialPort1.IsOpen = True) Then SerialPort1.Close() SerialPort1.PortName = cmbComPort.Text SerialPort1.BaudRate = 9600 SerialPort1.DataBits = 8 SerialPort1.StopBits = System.IO.Ports.StopBits.One SerialPort1.Parity = System.IO.Ports.Parity.None SerialPort1.DtrEnable = True SerialPort1.RtsEnable = True SerialPort1.Open() btnOpenCom.Text = "关闭串口" GroupBox2.Enabled = True Else If (SerialPort1.IsOpen = True) Then SerialPort1.Close() btnOpenCom.Text = "打开串口" GroupBox2.Enabled = False End If Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived End Sub Private Sub btnReadSet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReadSet.Click Dim bSend(0 To 5) As Byte bSend(0) = &H4C bSend(1) = &H57 bSend(2) = CInt(txtDAddress.Text) bSend(3) = &H1 bSend(4) = bSend(2) bSend(3) bSend(5) = &HD SerialPort1.Write(bSend, 0, 6) Do Until (SerialPort1.BytesToRead = 9) CommFunc.Delay(50) Loop txtComRece.Text = "" Dim n As Integer = SerialPort1.BytesToRead ''读取当前有多少数据可读。 Dim binary(n) As Byte ''新建内容。 SerialPort1.Read(binary, 0, n) ''读取 For Each b As Byte In binary txtComRece.AppendText(b.ToString("X2") & " ") Next Select Case binary(3).ToString("X2") Case "03" cmbbtl.Text = "1200" Case "04" cmbbtl.Text = "2400" Case "05" cmbbtl.Text = "4800" Case "06" cmbbtl.Text = "9600" Case "07" cmbbtl.Text = "19200" End Select lblsblx.Text = binary(4).ToString("X2") & binary(5).ToString("X2") End Sub Private Sub btnReadCHState_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReadCHState.Click Dim bSend(0 To 5) As Byte bSend(0) = &H4C bSend(1) = &H57 bSend(2) = CInt(txtDAddress.Text) bSend(3) = &H3 bSend(4) = bSend(2) bSend(3) bSend(5) = &HD SerialPort1.Write(bSend, 0, 6) Do Until (SerialPort1.BytesToRead = 7) CommFunc.Delay(50) Loop txtComRece.Text = "" Dim n As Integer = SerialPort1.BytesToRead ''读取当前有多少数据可读。 Dim binary(n) As Byte ''新建内容。 SerialPort1.Read(binary, 0, n) ''读取 For Each b As Byte In binary txtComRece.AppendText(b.ToString("X2") & " ") Next lblOCHState.Text = Convert.ToString(binary(3), 2).PadLeft(4, "0") lblICHState.Text = Convert.ToString(binary(4), 2).PadLeft(7, "0") If (lblOCHState.Text.Substring(0, 1) = "1") Then chkOCH3.Checked = True Else chkOCH3.Checked = False If (lblOCHState.Text.Substring(1, 1) = "1") Then chkOCH2.Checked = True Else chkOCH2.Checked = False If (lblOCHState.Text.Substring(2, 1) = "1") Then chkOCH1.Checked = True Else chkOCH1.Checked = False If (lblOCHState.Text.Substring(3, 1) = "1") Then chkOCH0.Checked = True Else chkOCH0.Checked = False If (lblICHState.Text.Substring(0, 1) = "1") Then chkDI6.Checked = True Else chkDI6.Checked = False If (lblICHState.Text.Substring(1, 1) = "1") Then chkDI5.Checked = True Else chkDI5.Checked = False If (lblICHState.Text.Substring(2, 1) = "1") Then chkDI4.Checked = True Else chkDI4.Checked = False If (lblICHState.Text.Substring(3, 1) = "1") Then chkDI3.Checked = True Else chkDI3.Checked = False If (lblICHState.Text.Substring(4, 1) = "1") Then chkDI2.Checked = True Else chkDI2.Checked = False If (lblICHState.Text.Substring(5, 1) = "1") Then chkDI1.Checked = True Else chkDI1.Checked = False If (lblICHState.Text.Substring(6, 1) = "1") Then chkDI0.Checked = True Else chkDI0.Checked = False End Sub Private Sub btnSCFSSZ_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSCFSSZ.Click Dim bSend(0 To 7) As Byte txtComRece.Text = "" If (Val(txtmccd.Text) > 200) Then Exit Sub Dim TDSC As Int16 = 0 ''通道输出的状态串 If (chkSCFS3.Checked) Then TDSC = 1 * 2 * 2 * 2 If (chkSCFS2.Checked) Then TDSC = 1 * 2 * 2 If (chkSCFS1.Checked) Then TDSC = 1 * 2 If (chkSCFS0.Checked) Then TDSC = 1 bSend(0) = &H4C bSend(1) = &H57 bSend(2) = CInt(txtDAddress.Text) bSend(3) = &H5 bSend(4) = TDSC bSend(5) = CInt(txtmccd.Text) bSend(6) = bSend(2) bSend(3) bSend(4) bSend(5) bSend(7) = &HD SerialPort1.Write(bSend, 0, 8) Do Until (SerialPort1.BytesToRead = 5) CommFunc.Delay(50) Loop txtComRece.Text = "" Dim n As Integer = SerialPort1.BytesToRead ''读取当前有多少数据可读。 Dim binary(n) As Byte ''新建内容。 SerialPort1.Read(binary, 0, n) ''读取 For Each b As Byte In binary txtComRece.AppendText(b.ToString("X2") & " ") Next End Sub Private Sub btnReadSCFSSZ_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReadSCFSSZ.Click Dim bSend(0 To 5) As Byte txtComRece.Text = "" bSend(0) = &H4C bSend(1) = &H57 bSend(2) = CInt(txtDAddress.Text) bSend(3) = &H6 bSend(4) = bSend(2) bSend(3) bSend(5) = &HD SerialPort1.Write(bSend, 0, 6) Do Until (SerialPort1.BytesToRead = 7) CommFunc.Delay(50) Loop txtComRece.Text = "" Dim n As Integer = SerialPort1.BytesToRead ''读取当前有多少数据可读。 Dim binary(n) As Byte ''新建内容。 SerialPort1.Read(binary, 0, n) ''读取 For Each b As Byte In binary txtComRece.AppendText(b.ToString("X2") & " ") Next End Sub Private Sub btnWSet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWSet.Click Dim bSend(0 To 7) As Byte txtComRece.Text = "" Dim TDH As Byte = 0 ''通道号 Dim TDSC As Int16 = 0 ''通道输出的值 If (rbtnAll.Checked) Then If (chkCHZ3.Checked) Then TDSC = 1 * 2 * 2 * 2 If (chkCHZ2.Checked) Then TDSC = 1 * 2 * 2 If (chkCHZ1.Checked) Then TDSC = 1 * 2 If (chkCHZ0.Checked) Then TDSC = 1 TDH = &HFF End If If (rbtnCH3.Checked) Then If (chkCHZ3.Checked) Then TDSC = 1 TDH = &H3 End If If (rbtnCH2.Checked) Then If (chkCHZ2.Checked) Then TDSC = 1 TDH = &H2 End If If (rbtnCH1.Checked) Then If (chkCHZ1.Checked) Then TDSC = 1 TDH = &H1 End If If (rbtnCH0.Checked) Then If (chkCHZ0.Checked) Then TDSC = 1 TDH = &H0 End If bSend(0) = &H4C bSend(1) = &H57 bSend(2) = CInt(txtDAddress.Text) bSend(3) = &H4 bSend(4) = TDH bSend(5) = TDSC If (rbtnAll.Checked) Then bSend(6) = bSend(2) bSend(3) bSend(5) Else bSend(6) = bSend(2) bSend(3) bSend(4) bSend(5) End If bSend(7) = &HD SerialPort1.Write(bSend, 0, 8) Do Until (SerialPort1.BytesToRead = 5) CommFunc.Delay(50) Loop txtComRece.Text = "" Dim n As Integer = SerialPort1.BytesToRead ''读取当前有多少数据可读。 Dim binary(n) As Byte ''新建内容。 SerialPort1.Read(binary, 0, n) ''读取 For Each b As Byte In binary txtComRece.AppendText(b.ToString("X2") & " ") Next End Sub Private Sub Frm_Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load cmbComPort.Items.AddRange(CommFunc.GetAvaliableSerialPorts()) End Sub Private Sub btnBeginOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBeginOut.Click T_Out.Enabled = Not T_Out.Enabled If (T_Out.Enabled) Then KGLOutInfo.CH0_CurrentIndex = 0 KGLOutInfo.CH0ON_T = txtCHT0ON.Text KGLOutInfo.CH0OFF_T = txtCHT0OFF.Text KGLOutInfo.CH0_Status = 0 KGLOutInfo.CH1_CurrentIndex = 0 KGLOutInfo.CH1ON_T = txtCHT1ON.Text KGLOutInfo.CH1OFF_T = txtCHT1OFF.Text KGLOutInfo.CH1_Status = 0 KGLOutInfo.CH2_CurrentIndex = 0 KGLOutInfo.CH2ON_T = txtCHT2ON.Text KGLOutInfo.CH2OFF_T = txtCHT2OFF.Text KGLOutInfo.CH2_Status = 0 KGLOutInfo.CH3_CurrentIndex = 0 KGLOutInfo.CH3ON_T = txtCHT3ON.Text KGLOutInfo.CH3OFF_T = txtCHT3OFF.Text KGLOutInfo.CH3_Status = 0 btnBeginOut.Text = "启动定时开关量输出(ON)" Else btnBeginOut.Text = "启动定时开关量输出(OFF)" End If End Sub Private Sub T_Out_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles T_Out.Tick If (chkCHO0.Checked) Then KGLOutInfo.CH0_CurrentIndex = 1 lblCH0.Text = KGLOutInfo.CH0_CurrentIndex If (KGLOutInfo.CH0_CurrentIndex >= KGLOutInfo.CH0ON_T And KGLOutInfo.CH0_Status = 1) Then KGLOutInfo.CH0_CurrentIndex = 0 ''输出 KGLOutInfo.CH0_Status = 0 Call T_KGLOut(KGLOutInfo.CH0_Status, &H0) End If If (KGLOutInfo.CH0_CurrentIndex >= KGLOutInfo.CH0OFF_T And KGLOutInfo.CH0_Status = 0) Then KGLOutInfo.CH0_CurrentIndex = 0 ''输出 KGLOutInfo.CH0_Status = 1 Call T_KGLOut(KGLOutInfo.CH0_Status, &H0) End If End If If (chkCHO1.Checked) Then KGLOutInfo.CH1_CurrentIndex = 1 lblCH1.Text = KGLOutInfo.CH1_CurrentIndex If (KGLOutInfo.CH1_CurrentIndex >= KGLOutInfo.CH1ON_T And KGLOutInfo.CH1_Status = 1) Then KGLOutInfo.CH1_CurrentIndex = 0 ''输出 KGLOutInfo.CH1_Status = 0 Call T_KGLOut(KGLOutInfo.CH1_Status, &H1) End If If (KGLOutInfo.CH1_CurrentIndex >= KGLOutInfo.CH1OFF_T And KGLOutInfo.CH1_Status = 0) Then KGLOutInfo.CH1_CurrentIndex = 0 ''输出 KGLOutInfo.CH1_Status = 1 Call T_KGLOut(KGLOutInfo.CH1_Status, &H1) End If End If If (chkCHO2.Checked) Then KGLOutInfo.CH2_CurrentIndex = 1 lblCH2.Text = KGLOutInfo.CH2_CurrentIndex If (KGLOutInfo.CH2_CurrentIndex >= KGLOutInfo.CH2ON_T And KGLOutInfo.CH2_Status = 1) Then KGLOutInfo.CH2_CurrentIndex = 0 ''输出 KGLOutInfo.CH2_Status = 0 Call T_KGLOut(KGLOutInfo.CH2_Status, &H2) End If If (KGLOutInfo.CH2_CurrentIndex >= KGLOutInfo.CH2OFF_T And KGLOutInfo.CH2_Status = 0) Then KGLOutInfo.CH2_CurrentIndex = 0 ''输出 KGLOutInfo.CH2_Status = 1 Call T_KGLOut(KGLOutInfo.CH2_Status, &H2) End If End If If (chkCHO3.Checked) Then KGLOutInfo.CH3_CurrentIndex = 1 lblCH3.Text = KGLOutInfo.CH3_CurrentIndex If (KGLOutInfo.CH3_CurrentIndex >= KGLOutInfo.CH3ON_T And KGLOutInfo.CH3_Status = 1) Then KGLOutInfo.CH3_CurrentIndex = 0 ''输出 KGLOutInfo.CH3_Status = 0 Call T_KGLOut(KGLOutInfo.CH3_Status, &H3) End If If (KGLOutInfo.CH3_CurrentIndex >= KGLOutInfo.CH3OFF_T And KGLOutInfo.CH3_Status = 0) Then KGLOutInfo.CH3_CurrentIndex = 0 ''输出 KGLOutInfo.CH3_Status = 1 Call T_KGLOut(KGLOutInfo.CH3_Status, &H3) End If End If End Sub Private Sub T_KGLOut(ByVal TDSC As String, ByVal TDH As Byte) Dim bSend(0 To 7) As Byte txtComRece.Text = "" 'Dim TDH As Byte = 0 ''通道号 'Dim TDSC As Int16 = 0 ''通道输出的值 'If (rbtnAll.Checked) Then ' If (chkCHZ3.Checked) Then TDSC = 1 * 2 * 2 * 2 ' If (chkCHZ2.Checked) Then TDSC = 1 * 2 * 2 ' If (chkCHZ1.Checked) Then TDSC = 1 * 2 ' If (chkCHZ0.Checked) Then TDSC = 1 ' TDH = &HFF 'End If 'If (rbtnCH3.Checked) Then ' If (chkCHZ3.Checked) Then TDSC = 1 ' TDH = &H3 'End If 'If (rbtnCH2.Checked) Then ' If (chkCHZ2.Checked) Then TDSC = 1 ' TDH = &H2 'End If 'If (rbtnCH1.Checked) Then ' If (chkCHZ1.Checked) Then TDSC = 1 ' TDH = &H1 'End If 'If (rbtnCH0.Checked) Then ' If (chkCHZ0.Checked) Then TDSC = 1 ' TDH = &H0 'End If bSend(0) = &H4C bSend(1) = &H57 bSend(2) = CInt(txtDAddress.Text) bSend(3) = &H4 bSend(4) = TDH bSend(5) = TDSC 'If (rbtnAll.Checked) Then ' bSend(6) = bSend(2) bSend(3) bSend(5) 'Else bSend(6) = bSend(2) bSend(3) bSend(4) bSend(5) 'End If bSend(7) = &HD SerialPort1.Write(bSend, 0, 8) Do Until (SerialPort1.BytesToRead = 5) CommFunc.Delay(50) Loop txtComRece.Text = "" Dim n As Integer = SerialPort1.BytesToRead ''读取当前有多少数据可读。 Dim binary(n) As Byte ''新建内容。 SerialPort1.Read(binary, 0, n) ''读取 For Each b As Byte In binary txtComRece.AppendText(b.ToString("X2") & " ") Next End Sub End Class