473,396 Members | 1,784 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,396 software developers and data experts.

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.EventArgs) Handles SUComm1.OnComm

Static SUBuff As String
Dim NewChar As Char

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

End Sub

Sub HandleInput(ByVal 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.SelectionStart = Len(SUOutput.Text)
SUOutput.SelectedText = Str(Asc(Buffer)) + Chr(13) +
Chr(10)
PCOutput.SelectionStart = Len(PCOutput.Text)
PCOutput.SelectedText = "5" + Chr(13) + Chr(10)
SUComm1.Output() = ENQStr
ElseIf Buffer = ETXStr Then
'ETX Received from SU send STX back. Not waiting for CR.
SUOutput.SelectionStart = Len(SUOutput.Text)
SUOutput.SelectedText = Str(Asc(Buffer)) + Chr(13) +
Chr(10)
PCOutput.SelectionStart = Len(PCOutput.Text)
PCOutput.SelectedText = "2" + Chr(13) + Chr(10)
SUComm1.Output() = STXStr
ElseIf Buffer = CRStr Then
'CR Received from SU output to screen.
SUOutput.SelectionStart = Len(SUOutput.Text)
SUOutput.SelectedText = Chr(13) + Chr(10)
Else
If Asc(Buffer) > 32 Then
'Output buffer to the screen.
SUOutput.SelectionStart = Len(SUOutput.Text)
SUOutput.SelectedText = Buffer
Else
'output asc value to the screen.
SUOutput.SelectionStart = Len(SUOutput.Text)
SUOutput.SelectedText = Str(Asc(Buffer))
End If
End If
End Sub
Nov 20 '05 #1
1 2514
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
securityexception
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 SecurityException 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 FileIOPermission

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
compermission = New FileIOPermission(PermissionState.Unrestricted)
compermission.PermitOnly()
msCommPort.Open(1, 9600, 8, Rs232.DataParity.Parity_None,
Rs232.DataStopBit.StopBit_1, 4096)
msCommPort.Write("PON")
System.Threading.Thread.Sleep(5000)
msCommPort.Write("AVL:000")
msCommPort.Close()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
msCommPort.Open(1, 9600, 8, Rs232.DataParity.Parity_None,
Rs232.DataStopBit.StopBit_1, 4096)
msCommPort.Write("POF")
msCommPort.Close()
Button4.FlatStyle = Windows.Forms.FlatStyle.Flat
Button4.BackColor = Color.Gray
Button4.Text = "Muted"
End Sub

"Pete" <pe********@hotmail.com> wrote in message
news:8e**************************@posting.google.c om:
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.EventArgs) Handles SUComm1.OnComm

Static SUBuff As String
Dim NewChar As Char

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

End Sub

Sub HandleInput(ByVal 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.SelectionStart = Len(SUOutput.Text)
SUOutput.SelectedText = Str(Asc(Buffer)) + Chr(13) +
Chr(10)
PCOutput.SelectionStart = Len(PCOutput.Text)
PCOutput.SelectedText = "5" + Chr(13) + Chr(10)
SUComm1.Output() = ENQStr
ElseIf Buffer = ETXStr Then
'ETX Received from SU send STX back. Not waiting for CR.
SUOutput.SelectionStart = Len(SUOutput.Text)
SUOutput.SelectedText = Str(Asc(Buffer)) + Chr(13) +
Chr(10)
PCOutput.SelectionStart = Len(PCOutput.Text)
PCOutput.SelectedText = "2" + Chr(13) + Chr(10)
SUComm1.Output() = STXStr
ElseIf Buffer = CRStr Then
'CR Received from SU output to screen.
SUOutput.SelectionStart = Len(SUOutput.Text)
SUOutput.SelectedText = Chr(13) + Chr(10)
Else
If Asc(Buffer) > 32 Then
'Output buffer to the screen.
SUOutput.SelectionStart = Len(SUOutput.Text)
SUOutput.SelectedText = Buffer
Else
'output asc value to the screen.
SUOutput.SelectionStart = Len(SUOutput.Text)
SUOutput.SelectedText = 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
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...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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: 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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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...
0
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...

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.