473,765 Members | 2,070 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_Clic k()
' open comms port
'mscomm1.CommPo rt = 1 'control is using COM1
'mscomm1.Settin gs = "9600,n,8,1 " 'set up the port parameters
'mscomm1.RThres hold = 1 'set the oncomm event to trigger whenever data
arrives
'mscomm1.PortOp en = 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.PortOpe n = 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.TimerInterv al = 100

End Sub

Private Sub Mscomm1_OnComm( )
' responses from Elite 2 pushed to textbox
If mscomm1.CommEve nt = NETComm_EV_RECE IVE 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.InputDa ta
MsgBox "received"
'txtOutput = sBuffer
'sBuffer = ""
'Me.TimerInterv al = 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 3969
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_Clic k()
' open comms port
'mscomm1.CommPo rt = 1 'control is using COM1
'mscomm1.Settin gs = "9600,n,8,1 " 'set up the port parameters
'mscomm1.RThres hold = 1 'set the oncomm event to trigger whenever data
arrives
'mscomm1.PortOp en = 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.PortOpe n = 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.TimerInterv al = 100

End Sub

Private Sub Mscomm1_OnComm( )
' responses from Elite 2 pushed to textbox
If mscomm1.CommEve nt = NETComm_EV_RECE IVE 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.InputDa ta
MsgBox "received"
'txtOutput = sBuffer
'sBuffer = ""
'Me.TimerInterv al = 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.HoldStri ng,Me.HoldCount er,1)
...send or do whatever to the character in StrToSend
If Me.HoldCounter < Len(Me.HoldStri ng) Then
Me.HoldCounter = Me.HoldCounter + 1
Else
Me.TimerInterva l = 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(strSomeSstr ing)

mscomm1.Output = mid(strSomeStri ng,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(txtOutp ut), 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
2345
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
2457
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 measuring pressure. I'd like to create trigger which will read data from this device. Can anyone tell me how can I open COMM port, initialize and read data?
1
3642
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 Advance, Sarath.B
7
2767
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 while, the serial port seems corrupted because when my data is sent, it doesn't go through the serial port, so as same to receive process. In order to fix this, I have to close the port and reopen the port again. Why?!! Is there any way to fix...
3
5282
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 and get a valid file handle back. But when I try to write to it, the WriteFile comes back and tells me the handle is invalid. The program has control of the port because using Hyperterminal, I can't connect when the program is connected. There...
4
2636
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) sets of data seperated by CR/linefeed. At first, it simply seemed like i was getting messed up data, due to encoding it wrong, or using the wrong font, or something like that, but it turns out, when i analyze the byte stream, that the data i get...
2
9210
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 equipment, the protocol calls for 9600 8 N 1 all cool there, Then it specifies the following Baud Rate 9600 Startbit Low
2
1912
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 should use a Visual Basic Front End and the VB component as opposed to Access. Has anyone had good luck interfacing to a Comm Port using Access?
2
10293
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 String Select Case MSComm1.CommEvent ' Event messages. Case comEvReceive
0
10156
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9951
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8831
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7375
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5275
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2805
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.