Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Split Data from Microcontroller

Status
Not open for further replies.

narudol

New Member
Hi everyone , I'm new in VB and This board

I make A/D Converter for measure dc voltage and current

A/D sent (Volt/Amp) like this ---> 0.0000/0.0000
sometimes it has - like -0.0000/0.0000

How to split this data to 2 Textboxs


Thank you
sorry for my poor english

Jo
 
Option Explicit
Dim rdet As String
Dim PortNumber As Integer
Dim vol
Dim amp
Dim ohm#
Dim cut
'//»ØèÁ¡´à¾×èÍ Disconnect//
Private Sub Command2_Click()
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If
Label13.Caption = ""
Label14.Caption = ""
Label13.BackColor = vbRed
Label14.BackColor = vbRed
End Sub

'//àÁ×èÍâËÅ´¿ÍÃìÁ¢Öé¹ÁÒ àÃÔèÁÃѺ¤èÒ//
Private Sub UserControl_Initialize()
MSComm1.CommPort = 13 ' ¡Ó˹´ Com port
MSComm1.Settings = "9600,N,8,1"
End Sub
'//»ØèÁ àÃÔèÁÃѺ¤èÒ//
Private Sub Command1_Click()
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
MSComm1.RThreshold = 1
MSComm1.InputLen = 0
If MSComm1.InBufferCount Then
rdet = MSComm1.Input 'get data
Label13.Caption = Left(rdet, 6)
Label14.Caption = Right(rdet, 7)
Label13.BackColor = vbGreen
Label14.BackColor = vbGreen
End If
End If
End Sub
'//૵¤èÒäÁâ¤Ã«Í¿·ì Communication ¤Í¹â·ÃÅ//
Private Sub MSComm1_OnComm()
' If comEvReceive Event then get data and display
If MSComm1.CommEvent = comEvReceive Then
End If
End Sub
'// à¡çº¤èÒŧµÒÃÒ§Íѵâ¹ÁѵÔ//
Private Sub Label3_Click()
cut = Val(Label3.Caption)
cut = Right(rdet, 8)
ohm = 5 / cut
Label3.Caption = ohm
End Sub
Private Sub UserControl_Terminate() 'Close the COMM port àÁ×èͻԴâ»Ãá¡ÃÁ
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If
End Sub


This my code
 
Hi everyone , I'm new in VB and This board

I make A/D Converter for measure dc voltage and current

A/D sent (Volt/Amp) like this ---> 0.0000/0.0000
sometimes it has - like -0.0000/0.0000

How to split this data to 2 Textboxs


Thank you
sorry for my poor english

Jo

hi,
I would get the complete string, by reading the MSCOMM and then test the left most character in the string for the '-' sign.

Does the ADC send a CRLF code at the end of the data,?
ie: 0.0000/0.0000 CRLF [ 0x0d,0x0a]

A simple example.

Code:
Private Sub Form_Load()
Dim test, data As String

If test = InStr(1, data, "-") = 0 Then
'.....
Else
'....
End If

'OR

If Left(data, 1) = "-" Then
'...
Else
'...
End If

End Sub
 
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top