Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




MSCOMM -- Best Way To Read Data


When using the MSComm control to check for data coming in from the serial port, is it best to do so by using the OnComm and then getting the Input property or should I use the

VB Code:
DoDoEvents()variable = variable & mscomm1.InputLoop until Len(variable) > 10

???
-----------------------
By the way, why do my posts always have a blue letter icon with a black circle in the middle?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Read Data From MSComm
Hi all,

i try to understand this, which i do not know how to explain. The picture below descript the form that i've done.


Then the code

Code:
Option Explicit
Public bolComOpen As Boolean

Private Sub Option1_Click(Index As Integer) 'option to select handsking type
Select Case Index
Case Option1(0).Value = vbChecked
MSComm1.Handshaking = comNone
Case Option1(1).Value = vbChecked
MSComm1.Handshaking = comRTSXOnXOff
Case Option1(2).Value = vbChecked
MSComm1.Handshaking = comRTS
Case Option1(3).Value = vbChecked
MSComm1.Handshaking = comRTSXOnXOff
End Select
End Sub

Private Sub Command1_Click() 'command to start sending data
'Dim inputstring
On Error GoTo ErrorHandler
Command1.Enabled = False 'command1 = start button
Command2.Enabled = True 'command2 = Stop button
Command3.Enabled = False 'command3 = close button
With MSComm1
.CommPort = Right(Trim(Combo1.Text), 1) 'combo1 = to display port option
.Settings = Text1 'text1 = textbox to display parameter
.PortOpen = True
End With
bolComOpen = True
Command1.BackColor = vbGreen
Text2 = "" 'text2 = text for display incoming data
Text3 = "" 'text3 = text for display buffer size
Combo1.Enabled = False
Text1.Enabled = False
Do
With MSComm1
If MSComm1.InBufferCount = 256 Then
Text3 = .InBufferSize 'size buffer display on the buffer size textbox
Text2.Text = Right(Text2.Text & .Input, 100) 'incoming data from serial port with the length of 100
Open "C:Documents and Settingsece30966 est program est.cli" For Output As #1
Print #1, Text2.Text
Debug.Print Text2.Text
Close #1
End If
End With
DoEvents
Loop Until Not bolComOpen
MSComm1.PortOpen = False
Command1.Enabled = True
Command2.Enabled = False
Command3.Enabled = True
Exit Sub
ErrorHandler:
MsgBox Err.Description
Command1.Enabled = True
Command2.Enabled = False
Command3.Enabled = True
End Sub

Private Sub Command2_Click()
bolComOpen = False
Command1.BackColor = vbRed
Combo1.Enabled = True
Text1.Enabled = True
Command1.Enabled = True
Command2.Enabled = False
Command3.Enabled = True
End Sub

Private Sub Command3_Click()
Unload Me
End Sub

Private Sub Form_load()
Combo1.Enabled = True
Text1.Enabled = True
Command1.Enabled = True
Command2.Enabled = False
Command3.Enabled = True
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If MSComm1.PortOpen = True Then
MsgBox "click stop to close the connection first"
Cancel = True
End If
End Sub


The input send using serial port is for example 01010111
then data read as a character and save in C:Documents and Settingsece30966 est program est.cli.

Since the file in .cli. Then what i do is to open using visual c++. i opened the file as type binary. and display this.



Can anyone please help me how to read this. how to read this data and compare with the input which is 01010111. Thanks.. please guide

Using Mscomm Control To Read Data From A Chip
Using the below piece of code i am trying to Read address memory location 0800Hex, to call this location i send the MSB as 8 and the LSB as 0 like so

Read_page=(8,0)

However this only returns the contents of memory address 0, whichi have no problem reading from.
Any ideas on how to address the correct location.


Function Read_page(Address_MSB as Byte, Address_LSB as Byte)
'33h is the read page command
Dim outbyte(10) as Byteoutbyte(0) = 51
'Send MSB address of the start of the page
MSComm1.Output=outbyteoutbyte(0)=Address_MSB
'Send LSB address of the start of the page
MSComm1.Output=outbyteoutbyte(0) =Address_LSB MSComm1.Output = outbyte
End Function
[color=royalblue][color=darkblue][color=green][color=darkblue]

ANSIW?? Can You Set MSCOMM To Read It?
I am working on a program that monitors the COM Port, waiting for data to be streamed from a phone system.

I created a test enviroment where I have two programs. One sending data from a text file, the other receiving the data and then entering it into a database.

Everything works in the test enviroment, but when I place the program on the monitoring system the program locks up. My first thought is that it is caused by a loop I have in the program looking for the first line of text.

I'm thinking that the data my program is getting from the ACD system doesn't make sense. When I looked at the Hyperterminal session that normally monitors and captures the data the emulation was set to ANSIW.

Is there a way to set the MSCOMM to be able to read ANSIW information?

Read Binary Value From MSComm!!!!
Hi,

I'm trying to send a hex value from a device to the serial port. I need to read the hex value from the port but if it's in text mode then I get a letter, not the actual hex, so how do I go about getting the hex value? ie The hex value is obviously sent digitally so, get the '101010101' or whatever, instead of the letter... I am baffled and I can't use asc() as it's not the ascii value of the letter that I'm after, it's the hex value. (Not the hex of the asc either!) And hex() can't be done on a string... I'm am completely baffled!!! Any help, any code, any ideas!!! Plllllllleaaaaase! Maybe there's another way or an easier thing I'm missing...

cheers

Dom

Read String From COM1 Without MSCOMM
Hello all VB masters,
I'm a VERY VERY newbie in VB, but I got a very difficult task
I need to read string from serial port (COM1), and for some reason, I can't use MSCOMM component . I already search the internet for the answer but still I stuck. Here is some code I've made :


fCOM = FreeFile
Dim LineText As String

Open "COM6" For Input As #fCOM
LineText = fCOM

Close #fCOM
Text1.Text = Text1.Text + LineText




but what I've got is just "1" character on my text1 component. Any suggestion from masters?
Thanks for read my post

Read MSCOMM Input Buffer Without Emptying It
Is there anyway I can read a byte from the MSCOMM input buffer without removing that byte?

Mscomm Saving To A Text File (serial Read)
Hello
I am new with using the mscomm 6 control so I'll expain what I have done and what isn't working.

I am reading a serial port in and everything is fine except for the saving to a text file. What the text file shows would be this:
Th
This
This is
This is a
This is a te
This is a test

When actually all I want is "This is a test" one time to appear in the text file. I will need to keep appending to this file. I know kind of why it is doing this one because I'm not stopping the buffer to read and then clearing the buffer. Second reason is I'm using a timer control I think this is probably wrong. However, I need the program to save and read atleast every 10secs if not in real time in which the program is doing now.

I am also concerned by stopping and starting or clearing the buffer of losing any data or actually not getting any read in time.

Here is my current code:

Dim MyData As Variant
Dim buffersig
Private Sub cmdSend_Click()
MyData = InputBox("Please type data to send")
mscomm1.Output = MyData
End Sub

Private Sub Display_Click()
mscomm1.InputLen = 0
mscomm1.InBufferCount = 0
mscomm1.OutBufferCount = 0
' Fire CommEvent every time (1) character is received
mscomm1.RThreshold = 0

End Sub

Private Sub Form_Load()
mscomm1.CommPort = 1
mscomm1.Settings = "9600,n,8,1"
mscomm1.PortOpen = True
End Sub

Private Sub exit_Click()
On Error GoTo Err_exit_Click

mscomm1.PortOpen = False
DoCmd.Close

Exit_exit_Click:
Exit Sub

Err_exit_Click:
MsgBox Err.Description
Resume Exit_exit_Click

End Sub

Private Sub Form_Timer()
buffersig = buffersig & mscomm1.Input
Display.Caption = buffersig
Open "c: estfile.txt" For Append As #1
Write #1, buffersig
Close #1
End Sub


I'm not sure if there is an easier way or exactly what direction to go towards. Any help is greatly appreciated.

Thanks so much
Dan Schuessler

MSCOMM: How To Read One Single Byte Fast From A Com Port
Hello!

I have an application that deals with com port using MSCOMM.

My initialisation is:

MSComm1.CommPort = 1
MSComm1.Settings = "38400,N,8,1"
MSComm1.InputMode = comInputModeBinary
MSComm1.NullDiscard = False
MSComm1.InBufferSize = 1024
MSComm1.InputLen = 0
MSComm1.RThreshold = 1
MSComm1.PortOpen = True

The application using the com port works.
The problem is, I expect that if there has ONE single byte been received, the OnComm event should happen AT ONCE and not with a delay (in which several new bytes will be received). If I change MSComm1.InputLen = 1, I only read one byte from the buffer , therefore I thought, on every byte received by the RS232 Port, a OnComm event will be caused and I read this single byte. After that I wait for the next byte etc. But if I am doing this, the OnComm event seems to be too slow to react on every single received byte and therefore only appears sometimes.
The need for this fast reaction is, that I have an acknoledge timeout, and if the
reaction of OnComm is too long, the timeout appears, although the acknoledge
byte has been received, but could not be decoded, cause OnComm did not happen.

Has anyone an idea to react on EVERY SINGLE received byte AT ONCE?

Thank you for every help!

MSCOMM Serial Port Data Capture And Manipulation Of Data
Dear frens,

I'm writing a VB project which will receive data from a device via
RS232. I have a few problems


1) First, I can use VB to capture the RS232 data but what i get is some
characters which i think should be ASCII characters whereas i can
capture the RS232 data with some " SERIAL MONITORING" software which
will display the data nicely in HEX, for eg
A1 23 FE 41 1C 43
My question is how can i convert the RS232 data i captured above to the
HEX i mentioned, ie A1 23 FE AI and etc...? I tried using HEX but what
it came out was a continuous stream of 0s... Any idea how?


2) The question 1) is the 1st stage of my project. The 2nd project is
to parse through the patterns of the HEX data and find more specific
patterns. For eg
(i) A1 B4
(ii) A2 34
(iii) 28 33


And then for each pattern i got, i need to set a bit of a data type of
16 bits. For example, if i get (i) A1 B4, i need to set the 1st bit of
that data type to 1
If i get (ii) A2 34, i need to set the 5th bit of that data type to 1
also.


How can i search thru the RS232 data i mentioned above? I'm not very
clear of the data types and functions of VB because this is only my 2nd
month using VB.


Also, which data type is suitable for the "data type of 16 bits" i
mentioned above for the bit setting?


Any help is appreciated... Thank you very much.


Albert Leng
(albertleng@gmail.com)

Mscomm Data Capturing And Saving Data Online To Adatabase
hai iam raheem,


i am new in vb .i am working as pabx technician.
I developed a program to capture the SMDR coming
from the pabx with the help of vbterminal(vb sample)
it capturing the data like the hyper terminal and it is showing in atext box line by line.Actually i want this
data to saved in to a database immediatly as it showing in the text box . can anybody help me for developing a program to do this . I have the sample
data captured from pabx.
********************************************************************** **********

Date Time T Ext CO Dial Number Ring Duration Acct code CC

********************************************************************** **********

02/06/06 10:51AM 1 E1001 T10601 9 00:00'00

02/06/06 10:52AM 1 E1001 T10601 9 00:00'02

02/06/06 10:53AM 1 E1001 T10501 <INCOMING> 0'05 NA


pls help me

Hex Data With Mscomm
I am trying to send and receive data to an OMC ECU. I have monitored the lines between it and a dos based program , and know what to send and what I should receive. The data is all in hex and needs to be sent and received that way. (ie 01 00 00 00 01) or (01 04 00 f6 74). Can someone tell me how to send hex data because mscomm.output sends a string not hex numbers, and how to display the data as hex numbers in a textbox.

Using Data From Mscomm
Code:
Private Sub MSComm1_OnComm()
Dim InBuff As String

Select Case MSComm1.CommEvent
' Handle each event or error by placing
' code below each case statement.



' Errors
Case comEventBreak ' A Break was received.
Case comEventCDTO ' CD (RLSD) Timeout.
Case comEventCTSTO ' CTS Timeout.
Case comEventDSRTO ' DSR Timeout.
Case comEventFrame ' Framing Error.
Case comEventOverrun ' Data Lost.
Case comEventRxOver ' Receive buffer overflow.
Case comEventRxParity ' Parity Error.
Case comEventTxFull ' Transmit buffer full.
Case comEventDCB ' Unexpected error retrieving DCB]

' Events
Case comEvCD ' Change in the CD line.
Case comEvCTS ' Change in the CTS line.
Case comEvDSR ' Change in the DSR line.
Case comEvRing ' Change in the Ring Indicator.
Case comEvReceive ' Received RThreshold # of chars.
InBuff = MSComm1.Input
Call HandleInput(InBuff)
Case comEvSend ' There are SThreshold number of
' characters in the transmit buffer.
Case comEvEOF ' An EOF character was found in the
' input stream.
End Select

End Sub

Sub HandleInput(InBuff 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.
Text1.SelStart = Len(Text1.Text)
Text1.SelText = InBuff

End Sub


So all of that was delicious copypasta from the Microsoft support.


Code:
Private Sub combobox_Click()
Dim Path As String
Path = "C:Program FilesMicrosoft Visual Studio 8"
If combobox.ListIndex = 0 Then
Picture1.Picture = LoadPicture(Path + "zzz1.gif")
Text2.Text = "zzz 3"
asd = 3
End If

If combobox.ListIndex = 1 Then
Picture1.Picture = LoadPicture(Path + "yyy.jpg")
Text2.Text = "yyy 5"
asd = 5
End If

If combobox.ListIndex = 2 Then
Picture1.Picture = LoadPicture(Path + "xxx.jpg")
Text2.Text = "xxxx 7"
asd = 7
End If
End Sub


So I suppose ASD would have to be 1 of the variable with an array from the mscomm sub, just not sure which. Need you guys to tell which one issit, or do I have to make a new var.

Which Data? And How To Send With MScomm....
Hey all, posting in hope to see if someonw could point me in the right direction.

I've just began to learn VB 6 (from books) and have no other previous experience with any other programming langauge.

What i'm trying to do is send the appropiate date to a microcontroller, the problem i'm having is, I don't know which data i need to send, or how to send it...

Here's some info on the APIhttp://reprap.org/bin/view/Main/Step..._a_single_step
http://reprap.org/bin/view/Main/PICCommsLibrary
http://reprap.org/bin/view/Main/Modules

I belive the original program which was used was Java, but i presume i should still be able to send the data i need with VB if i could just figure out what data to send and how to send it.

I'm not looking for anyone to write the code for me, just someone who could maybe point me in the right direction as i've searched and read page after page without any progress..

Thanks.

P.s. If anyone needs any more info just ask and i'll help all i can.

Reading Gps Data Using Mscomm
i am creating an MS Access database for someone. on one of the forms, i need a button that, when pressed, will fill in the current gps coordinates. i have added a mscomm control to the form named 'MSComm0'; my gps unit is made by garmin and connects to com port 1.

i am having trouble getting any data using mscomm. i know the unit is functioning, and i know that my settings are all correct because i have tested it with hyperterminal.

the gps data comes as a series of strings, all starting with '$'. the one i'm after starts with '$GPGGA'. none of them are the exact same length, although i believe they are each seperated by a line break.

below i have included the code that runs on the button click event. for now, i'm just displaying the return string in a message box. it is always blank. i have tested the value of i at the end, and it is always 15.

i suspect i'm missing something very fundamental, but i can't figure out what it is. thanks in advance for any help you can give!

Dim gps As String
Dim max_tries As Integer
Dim i As Integer

gps = "new coordinates"
max_tries = 15
i = 0

MSComm0.CommPort = 1
MSComm0.Settings = "4800,N,8,1"
MSComm0.PortOpen = True

Do While InStr(gps, "$GPGGA") < 1
gps = MSComm0.Input
i = i + 1
If i >= max_tries Then Exit Do
Loop

MSComm0.PortOpen = False

MsgBox (gps)

Deleting Data Using MSComm
I have a transmitter and a receiver, both are connected with a RS-232. The transmitter sends out data, but there are certain data that I like to filter out before receiving. Here is what I have:


Code:
Private Sub MSComm1_OnComm()
Dim inData as String
Select Case MSComm1.CommEvent
Case comEvReceive
inData = MSComm1.Input
If Instr(inData, "Something") > 0 Then
'Delete that "Something"
End If
What code would I put in replace of that 'Delete that Something line? Any help is appreciated. Thanks.

How To Know If Mscomm Receiving Data???
I am connection three push button sending different data in to computer. I had use hyperteminal to check and the computer did receive the data. How am I going to know if VB mscomm is receiving the data??? And how am I suppose to link it with my program?

MSComm Receive Data
Hello

Im using the MSComm to send and receive binary data to a video server, the sending part works fine, but when a receive more than 8 byets, the input variable only keeps the bytes over the eighth byte. ...Please some can some one tell me where im wrong??? these are the settings and the OnComm part

Code:
MSComm1.CommPort = 1
MSComm1.Settings = "38400,O,8,1"
MSComm1.InputMode = 1
MSComm1.InputLen = 0
MSComm1.RThreshold = 1
MSComm1.SThreshold = 1
MSComm1.DTREnable = True
MSComm1.RTSEnable = True
MSComm1.NullDiscard = False

If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
End If

Private Sub MSComm1_OnComm()
Dim buffer As Variant
Dim Arr() As Byte
Dim i As Integer
Dim iTemp As Integer
Dim sTemp As String
Dim strINPUT As String


Select Case MSComm1.CommEvent
Case comEvReceive
Do While MSComm1.InBufferCount > 0
buffer = MSComm1.Input
Arr = buffer

For i = LBound(Arr) To UBound(Arr)

iTemp = Asc(Chr$(Arr(i)))
sTemp = Hex$(iTemp)

If Len(sTemp) = 1 Then 'For display in a text box
strINPUT = strINPUT & "0" & sTemp & " "
Else
strINPUT = strINPUT & sTemp & " "
End If

Text1.Text = strINPUT

Next
Loop

Speed Of Data Sent (mscomm)
I'm sending data to a ticket printer via mscomm. If I step through my code, the data is received and the ticket is printed. If I run the executed code, the ticket is not printed and no errors are generated.

How do I slow things down? Is this the problem? I've tried sending the ticket data and then using sleep. Also tried with DoEvents but still no luck.

Here's the code snippet:


Code:
...
' Sets the printer to "on-demand" mode
Call ResetPrinter(cOperationCommand & "|C|^")

' Set the string of info to be printed.
strTicketInfo = "^P|0|1|" & strTicketInfo & strBarCodeNo & "|^"

' Print the ticket.
SendDataToPrinter (strTicketInfo)

kstrTestResult = "Passed."

...

Public Sub SendDataToPrinter(pvntData As Variant)

MSComm1.Output = pvntData

End Sub

Using MSComm To Get Data From A Microcontroller
I am new to Visual Basic, and am using Visual Studio.NET 2002. My overall goal is to transmit temperature information from an Atmel AVR 8 bit microcontroller and to display it in a textbox on a form.
On a form I have two radio buttons for enabling and disabling the serial port communication, a command button that when pressed should read the data from the serial port, a text box to display the data and the MSComm control. I am having alot of problems trying to implement this.

Currently, I am sending the word "test" with a new-line and carriage return to the serial port of the PC. If I use a hyper-terminal, the word displays fine. However when I try and display the information on the GUi nothing happens. Please show me the simplest way to receive information from the serial port.

Here is my code:

Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub AxMSComm1_OnComm(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AxMSComm1.OnComm

End Sub

' Button 1 Procedure
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dummy
' sends RDO command + CR
'AxMSComm1.Output = "rd0" + Chr$(13)
'waits for 2 characters to be received
'into the serial buffer (data + CR)
Do
dummy = JunkEvents()
Loop Until AxMSComm1.InBufferCount >= 5
'print value in text box
TextBox1.Text = Val(AxMSComm1.Input)
End Sub

Private Function JunkEvents()
Dim counter
counter = counter + 1
End Function

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

' Text Box Procedure
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub

'Radio Button Procedure
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
'Enable Port
AxMSComm1.PortOpen = True
AxMSComm1.Output = "CPA00000000 + Chr(13)"
End Sub

'Radio Button 2 Procedure
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
'Disable Port
AxMSComm1.PortOpen = False
End
End Sub

'Group Box Procedure
Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter
End Sub
End Class

Send 12 Bit Data Using MSCOMM
Hi, I got an instrument that supposed to be controlled with vb through MSCOMM. The problem is: this instrument received 12 bit data (with 9600 bps, non-parity, stop bit: 1 bit), and when I code:


Code:
mscomm1.settings="9600,N,12,1"


an error occurred because 12 is not recognized as a valid value for data bit. According to documentation, the data bit supported by MSCOMM are 4 to 8.
Is there any other way to control this instrument using vb?

MScomm Loss Of Data
my app monitors a comm port, then processes the incomming data. The problem is I sometimes miss incomming data because my app is busy processing previous stuff.
I have done alot of breaking up of my processing, adding lots of doevents etc, but I still miss data.

Is there a way beyond some crazy multi threaded application to make sure this doesn't happen

thanks
- kurt

MsComm - Reading Data
I have currently connected a barcode scanner on COM1 and setup the proper settings using MSCOMM

1. OnComm Event, i.e. when I scan the barcode, it displays properly on text1.text but I'm unable to assign that value of text1.text to a varialble? How can I do it? Or what stage can I actually assign the scanned data to a variable?

2. I also want the scanned data to pad a Chr$(13) so that the text1 keypress event should know there is an ENTER key pressed so that it can do whatever I want to do. Right now it just displays the barcode and there two pipes added to end of the barcode number?

To put it simply, I want the scanned code to appear on the text1 box without those pipes and automatically activate the ENTER key.

I used the verterm.vbp example from MSDN. But the text box in that has got mutiline set to true. My text box is just one line.

If anyone can help me I would highy appreciate it...

Thanks

MSComm Data Conversion
I have been banging my head against several walls for hours!!!
I have a data logger that is sending binary data to the PC. When the data sent is ascii text ( i.e. $45) VB interprets it just fine and display the letter. However, what I need is for the logger to send 10 bytes of data, each byte is a number between 0 and 255. I need to display this value as text in a textbox.

When I recieve this data and try to display it in text mode, I get nothing. Using StrConv to move the data to Unicode doesn't help.

If MSComm is set to "comInputModebinary" each number is dispayed as a "?". VB will not allow for the casting of a 1 char string to an int (so I could do the conversion myself).

I am reading the whole input buffer, all 10 bytes, into a string, VBdidn't like trying to throw it into an array, I tried a binary array.

REmember, the data being sent is in a binary number form, I need to take this binary number, 0-255, and convert it into "0"-"255".

Thanks in advance!!!
-nick

Garbage Data On MSComm
Hi, I am making a new program in VB6. Iam using a Barcode Reader (Symbol LS5700) connected to a Serial Port. I use MSComm to read data from the Port but the data i got is garbage.

I just use this simple code.

Private Sub Form_Load()
MSComm1.CommPort = 1
If MSComm1.PortOpen = False Then MSComm1.PortOpen = True
MSComm1.RThreshold = 1
MSComm1.InputMode = comInputModeText
End Sub

Private Sub MSComm1_OnComm()
txtBarcode.Text = MSComm1.Input
End Sub

Is there a special programming that i need to do, or my code is wrong.

Please help. I know a lot of you encountered this do. please share it to me.

Also if you think theres something i should have used instead of mscomm please tell me so.

Receiving Data Via MScomm In VB
We are using MScomm to read the data available on the serial port . We are unable to retreive the data fully. We are getting only first few characters and others are lost. Can you suggest a way to overcome this problem


The setting for MScomm are as follows:

MSComm settings 9600,n,8,1
Rthreshold 0
Inputlen 0
Handshaking none
InputMode comInputModeText

Thanks in advance
lakshmi

Stream Data Through MSComm
Hi,

i have been playing with the MScomm control and i have been able to get it to pass data back and forth. But i am not able to get it to process data as it recieves it. let me explain. i built a chat app with two richtext boxes. one for typing your text and one for viewing what the other computer sent. i would like to be able to type a character into the input box and have it be displayed on the remote computer right away. right now, i have to generate an OnComm event to be able to flush the buffer. i tried setting the inbuffersize to 1 and just about everything else i can think of. but i still have to push a button to generate an oncomm event and flush the recieve buffer.

please tell me if i have to live with it, or is there something i can do?


Shaba

MSComm Receive Data
Hello

Im using the MSComm to send and receive binary data to a video server, the sending part works fine, but when a receive more than 8 byets, the input variable only keeps the bytes over the eighth byte. ...Please some can some one tell me where im wrong??? these are the settings and the OnComm part

MSComm1.CommPort = 1
MSComm1.Settings = "38400,O,8,1"
MSComm1.InputMode = 1
MSComm1.InputLen = 0
MSComm1.RThreshold = 1
MSComm1.SThreshold = 1
MSComm1.DTREnable = True
MSComm1.RTSEnable = True
MSComm1.NullDiscard = False
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
End If



Private Sub MSComm1_OnComm()
Dim buffer As Variant
Dim Arr() As Byte
Dim i As Integer
Dim iTemp As Integer
Dim sTemp As String
Dim strINPUT As String

Select Case MSComm1.CommEvent
Case comEvReceive
Do While MSComm1.InBufferCount > 0
buffer = MSComm1.Input
Arr = buffer

For i = LBound(Arr) To UBound(Arr)
iTemp = Asc(Chr$(Arr(i)))
sTemp = Hex$(iTemp)

If Len(sTemp) = 1 Then   'For display in a text box
strINPUT = strINPUT & "0" & sTemp & " "
Else
strINPUT = strINPUT & sTemp & " "
End If

Text1.Text = strINPUT

Next
Loop



Binary Data In Using MSComm?
Hello! I'm new to vb and also new here! I have a problem and if someone could help i'd be gratefull! I need to read 24 bit data from a ad. It's sending it all the time. I need a little program that shows me the data that comes in, displays it for example in text box? Make any sense?
Edit: I don't need to read the value all the time, lets say in every 10 seconds when 24 bits have arrived.



Edited by - jusmar74 on 2/15/2005 2:00:50 AM

Receive Data Using Mscomm
I need one application Video on demand. In this application I want to do when any one can call during runing this application his/her show one list of songs and select it by dialing a number. So this type of data i want to receive using mscomm.
Can i use this commmponent to do this OR how can i do this please answare me.


Does anyone have some sample code or experience at doing this? I know how to get the MSComm control to receive a call.


 

Receive Data Using Mscomm
I want do send & receive data using mscomm

how can i do it

can you please help in this topic must replay

topic continued at http://www.vbcity.com/forums/topic.asp?tid=151633

 

Edited by - Geof on 12/25/2007 5:49:01 AM

MSComm Receive Data
Hello

Im using the MSComm to send and receive binary data to a video server, the sending part works fine, but when a receive more than 8 byets, the input variable only keeps the bytes over the eighth byte. ...Please some can some one tell me where im wrong??? these are the settings and the OnComm part

MSComm1.CommPort = 1
MSComm1.Settings = "38400,O,8,1"
MSComm1.InputMode = 1
MSComm1.InputLen = 0
MSComm1.RThreshold = 1
MSComm1.SThreshold = 1
MSComm1.DTREnable = True
MSComm1.RTSEnable = True
MSComm1.NullDiscard = False
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
End If



Private Sub MSComm1_OnComm()
Dim buffer As Variant
Dim Arr() As Byte
Dim i As Integer
Dim iTemp As Integer
Dim sTemp As String
Dim strINPUT As String

Select Case MSComm1.CommEvent
Case comEvReceive
Do While MSComm1.InBufferCount > 0
buffer = MSComm1.Input
Arr = buffer

For i = LBound(Arr) To UBound(Arr)
iTemp = Asc(Chr$(Arr(i)))
sTemp = Hex$(iTemp)

If Len(sTemp) = 1 Then 'For display in a text box
strINPUT = strINPUT & "0" & sTemp & " "
Else
strINPUT = strINPUT & sTemp & " "
End If

Text1.Text = strINPUT

Next
Loop

Mscomm Sending Raw Or Hex Data
ok I'm new to VB and all I've done some basic programming, but his is what i need to do. I need to send codes like "2A6474763E0D0A" to my HDTV box to change the options and ect. I have used a program "RS232 Hex Com Tool v5.0" and connected and sent these hex commands to the unit and it work awesome, but to cut and copy codes into that program is not very effective. I can get the mscomm1 to set to 576000,n,8,1 with no problem but i can not get it to send the commands, ive tried this....

MSComm1.Output = "2A6474763E0D0A"

but i get no responce from my unit at all, anyone have any ideas?

Thank you in advance

Sending Data Bit By Bit With MSCOMM
I am trying to control an A/D converter via the serial port using MSCOMM. The only code example I can find was written with Turbo C and in that example the author sends and receives all data one bit at a time. She does this because after each bit she must send a signal to the chip's CLK. How can I emulate this? Perhaps I am overlooking something very obvious, but since the MSCOMM.Output method accepts only a string or a byte array I'm stumped. Of course, there are many variables in getting the A/D to even work at all, but I'm fairly confident that I understand the C program pretty well.

Thanks for any input. -Scott

MSCOMM - Receiving Data
Hello friend,

i am in dire straits. i'm in need of a help to develop a software that will be able to trap the keys pressed after a phone call has been receieved thru' MSCOMM control using a modem. i need to perform operations based on the keys pressed. i do not have the necessity to converse with voice.

so far, only a connection is being able to be recognised. after that ...i've tried a lot many things... but nothing has worked out in my favour. Please HELP ME.

i've tried something in handshaking... does the CDHolding have to be trapped ?..but doesnot work.

what happens after the call has been recognised is that sound (noise) bits is heard and @ end an unending noise strip continues.. then i disconnect .... feeling THAT's ENOUGH after long hours of tries, involving friends from the caller end too.PLEASE HELP ME..... VERY URGENT....

Thank you,
sincerely,
KAMAL


Kamal R

Sending Binary Data With MSComm
I'm really new at working with mscomm. I've gone thru a number of posts on this site including stickies and Bill Soo's mini-tutorial--but I'm still having problems trying to figure out the following.
I'm trying to send binary data to an external timer thru the serial port.
Below is an example of my code ..
Dim bytArray(7) As Byte
MSComm1.Settings = "9600,N,8,1"
MSComm1.InputMode = comInputModeBinary
MSComm1.InputLen = 0
MSComm1.PortOpen = True
bytArray(0) = 200
bytArray(1) = 30
bytArray(2) = 0
bytArray(3) = 5
bytArray(4) = 1
bytArray(5) = 0
bytArray(6) = 0
bytArray(7) = 245

MSComm1.Output = bytArray

The above doesn't work. Can someone tell me what I'm doing wrong or/and point me in the direction of some sample code that does something similar?

Mscomm Transfer Data Problem
hi
i need to write a program to read the data from the balance
-serial interface
-full duplex
-rs232
-1200,Odd parity.1 start bit,7-bit ASCII,1 stop bit
-handshake :
*2-wire interface
via software(Xon/Xoff)
*4-wire interface
via hardware handshake lines(CTS/DTR)

the data input format for control the balance is : Esc + char + CR + LF
and it will return 22 characters after request the weighting (ex. char = L)

the cable is 9pin(com.)-25pin(balance).
but i dont know why the balance cant receive any command from the computer(including the "tare" function). do any error exist in my program code?

the comuter is using win2k? did it affect?

here is my porgram code


Quote:




Private Sub exit_Click()
End
End Sub

Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.Handshaking = comNone ' xonxoff?
MSComm1.RThreshold = 1
MSComm1.RTSEnable = True
MSComm1.DTREnable = True
MSComm1.Settings = "1200,O,7,1"
MSComm1.InputLen = 0
MSComm1.InBufferSize = 512
MSComm1.PortOpen = True
End Sub

Private Sub MSComm1_OnComm()
On Error GoTo comm_error

Select Case MSComm1.CommEvent
Case comEvReceive
comBuf = MSComm1.Input
Case comEvSend ' handle all known events
Case comFrame
MsgBox (" MSCOMM FRAMING ERROR ")
Case comOverrun
comBuf = MSComm1.Input
MsgBox (" MSCOMM OVERRUN ERROR ")
Case comRxOver
MsgBox (" MSCOMM RX BUFFER OVERFLOW ERROR ")
Case comRxParity
MsgBox (" MSCOMM PARITY ERROR ")
Case comEvCTS
Case comEvDSR
Case comEvCD
Case comEvRing
Case comEvEOF
Case comBreak
Case comCDTO
Case comCTSTO
Case comDCB
Case comDSRTO
Case Else
MsgBox ("MSComm1 Error: Unknown error or event number " & MSComm1.CommEvent)

End Select
Exit Sub

comm_error:
' do whatever you want for errors here
End Sub

Private Sub send_Click()
Dim temp As String
Dim press As Integer
If (MSComm1.PortOpen = True) Then
temp = Chr$(27) + "L" + Chr$(13) + Chr$(10)
MSComm1.Output = temp
Do
dummy = DoEvents()
If (MSComm1.InBufferCount > 0) Then
out.Text = MSComm1.InBufferCount
End If
Loop Until MSComm1.InBufferCount >= 22
out.Text = MSComm1.Input
Else
press = MsgBox("Please enable the connection first!", vbExclamation)
End If
End Sub

Private Sub tare_Click()
Dim temp As String
Dim press As Integer
If (MSComm1.PortOpen = True) Then
temp = Chr$(27) + "T" + Chr$(13) + Chr$(10)
MSComm1.Output = temp
Else
press = MsgBox("Please enable the connection first!", vbExclamation)
End If
End Sub

MSComm Receive Hex Data Error
Hello All:
I am receiving data in hex format using serial communication MSCOMM control.The data reads ok but when it find hex(0) means EndofFile character in ASCII it exits and does not read data after the EndofFile character.
The code for receiving hex data is:

Private Sub MSComm1_OnComm(ByVal sender As Object, ByVal e As System.EventArgs) Handles MSComm1.OnComm

Dim m_cardData As String
Do
Loop Until MSComm1.InBufferCount > 185
m_cardData = MSComm1.Input
txtCardData.Text = m_cardData

If m_cardData <> "" Then
With MSComm1
.Handshaking = MSCommLib.HandshakeConstants.comNone
.RThreshold = 0
.RTSEnable = False
.SThreshold = 0
.PortOpen = False
End With
End If
End Sub

Any help?

Problems With MSComm And Binary Data
Hi, first of all sorry for my english ... isn't my mother tonge.

I have a problem with MSComm. I need to send binary data (the binary number 00001100) using the MSComm. I declare a variable as follows:

Dim data as byte

and after that I fill it this way:

data=Cbyte(12)

In order to send the data i used the MsComm control :

Mscomm.portopen=true
Mscomm.output=data

But it doesn't work. It gives me an error : the value of the property is not valid

What am i doing wrong? Please help me i am complete stucked on this and i cant move forward if i don't send this data to the modem i am using

Help On Displaying Data In MSComm.Input
Hi All.. I'm working on receiving SMS from my GSM phone. However, I'm unable to display the data from Commport to TextBox. When I tried to run my program, The Textbox doesn't show anything where it suppose to display "OK". What should i change to the code to make it display the data?
My code is as shown below:-


Private Sub Form_Load()

MSComm1.CommPort = 2
MSComm1.Settings = "115200,N,8,1"
MSComm1.InputLen = 0
MSComm1.PortOpen = True
' Send an 'AT' command to the phone
MSComm1.Output = "AT" & Chr$(13) & Chr(10) & vbCr
' The phone should respond with an 'OK'
Buffer$ = Buffer$ & MSComm1.Input
Text1.Text = Buffer$

End Sub

Receiving Data Using MSComm Control
Hi All,

I have two small applications, a client and a server. The client dials the server and a connection is established (2 modems & a phone line).

I have controlled the modems using MSComm controls.

I then send a string from the client to the server using MSComm.Output.
I know that the string is sent because if I use HyperTerminal in place of the server, the string arrives immediately. However, in the server program, I can never get anything using MSComm.Input, there seems to be nothing in the buffer.

I use the following code to receive the data from the port:

Buffer = ""
Do
DoEvents
Buffer = Buffer & comModem.Input
Loop Until (Len(Buffer) > 0)

I have also sent data to another device via modem successfully using a similar VB client application, but when data was sent from the device back to the VB application, I was not able to pick it up. I don't know why I can send data but not receive it.

Does anyone know what I am doing wrong? I am using MS Visual Basic 6.0.

Thanks for any help,
Jonathan Dudley

Mscomm Not Getting All Data From Card Reader
Hi all, i am trying to read information from a card reader into a text box but when i run the code i loose most of the data but if i step the code i get all the data, i can add a timer to slow the code but this is unreliable. also i would like to split the data from the tracks located on the magnetic strip, any help greatly recieved.

Thanks

Problem In Reading Data From MSComm
Hi all...

I am facing problem in reading data from comm port. I am using nokia 6230i phone to connect to PC. I am using following code:

Private Sub Form_Load()
MSComm1.CommPort = 4
MSComm1.Settings = "9600,N,8,1"
MSComm1.InputLen = 0
MSComm1.RThreshold = 1
MSComm1.DTREnable = True
MSComm1.PortOpen = True

MSComm1.Output = "AT" & Chr$(13) & Chr(10)
MSComm1.Output = "AT+CMGF=1" & vbCrLf

End Sub

Private Sub MSComm1_OnComm()
If (MSComm1.CommEvent = comEvReceive) Then
Text2.Text = MSComm1.Input 'Error in this line
Else
Text2.Text = MSComm1.CommEvent
End If
End Sub

It should reply with "OK", but I am getting error: "Error reading comm device".
I need help immediately.

And one more thing when I run this form, it shows first to me "Change in CTS detected" event eventhough I haven't sent any data to comm port.

I don't know where is the exact problem?

Help me plz.....
Thanks..

Mscomm Receiving Incomplete Data
Hi,

I am reading from a card reader via serial port. The card reader generates multiple signals that i have to capture and send back some other signals. On OnComm() event, I am experiencing that mscomm does not receive the whole string rather it gets the chunks of the string. e.g.

the card reader sends me the following string
LOGGER RESETxh0D
by mscomm receives
LOGGER R
and in the next turn it receives
ESETxh0D LOGGER RESET

card reader expects that immediately after LOGGER RESET, my application should send acknowledgement and Time and Date. I have done the following to check for LOGGER RESET:

Private Sub MSC_OnComm()

Dim out As String
Dim variable As String

variable = ""
variable = MSC.Input

If Left(variable, 12) = "LOGGER RESET" Then
out = Chr$(&H6) & DateTime.Time$ & " " & DateTime.Date$
MSC.Output = out
End if

End Sub

But once in a blue moon, i receive the whole string as LOGGER RESET, many a times I receive chunks, can anyone explain why and what should I do?

MSCOMM Data Receive Problem
I'm doing a Router program which involves a (NAC)Network Access Controller connect to Com1 and another Machine connected to Com2.

My problem is I don't get the complete data from the NAC. I only get part of it. Sometimes when I store it to a string, the string itself empties or losses some of the data. I just don't get it why it's doesn't come in as a whole packet.

heres the code on my OnComm

Dim ctr As Integer
Dim mInstring As String
Dim Raw_Transmitted_Data As String
Dim Transmitted_Data As String
Dim ETX_Reached As Boolean

Select Case MSComm1.CommEvent
Case comEvReceive 'receive RThreshold # of characters.'
' MsgBox ("Incomming")

mInstring = MSComm1.Input
ctr = 1
ETX_Reached = False

Do While (ctr <= Len(mInstring)) And (ETX_Reached = False)

Debug.Print "mInstring ---> "; mInstring; vbCrLf
Debug.Print "RTD ---> "; Raw_Transmitted_Data; vbCrLf

Raw_Transmitted_Data = Raw_Transmitted_Data + Mid(mInstring, ctr, 1)

If (Mid(mInstring, ctr, 1) = Chr(3)) Then
ETX_Reached = True
GoTo Endloop
End If

ctr = ctr + 1

Loop

Endloop:
If ETX_Reached = True then
Transmitted_Data = Raw_Transmitted_Data

Receive Data From My Reader Using MScomm
The program below show the receive function. When i swap the tag to the reader, the reader will receive the data and show the tad id to the monitor. But when i RUN this program, the data didn't come out
Please have me to check the code below, and give me a idea to solve it. THK

Option Explicit

Private Sub MSComm1_OnComm()
Dim tRECEIVED As String

If MSComm1.CommEvent = comEvReceive Then
tRECEIVED = MSComm1.Input
Label2.Caption = tRECEIVED
Label3.Caption = "Detected"
Else
Label3.Caption = "Not detect"
End If

End Sub

Private Sub Form_Load()
Label1.Caption = "Attach an RFID Tag Reader"
Label2.Caption = ""
Label3.Caption = "Not detect"
MSComm1.PortOpen = True
End Sub

Byte Type Data To MSCOMM?
Hi all,
I have a question about data transfer via MSCOMM (serial port).
lets say i have a byte data, the value is 5.
then sent through serial port via MSCOMM.
is it correct that the real data transfered is:
00000101 (without other setting bit).
and if for example the MSComm1.setting = 9600,E,8,1
and the start bit, parity bit and stop bit is included is it going to be as follows:
0 00000101 11 (start bit,8 databit, parity bit and stop bit)

Thank you

PS: can any body knows an esier way to see our own posted threads in this forum after several days, like myposts button in another forum?

regards
Pramono

Capturing Data From Com Port (mscomm)
Hi Friends,

I am basically a Oracle D2K programmer. I've worked a bit in VB a long time back. I need some help with com port data capturing. the data is comming continuesly. I need to capture it properly and extract the useful party of it.


VB Code:
Private Sub Command1_Click()    MSComm1.CommPort = 1    If MSComm1.PortOpen = True Then        MSComm1.PortOpen = False    End If    MSComm1.PortOpen = TrueEnd Sub Private Sub Command2_Click()Text1.Text = MSComm1.InputEnd Sub


I've used a very simple form with 2 command buttons and 1 text box

the 1st command button opens the port and command button 2 assigns the value of mscomm1.input to text1.text

the result which i get each time is

set1
-------------

':0 0000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000


set2
-----------------

':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 0000000000

set3
---------------
:0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000
':0 000000000000

as you can see there is a symetry in data but it can not be used directly as when the application runs real fast 1/100 times it also captures junk values. can anybody please suggest me how can I regularise the dataflow in such a way that I can extract the useful value from input everytime I press the command button 2

If you need any further information or details, please feel free to ask me.

Hope to get a reply soon

Warm Regards
Vivek Bajaj

Synchronize Data From Diff MScomm
Hi,

I have three devices sending data to the computer via blue tooth. I written a client application in VB and have used ActiveX to duplicate it 3ice so that three programs are created which do the same thing i.e get data from the com buffer, process it and then save it to file.
The problem i have is that because i have used the timer function to get the data from the buffer the 3 ActiveX monitors start at different times the data they store are not synchronised in time. I tried resetting the MSComm but the data recieved are still unsynchronised becasue the first first monitor is resetted and then the next and then the other so there is some lag .
If you need more details please ask me.
If anybody could help, I will be very thankful.

MSComm Incoming Data Detection
this one requires some l33t skillz

i have built an SMS gateway that succesfully receives SMS , processes them and sends out reply data to the originating number.

however, when the load gets very high, usually around lunchtime, i occasionally get collisions when trying to send an outgoing SMS reply and the modem is processing an incoming SMS.

i use MScomm_OnComm to receive the SMS from the simcard on the GSM modem, using a poll delay every few seconds. OnComm does not fire (i think) unless i specifically check for new SMS messages using AT+CMGL="REC UNREAD". upon OnComm, i flag a boolean value that holds outgoing SMS at_commands until the receiving data has been processed.

now, this method works fine 99.5% of the time. but when the incoming load gets too heavy, i get a collission. an example of this would be when you use a mobile fone to send out an SMS and there so happens to be one coming in at that very instant : you get a Message Sending Failed notice on your mobile.

is there any way to check the modem for incoming activity, especially if i just checked for unread sms messages before sending the outgoing, but none are detected as during that milisecond, the incoming one had not been fully received by the simcard/modem .

i am at my wits end, i've even tried putting in two boolean locks to try and catch the situation but have failed so far. whats worse , the gateway has already gone live and i've only recently detected the problem. could not simulate beforehand using just my one cellfone hitting the modem.

please help. TQ
i can post code if necessary. i've gotten desperate enough to not bother about source code proprietorship. i'm also willing to contract anybody who can look at the code and figure out a solution.

Copyright 2005-08 www.BigResource.com, All rights reserved