473,387 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

VBA MSComm troubles

Hello,
I have a program in Access that uses VBA to capture data being sent over the serial port from a Cosmo Flow Test Machine. This determines the air pressure's leak rate escaping from a muffler.

I have written several programs that send data out serially, but I am new to "listening" to receive the data.

I can setup an instance of HyperTerminal, provided the settings used in the given manual for the device and successfully retreive data results. When using the same settings in my VBA code, I never get any data; none. The data coming from HyperTerminal seems to be 'stream' based rather than packet, thus I used the code to keep adding the characters to the end until it finishes the loop.

Here's the code:
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cmdHHP_Click()
  3.  
  4. Dim strLeakRate As String
  5. Dim strUprLmt As String
  6. Dim strLwrLmt As String
  7. Dim strChar As String
  8.  
  9. strUprLmt = 3.77
  10. strLwrLmt = 0
  11.  
  12. lblStatus.Caption = "RETREIVING LEAK TEST DATA"
  13.  
  14.     MSComm0.CommPort = 1
  15.     MSComm0.Settings = "1200,N,8,1"
  16.     MSComm0.PortOpen = True
  17.  
  18.         Do Until strChar = ":"
  19.             strChar = MSComm0.Input
  20.             strLeakRate = strLeakRate & MSComm0.Input
  21.         Loop
  22.  
  23.     MSComm0.PortOpen = False
  24.  
  25. lblStatus.Caption = "DATA RETREIVED"
  26.  
  27.     strLeakRate = Mid(strLeakRate, 6, 11)
  28.     lblLeakRate.Caption = strLeakRate
  29.  
  30.  
  31.  
  32.         If strLeakRate > strUprLmt Then
  33.             cmdFailed
  34.             Exit Sub
  35.         Else
  36.             DoCmd.RunMacro "macHHP"
  37.         End If
  38.  
  39.  lblStatus.Caption = "PRINTING LABEL"
  40.  
  41. '''''''''''
  42. cmdReset
  43. '''''''''''
  44.  
  45. End Sub
  46.  
  47. Public Sub cmdFailed()
  48.  
  49.  MsgBox "Test Failed. Please try the leak test at most 3 times for any one DPF.", vbCritical + vbOKOnly, "LEAK TEST FAILED"
  50. End Sub
  51.  
  52. Public Sub cmdReset()
  53.  
  54.  strChar = ""
  55.  strLeakRate = ""
  56.  lblLeakRate.Caption = "-----"
  57.  lblStatus.Caption = "READY"
  58.  
  59. End Sub
  60.  
  61.  
Looking at the form versus the code, it doesn't seem like it's preforming the first working line. I have a label that changes status when they click a 'start' button. As soon as the button is clicked, I would imiagine that the display message should change to 'RETREIVING LEAK TEST DATA'.

Another concern is that it doesn't seem like the port is actually ever opening. The code currently hangs in the loop waiting to receive the ":" char to denote the end of the string. I manually break the code and debug, then go back to the form to try again and I DO NOT receive a 'port already open' error as would be expected.

One last question... The manual claims that the end of the string is denoted by carriage return, <CR>. It lists what I would think to be the hexadecimal code for that as (0DH). How would I go about using that as the delimiter to signify the end of the string?

Any info anyone could share would be most appreciated.
Thanks in advance,
dbrother.
Feb 8 '08 #1
1 2884
Bum
19
Hi dbrother,

you have a loop where you're looking for a colon. Are you sure a colon is supposed to come through? Why don't you try to say

code[vb]
strchar = ""
do until strChar <> ""

this way, if anything comes through you can see it.

also, the reason your program might seem like it's hanging up is b/c of this loop. You need to use DoEvents in the call to free up the interface so you can click a cancel button or something. Also, you need something in this loop to eventually get you out if nothing ever shows up. You know, like a counter.

Also, some of these call like

code[vb]
strChar = MSComm0.Input
strLeakRate = strLeakRate & MSComm0.Input

/code

could go inside your "ONComm" event for mscomm0

Also, are you sure the baud settings are correct? Most machines I've ever talked to used 9600 or more.

Hope this helps,

B
Feb 14 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: jinoy | last post by:
how can i detect an incoming caller's telephone keystroke using modem, using mscomm or other? how can i detect an outgoing call using mscomm? how can i get a caller id using mscomm?
1
by: Peter Krikelis | last post by:
Hi, I am trying to develope a User Control Library that features MScomm control. I test my user control in a test application. When I run the application I receive the following: An...
0
by: morgal | last post by:
That is one reason I quit using MS custom controls, you have to buy the license. In VB 6 they give you a try it license and then you develop a huge application or small one and find out you don't...
4
by: AA | last post by:
Hi I am developing an app in which I have used a MSComm object. I have opened the port, performed the transactions, and then closed the port. But when I check in the task mamager, the memory...
6
by: Barry Martin | last post by:
I am using an activex control mscomm to control a serial port in VB.NET. I place the control on the main form and set its port, baud rate, etc. properties. After creating a code module that needs...
9
by: Carl Gilbert | last post by:
Hi I'm trying to open a vb6 project in vb.net which uses the mscomm component. When running the vb upgrade wizard in vb.net, an error is raised: Upgrade failed, unable to load reerenced...
1
by: Pete | last post by:
Hello, Have just started using VB.Net and have been trying to work on some updates to a very old piece of code. Currently we send messages via the serial port in the following formate ...
0
by: swati2106 | last post by:
HI, I have develop a apllication , To store the GPS data in database, for that , to read GPS data I have used the Mscomm port, In which I create the object of class RS232 n open that port,...
0
by: cmdolcet69 | last post by:
I get the following error message when I output to the mscomm: An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in COM.exe Additional information: Exception...
0
by: daveman | last post by:
Hello, I'm encountering a "Blue Screen of Death" when I try to send data to a bluetooth sensor via a serial port, using the MSCOMM ActiveX object. I was wondering if anyone has any ideas how to...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.