473,651 Members | 2,634 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MSCOMM Troubles

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>

The <CR> showing the end of a message arriving on the comm port. For
some reason the handle input routine that I've written recognises
every other character and outputs it correctly to the text box I'm
using. But always seems to fail when it comes to the <CR> character.
Displaying a weird box instead.

I've tried several different ways of looking at the data and have cut
and pasted the text outputted into notepad where the weird black boxes
remain, but then in MSWord it happily starts a newline.

Not at all sure where I'm going wrong. Am I using the wrong comparison
to detect the <CR>? It never seems to make it into this part of the if
statement. All other characters are being displayed fine but this
isn't!

Hope someone can help?

Pete
Private Sub SUComm1_OnComm( ByVal sender As System.Object, ByVal e
As System.EventArg s) Handles SUComm1.OnComm

Static SUBuff As String
Dim NewChar As Char

SUBuff = SUComm1.Input()
Call HandleInput(SUB uff)

End Sub

Sub HandleInput(ByV al SUBuff As String)

' This is where you will process your input. This
' includes trapping characters, parsing strings,
' separating data fields, etc. For this case, you
' are simply going to display the data in the TextBox.

Dim BufferSize, Counter As Integer
Dim NextChar, Buffer As String
Dim ENQInt, ETXInt, STXInt, ACKInt, CRInt As Integer
Dim ENQStr, STXStr, ACKStr, ETXStr, CRStr As String
Dim CommStr, IDStr, ProStr, ValStr As String

STXStr = Chr(2)
ETXStr = Chr(3)
ENQStr = Chr(5)
ACKStr = Chr(6)
CRStr = Chr(13)
CommStr = Chr(111)
IDStr = Chr(105)
ProStr = Chr(112)
ValStr = Chr(118)

Buffer = SUBuff

If Buffer = ENQStr Then
'ENQ Received from SU send ENQ back. Not waiting for CR.
SUOutput.Select ionStart = Len(SUOutput.Te xt)
SUOutput.Select edText = Str(Asc(Buffer) ) + Chr(13) +
Chr(10)
PCOutput.Select ionStart = Len(PCOutput.Te xt)
PCOutput.Select edText = "5" + Chr(13) + Chr(10)
SUComm1.Output( ) = ENQStr
ElseIf Buffer = ETXStr Then
'ETX Received from SU send STX back. Not waiting for CR.
SUOutput.Select ionStart = Len(SUOutput.Te xt)
SUOutput.Select edText = Str(Asc(Buffer) ) + Chr(13) +
Chr(10)
PCOutput.Select ionStart = Len(PCOutput.Te xt)
PCOutput.Select edText = "2" + Chr(13) + Chr(10)
SUComm1.Output( ) = STXStr
ElseIf Buffer = CRStr Then
'CR Received from SU output to screen.
SUOutput.Select ionStart = Len(SUOutput.Te xt)
SUOutput.Select edText = Chr(13) + Chr(10)
Else
If Asc(Buffer) > 32 Then
'Output buffer to the screen.
SUOutput.Select ionStart = Len(SUOutput.Te xt)
SUOutput.Select edText = Buffer
Else
'output asc value to the screen.
SUOutput.Select ionStart = Len(SUOutput.Te xt)
SUOutput.Select edText = Str(Asc(Buffer) )
End If
End If
End Sub
Nov 20 '05 #1
1 2528
Hi,
Note Dick's comment concerning

"If Right$(Buffer, 2) = vbCrLf Then"

-----------

I developed an application that takes a 10-digit barcode string from my
com
port and processes it. I noticed, however, that for each string
transmitted
by the barcode scanner I get 2 comm events (or 2 OnComm's). The first
one
only contains the first 7 characters or the string. The second contains
the
last three characters. I set up the code to handle this so that the two
strings are combined to form the desired 10-digit string.

But I'm wondering, Why does this happen? What settings do I need to
have in
place to guarantee a full 10-digit string every time? Is this the
function
of the InputLen property of the MSCOMM object? What about
InBufferCount?
<<

This is completely normal. Just double-buffer data and process it when
it
all arrives. Set InputLen = 0 (the default), and RThreshold = 1. For
example,

Private Sub MSComm1_OnComm ()
Static Buffer As String
Buffer = Buffer & MSComm1.Input
If Right$(Buffer, 2) = vbCrLf Then
Process Buffer 'do something interesting here
Buffer = "" 'cleanup
End If
End Sub

Dick
--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.

If you really want to use the MSCOMM32.ocx with VB.NET then to add it to
the toolbox, right click on the toolbox, select "Add/Remove items...",
select the "COM Componets" tab and tick "Microsoft Communications
Control". Press OK and you should have it in your toolbox.

If you have the time I would rewrite the code. Have a look at
http://www.codeproject.com/dotnet/Do...Communications
I know its C# and this is a vb newsgroup but the principles are the
same.
----- Steve Liebenberg wrote: -----

I have used the ms comms control extensively in my vb6
prof. developments which I am in the process of converting
to vb.net.
However, I do not seem to find the comms control in
the .net toolbar. How can I register this control in .net?


I have written a VB app using the RS323.vb code from the VB resource
kit.
When I try to run the code from a network drive I get a
securityexcepti on
error. If I copy the file to the local c drive it works perfectly. I
have
seen posts that say the best thing to do is change the runtime security
policys on the PCs. I would rather code the program so I don't have to
change the security policy at all. I have seen a few examples of
permission
code but none are dealing with a serial port. Below is a partial copy
of
the code I am trying to make work. I think I doing this correctly, but
it
still gives the SecurityExcepti on when run on the network drive. Part
of
the problem, I think, is which permission do I need to use in the Dim
compermission line? The ultimate goal is to put this application on a
network drive and let people use it without making any changes to the
PC.
Can this be done? Thank you for your time.

Jason Dravet

'Imports System.Security
Imports System.Security .Permissions

Public Class Form1
Inherits System.Windows. Forms.Form
Private msCommPort As New Rs232
Dim setmute As Boolean = True
Dim volumelevel As Integer = 24
Dim compermission As FileIOPermissio n

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
compermission = New FileIOPermissio n(PermissionSta te.Unrestricted )
compermission.P ermitOnly()
msCommPort.Open (1, 9600, 8, Rs232.DataParit y.Parity_None,
Rs232.DataStopB it.StopBit_1, 4096)
msCommPort.Writ e("PON")
System.Threadin g.Thread.Sleep( 5000)
msCommPort.Writ e("AVL:000")
msCommPort.Clos e()
End Sub

Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button2.Click
msCommPort.Open (1, 9600, 8, Rs232.DataParit y.Parity_None,
Rs232.DataStopB it.StopBit_1, 4096)
msCommPort.Writ e("POF")
msCommPort.Clos e()
Button4.FlatSty le = Windows.Forms.F latStyle.Flat
Button4.BackCol or = Color.Gray
Button4.Text = "Muted"
End Sub

"Pete" <pe********@hot mail.com> wrote in message
news:8e******** *************** ***@posting.goo gle.com:
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>

The <CR> showing the end of a message arriving on the comm port. For
some reason the handle input routine that I've written recognises
every other character and outputs it correctly to the text box I'm
using. But always seems to fail when it comes to the <CR> character.
Displaying a weird box instead.

I've tried several different ways of looking at the data and have cut
and pasted the text outputted into notepad where the weird black boxes
remain, but then in MSWord it happily starts a newline.

Not at all sure where I'm going wrong. Am I using the wrong comparison
to detect the <CR>? It never seems to make it into this part of the if
statement. All other characters are being displayed fine but this
isn't!

Hope someone can help?

Pete
Private Sub SUComm1_OnComm( ByVal sender As System.Object, ByVal e
As System.EventArg s) Handles SUComm1.OnComm

Static SUBuff As String
Dim NewChar As Char

SUBuff = SUComm1.Input()
Call HandleInput(SUB uff)

End Sub

Sub HandleInput(ByV al SUBuff As String)

' This is where you will process your input. This
' includes trapping characters, parsing strings,
' separating data fields, etc. For this case, you
' are simply going to display the data in the TextBox.

Dim BufferSize, Counter As Integer
Dim NextChar, Buffer As String
Dim ENQInt, ETXInt, STXInt, ACKInt, CRInt As Integer
Dim ENQStr, STXStr, ACKStr, ETXStr, CRStr As String
Dim CommStr, IDStr, ProStr, ValStr As String

STXStr = Chr(2)
ETXStr = Chr(3)
ENQStr = Chr(5)
ACKStr = Chr(6)
CRStr = Chr(13)
CommStr = Chr(111)
IDStr = Chr(105)
ProStr = Chr(112)
ValStr = Chr(118)

Buffer = SUBuff

If Buffer = ENQStr Then
'ENQ Received from SU send ENQ back. Not waiting for CR.
SUOutput.Select ionStart = Len(SUOutput.Te xt)
SUOutput.Select edText = Str(Asc(Buffer) ) + Chr(13) +
Chr(10)
PCOutput.Select ionStart = Len(PCOutput.Te xt)
PCOutput.Select edText = "5" + Chr(13) + Chr(10)
SUComm1.Output( ) = ENQStr
ElseIf Buffer = ETXStr Then
'ETX Received from SU send STX back. Not waiting for CR.
SUOutput.Select ionStart = Len(SUOutput.Te xt)
SUOutput.Select edText = Str(Asc(Buffer) ) + Chr(13) +
Chr(10)
PCOutput.Select ionStart = Len(PCOutput.Te xt)
PCOutput.Select edText = "2" + Chr(13) + Chr(10)
SUComm1.Output( ) = STXStr
ElseIf Buffer = CRStr Then
'CR Received from SU output to screen.
SUOutput.Select ionStart = Len(SUOutput.Te xt)
SUOutput.Select edText = Chr(13) + Chr(10)
Else
If Asc(Buffer) > 32 Then
'Output buffer to the screen.
SUOutput.Select ionStart = Len(SUOutput.Te xt)
SUOutput.Select edText = Buffer
Else
'output asc value to the screen.
SUOutput.Select ionStart = Len(SUOutput.Te xt)
SUOutput.Select edText = Str(Asc(Buffer) )
End If
End If
End Sub


Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4923
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
3519
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
2148
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
3450
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
6582
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
9050
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.
0
1573
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
1698
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
1861
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
8347
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8792
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
8694
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...
1
8457
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8571
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
7294
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
6157
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
4143
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
2696
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.