473,775 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VBA MSComm troubles

19 New Member
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 2913
Bum
19 New Member
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
4935
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
3529
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 unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in axinterop.mscommlib.dll
0
2154
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 have rights to use the control. You have to contact the manufacturer of the control--MS may not be the manufacturer, in the original VB 6 docs it told you who to contact. Then you must pay them what they are asking, some are a one time fee and...
4
3456
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 being held by the MSComm is not being released. I am using the SetPortOpen method. Is there any way of releasing this memory explicitly. Regards.
6
6620
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 to access the serial port, I cannot seem to be able to access the mscomm control from within a code module. In VB6 you could use the statement frmMain.Mscomm1.output = "some data string" in the code module but this won't work in VB.NET. Does...
9
9067
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 component mscomm32.ocx (1.1.0) You need to install this component before you upgrade the project. Does anyone know how to install the mscomm component.
1
2534
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 i176.8005 <CR> i176.800555.44 <CR> o176.8005.222 <CR>
0
1579
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, n store the data in to one string type variable , msStr but some time it store the Mscomminput, n some times it stores nothing, but in mscomm.input will have a GPS data, why it is So?
0
1705
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 from HRESULT: 0x800A1F52. No one has been able to tell me why this isn't working. I know VB 2003 doesn't have serial control however I need to send this with the mscomm. It will break at the line : comm1.Output = Packet(i)
0
1870
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 fix the problem. As some background, I am trying to use VB to communicate with a Wi-Tilt bluetooth accelerometer, a sensor which sends data over a COM serial port. I have no problem talking to the device in Hyperterminal; it streams data into...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10268
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10107
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9916
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8939
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7464
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6718
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5360
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4017
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.