|
-
Dec 5th, 1999, 02:27 AM
#1
Thread Starter
Addicted Member
Hello, I have built an external device that transmits ASCII characters 0,1,2,3,4,5,6,7,8,9, and * via a serial connection. Using hyperterminal, I can connect to my device and indeed my device is transfering the characters correctly. I need MSComm to fire EACH time one character has been recieved.
Now, I have a MSComm Control, here is the settings I have used:
With comKeypad
.CommPort = CInt(sSetting)
.Settings = "9600N,8,1"
.InputLen = 1
.DTREnable =False
.EOFEnable = False
.RTSEnable = False
.Handshaking = comNone
.RThreshold = 1
.SThreshold = 0
End With
Now, since my device used NO handshaking signals, OnCOMM should fire everytime one single character is recived. Inside of OnCOMM(), I'm incrementing a variable and printing it to the debug window so I can keep track of how many times OnCOMM fires. Unfortunately, OnCOMM is firing 4-7 times per character. It correctly sends the one character to, say a text box, but still, the event fired way too many times. This is a big problem for me. I need to have it either fire only once, or fire a consistant number of times for each character.
So what could be the deal? Or maybe did I set the connection up wrong?
-
Dec 5th, 1999, 10:01 PM
#2
Junior Member
Hello Philip,
I need more info about your project.
1- Do you know the amount of byte send between your external device and the computer.
2- Does all byte sent through the COM port are ASCII.
3- Does the software request a command to the external device or is in the waiting state. (like embedded system)
On my side I only use the on_comm_event to detect error in the communication.
I use a subroutine, it's faster about 5 times faster. This only depends on speed issue for your project.
Let me know,
Regards,
Sebastian
[email protected]
-
Dec 6th, 1999, 03:21 AM
#3
Junior Member
There 2 ways to solve that problem.
If you still want to use the on_comm_event
there a property on the mscomm1 that is call inputlen. Set it to 1 and it will can the on_comm_event everytime one character is in the input buffer of the COM port. This should work.
The input mode has to be in ascii also.
(I guest you know about this, it's just because you did not mention it)
They other way you can do it, is to loop the software.
Something like:
Sub InBuffer()
Do
Doevents
loop until mscomm1.inputbuffer >= 1
data = mscomm1.input
Call YourSubroutine(data) 'For calculation or conversion
Exit sub
You can use a timer to call that function or do something similar.
Hope that help,
I you want, you can send me the code and I will have a look.
[email protected]
-
Dec 6th, 1999, 12:15 PM
#4
Thread Starter
Addicted Member
Thanks Sabastian:
Yes my design is an embedded project, using a 8051 to transmit ASCII bytes to the PC. I really need to be able to count exactly how many bytes have been transfered. I tried the incrementing an integer thing, but as I noted, that isn't accurate at all.
I do not know how many bytes will be sent between my device and the PC. Think of it as a keypad interfaced to the 8051. Everytime a user presses a key, it sends one byte to the PC. The software IS in a waiting state. I'm not "getting" the data from the device. The device sends it and I need to be able to detect it. Have any suggestions?
I really appreciate you taking any time you can in helping me out. This is part of our senior project and very fundamental to our project. I did not anticipate the problems with MSComm.
Thanks!!
-
Dec 24th, 2001, 02:30 PM
#5
-
Jan 19th, 2002, 12:23 AM
#6
Hai, philip G. i wander did u solve the problem because i face the same problem as your's. ComputerGuy, Can u provide me with some help here, please.
Here is my situation. i got a application that will wait for a signal from my 8051 external device, when the user press a push button on my external device, my 8051 external device will send a text "R" to my application , and the OnComm_() will detect the input and fire a record function to record voice for the line in of my PC sound card. Then when the user finish recording, user need to push the switch again and the 8051 external device will send a "S" text to the serial port and again the OnComm_() will detect the input and fire a function to stop the recording. Here is my code but it is not working, can u help me out.;
Private Sub Form_Load()
If MSComm1.PortOpen = False Then MSComm1.PortOpen = True
End Sub
Private Sub MSComm1_OnComm()
Dim Dummy As String
Select Case MSComm1.CommEvent
'Events
Case comEvReceive
MSComm1.InputLen = 0
Dummy = MSComm1.Input
If Dummy = "R" Then
Do
'Open a WaveAudio called Record
mciSendString "open new type waveaudio Alias record", 0&, 0, 0
'Start Recording
mciSendString "record record", 0&, 0, 0
Loop
End If
Dim Dummy2 As String
Select Case MSComm1.CommEvent
'Events
Case comEvReceive
MSComm1.InputLen = 0
Dummy2 = MSComm1.Input
If Dummy2 = "S" Then
Do
'Stops recording
mciSendString "stop record", 0&, 0, 0
'Saves the sound
mciSendString "save record C:\Windows\Desktop\MyWav.wav", 0&, 0, 0
'Close "Record"
mciSendString "close record", 0&, 0, 0
Loop
End If
end Sub
Hope u can help me with the code. The test the code, but it is not firing when i try to send a text from my 8051 external device to the serial port. I check the device and it is fine. Please help me. can u mail me ur code about ur project. Thanks for your time .and have a nice day.
-
Jan 20th, 2002, 06:56 AM
#7
-
Jan 21st, 2002, 12:16 PM
#8
Thanks, kinjalgp for the reply. Checked the baud rate, it is fine. i got my function done with a timer. Here is my code:
Private Sub Timer1_Timer()
If comEvReceive Then
Text2.Text = MSComm2.Input
If Text2.Text = "START RECORD" Then
'Open a WaveAudio called Record
mciSendString "open new type waveaudio Alias record", 0&, 0, 0
'Start Recording
mciSendString "record record", 0&, 0, 0
Else
If Text2.Text = "THANKS YOU" Then
'Stops recording
mciSendString "stop record", 0&, 0, 0
'Saves the sound
mciSendString "save record C:\Windows\Desktop\MyWav.wav", 0&, 0, 0
'Close "Record"
mciSendString "close record", 0&, 0, 0
End If
End If
End If
End Sub
but i face a new problem here. The save function here only allow me to save one wave file. what i need is that the save function will assign a new file name to the recorded wave file like file1, file2, file3 ect and save all of them after each recording. Can i do this, can u provide me with some caode. Thanks, Mate
-
Jan 23rd, 2002, 11:00 AM
#9
Fanatic Member
No Big deal in that buddy!
Here is yor modified code:
Code:
'At the beginning of the Form Code
Dim Counter as Long
Private Sub Timer1_Timer()
If comEvReceive Then
Text2.Text = MSComm2.Input
If Text2.Text = "START RECORD" Then
'Open a WaveAudio called Record
mciSendString "open new type waveaudio Alias record", 0&, 0, 0
'Start Recording
mciSendString "record record", 0&, 0, 0
Else
If Text2.Text = "THANKS YOU" Then
'Stops recording
mciSendString "stop record", 0&, 0, 0
'Saves the sound
mciSendString "save record C:\Windows\Desktop\File" & Counter & ".wav", 0&, 0, 0
Counter=Counter+1
'Close "Record"
mciSendString "close record", 0&, 0, 0
End If
End If
End If
End Sub
Kinjal
-
Jan 23rd, 2002, 08:53 PM
#10
kinjalgp, thanks for the reply. Try ur code but it is not working. It keep replace the previous recorded file after i try it for a number of time. And at the end only one file had been recorded that is File0. Can u help me again. Thanks mate.
-
Jan 23rd, 2002, 09:11 PM
#11
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|