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




MScomm Control Serial Data Problem


I have been working on this very simple app to log an ascii data stream to a text file. This data stream is coming from a Fujitsu 9600 pbx. I have tried many things for some reason it just does not want to write the file how it is. It will print it to the text box fine but the file is all messed up. The file that I have included has the vb source, the logfile how it is now logfilewrong.txt, The old logfile that I had setup using straight redirection from a serial port on a linux box( which did not work correctly because it would timeout sometimes and cause the switch to close the port, the logfile was perfect though) I did not know enough c programming or other unix type languages to tackle the problem in that environment so I thought it would be really easy to do it in vb... Well it does not seem to be. Some people suggested using byte data types and put but that will not work this is an ascii stream with non numeric characters. I don't see this as being so hard all I want is an app that when it starts does this... Opens the port at 9600,7,E,1, Then logs all data to a text file opened for append, This logging is constant and there should not be a large buffer, At around midnight I have another app that I wrote that parses this file and loads the data into a database that is why I need it opened for append, I will move the file at that time and it will automatically make a new one that way I don't have dupe data in the database. Then It should close the file and port when terminated, which should be never I have been playing with the code moving the open and close statements but they should be in with the print statement to achieve the desired results of making the new file when moved... Any ideas???




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Mscomm Control - Sending /receiving Data To/from Serial Port (com1)
I'm a newbie using Mscomm control..
I'm not able to send /receive data to/from the Serial port i.e. com1 using mscomm control....
Correct me if i'm wrong...the code is as follows

VB Code:
Option Explicit Private dummy As String Private Sub MDIForm_Load()        ' handle the error if the comm port doesn't exsist    On Error GoTo err_handler        ' open both the send and recv form    frmSend.Show    frmRecv.Show        ' test to see if the comm port is already open    If MSComm1.PortOpen = False Then MSComm1.PortOpen = True        Exit Sub    err_handler:    'in case the comm port does not exsist    If Err.Number = 8002 Then MsgBox Err.Number & " : " & Err.Description, vbOKOnly, App.Title    frmSend.cmdSend.Enabled = False    End Sub Private Sub MDIForm_Unload(Cancel As Integer)        ' close the comm port if it is open    If MSComm1.PortOpen = True Then MSComm1.PortOpen = False    End Sub Private Sub MSComm1_OnComm()        Dim pos As Integer        ' test to see if we recv'd data    If MSComm1.CommEvent = comEvReceive Then                ' move the data from the input buffer into a variable        ' keep adding the data as it comes in to the variable        dummy = dummy & MSComm1.Input                ' test to see if we have gottn everything        pos = InStr(dummy, vbCrLf)        If pos > 0 Then                        ' add the data to the list box            frmRecv.lstData.AddItem Left(dummy, pos - 1)                        ' clear out the variable            dummy = ""        End If    End If    End Sub Private Sub cmdSend_Click()    ' test to make sure something was entered into the textbox    If Len(txtMessage.Text) = 0 Then Exit Sub        ' send the message out the comm port    mdiMain.MSComm1.Output = txtMessage.Text & vbCrLf        ' clear the sent message from the text box    txtMessage.Text = ""    End Sub

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)

Interesting Serial Mscomm Recieve Only Data
I have some hardware that was built by a friend to read data right from my car's computer edge card. It's really cool except that I'm having problems running any kind of GUI. Seems as if the data is coming in so fast that my code is worthless to most laptops that aren't fast p3's or better.
The data being sent doesn't require a handshake or anything, it's just sent continuesly. The data is 276 bytes in length. 2 bytes are start/stop 55 AA , then data, then checksum of the data not including the start/stop bytes. This data is sent at a speed of 57.6 , it's VERY fast from what I've gathered. Lots of my friends that are EE's tell me VB might not be up to speed to display tabulated converted data. Some say it is, I hope it is and that somebody would have a snippet of code to start me off in the "new" right direction.
The data is binary but I haven't gotten it to work yet by storing into a byte array, I get a mistype error? I have been lucky telling VB that the data is ascii text and on the mscomm event, I then convert the ascii into hex to then be converted into dec to the get converted by a formula and spit out into an activex controller for eye candy. It's basically a TON of data that needs to be processed very fast and then displayed either to a text box or activex "gauge".
Another issue I was having was that of too many text box's and some kind of overflow. I was setting the data to an array() and then textbox#.text = array(#) but it couldn't handle more than I believe 15 box's before I got the errors!!!
I'm almost at my whits end.
The best part about this hardware is that it has 6 extra inputs for anything and one is already formatted for my DIY wideband oxygen sensor hardware. Oh, and if it makes it any easier to understand, all of the ecm's ram is what is being sent to the serial port along with the 6 extra 10-bit analog inputs. It comes out to being about 15 frames per second which is fast in my book.
Again, any help to get some reliable code to display this data would be MUCH appreciated. My last resort is to pay a programmer but this is non commercial so I really want to do it myself.

Serial Port Commucation. Can I Use MSComm Control?
Hello Everybody,

I connected a serial cable between two systems. In one of the system it said in the back of my cpu, the port is "SERIAL A". Then I included "MSComm Control" in my project and checked from ports 1 to 16. I didn't get any data from the other machine. Actually in the first machine I could run my program only in port 1 & 3 where port 3 is modem. For all the other port numbers it says "invalid port number". So I opened port 1 and repetedly posted a string in loop. In my second machine, only port numbers 1 & 2 were available. I didn't get any input from my other machine.

Please can any one help me......

Serial Port Commucation. Can I Use MSComm Control?
Hello Everybody,

I connected a serial cable between two systems. In one of the system it said in the back of my cpu, the port is "SERIAL A". Then I included "MSComm Control" in my project and checked from ports 1 to 16. I didn't get any data from the other machine. Actually in the first machine I could run my program only in port 1 & 3 where port 3 is modem. For all the other port numbers it says "invalid port number". So I opened port 1 and repetedly posted a string in loop. In my second machine, only port numbers 1 & 2 were available. I didn't get any input from my other machine.

Please can any one help me......

Opening Serial Ports With The MSComm Control.
Opening serial ports using the MSComm control takes around .5 seconds. Closing the port also takes around the same time.

I have a program that needs to open 2 ports, print something, and then close both port before starting the program.

So far I have just disabled the main form and had a timer take care of it, and reenabling the main form, but I don't feel this is a good solution.

Is there a better way to handle serial communications?
Is there an API designed for just this task?

Thanks.

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

How To Retrieve Data With Mscomm Control?
Option Explicit
Dim dummy As String

Private Sub Command1_Click()
MSComm1.Output = "ati" + vbCr
Do
dummy = DoEvents()
If MSComm1.InBufferCount Then
Text1.Text = Text1.Text + MSComm1.Input
End If
Loop
End Sub

Private Sub Form_Load()
MSComm1.PortOpen = True
End Sub


dear all,
i am doing a project, and after reading quite a lot forums about
mscomm, and a lot of coding too, i still can't get a hold on how we actually receive message from the device. note that i am using a nokia 6610 mobile phone as the modem, therefore i use the at commands i downloaded from forum nokia (at command set for nokia gsm products, version 1.0).

what i'm trying to do is, retrieve the text "nokia" from the device,
generated from the at command "ati" (similar to at+gmi) which supposed to request manufacturer identification. it works just fine with the
hyperterminal. i've traced this code, and apparently when it is executing "mscomm1.input", a "run time error '8020' : error reading comm device" occurs. it happens all the time =(

any idea about what am i suppose to do?

MSComm Control && Data String
I have a weather station monitor connected to my pc via serial port. The software that came with it doesn't do what I want it to, so I'm trying to write my own. I've added the MSComm control to the project, but I'm having a hard time getting the data the way I want it.
First, a little info to explain how it works. The weather monitor sends the data in packets. For example, the data for the indoor temperature comes in bytes(?) like this:

FF
FF
6
0
43
2
etc, etc, etc

In order to get the actual temperature, you have to concatenate the 2 to the 3 from the 43, and then concatenate a decimal point and the 4 from 43. When you're done concatenating, you should have 23.4, which is the temperature in celcius. Then, since I don't do metric very well,
I convert it to Farenheit: (23.4 * 9) / 5 + 32 = 74.12

I want to combine each byte into one string so I can manipulate it and extract the data I want. So the string for the above packet would look something like this:

FFFF6043245117D253933 (indoor temp)
-and-
FFFF312129421DA (rainfall amount)

The first number after the FFFF tells you what each packet represents (6= indoor temp, 3 = rainfall amount, etc)
I tried to set the InputLen property of the mscomm control to receive the entire string, but that only works if each packet is the same length. In my case, each packet is a different length.
So the question, how do I concatenate each incoming byte until I get the complete packet? As far as I can tell, there is no EOF character. I've tried several different ways to join the bytes together, but my brain is fried and I can't seem to figure it out.
I'm posting my code, but please don't laugh too hard. Instead, be gentle and tell me where I'm going wrong.

Private Sub MSComm1_OnComm()
    Dim strData As String
    Dim strInput As String
    
    'Convert data from weather station to readable format
    strData = StrToHex(MSComm1.Input)
    
    Do Until strData = "FF"
        strInput = strInput & strData
    Loop
    List1.AddItem strInput
        
End Sub

Sorry this was so long, but it needed explaining!






Robert
"If at first you don't succeed,
get a bigger hammer!"

Mscomm Control Check Received Data
Hello People,

I've some problems with my mscomm control.
I'm connecting to a device with these settings: 38400,n,8,1
To receive the data I want I need to send 7 Characters, one-by-one. When I sent a character I get the same one back, after receiving I can send the next character. After these 7 characters the device sends 3 characters in one time.
First I made the routine this way;

Code:
Function ExplodeString(Source As String, Optional fillChar As String = ",") As String
ExplodeString = Left$(Replace(StrConv(Source, vbUnicode), vbNullChar, fillChar), Len(Source) * 2 - 1)
End Function

Public Sub MyPause(Optional ms As Long = 5)
On Error Resume Next
Dim tc As Long
tc = GetTickCount
While GetTickCount < tc + ms: Sleep 1: DoEvents: Wend
End Sub

Private Sub Command1_Click()
X = Split(ExplodeString("Q000123"), ",")
For a = 0 To 6
A = X(a)
MSComm1.Output = A
MyPause (1)
Next
End Sub

Private Sub MSComm1_OnComm()
If MSComm1.InBufferCount = 1 Then
Text1.Text = MSComm1.Input
ElseIf MSComm1.InBufferCount = 3 Then
Text2.Text = MSComm1.Input
End If
End Sub
This works perfectly in Microsoft Windows Xp the values that are important to me are in the text2.text. But when I use the program with Windows 98 it goes completely wrong. Then the pause of 1 MS is not enough.
So now I want to make a check that checks wether or not the received value is the same as the sent value. So I changed the following.



Code:

X= Split(ExplodeString("Q000123"), ",")
For a = 0 To 6
A = X(a)
MSComm1.Output = A
MyPause (2)
If Text1.Text <> A Then
Text1.Text = ""
MyPause (2)
Text3.Text = Text3.Text & "N1"
If Text1.Text <> A Then
Text1.Text = ""
MyPause (4)
Text3.Text = Text3.Text & "N2"
If Text1.Text <> A Then
Text1.Text = ""
MyPause (8)
Text3.Text = Text3.Text & "N3"
End If
If Text1.Text <> A Then
Text1.Text = ""
MsgBox ("Error")
Exit Sub
End If
End If
End If
Next
But this still gives the same problem. It works with Windows XP but in windows 98 it goes wrong.

So I have two questions;

- What is the difference between windows 98 en windows xp with Comport communication (Windows 98 seems to go a lot faster)
- Does anyone have a solution to check the received value with the sent value

Cheers,

c0mKi

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]

Mscomm Control For Data Reception And Transfer
Hey Guys I need your help,


I am having Mscomm client and server using modem communication. I dial server from client to server to transfer my data.

How my server after getting a dial, stop the dialing and receive the data.

Is the "MScomm.portopen = true" statement responsible for acting as lifting receiver for modem.

As we have option to lift receiver on phone but in modem this option is not possible.

Is "MScomm.portopen = true" the answere?

Receive Binary Data By MSComm Control?
Hi! I just need to know how to receive BINARY DATA by using the OnComm in MSComm control and place the received data into textbox. Thank for your help!!!!

regards, Jesse

Getting Data From A PABX System Using Mscomm Control
hi people.
i'm a newbie in using the mscomm control in vb6. i don't have much experience in programming either. but i have a new project to create. here are the conditions:
there is already an existing pabx system. the said system generates data like answered calls, dropped calls and transferred calls. it has its own software that receives and generates the data. it transfers the data to the computer through the serial port.

now, my project is to get the data, generated by the pabx from the serial port and generate queries and printable reports (ex: Operator 1 - 20 calls    20 answered calls     0 dropped calls; something like that) i already did some research in the net for some sample codes and programs, hoping to find something similar to my problem. i tried the simplest of them, like getting the data from the serial and display it in a text box. (ex: text1.text = MSComm1.input) The codes worked well. But what confuses me is that, the text displayed in the textbox goes like this : üüý=z‚ÿüüýýüüýýüüýý<z‚üýýüüý. but data that should be displayed is this: 01/19 11:56 00:01:41 T7 001 8259805 236 T 123.

do you have any idea why this happens? and, do you have any idea how to diplay the data right?
the project should be done asap. pls help.

Using MSComm Control For Sending Data Between 2 Ipaq's
I am trying to send data between two IPAQ's using a serial connection. Both the IPAQ's have bluetooth capability and I am using the com7 and com8 ports to receive and send data respectively.

The code is as follows:

1. Connect button - opens the ports.

Private Sub ConnectBtn_Click()
        ' Open the ports for the IPAQ
        InputPort.PortOpen = True
        OutputPort.PortOpen = True
End If

2. Disconnect button disconnects the ports

Private Sub DisconnectBtn_Click()
        ' Ask both the comm controls to shut the ports
        InputPort.PortOpen = False
        OutputPort.PortOpen = False
End Sub

3. Send button takes the data that the user input into a text box and sends it out of the port.

Private Sub SendBtn_Click()
    
    Dim Response As Integer
    Dim i As Long
    
    ' Get the string from the user and put it in the text for strings to send
    BlueChat.Text = BlueChat.Text & SendText.Text & vbCrLf
    SendBuffer = SendText.Text & vbCr
    
    ' Send the data out of the port.
    i = 1
    While (i < Len(SendBuffer))
        OutputPort.Output = Mid(SendBuffer, i, 1)
        i = i + 1
    Wend
    
    ' Set the parameters for the output buffer to send out the data
    Response = MsgBox(SendBuffer & OutputPort.OutBufferCount, vbOKOnly, "BlueChat")
        
     SendText.Text = ""
     SendBuffer = ""
End Sub

4. On Comm event handler takes the data from the user.

Private Sub InputPort_OnComm()
    Dim Response As Integer
    
    Select Case InputPort.CommEvent
        Case comEvReceive
            WaitTimer.Enabled = True
            While InputPort.InBufferCount > 0
                ReceiveBuffer = ReceiveBuffer + InputPort.Input
                Response = MsgBox(ReceiveBuffer, vbOKOnly, "BlueChat")
            Wend
    End Select
End Sub

5. Using the timer on the input port.

Private Sub WaitTimer_Timer()
    BlueChat.Text = BlueChat.Text & "--->" & ReceiveBuffer & vbCrLf
    ReceiveBuffer = ""
    WaitTimer.Enabled = False
End Sub


The behavior that I am seeing is as follows -

If I type a string in the textbox and select Send, the Send Btn function gets invoked. The SendBuffer string gets filled in with the contents of the textbox and a vbCr. The device sends out the data using the while loop - byte by byte. After that, I would expect the OutBufferCount to be 0 when displayed in the MessageBox, but it appears to be some positive number. Looks like the port could not send all the data out.

After that, any further attempts to send text out does not result in anything going out and the OutBufferCount keeps incrementing.

On the receiving side, we receive certain chars of the text - in my case, normally only the first 2 and then no more.

On multiple attempts of reconnecting, I am seeing the same behavior. I see the same behavior even if I had just put

OutputPort.Output = SendBuffer.

Looks like the port just times out for some reason or gets an error condition. Both the ports have the setting 9600,N,8,1, no handshaking and sending out ascii text data only.

Any help would be appreciated since I need this project to be done urgently !!!

Thanks in advance,
Hrishi

How Can I Send Binary Data Use MSComm Control?
I try to use MSComm RS232 to send binary command to board, but i don't know how to use. If the format just like send normal ASIC characters?? If send binary data need send byte one by one??
I wonder if someone can give me a easy example.

Thank you!

Best Regards,

Kevin Shen

Receiving Data Using The MSComm Control's OnComm Event
I've been reading loads of threads relating to this and users are always directed to this link:http://support.microsoft.com/default...b;en-us;194922

Following each step i have created the two example programs but they still don't work! any idea with help? i copied and pasted the exact two scripts and connected COM1 and COM2 ports with a null modem cable (two female DB9 connectors on each end)

I know the first application works as i tried sending a string of text when connecting COM1 to a CRO using a cable with a female DB9 connector on one end and a coaxial cable on the other and observed activity on the CRO

Any ideas what could be the problem with the Rx code? Am i meant to add extra lines of my own code to make it work?

Any help would be much appreciated guys

How To Know Whether RS232 Mscomm Control Is Ready To Receive Data
Hi,
First time I am working in RS232 MScomm serial port communication.I want to know whether RS232 is ready to receive data from microcontroller as well as it is ready to send data to microcontroller from PC using vb6.I have written program. when I run it misses some character.
Please help me with some example coding.
Thanks in advance.
Vijaya.

Problem Receiving Large Amount Of Data In MSCOMM Control
Hi,

I use the MSCOMM control to send and receive data packets that are 10 bytes long. This works perfectly well..

I now want to receive 524 bytes of data I do the following


Code:

dim cCh as string


Private Sub SetupCOMM
comRS485.PortOpen = False
comRS485.RThreshold = 524
comRS485.InputLen = 524
comRS485.InBufferSize = 524
comRS485.PortOpen = True
end sub

Private Sub comRS485_OnComm()

Dim n As Integer


Select Case comRS485.CommEvent

Case comEvReceive:

cCh = cCh & comRS485.Input


End Select

End Sub

The


cCh contains the data captured by the MSCOMM.

Using the above code I can sometimes receive the correct amount of data. But mostly it does not receive all the data.

It seems data is being lost somewhere...could anyone explain where ???

thanks
arunb

Serial I/O Without MSCOMM.OCX
Hi,

Anyone have some example code to open a serial port without using MSCOMM type OCX but file I/O. Code in VBA would be nince.

Thanks,

Paul...

Regards,

Paul Belikian

MSComm With Serial Device.
Hi, I'm pretty new to this, and I have a small problem.
I want to communicate with a serial device that has a number of funktions depending on what you send to it.
Ex. if you send a "T" you get the time and date, and the communication is to be performed as follows:

PC: <ENQ>00T
Device: <STX>20040216180950<ETX>xx
PC: <ACK>
Device: <EOT>


where ENQ, STX, ETX, ACK and EOT are the corresponding ascii characters, and "xx" is a bcc byte.

This should be a piece of cake, but I just can't get it to work.
Does anyone have an exaple of this kind of communication?

MScomm Serial Interface
hello everyone, Im new to VB6. Im using MSCOMM component to communicate with my microcontroller. I have a microcontroller output in decimal form and I want to send them to my pc through serial. my concern is how to capture that decimal value from the microcontroller and display it in a GUI let say a label1 maybe just to see the value. Can anyone help me.

MSComm Serial Communications
Tips on setting START bits using MSComm control under vB6,
Is it defaulted as 1 start bit or derived from flow control?

MSCOMM With More Than 16 Serial Ports
MSCOMM can adress up to COM16. I am using higher comport-numbers.
Do anyone have a solution with MSCOMM?

Serial Communications - MSComm
According to the spec for the USB device I'm communicating with, the device only responds to commands sent and it takes about 2mS to send its response. They recommend a 100mS timeout before assuming there will be no response, and doing a retry. Every string rec'd is supposed to start with a Chr(2) and end with a chr(3) [ end and start of text ]. Once I have the string I turn off the timer function which originally was called Right After the MScomm send routine...

Problem is I'm getting a lot of retrys due to not finding both of the characters...

What I'm doing is this:
' function examines the CommEvent property, case finds the comevreceive event and extracts the string therein...

Public Function inputHVPSInputString(ByRef strRecdString As String) As Integer
Dim str As String
Dim t1 As Single


t1 = Timer ' Set t1 equal to this instant

Select Case MSComm1.CommEvent

Case comEvReceive ' Received RThreshold # of chars.

Do
DoEvents
str = str & MSComm1.Input
Loop Until InStr(str, Chr(3)) Or Timer - t1 > 1
str = str & MSComm1.Input
On Error Resume Next ' for the mscomm error, run the In on instr()
If (InStr(str, Chr(3)) > 0) And (InStr(str, Chr(2)) >= 0) Then

' Found End of Text char not in zero position, good data rec'd
HVPSCommReceiveTimer.Enabled = False
TbxHVPSRecdDisp.Text = str
strRecdString = str ' return found string
inputHVPSInputString = XIASUCCESS ' return good value
Exit Function
Else
' MsgBox "Receive Data Error " & vbCrLf & "inputHVPSInputString() did not find End of Text char in this data recd = " & str
TbxHVPSRecdDisp.Text = "Recd Data Error missing Chr(2) or (3)"
HVPSCommReceiveTimer.Enabled = False
inputHVPSInputString = XIAInit_Value
Exit Function
End If

Using Mscomm With Usb To Serial Conveter
Hi freinds ...

I made a simple application that sends character "w" and print on form the received characters , to simplify the matter i connected the input and output lines together so that what sent is received again by the application ... I tried this application on a PC with a built in serial port and it worked fine then i tried it with a usb to serial converter but it failed ... Notice : I use only three wires in db9 which are Gnd , Tx,Rx. Thanks for answering

Serial Comm Without MSCOMM
Hi all,

does anyone know how I can use a serial port without using the mscomm control?

MSComm && Serial LCD Display
I have an LCD display module (2 lines & 16 characters per line) that I am trying to wirite a app for. The LCD module is a parallel interface with a daughterboard attached to convert it to serial.

All I want to do is mirror everything that is typed into a Text Box onto the LCD screen. So far I have managed to do this to a certain extent with the following code:


Private Sub txtOutput_KeyPress(KeyAscii As Integer)

Dim Buffer As Variant

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

Buffer = Chr$(KeyAscii)
MSComm1.Output = Buffer

End Sub


Now, as my lcd screen is 2 lines of 16 characters I want the text that is entered into the text box to automatically go onto the second line of the LCD when we get to > 16 characters typed into the Text Box. Can anyone help with this?

Also I want to be able to clear the LCD from within VB but I do not know how to do this other than cut the power to the module!?

I would also like to be able to delete teh last typed character from the display.

The very brief instruction manual (single sheet of A5) that came with the display states that instructions to the display (new line, clear display, delete etc) must be prefixed by the single byte <254> which puts the LCD display into instruction mods???? Anyone advise me on how to do this?

Thanks...

Serial Printing (Mscomm)
Hi,
Need to print some labels on a INTERMEC 3440 printer, using MsComm control.

NOTE: I can't use the Printer object or Printer port (LPT1). It has to be Com1.

Can anybody show me an example of sending data to com ports?

Serial Printing (Mscomm)
Hi,
Need to print some labels on a serial printer using MsComm control.

Can anybody show me an example of sending data to comm ports?

VB6, MSComm, Serial Ports?
Has anybody used COM ports, MSComm1, and detecting serial ports????

Does anybody know how to find out what COM ports are available on a computer using VB6. I found out that the WIN.INI file on my computer lists COM ports 1 throu 4 but that doesn't mean that they are available does it. For example when I look under Control Panel/System/DeviceManager/Ports all that is listed is COM1 and LPT1.

I have also tried openeing them with MSComm1 and catching the error if it is already oppened. My end result was 1, and 2 are not used and 3 and 4 are being used. The unusual thing is when I send 2 bytes to port 2 I get two bytes back in my input buffer.I only have COM1 in device manager though. COM1 works fine.

Basically I am trying to find an INI file or someway to find out what COM ports are availlable on a computer. Any ideas?

Serial Communication W/MSComm
I am trying to interface to some external devices through my serial port. I need to send out some commands in hex, but I can't seem to do it. I also need to recieve back hex characters up to 64 bytes. I am in desperate need for help. Thanks

MSCOMM/Serial Communications
Hi All,

Just a Question?

I have opened a hyperterminal session and then created a vb app with a MSCOMM control.
What I was trying to do was to send data to the hyperterminal session through the VB app.

I have tried the following code (on a button click)

Private Sub Command1_Click()
  With MSComm1
    If .PortOpen = True Then
        'send the data (including a tailing carriage return as often needed)
        .Output = "TEST" & vbCr
  End With
End Sub

But it says that the port is already open.

Therefore is it possible to have a COM port open with an APP such as hyperterminal and then simulate the transmission of data through a VB app?

Cheers

Serial Communication Using MsComm
Hi Guru,

I am doing a small communication project using mscomm control.
In this project I am receiving and sending the data. After some time while running the project/exe the communication is not happeing in both ways but project is not hanging, Only communication is not happening. What could be wrong with this one?

In some times I am getting error message like 'Change in CD detected' or 'change in CTR detected'. What are these errors. Why it is comming. pls. anybody can explaine me in detail.

I Would like to know what exactly the DoEvents() will do.
I would like to have solution for the above one.

Thank you

Benny

Serial Port Communication With MSComm...
Hey all, just a quick (hopefully easily resolved) question. I'm trying to write a program to send a file across a serial port, and I'm kind of stuck. I've managed to get text to go from my application to hyperterminal, but I'm not quite sure how to recieve text in my application, or more importantly, how to send and recieve files. If anyone could point me in the right direction, I'd really appreciate it. I've pasted the beginnings of the program code below.
---------------------------------------------

Private Sub Form_Load()
cmbCommPort.AddItem (1)
cmbCommPort.AddItem (2)

cmbPortSpeed.AddItem (2400)
cmbPortSpeed.AddItem (4800)
cmbPortSpeed.AddItem (9600)
cmbPortSpeed.AddItem (19200)
cmbPortSpeed.AddItem (38400)
cmbPortSpeed.AddItem (57600)
cmbPortSpeed.AddItem (115200)

End Sub

Private Sub cmdExecute_Click()

Dim fileName As String
Dim commPort As Integer
Dim portSpeed As String
Dim inputBuff As String

fileName = txtFilename.Text
commPort = Val(cmbCommPort.Text)
portSpeed = cmbPortSpeed.Text

MSComm1.commPort = commPort
MSComm1.Settings = portSpeed + ",n,8,1"

'Enable Port
MSComm1.PortOpen = True

'Configure Port as InPut or Output
If optSend.Value = True Then
MSComm1.Output = "CPA00000000" + Chr(13)
MSComm1.Output = txtFilename.Text + Chr(13)
End If

' How exactly is the input portion to be used? Can you send items from
' hyperterminal and capture them to a text box? And how would you go
' about sending/receiving a file?

If optRecieve.Value = True Then
inputBuff = MSComm1.Input
txtFilename.Text = inputBuff
End If

MSComm1.PortOpen = False

End Sub


Private Sub cmdExit_Click()
End
End Sub

Mscomm Using Usb To Serial (rs232) Adapter
Hi, i'm builing an application to capture some data from an external device, my program works fine when i plug it to the serial port of my test computer. The problem arises when i try to use it in a laptop that has no serial port, i'm using an USB to serial adapter but my program can't listen to the port for some reason, i'm not getting any errors it just doesn't listen or write to the port.

I opened Hyper Terminal and other program to read the port and both work fine, so in resume my problem is: My application works with the serial port but not with the usb to serial adapter.

MSComm And Bluetooth Serial Ports
Hi,

I'm working on a VB6 app. that uses the MSComm contro to connect to a Bluetooth serial port. Hower, when I attempt to open the port using COM 17 or 18 (the automatically assigned port number from the BT hardware), the control returns an error of "Invalid Port Number".

I assume this is a limitation of the control, but I'm not sure. Has anyone run into this or know of a solution/work-around? I would be willing to utilize another .OCX/.DLL if needed.

TIA!

Pleeeese Help Me - MSCOMM And Serial Comms
Thanks for taking the time to consider my problem.

I am developing a POS system which uses a Posiflex customer poll display. With the manual, they provide a number of Hexidecimal codes which can be used to reset, clear, change the font etc, of this display, but I do not know how to send these hex codes to the screen for it to register them as commands. Using MSCOMM, I can output text to the display, but cannot access it's functions. The display uses com2 by the way!

Thank you again for your consideration of my problem.

Serial Port Communication Without MSCOMM
I want to open, with VB, a serial port (COM 2) for communication but I don't want to use MSCOMM since I plan to use my code, when it's done, with the VB part of SIMPLICITY HMI wich can't use MSCOMM. Is there any way to do that?If so, how?

thank you very much

Serial String Termination && MSComm
Hi.

I am trying to communicate to VB6 via a serial cable & the MSComm control uding a PIC microprocessor.

I can send the data from the PIC, which reaches the PC fine. I can view the data in hyperterminal, and i can see the data filling up the serial buffer from VB, I can also get the data using mscomm1.Input (once I know it is in the buffer). HOWEVER - the MSComm1_OnComm() event never seems to fire.

I know the data is there, but I cant work out why the event doest trigger. Does the sting need a termination code? I have tried CR, LF & 0xFF, but i cant seem to get it to work.

For anyone interested, the PIC Basic code used to send the data in the first place is; Code:SerOut PORTB.3, 16780, [DEC 3, 0xFF]
PORTB.3 is an output pin on the chip, 16780 means serial settings; '2400, N, 8, 1' the last bit is the data sent.

The reason I need the event to fire is that my code is a test for a piece of software that i cannot alter. It wasnt written in VB, but I assume it works along the same lines (as it doesnt work with the present set up).

Any ideas?
Thanks!
PN.

MSComm , Not Getting Response From Serial Port
Hi friends,
I want to do serial port communication using VB, I am using MScomm control and following code in form load event

but it dont get response from modem...
please give your suggetion or alternate code.

thanks

'=================

   Dim Instring As String

   MSComm1.CommPort = 1

   MSComm1.Settings = "9600,N,8,1"

   MSComm1.InputLen = 0

   MSComm1.PortOpen = True


   MSComm1.Output = "ATV1Q0" & Chr$(13)

   Do
      DoEvents
   Buffer$ = Buffer$ & MSComm1.Input
   Loop Until InStr(Buffer$, "OK" & vbCrLf)
 
   MSComm1.PortOpen = False

Sending &lt;Ctrl+Z&gt; To The Serial MsComm
Hi,

I have a Proble with Serial Communication using MSComm Control.
I am trying to communicate to a Mobile Eqipment using GSM Standards, every thing is working fine but the problem is I am unable to Send Control Characters like <Ctrl-Z> so the Msg can be sended.

Pls advice.
Thanks.

Start Bit For Serial Comm Using MSCOMM
Hi

I am using the MSComm component in a VB 6.0 application to send a bitstream from a shift register using the RS232 serial port to the PC.

RS232 protocol specifies that a start bit, 8 data bits and a stop bit should be sent in serial communications.

In the MSCOMM component setting however we can specify only the stop bit e.g 9600,n,8,1, can you please tell me how the start bit is specified?

Thks!

MScomm Serial Communication In Visual Basic
hi,
 i want to know how to get data directly from mscomm serial port in text box without hitting or clicking button on a form.
Can some body help me, pls replay its very urgent .


Edit: Moved from VB6 - CodeBank to VB General



Edited by - jseal on 5/2/2007 8:00:23 AM

Mscomm Serial Port To DryDo At Vbcity
I am sending the data by this code and getting the data back in the text box but I want
that the data which is coming in the textbox is should be loop ,it should not be stop until I end my program.
And I am sending this data to robots which they reply data back to me in vb form .
 And What code u send is correct but it does not show me the vb Form it directly
send data to robot by which it walks ,but does not display the data in text box .
And I don't Know how to use loop to get the data in textbox in a loop

    That data should be display in consecutive or sequential manner in the Textbox or label control .

Code:

Private sub Command1_click()
Dim bytetosend(0 To 1) As Byte
Dim buffer As Variant
bytetosend(0) = &H59
buffer = bytetosend()
MSComm1.Output = buffer

Do
    dummy = DoEvents()
    Loop Until MSComm1.InBufferCount > 5
    datain = MSComm1.Input

Text2.Text = Hex$(Asc(Mid$(datain, 1, 1)))
Label1.caption=Hex$(Asc(Mid$(datain, 1, 1)))
Thank u very, much if u read this mail today then please reply me today only if u can
and not make it possible then give me a reference from which i can query this .
Thank u
Thank u
Thank u

Thread locked: Continued here



Edited by - jseal on 5/4/2007 10:48:43 AM

Serial MSComm - Getting Past Error Events
I'm having trouble with a simple serial port hook up. I have some custom hardware that seems to work fine. I use it with Hyperterm and I can see what's happening. When it starts up, it just spews some characters to the serial port saying "Hello, I'm awake". It sends a few spaces and a CRLF just before the message to give a clean out any kinks in my hardware serial drivers.

So now I run my small VB6.0 code where I expect to get some CommEvents every time a character is received (I set RThreshold to "1") and I'm using 19200,N,8,1 for comm parameters, with no handshaking.

I get two comm events, apparently, and they are just two break msg's. See my code pasted below - but the text that I see from my code is:

EV=1 Brk Recd
EV=2 Brk Recd

But I should have about 20 CommEvents, the first few being spaces, then CRLF then my text. (Just like it appears in Hyperterm). Plus the comEvReceive event never seems to happen, just those breaks.

Do I need some way to tell MSComm - yeah, okay break received, discard that 'error' and get on with receiving? I did see a framing error in one setup. Do error events halt the hardware or something? Do I need to close and reopen my port, or otherwise set it right to get to the good text?

Any suggestion much appreciated.

Ross.


****** my code ********

'Global def'n in Module1:
Dim EVcount As Integer


'In my frmMain code:

Private Sub MSComm1_OnComm()
EVcount = EVcount + 1

Select Case MSComm1.CommEvent
' Events
Case comEvReceive ' Received RThreshold # of chars.
MsgBox MyComPort, vbInformation, "A RECEIVE EVENT!"
MyForm.tbInfo.Text = Me.ActiveForm.tbInfo.Text _
& vbCrLf & "EV=" & EVcount & MSComm1.Input
' Errors
Case comEventBreak ' A Break was received.
MyForm.tbInfo.Text = MyForm.tbInfo.Text & vbCrLf & " EV=" & EVcount & " Brk Rcd "
Case comEventFrame ' Framing Error
MyForm.tbInfo.Text = Me.ActiveForm.tbInfo.Text & vbCrLf & "EV=" & EVcount & " Frm Error"
Case comEventOverrun ' Data Lost.
MyForm.tbInfo.Text = "other3"
Case comEventRxOver ' Receive buffer overflow.
MyForm.tbInfo.Text = "other4"
Case comEventRxParity ' Parity Error.
MyForm.tbInfo.Text = "other5"
Case comEventTxFull ' Transmit buffer full.
MyForm.tbInfo.Text = "other6"
Case comEventDCB ' Unexpected error retrieving DCB]
MyForm.tbInfo.Text = "other7"

End Select
End Sub

Help With MSComm And Serial Device Parser Requested
I have a laboratory device that I am trying to write an interface to.

The device is an echo-back serial device with a command parser that acts very squirrely. If a recognized legal character is sent to the device, it will echo it back. If the character is not legal, it will send some other character (various error sequences).

the commands that are required are between 3 and 6 characters long. When the parser sees a proper and complete command, it resets itself for the next command. If you need to reset the parser, you can send a "Q" between 1 and 3 times. The parser also resets after sending an error.

The best way to detect an error is to watch the echo, and if it is not the same character, then you need to go back and send each character of the command again from the beginning.

I am just having no luck with this. I can communicated through a direct com1 connection in hyperterminal, and I can see the results when a command is rejected by the parser, but I can make it work in VB with the MSComm control.

Thank you

Chris Nogy

Tracking The Incoming Call Using MSCOmm. CLI With MSComm Control
I am trying to trap the phone number of the call being received at my phone line using MSComm Control. I am able to sense that a ring is occuring but I need to trap the phone number. Is this possible?

I am using the following code:

Private Sub Receive()
Dim FromModem$
MSComm1.CommPort = 2
MSComm1.Settings = "28800,E,8,1"
MSComm1.PortOpen = True
MSComm1.InBufferCount = 0
Do
dummy = DoEvents()
If MSComm1.InBufferCount Then
FromModem$ = FromModem$ + MSComm1.Input
MsgBox (FromModem$)
End If
Loop
End Sub

Unable To Capture Text From Serial Port Using MSCOMM!
Code:
Private Sub Form_Load()
MSComm1.PortOpen = True
If Right$(App.Path, 1) = "" Then
Open App.Path & "outputDATA.TXT" For Output As #1
Else
Open App.Path & "outputDATA.TXT" For Output As #1
End If
End Sub

Private Sub MSComm1_OnComm()
Print #1, MSComm1.Input
End Sub

Private Sub Form_Unload(Cancel As Integer)
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If
End Sub
Currently I have two computers connected via a COM cable. On the "transmitting" computer I've written a program that opens a file and reads it line by line, transmitting each line. This works, as I've opened HyperTerminal and it shows me each of the lines being transmitted.

The part I'm having trouble with is the "receiving" program. This seems so easy and I've read through a lot of the threads here and I can't understand what I'm missing!!

I placed a break on the Print command and when I run the transmitting program and switch back to the receiving program I place my cursor over the MSCOMM1.Input item and I see the following text in the little yellow box that appears.

MSComm1.Input="1st Test Line[][]2nd Test Line[][]"

Now the [][] are the vbCRLf that is coming from the carriage returns.

When I open the outputdata.txt file it is completely empty!!

What am I missing?

Thanks

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