|
-
Aug 25th, 2009, 11:33 PM
#1
Thread Starter
New Member
-
Aug 26th, 2009, 04:47 AM
#2
Thread Starter
New Member
Re: Help With MsComm Input
-
Aug 26th, 2009, 06:44 AM
#3
Re: Help With MsComm Input
Welcome to VBForums 
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.
-
Aug 26th, 2009, 07:16 AM
#4
Thread Starter
New Member
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
-
Aug 26th, 2009, 07:23 AM
#5
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.
-
Aug 26th, 2009, 08:41 AM
#6
Thread Starter
New Member
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
-
Aug 26th, 2009, 09:16 AM
#7
Member
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?
Please rate my post if it has been helpful.
Mark the thread as [Resolved] when your problem is solved!

-
Aug 26th, 2009, 09:39 AM
#8
Thread Starter
New Member
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
-
Aug 26th, 2009, 04:28 PM
#9
Re: Help With MsComm Input
 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?
<--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
If topic has been resolved, please pull down the Thread Tools & mark it Resolved.
Is VB consuming your life, and is that a bad thing?? 
-
Aug 27th, 2009, 03:15 AM
#10
Thread Starter
New Member
Re: [RESOLVED] Help With MsComm Input
I'm just an air gun hobbyst
-
Aug 27th, 2009, 09:51 PM
#11
Re: [RESOLVED] Help With MsComm Input
 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
Last edited by CDRIVE; Aug 27th, 2009 at 10:31 PM.
Reason: Original code required a Timer
<--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
If topic has been resolved, please pull down the Thread Tools & mark it Resolved.
Is VB consuming your life, and is that a bad thing?? 
-
Aug 28th, 2009, 01:14 AM
#12
Thread Starter
New Member
Re: [RESOLVED] Help With MsComm Input
thanks cdrive, your code is working.. 
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"
-
Aug 28th, 2009, 09:22 AM
#13
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
<--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
If topic has been resolved, please pull down the Thread Tools & mark it Resolved.
Is VB consuming your life, and is that a bad thing?? 
-
Aug 28th, 2009, 09:36 AM
#14
Thread Starter
New Member
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
Last edited by afritz3050; Aug 28th, 2009 at 09:40 AM.
-
Aug 28th, 2009, 09:43 AM
#15
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.
<--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
If topic has been resolved, please pull down the Thread Tools & mark it Resolved.
Is VB consuming your life, and is that a bad thing?? 
-
Aug 28th, 2009, 09:51 AM
#16
Thread Starter
New Member
Re: [RESOLVED] Help With MsComm Input
Last edited by afritz3050; Aug 28th, 2009 at 09:57 AM.
-
Aug 28th, 2009, 05:58 PM
#17
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
<--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
If topic has been resolved, please pull down the Thread Tools & mark it Resolved.
Is VB consuming your life, and is that a bad thing?? 
-
Aug 29th, 2009, 01:46 PM
#18
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
<--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
If topic has been resolved, please pull down the Thread Tools & mark it Resolved.
Is VB consuming your life, and is that a bad thing?? 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|