[RESOLVED] Help With MsComm Input
I got this string from Mscomm.input
http://i26.tinypic.com/10folth.jpg
I try to remove the vbCr & vbCrLf, but still the result like this,
Code:
Shooti
ng Chron
y, V6.03
i,25/DEC
/1999,1F
how to make that string to one line string?
anyone can help me??
note: sorry for my bad english :)
Re: Help With MsComm Input
Re: Help With MsComm Input
Welcome to VBForums :wave:
Please do not bump your threads. For some of the reasons, see this. People will read your thread (and hopefully reply) when they get the time to do so.
Take a look at which variables you are using... I notice you are storing a result to B, and then completely ignoring B.
If you can't get it to work, post your code (as text) including the FillToListView routine.
Re: Help With MsComm Input
I'm cleanup some code, they look like this now...
Code:
Private Sub MSComm1_OnComm()
Dim A As String
Dim B As String
Dim vResult As String
Dim vChrony As String
If MSComm1.CommEvent = comEvReceive Then
A = MSComm1.Input
B = Replace(A, vbCr, "")
vResult = Replace(B, vbLf, "")
FillToListview vResult
Debug.Print vResult
End If
End Sub
Private Sub FillToListview(vIsi As String)
Dim VLst As ListItem
Set VLst = ListView1.ListItems.Add(, , vIsi)
VLst.SubItems(1) = Now
End Sub
the result still like this
http://i31.tinypic.com/1zou3pe.jpg
Re: Help With MsComm Input
As your ListView is showing different items, it means you are receiving completely separate strings (it will not create any extra items depending on the characters), so MSComm1_OnComm is actually firing more than once.
Rather than work with the input each time, you need to append it to what you had before, and only when the whole item is finished add it to the ListView etc.
I don't use MSComm, so I have no idea how to detect if it is finished or not... but there may be a character at the end of the data (depending on how it is being sent) that tells you it is the end of the data.
Re: Help With MsComm Input
thanks si the geek....
i solved the problem, just set RThreshold to 40...
now i must figure how to clear mscomm buffer
Re: Help With MsComm Input
Google!
http://www.google.com/intl/en/#hl=en...fe100d9e542c1e
Maybe this helps
http://www.xtremevbtalk.com/showthread.php?t=227338
Btw. Nice app you have there. May i ask what it is or what it does if it's not a secret?
Re: Help With MsComm Input
thanks BytePtr, i already google it :)
i try to make app for shooting chrony because the Chrony Ballistics Software is very expensive, at least for me...
i hope it will work
Re: Help With MsComm Input
Quote:
Originally Posted by
afritz3050
thanks BytePtr, i already google it :)
i try to make app for shooting chrony because the Chrony Ballistics Software is very expensive, at least for me...
i hope it will work
This is a totally cool endeavor! I assume you're a reloader?
Re: [RESOLVED] Help With MsComm Input
I'm just an air gun hobbyst
Re: [RESOLVED] Help With MsComm Input
Quote:
Originally Posted by
afritz3050
I'm just an air gun hobbyst
As per your request via PM, this is one of the ways that I do it. This demo uses a TextBox, so change that to your needs. Let me know how it works for you. RThreshold = 1 ;)
Code:
Private Sub MSComm1_OnComm()
Dim InBuffer As String
Dim strTrim As String
If MSComm1.CommEvent = comEvReceive Then
InBuffer = MSComm1.Input
Text1.Text = Text1.Text & InBuffer
strTrim = Replace(Text1.Text, vbCrLf, " ") ' Replace with a space & don't use Chr(13)!
Text1.Text = strTrim
End If
End Sub
Re: [RESOLVED] Help With MsComm Input
thanks cdrive, your code is working.. :afrog:
but i have another problem...
i want to select the mscomm.input, i try like this..
Code:
Option Explicit
Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.Settings = "4800,n,8,1"
MSComm1.RThreshold = 1
MSComm1.InputMode = comInputModeText
MSComm1.PortOpen = Not MSComm1.PortOpen = True
End Sub
Private Sub MSComm1_OnComm()
Dim InBuffer$
Dim vStatusBar As String
Dim strTrim As String
If MSComm1.CommEvent = comEvReceive Then
InBuffer$ = MSComm1.Input
If InStr(InBuffer$, "Err") Then
Exit Sub
ElseIf InStr(InBuffer$, "Shoot") Then
txtReceived.Text = txtReceived.Text & InBuffer$
strTrim = Replace(txtReceived.Text, vbCrLf, "")
txtReceived.Text = strTrim
Debug.Print txtReceived.Text
Else
'fill data to listview
End If
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
End Sub
when i try it, the txtReceived.Text is "Shooti" not "Shooting Chrony, V6.03i,25/DEC/1999,1F"
there are three type output string from chrony,
1. Error message like "-err1-" or -err2-
2. Chrony information like "Shooting Chrony, V6.03i,25/DEC/1999,1F"
3. Velocity information like "-02-, 15262V, 793.14Vf"
Re: [RESOLVED] Help With MsComm Input
I'm shooting (no pun intended) in the dark because I don't have your software.
Question: What's your InBufferSize?
I also re-read your first few posts and I'm a bit confused because You described the same thing happening in those posts.
Please start a new project and run this code with Chrony so I can see how MSComm sees your data without any formatting at the VB end. Please post the results.
Code:
Option Explicit
Private Sub Form_Load()
Text1.Text = ""
' Text1.MultiLine = True ' Set this in Properties @ design time
MSComm1.CommPort = 1 ' Change to your port
MSComm1.RThreshold = 1
MSComm1.PortOpen = True
End Sub
Private Sub MSComm1_OnComm()
If MSComm1.CommEvent = comEvReceive Then
Text1.Text = Text1.Text & MSComm1.Input
End If
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
End Sub
Re: [RESOLVED] Help With MsComm Input
InBufferSize is default : 1024
the result is : Shooting Chrony, V6.03i,25/DEC/1999,1F
if i added debug.print Text1.Text, the result is like this
Code:
Shooting Chron
Shooting Chrony, V6.03
Shooting Chrony, V6.03i,25/DEC
Shooting Chrony, V6.03i,25/DEC/1999,1F
Shooting Chrony, V6.03i,25/DEC/1999,1F
Re: [RESOLVED] Help With MsComm Input
Whoops, I think I see where the problem is. Use your Instr() function on the TextBox, not the InBuffer. Also, Instr() returns the position of the text your searching for so I don't think your code is complete there either.
Re: [RESOLVED] Help With MsComm Input
Re: [RESOLVED] Help With MsComm Input
This may or may not be useful to you. Sometimes a Timer control can be useful when using MSComm. Polling (which does not use On_Comm at all) is also useful and is also used (usually) with a Timer.
You will note that Debug.Print and Text1.Text will be identical.
Code:
Private Sub Form_Load() ' InbuffSize=1024
Timer1.Enabled = False
Timer1.Interval = 1000
Text1.Text = ""
' Text1.MultiLine = True ' Set this in Properties @ design time
MSComm1.CommPort = 1 ' Change to your port
MSComm1.RThreshold = 1
MSComm1.PortOpen = True
End Sub
Private Sub MSComm1_OnComm()
If MSComm1.CommEvent = comEvReceive Then
Timer1.Enabled = True
End If
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
End Sub
Private Sub Timer1_Timer()
Text1.Text = Text1.Text & MSComm1.Input
' Do your Text1 string parsing here
Debug.Print Text1.Text
Timer1.Enabled = False
End Sub
Re: [RESOLVED] Help With MsComm Input
I'm assuming that you're using Instr() to find certain strings and then put them ListView cells. While I don't show any ListView code here, I do show one way of using the return val of Instr() to do something.
Note: I test nearly all my MSComm code with a Loop Back Tester as shown here.
Code:
Option Explicit
Private Sub Command1_Click()
MSComm1.Output = "Line1 " & vbCrLf & "Line2 " & vbCrLf & "Line3 "
End Sub
Private Sub Command2_Click()
Dim lngPos As Long
lngPos = InStr(1, Text1.Text, "Line2") ' Search for pos of "Line2"
If lngPos <> 0 Then ' If "Line2" exists then lngPos is greater than (0) zero
Text1.Text = "Shooting for " & Text1.Text ' Do something with that information.
Else
MsgBox "Line2 not found"
End If
End Sub
Private Sub Form_Load()
MSComm1.PortOpen = True
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
MSComm1.PortOpen = False
End Sub
Private Sub MSComm1_OnComm()
Dim InBuffer As String
Dim strTrim As String
If MSComm1.CommEvent = comEvReceive Then
InBuffer = MSComm1.Input
Text1.Text = Text1.Text & InBuffer
strTrim = Replace(Text1.Text, vbCrLf, " ") ' Replace with a space & don't use Chr(13)!
Text1.Text = strTrim
End If
End Sub