473,378 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

comm port programming

al
Hi,

I am creating an application in access 97, so coding in vba. I am at
the stage of sending values to my external machine, but am stuck at a
point.

I need to send each character at an interval of 0.1 seconds.

So using the timer_event, i have set the timerinterval to 100.

Now what i need to know is how i can actually use this in a loop so
that it will repeat the function of send every 0.1 seconds.

i am having trouble with calculating how many charcaters are in the
string i'm sending, and thus not knowing how many times to loop through
the send code.

I know this may sound like nonsense, heres some code to help show what
i'm trying to achieve.

Option Compare Database
Option Explicit
Public sBuffer As String
'************************************************* ********************************
'TESTS TO PERFORM DURING TESTING PHASE

'Insulation Resistance - Voltage (500v dc) Resistance (2 M ohms) Time
(2 secs)
' strTest = Chr$(64) & Chr$(231) & Chr$(18) & "I" & Chr$(0) &
Chr$(5) & Chr$(0) & Chr$(0) & Chr$(0) & Chr$(0) & Chr$(2) & Chr$(0) &
Chr$(0) & Chr$(2) & Chr$(0) & Chr$(0) & Chr$(1) & Chr$(1) & Chr$(9) &
Chr$(9) & Chr$(9) & Chr$(9)
'Load Functional testing - Voltage (240v) Time (5 secs) Current Range
(0.5 to 13A)
' strTest = Chr$(64) & Chr$(231) & Chr$(18) & "R" & Chr$(1) &
Chr$(0) & Chr$(115) & Chr$(100) & Chr$(0) & Chr$(170) & Chr$(170) &
Chr$(240) & Chr$(0) & Chr$(1) & Chr$(0) & Chr$(220) & Chr$(5) & Chr$(4)
'AC Flash - Voltage (1000v ac) Trip Current (10 mA) Ramp UP (1 secs)
Peak Hold (1 secs) Ramp Down (0.5 secs)
' strTest = Chr$(64) & Chr$(231) & Chr$(13) & "A" & "B" & "t" &
Chr$(232) & Chr$(3) & Chr$(160) & Chr$(0) & Chr$(1) & Chr$(0) &
Chr$(160) & Chr$(0) & Chr$(0) & Chr$(0) & Chr$(0) & Chr$(10) & Chr$(0)
'Earth/Ground Continuity - Current (25 A) Upper (0.5 ohms) Time (2
secs)
' strTest = Chr$(64) & Chr$(231) & Chr$(9) & "E" & Chr$(25) &
Chr$(0) & Chr$(2) & Chr$(0) & Chr$(0) & Chr$(0) & Chr$(100) & Chr$(0)
'Phase Neutral Continuity - Upper(100 ohms) Lower (5 ohms) Time (1
secs)
'strTest = Chr$(64) & Chr$(231) & Chr$(12) & "P" & Chr$(0) &
Chr$(0) & Chr$(1) & Chr$(0) & Chr$(0) & Chr$(0) & Chr$(5) & Chr$(0) &
Chr$(1) & Chr$(0) & Chr$(0)
'************************************************* ***********************************

Private Sub cmdConnect_Click()
' open comms port
'mscomm1.CommPort = 1 'control is using COM1
'mscomm1.Settings = "9600,n,8,1" 'set up the port parameters
'mscomm1.RThreshold = 1 'set the oncomm event to trigger whenever data
arrives
'mscomm1.PortOpen = True 'open the port
End Sub

Private Sub cmdRemote_Click()
' obtain remote control of Elite 2
Dim strTest As String
strTest = Chr$(64) & Chr$(224) & Chr$(0)
mscomm1.Output = strTest
End Sub

Private Sub cmdSend_Click()
' send test values as required
Dim strTest As String
'EarthBond from manual
strTest = Chr$(64) & Chr$(231) & Chr$(9) & "E" & Chr$(24) & Chr$(0)
& Chr$(0) & Chr$(12) & Chr$(0) & Chr$(10) & Chr$(0) & Chr$(100) &
Chr$(0)
mscomm1.Output = strTest

'*** WE ARE RECEIVING NO RESPONSE HERE, REGARDLESS OF WHICH TEST WE
SEND ***
End Sub

Private Sub cmdStatus_Click()
' request status of Elite 2
Dim strTest As String
strTest = Chr$(64) & Chr$(228) & Chr$(0)
mscomm1.Output = strTest
End Sub
Private Sub cmdClose_Click()
' close connection
mscomm1.PortOpen = False
End Sub

Private Sub cmdLocal_Click()
' switch to local control of Elite 2
Dim strTest As String
strTest = Chr$(64) & Chr$(237) & Chr$(0)
mscomm1.Output = strTest
End Sub
Private Sub Form_Load()

'will set the timer for 0.1 seconds
'Me.TimerInterval = 100

End Sub

Private Sub Mscomm1_OnComm()
' responses from Elite 2 pushed to textbox
If mscomm1.CommEvent = NETComm_EV_RECEIVE Then

'call timer
End If
End Sub

Private Sub Form_Timer()

'check to see how many characters are in strTest

'if strTest is minus the original count but doesn't = 0
If strTest = strTest - 1 And Not Null Then

'send the next chr
'sBuffer = sBuffer & mscomm1.InputData
MsgBox "received"
'txtOutput = sBuffer
'sBuffer = ""
'Me.TimerInterval = 0
End Sub

Any help on how timer intervals work and ideas on how i can send data
through the comm port is very much apreciated,

Many thanks,

Alex

Nov 13 '05 #1
3 3932
al wrote:
Hi,

I am creating an application in access 97, so coding in vba. I am at
the stage of sending values to my external machine, but am stuck at a
point.

I need to send each character at an interval of 0.1 seconds.

So using the timer_event, i have set the timerinterval to 100.

Now what i need to know is how i can actually use this in a loop so
that it will repeat the function of send every 0.1 seconds.

i am having trouble with calculating how many charcaters are in the
string i'm sending, and thus not knowing how many times to loop through
the send code.

I know this may sound like nonsense, heres some code to help show what
i'm trying to achieve.

Option Compare Database
Option Explicit
Public sBuffer As String
'************************************************* ********************************
'TESTS TO PERFORM DURING TESTING PHASE

'Insulation Resistance - Voltage (500v dc) Resistance (2 M ohms) Time
(2 secs)
' strTest = Chr$(64) & Chr$(231) & Chr$(18) & "I" & Chr$(0) &
Chr$(5) & Chr$(0) & Chr$(0) & Chr$(0) & Chr$(0) & Chr$(2) & Chr$(0) &
Chr$(0) & Chr$(2) & Chr$(0) & Chr$(0) & Chr$(1) & Chr$(1) & Chr$(9) &
Chr$(9) & Chr$(9) & Chr$(9)
'Load Functional testing - Voltage (240v) Time (5 secs) Current Range
(0.5 to 13A)
' strTest = Chr$(64) & Chr$(231) & Chr$(18) & "R" & Chr$(1) &
Chr$(0) & Chr$(115) & Chr$(100) & Chr$(0) & Chr$(170) & Chr$(170) &
Chr$(240) & Chr$(0) & Chr$(1) & Chr$(0) & Chr$(220) & Chr$(5) & Chr$(4)
'AC Flash - Voltage (1000v ac) Trip Current (10 mA) Ramp UP (1 secs)
Peak Hold (1 secs) Ramp Down (0.5 secs)
' strTest = Chr$(64) & Chr$(231) & Chr$(13) & "A" & "B" & "t" &
Chr$(232) & Chr$(3) & Chr$(160) & Chr$(0) & Chr$(1) & Chr$(0) &
Chr$(160) & Chr$(0) & Chr$(0) & Chr$(0) & Chr$(0) & Chr$(10) & Chr$(0)
'Earth/Ground Continuity - Current (25 A) Upper (0.5 ohms) Time (2
secs)
' strTest = Chr$(64) & Chr$(231) & Chr$(9) & "E" & Chr$(25) &
Chr$(0) & Chr$(2) & Chr$(0) & Chr$(0) & Chr$(0) & Chr$(100) & Chr$(0)
'Phase Neutral Continuity - Upper(100 ohms) Lower (5 ohms) Time (1
secs)
'strTest = Chr$(64) & Chr$(231) & Chr$(12) & "P" & Chr$(0) &
Chr$(0) & Chr$(1) & Chr$(0) & Chr$(0) & Chr$(0) & Chr$(5) & Chr$(0) &
Chr$(1) & Chr$(0) & Chr$(0)
'************************************************* ***********************************

Private Sub cmdConnect_Click()
' open comms port
'mscomm1.CommPort = 1 'control is using COM1
'mscomm1.Settings = "9600,n,8,1" 'set up the port parameters
'mscomm1.RThreshold = 1 'set the oncomm event to trigger whenever data
arrives
'mscomm1.PortOpen = True 'open the port
End Sub

Private Sub cmdRemote_Click()
' obtain remote control of Elite 2
Dim strTest As String
strTest = Chr$(64) & Chr$(224) & Chr$(0)
mscomm1.Output = strTest
End Sub

Private Sub cmdSend_Click()
' send test values as required
Dim strTest As String
'EarthBond from manual
strTest = Chr$(64) & Chr$(231) & Chr$(9) & "E" & Chr$(24) & Chr$(0)
& Chr$(0) & Chr$(12) & Chr$(0) & Chr$(10) & Chr$(0) & Chr$(100) &
Chr$(0)
mscomm1.Output = strTest

'*** WE ARE RECEIVING NO RESPONSE HERE, REGARDLESS OF WHICH TEST WE
SEND ***
End Sub

Private Sub cmdStatus_Click()
' request status of Elite 2
Dim strTest As String
strTest = Chr$(64) & Chr$(228) & Chr$(0)
mscomm1.Output = strTest
End Sub
Private Sub cmdClose_Click()
' close connection
mscomm1.PortOpen = False
End Sub

Private Sub cmdLocal_Click()
' switch to local control of Elite 2
Dim strTest As String
strTest = Chr$(64) & Chr$(237) & Chr$(0)
mscomm1.Output = strTest
End Sub
Private Sub Form_Load()

'will set the timer for 0.1 seconds
'Me.TimerInterval = 100

End Sub

Private Sub Mscomm1_OnComm()
' responses from Elite 2 pushed to textbox
If mscomm1.CommEvent = NETComm_EV_RECEIVE Then

'call timer
End If
End Sub

Private Sub Form_Timer()

'check to see how many characters are in strTest

'if strTest is minus the original count but doesn't = 0
If strTest = strTest - 1 And Not Null Then

'send the next chr
'sBuffer = sBuffer & mscomm1.InputData
MsgBox "received"
'txtOutput = sBuffer
'sBuffer = ""
'Me.TimerInterval = 0
End Sub

Any help on how timer intervals work and ideas on how i can send data
through the comm port is very much apreciated,

Many thanks,

Alex


I'm not going to bother getting into your code, however you should be
able to understand this concept well enough that you can use it or
discard it.

You could create 2 fields. One field holds the string (HoldString).
The second field holds the counter (HoldCounter). Set the visible
property of both to False (hidden)

A command button is pressed, or an event is fired. When fired, create a
string. Next, set the value to 1 in the counter field (HoldCounter) and
store the string to the field (HoldString). Now set the timer interval
to whatever.

In the OnTime event send the character of the string. Ex:
Dim strToSend As String
strToSend = Mid(Me.HoldString,Me.HoldCounter,1)
...send or do whatever to the character in StrToSend
If Me.HoldCounter < Len(Me.HoldString) Then
Me.HoldCounter = Me.HoldCounter + 1
Else
Me.TimerInterval = 0
Endif

I only close the timer when all of the chars have been processed and passed.
Nov 13 '05 #2
I don't think you need to use the forms timer event at all..

You got this event firing all the time..and you have some coding running.
This kind of makes controlling things a bit hard, as to "when" does the next
timer event occur.

I would try a simple approach first (remember the Kiss principle!!).

All you got is a string, and want to send one character..and then wait .1 of
a second..

Lets dump all this complex timer stuff...

Just build a function/loop that sends one char..and then waits ..1....

This approach is dead simple....

dim i as interger
dim strSomeString as string

strSomeString = "bla bla bal"

for i = 1 to len(strSomeSstring)

mscomm1.Output = mid(strSomeString,i,1)
Call sSleep(100)

next i

All you need is a sleep function that pauses the code. ...
You can find one here:
http://www.mvps.org/access/api/api0021.htm

You might also consider putting a doevents into the loop to yield
processing. I would try the above..and also a loop with DoEvents...

Further, you can just make the above a nice function..and use it anywhere in
your code..
SendMyDelayData strData1
SendMyDelayData strData2

etc. etc.

This makes coding much easier also...
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com
http://www.attcanada.net/~kallal.msn
Nov 13 '05 #3
al

Albert,

i like this way of doing things! I am quite new to access and
programming so have not had much experience as yet, i'm wondering if
you coulkd help me furthur?

I have got the string to send and the counter is working so it counts
every second until it has reached the end of the string.

Now, for pure testing purposes, is it possible to show me how to send
the string at that second at a time, so the a textbox is updated every
second to simulate what it would be like going out of the comm port? I
just want to see the string filtering through and updating a
textbox(txtOutput), then i'll know how to send it via comm once i can
do it in the same way to a textbox.
Thanks gratefully for your help,

Alex

Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Will | last post by:
Does Python have comm port support built in or does someone have a tool for sending and receiving data in & out of a PC com port? How about for the Mac ? Thanks - Will
0
by: Miran Kopmajer | last post by:
I have external device connected to my computer (Windows XP) and I have aplication developed in FORMS 9.0.4. running on Linux Red Hat Enterprise Device is called DPI605R and is used for...
1
by: sarath1111 | last post by:
hi all, I am using comm port for serial communication between 2 PC's using C language. Once I have initialized the COMM port, Is there any option of closing the port in C language. Thanks in...
7
by: Michael Chong | last post by:
I wrote a program that communicate with SerialComm. In every 300 milliseconds, my program continuously send & receive data via the serial port once the program starts. My program is once in a...
3
by: Frank Perry | last post by:
Howdy, I'm trying to write data out the com port. I have taken the code from the sample on the MSDN Library CD and used the parts that seem relevant. I can open the com port with CreateFile...
4
by: Iceman.Aragorn | last post by:
I'm having an odd problem where im reading input from a comm port (the maker of the software that exports the data TO the comm port is unhelpful). What im reading is fixed length (13 character)...
2
by: Max Healey | last post by:
I have written a number of applications that control various bits of hardware via serial data. using VB6 and the comm. control now some one has asked me to do one for a specific piece of...
2
by: Hank | last post by:
Hello, I would like to get some opinions on using the Comm Port with Access 2000. We have a few jobs coming in that require us to interface with a PLC via the Comm Port. My partner feels we...
2
by: herat007 | last post by:
hi , i have developed a prog in vb to send sms , but i get an error error:8020 "Error reading from comm port" my prog for mscomm_oncomm() is Private Sub MSComm1_OnComm() Dim strMessage As...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.