serial port comunication using visual basic

P

Thread Starter

prem

hi there hope someone can help me here..!!!

im doing a new project involving two serial ports of the computer. firstly, i have interfaced the 1st serial port to a 8051 microcontroller to get data from the microcontroller.

the second serial port is connected to a nokia 30 gsm connectivity terminal (it can be a gsm modem or a gsm phone).

My question here is how can i use visual basic codes to read input from the 1st serial port (which is the microcontroller) and when there is a specific input, this visual basic should send data (in this case a sms ) to the gsm phone through the 2nd serial port. This sms should be sent automatically when there is an input from the 1st serial port.

please if anyone can help me, send me the codes or any information.

your help is much appreciated..!!!

thanks
my mail add: [email protected]
 
<p>The easiest way to access COM ports in Visual Basic 6 is by placing the Microsoft Comm control on a form, and writing code to read and write each serial port. There are plenty of examples on the web of using the Microsoft Comm control to send and recieve data from a serial port. You will need one Microsoft Comm control on your form per serial ports you wish to use.

<p>Example of an infinite loop that takes data from one port and echos it onto another -
<pre>
Dim sInput as String
While (True)
DoEvents
sInput = MSComm1.Input
If (Len(sInput) > 0) Then
MSComm2.Output = sInput
End If
Wend
</pre>
 
hi¡

look you have to use mscomm control in visual basic, the mscomm control is a control that is include into visual basic its icon is like a phone.

into of its properties there are de comm 1 o comm 2 setting, speed, parity etc...

the instruction to read de port is input and the instruction to write is output is very easy to use.
 
Can somebody send me a sample code of how to interface the serial port with VB? basically i just want to read in 8 bits from and A/D converter.

If you got the code please send it to me at the email address below.

[email protected]
 
hi,

i'm having the same problem as yours. I try a lot of alternatives but still fail to do it. So, i hope that you can send me the vb code. Thanks... Your help will be appreciated.
 
Jumping on the bandwagon... i have a similar issue where I want to input data that is coming into the serial port, look at the last line of data, and then if that number in the last line is bigger than another number i want to create a pop-up window that says a message on it. Is this difficult to do? and if not, can someone send me the code on how you would do it? Thanks for your help.

[email protected]
 
N

Neil Kingston

<p>I would not recommend using infinite loops, instead use the MSComm event.
<pre>
Private Sub MSComm1_OnComm()

Dim strInput As String
Dim intInput As Integer
Const intMax As Integer = 150

strInput = MSComm1.Input
' Locate the value you are interested in within the input string
' in this example it is the last three characters, which we convert to an integer
intInput = CInt(Right(strInput, 3))
If intInput > intMax Then
MsgBox strInput & " is too large, please make it smaller!"
End If

End Sub
</pre>
<p>Neil Kingston<br>
Data Layers

<p>Connecting processes with IT<br>
http://www.opcware.com
 
Is it possible to send the text from visual basic thru serial com? Instead of using keyboard i will use pc to send input. (it works as keyboard.)

need help im novice in this language!!! Pls. send me a copy of your code. Thanks...

email add: [email protected]
 
Place a Microsoft Comm control on the form and send the data to its output property. For example if the data comes from txtAge the code would be

MSComm1.output = txtAge.text

Where MSComm1 is the Microsoft Comm control
 
E

Engr. Shahid bilal

<p>1- go to "project" menu<br>
2- select "components"<br>
3- on control tab click the check box of "Microsoft Comm control 6.0"<br>
4- u will see a sign of telephone on General where u can find out text box, label, etc.<br>
5- select that MSCOMM control object and drag and drop on your Form1.<br>
6-double click on form1.<br>
7-copy & paste the following code:<br>
<pre>
Private Sub Form_Load()


com1.CommPort = 2 ' comm port no.
com1.Settings = "1200,e,7,2"
com1.RThreshold = 24 'no. of chr to recive
com1.InputLen = 0 ' no. of chr on which oncomm event fires

com1.PortOpen = True 'open comm port

End Sub



Public Sub Com1_OnComm()
Dim txtBuf
Dim i As Integer
Dim c As Integer
Dim buffer
Dim stable
Dim EVMsg$
Dim ERMsg$
buffer = ""
txtweight.Text = ""
With com1

Select Case .CommEvent
Case comEvReceive
buffer = .Input
For i = 1 To Len(txtBuf)
c = Asc(Mid$(txtBuf, i, 1))
If (c < 32 Or c > 126) Then
txtweight = txtweight & "" & Hex(c) & ""
Else
txtweight = txtweight & Chr(c)
End If

Next i
'***************************************************************

' Error messages.
Case comBreak
ERMsg$ = "Break Received"

Case comFrame
ERMsg$ = "Framing Error"
Case comOverrun
ERMsg$ = "Overrun Error"
Case comRxOver
ERMsg$ = "Receive Buffer Overflow"
Case comRxParity
ERMsg$ = "Parity Error"

Case Else
ERMsg$ = "Unknown error or event"
'***************************************************************
End Select

End Sub
</pre>
<p>9- if any problem contact me, tell me how many char u want to tx/rx.
 
hi,

i have seen ur code for serial port communication using VB. it would be extremely useful if u wud tell me whether we need to put an command box. if yes, then what code should be written? ur code doesnt use a command box. then how do we receive our message back?

kindly reply back at this id.
thanx.
[email protected]
 
That is ok. But how will i USB port to Send or Receive a Data in Vb6. Because MSCOMM control is not able to access USB port.
 
Hello

i am madhu. i am working as a vb programmer. i am also
having same problem in reading data from pbx and write it as a log file. if u have any code plz tell me.

my mail id [email protected]

i am waiting for ur reply.
 
In the code snippet you have written:
for i = 0 to txtbuf
But, nowhere in the program the content of txtbuf
is mentioned. So i couldnt get ur point.

Thanking you
Shekhar
 
V
Respected Sir,

I am doing a project (weighing bridge software) which takes data from com1 port connected to a device.

The weigh-bridge vendor already given a software written in foxpro. In that software only it takes the data.

Now I am planning the same project write into vb. But in my code the data did not come from the com1 port. no data comes at all.

please give me a solution.

thaking you sir

with regards,
v.r.t.kumar
 
Top