serial port comunication using visual basic

<p>I am trying to use two serial ports (and perhaps more) on the same form with VB6, I have no problems getting one MSComm event defined and working but when I try to add the second I get a "duplicate Definition" error. Any ideas as to why this wont work for me?

<p>This code works great:
<pre>
Dim WithEvents MSCommRatio1 As MSCommLib.MSComm

Private Sub Form_Open(Cancel As Integer)
'code to load the form and
'set up the comm
'port,
End Sub


Private Sub MSCommRatio1_OnComm()
'code to read the port at the correct time.
'and put the data were I want it
End Sub
</pre>


<p>This code gives the error:
<pre>
Dim WithEvents MSCommRatio1 As MSCommLib.MSComm
Dim WithEvents MSCommRatio2 As MSCommLib.MSComm

Private Sub Form_Open(Cancel As Integer)
'code to load the form and set up
'the comm objects on two different ports
End Sub


Private Sub MSCommRatio1_OnComm()
'code to read the port at the correct time.
'and put the data were I want it
End Sub

Private Sub MSCommRatio2_OnComm()
'code to read the port at the correct time.
'and put the data were I want it
End Sub
</pre>
 
Hello!

I am using Atmel 8051 in our project. Please give me information regarding how to download visual basic hex file into the 8051 memory. Give the information regarding suitable cross compiler with respect to this requirement.

Thanks and regards,

Manjula
 
Hi,
I am working on a project which inputs 3 different measurements to a PC using RS232. I am new to VB 6. A PIC18F microcontroller is sending these 3 values to the PC, the VB program is supposed to display them on a simple stand alone program. I dont know much about programming in VB. I did research online but was unable to find a sample code meeting my design specifications. Are there any resources, sample code or suggestions for attacking this problem.
Thank you.
 
E

engr Shahid bilal

Hi,
I used your code for getting 10 characters from an 8051 microcontroller thru the rs-232 serial interface with the com 1 port. so i modified threshold value as 10, and the com1.Settings = "9600,N,8,1". But it still isnt working..we tested our microcontroller code with the hyperterminal so there is no problem there.

plz do help us out, this is a part of our project. Thanks.
 
R

Rachna Nambiar

Hi,

Even I have the same problem. Completely new to Visual Basic. I have to get data form the serial port, and display it along with the time at which it was received. Can anyone send me a code how to do this. the data will be 2 Ascii characters at a time.

I would be very grateful if i could get this code.. its very very urgent.

Email address is [email protected]
 
you can perform one step at once and obtein good results too.
just to say that its possible using the same port.

think a litle more... after that a show you how.

regards
 
hey...

me too working on a similar project. it would be of great help if u could send me the code to transfer data serially using Vb 2 serial port...
Please!

thanx...
adITi
email:- [email protected]
 
hi...

i also need your help. right now i developing a payment terminal program and the the terminal can send data via modem and another modem at the server receive the data... how i capture the data from the teminal and the modem at the server is using serial port communication...

pls. i need u guys help.
 
Hello!

I have an idea, but dont know whether it will workout or not. just try to send vb codes as strings in C code then generate hex code.. try out if it works pls let me also know...
 
B

Brian E Boothe

why is it that alot of these industrial control guys have no clue what a search engine is,, geesh

These productive microcontroller tools were developed by Hanover Software

BXC-51 BASIC 8051 Cross-Compiler <bxc51.html> - the BASIC-52
Compiler of choice

BEC-51 BASIC 8051 Cross-Compiler <bec51.html> - the Blue Earth
BASIC Compiler of choice

BXC-51 Library Toolkit <bxc51lt.html> - the BASIC/Assembly
programmers toolkit

BXC-51 IDE <bxc51ide.html> - the BXC-51 programmer's integrated
development environment (IDE)

BXC-51 Simulator <bxcsim.html> - the BXC-51 programmer's
simulation tool

QComm <qcomm.html> - the communications scripting tool

Infinitor <inf.html> - the programmer's editor

SXA-51 8051 Cross-Assembler <sxa51.html> - 8051 Cross-Assembler

BXA-51 8051 Cross-Assembler <bxa51.html> - 8051 Cross-Assembler
 
Hello there,

Could you please help me by sending VisualBasic code which can be used to send and receive thru a USB to RS232 converter?

Appreciate your help in advance.

Thanks
lakshmi
 
B

batu_industry

Hello!

If you have problem with Atmel 8051, I'll help you
make some program or use Visual Basic.

Send your question to: batu_industry @ yahoo. com
 
M
Instead of this:

> i = MSComm1.OutBufferCount
> MsgBox i
>
> j = MSComm1.InBufferCount
> MsgBox j


Write this:

> i=mscomm1.output
> msgbox i

> mscomm1.input=j
 
Can somebody send me a sample code of how to interface the serial port with VB? basically i just want to read in 16 bits from and A/D converter.

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

hareensunny [at] gmail.com
 
Not sure if i'm doing this right. Its my first time in a long time. I'm trying to build a CNC work station at home in my shop. I have read your com port program and it seam's strait forward enough. I'm trying to talk to a Stamp mother board Via (USB/com port) on the mother board i have wired a Hataci accallarator chip. Its Not meant for my application but it does read X Y Z axes AND Gforce.

This is the program that is loaded on the Stamp CPU eeprom and the Values it returns to the stamp program but i want to read the com port my self and using Stand alone VB program. The com. program u posted will probably work fine. The last time i programed anything was 17 years ago so im mostly trial and error right now.<pre>
'{$STAMP BS2pe}
'{$PBASIC 2.5}
' ==========
' ===============================================================
'
' File....... H48C_3-Axis.BS2
' Purpose.... Hitachi H48C 3-Axis Accelerometer Demonstration
' Author..... Copyright (c) 2005-2006 Parallax, Inc.
' E-mail..... [email protected]
' Started....
' Updated.... 02 FEB 2006
'
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' Test program for the H48C 3-Axis Accelerometer module.
'
' Connections:
'
' +------------+
' | * |
' CLK | o o | Vdd (+5v)
' | +--+ |
' DIO [ o | | o | CS\
' | +--+ |
' Vss | o o | 0G (free-fall indication)
' | |
' +------------+
'
' How it Works:
'
' An onboard MCP3204 12-bit ADC is used to read the VRef, X-, Y-, and
' Z-axis outputs from the Hitachi H48C accelerometer. The reference
' voltage output from H48C is 1.65 volts (3.3 / 2).
'
' After reading the reference voltage and an output channel the g-force
' for the channel is calculated with this formula:
'
' axis - vref 3.3
' G = ----------- x ------
' 4095 0.3663
'
' For use in the program the forumla can be simplified to:
'
' G = (axis - vref) x 0.0022
'
' To allow the display of fractional g-force in the integer system of the
' BASIC Stamp we multiply 0.0022 by 100 -- this will allow us to display
' g-force in 0.01g units.


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

Dio PIN 02 ' data to/from module
Clk PIN 08 ' clock output
CS PIN 03 ' active-low chip select


' -----[ Constants ]-------------------------------------------------------

XAxis CON 0 ' adc channels
YAxis CON 1
ZAxis CON 2
VRef CON 3

Cnt2Mv CON $CE4C ' counts to millivolts
' 0.80586 with **
GfCnv CON $3852 ' g-force conversion
' 0.22 with **

' -----[ Variables ]-------------------------------------------------------

axis VAR Nib ' axis selection
rvCount VAR Word ' ref voltage adc counts
axCount VAR Word ' axis voltage adc counts
mVolts VAR Word ' millivolts
gForce VAR Word ' axis g-force

dValue VAR Word ' display value
dPad VAR Nib ' display pad


' -----[ EEPROM Data ]-----------------------------------------------------


' -----[ Initialization ]--------------------------------------------------

Reset:
HIGH CS ' deselect module
DEBUG CLS, ' paint display
"=========================", CR,
"H48C 3-Axis Accelerometer", CR,
"=========================", CR,
CR,
" Count Volts G ", CR,
" ----- ----- -----", CR,
"VRef ", CR,
" X ", CR,
" Y ", CR,
" Z "


' -----[ Program Code ]----------------------------------------------------

Main:
FOR axis = XAxis TO ZAxis ' loop through each axis
GOSUB Get_H48C ' read vRef & axis counts

dValue = rvCount ' display vRef count
DEBUG CRSRXY, 6, 6
GOSUB RJ_Print

dValue = axCount ' display axis count
DEBUG CRSRXY, 6, (7 + axis)
GOSUB RJ_Print

mVolts = rvCount ** Cnt2Mv ' convert vref to mv
DEBUG CRSRXY, 13, 6, ' display
DEC (mVolts / 1000), ".",
DEC3 mVolts

mVolts = axCount ** Cnt2Mv ' convert axis to mv
DEBUG CRSRXY, 13, (7 + axis),
DEC (mVolts / 1000), ".",
DEC3 mVolts

' calculate g-force
' -- "gForce" is signed word

IF (axCount >= rvCount) THEN
gForce = (axCount - rvCount) ** GfCnv ' positive g-force
ELSE
gForce = -((rvCount - axCount) ** GfCnv) ' negative g-force
ENDIF
DEBUG CRSRXY, 20, (7 + axis), ' display g-force
" " + (gForce.BIT15 * 13),
DEC1 (ABS(gForce) / 100), ".",
DEC2 ABS(gForce)
NEXT
PAUSE 200
GOTO Main


' -----[ Subroutines ]-----------------------------------------------------

' Reads VRef and selected H48C axis through an MCP3204 ADC
' -- pass axis (0 - 2) in "axis"
' -- returns reference voltage counts in "rvCount"
' -- returns axis voltage counts in "axCounts"

Get_H48C:
LOW CS
SHIFTOUT Dio, Clk, MSBFIRST, [%11\2, VRef\3] ' select vref register
SHIFTIN Dio, Clk, MSBPOST, [rvCount\13] ' read ref voltage counts
HIGH CS
PAUSE 1
LOW CS
SHIFTOUT Dio, Clk, MSBFIRST, [%11\2, axis\3] ' select axis
SHIFTIN Dio, Clk, MSBPOST, [axCount\13] ' read axis voltage counts
HIGH CS
RETURN

' -------------------------------------------------------------------------

' Right-justify value in 5-digit field
' -- move cursor first, then call with value in "dValue"

RJ_Print:
LOOKDOWN dValue, >=[10000, 1000, 100, 10, 0], dPad
DEBUG REP " "\dPad, DEC dValue
RETURN</pre>

Any help would be gratefully appreciated .Please forgive me my spelling and grammer. Robbie64
 
Top