Hankala selittää mutta yritän.
Eli, lähetän tietoa koneelle USb kortista " if (a=1) { Serial.println("testi"); sekä Serial.println("12345") }"
VB:llä luen tiedot ja teen if lauseen jos tuleva tieto on "testi" niin haluaisin ottaa käyttöön tuon "12345" numerosarjan pelkästään.
Mistä vois lähteä liikenteesen.
Moi faaraot!
Jos kyseessä on VB6 ja 32-bittinen Windows niin...
'Formille: MsComm control & Tekstiruutu
'(MsComm ei välttämättä pelitä Vistan tai Uudemman kera)
Private Sub Form_Load()
MSComm1.CommPort = "COM1" 'tähän se portti johon laitteesi on kytketty
MSComm1.Settings = "9600,N,8,1" 'esim.
MSComm1.InputLen = 0
MSComm1.PortOpen = True
End Sub
Private Sub MSComm1_OnComm()
If MSComm1.CommEvent = 2 Then
Dim data As String
data = MSComm1.Input
If InStr(data, "testi") = 0 Then
Text1.Text = data 'esim.
End If
End If
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
On Error Resume Next
MSComm1.PortOpen = False
End Subjos taas kyseessä on VB.NET (2002 & uudemmat) niin...
'Huom esimerkki on väännetty SharpDevelop 4.2:lla
Imports System
Imports System.IO.Ports
Public Partial Class MainForm
Public Sub New()
Me.InitializeComponent()
End Sub
Sub MainFormLoad(sender As Object, e As EventArgs)
Me.button1.Text = "Start"
Me.button2.Text = "Stop"
timer1.Interval = 1000
timer1.Enabled = True
End Sub
Sub Button1Click(sender As Object, e As EventArgs)
timer1.Start
End Sub
Sub Button2Click(sender As Object, e As EventArgs)
timer1.Stop
End Sub
Sub Timer1Tick(sender As Object, e As EventArgs)
Application.DoEvents
ReadReceivedData
End Sub
Sub ReadReceivedData()
Dim myport As SerialPort = Nothing
Application.DoEvents
Try
myport = My.Computer.Ports.OpenSerialPort("COM1") 'tähän portti johon laitteesi on kytketty
myport.ReadTimeout = 10000
Do
Dim data As String = myport.ReadLine()
If data Is Nothing Then
Exit Do
Else
If Not data.Contains("testi") Then
textBox1.Text = data 'esim.
End If
End If
Loop
Catch ex As TimeoutException
textBox1.Text = ex.Message
Finally
If myport IsNot Nothing Then
myport.Close()
End If
End Try
End Sub
Sub MainFormFormClosing(sender As Object, e As FormClosingEventArgs)
timer1.Enabled = False
End Sub
End ClassAihe on jo aika vanha, joten et voi enää vastata siihen.