|
-
May 24th, 2000, 11:53 PM
#1
Hi, I want to create an application that reads from a RS232 port (COM) and print the data received on the screen. I have an RF module connected to the RS232 so the data is an analog waveform.
I want to be able to read and transmit data through the COM port. I do not have much experience with comm. ports.
Any help or source where I can look into is appreciated.
I'm working on a Robotics project.
Thanks,
Diego.-
Using VB6 (SP3)
-
May 25th, 2000, 12:20 AM
#2
Addicted Member
...
Well, an analog waveform is not digital. RS232 and all other types of PC communication ARE digital. Your analog waveform MUST be converted to Binary\Digital. An easy way to do this is using an ADC(Analog to Digital converter) to convert your waveform to digital, then to use a microcontroller to grab the data and send it via RS232 to the PC.
Hope that clears it up!
Phil
-
May 25th, 2000, 03:52 AM
#3
You are perfectly correct. Sorry for the misunderstanding. That is not really the problem, I can do that very easily and have 8-bit packets which is enough for the kind of communication that I'm doing.
My problem is how to read the data from the port using VB6.
Once I can read the data I can device a simple protocol to communicate with the device.
Thanks,
Diego
-
May 25th, 2000, 11:40 AM
#4
PowerPoster
Hope this sample code can help you much.
Code:
'Main Form >> frmMain.frm
Option Explicit
Dim ZZ$
Private Sub CmdAction_Click(Index As Integer)
Select Case Index
Case 0 'Send
MSComm1.InBufferCount = 0
MSComm1.Output = txtSend.Text
txtRx.Text = txtRx.Text & "<Tx> " & txtSend.Text & vbCrLf
txtRx.SelStart = Len(txtRx)
Case 1 'Setting
Load frmSetting
frmSetting.Show
End Select
End Sub
Private Sub Form_Load()
SaveSetting "xCOM", "Parameter", "ComPort", MSComm1.CommPort
SaveSetting "xCOM", "Parameter", "Settings", MSComm1.Settings
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If MSComm1.PortOpen Then MSComm1.PortOpen = False
Dim xForm As Form
For Each xForm In Forms
Unload xForm
Next
End Sub
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive
txtRx.Text = txtRx.Text & "<Rx> " & MSComm1.Input & vbCrLf
txtRx.SelStart = Len(txtRx)
End Select
End Sub
'Port Configuration form >> frmSetting.frm
Option Explicit
Private xComSetting(3) As String
Private Sub CmdAction_Click()
On Error GoTo Open_Err
SaveSetting "xCOM", "Parameter", "ComPort", Mid(Trim(Combo1.Text), 4, 1)
SaveSetting "xCOM", "Parameter", "Settings", Trim(Combo2.Text) & Chr(44) & Trim(Combo3.Text) & Chr(44) & Trim(Combo4.Text) & Chr(44) & Trim(Combo5.Text)
frmMain.MSComm1.CommPort = CInt(GetSetting("xCOM", "Parameter", "ComPort", 1))
frmMain.MSComm1.Settings = GetSetting("xCOM", "Parameter", "Settings", "9600,n,8,1")
frmMain.MSComm1.PortOpen = True
frmMain.CmdAction(0).Enabled = True
frmMain.Shape1.FillColor = vbGreen
Unload Me
Exit Sub
Open_Err:
MsgBox "(" & Err.Number & ") " & Err.Description, vbExclamation + vbOKOnly, "RS232"
frmMain.Shape1.FillColor = vbRed
If frmMain.MSComm1.PortOpen Then frmMain.MSComm1.PortOpen = False
End Sub
Private Sub Form_Load()
Dim xArray, xParse
Dim xCnt%
If frmMain.MSComm1.PortOpen Then frmMain.MSComm1.PortOpen = False
frmMain.Shape1.FillColor = vbRed
frmMain.CmdAction(0).Enabled = False
xCnt = 0
Combo1.ListIndex = CInt(GetSetting("xCOM", "Parameter", "ComPort", 1)) - 1
xArray = Split(GetSetting("xCOM", "Parameter", "Settings", "9600,n,8,1"), Chr(44), -1)
For Each xParse In xArray
xComSetting(xCnt) = xParse
xCnt = xCnt + 1
Next
Select Case xComSetting(0)
Case "1200"
xCnt = 0
Case "2400"
xCnt = 1
Case "4800"
xCnt = 2
Case "9600"
xCnt = 3
Case "14400"
xCnt = 4
Case "28800"
xCnt = 5
Case "33600"
xCnt = 6
Case "55600"
xCnt = 7
End Select
Combo2.ListIndex = xCnt
Select Case xComSetting(1)
Case "n"
xCnt = 0
Case "e"
xCnt = 1
Case "o"
xCnt = 2
Case "m"
xCnt = 3
Case "s"
xCnt = 4
End Select
Combo3.ListIndex = xCnt
Select Case xComSetting(2)
Case "6"
xCnt = 0
Case "7"
xCnt = 1
Case "8"
xCnt = 2
End Select
Combo4.ListIndex = xCnt
Select Case xComSetting(3)
Case "1"
xCnt = 0
Case "1.5"
xCnt = 1
Case "2"
xCnt = 2
End Select
Combo5.ListIndex = xCnt
End Sub
-
May 28th, 2000, 06:16 PM
#5
Addicted Member
to chris
Where can i find the 'MSComm1' object.
If I put this code into a form, the compiler can't find 'MSComm1'???
Thanks.
-
May 28th, 2000, 09:01 PM
#6
PowerPoster
Originally posted by c@lle
Where can i find the 'MSComm1' object.
If I put this code into a form, the compiler can't find 'MSComm1'???
Thanks.
If you paste the code into the form with (Name) = frmMain, then the MSComm1 control should pun in the frmMain form.
-
May 29th, 2000, 03:36 AM
#7
In case you can't find it:
Project --> Components --> Microsoft Comm Control
-
May 29th, 2000, 07:20 AM
#8
-
Jan 11th, 2002, 03:55 AM
#9
Hai Chris, i need to send a text file listed in the file list box of my form thrugh the serial port to a external device that contain a Motorola 8051 microcontroller. Can i use the code u post here. Or do u got any code for it???.Thanks.
-
Jan 11th, 2002, 07:02 AM
#10
Member
-
Jan 11th, 2002, 11:38 AM
#11
PowerPoster
Hi, choonchin, basically you can ignore the email that i sent to you. which i have misunderstand your question. To setup a serial communication between your app & the 8051 uController, all you need is to ensure both side is having the samebaud rate, start, data bit & parity settings and then juz open the serial port with MSComm control.
For sample code, you can get it from my home page too. 
regards,
-
Jan 11th, 2002, 12:51 PM
#12
Thanks to my dear coursemate, hsye for ur support. Try the code but i still don't get what i want.
Chris : can i have ur home page address please?.Thanks You.
All The Best.
Regards.
choonchin
-
Jan 11th, 2002, 01:05 PM
#13
Member
Chris:
u posted:
"setup a serial communication between your app & the 8051 uController, all you need is to ensure both side is having the samebaud rate, start, data bit & parity settings and then juz open the serial port with MSComm control. "
but how can we know when the 8051 or other UART is available, or power on at the time?! (as far as i know, 8051 didn't have the RTSenable func. ). b'cos if not, then what we send will not be received, isn't that?!
n about ur sample codes, i did download it n then got few places that not quite understand.
in mscomm, what i understand is the program just copy text from txtSend.txt to txtRs.txt only. i tried to delect the procdata loop n it still ca display teh text, same as original. so, can u plis kindly explain it to me?!
n also the 'commport' file, i can't open my port for all the settings ( Com 1 to Com 4 ), n again, i don't know why?
ur kindly explanations really can help me much. as u can c, i'm doing same topic but no one ( i luv sastraxi ) help me!!!!
thx!!!!!!!!!!!!!!!!
( i did try to send u thru ur homepage, but it loads too slow. so, i'm not sure about it! )
-
Jan 12th, 2002, 11:27 AM
#14
PowerPoster
When you click the send button, the following code will be executed:
VB Code:
MSComm1.InBufferCount = 0
MSComm1.Output = txtSend.Text
txtRx.Text = txtRx.Text & "<Tx> " & txtSend.Text & vbCrLf
txtRx.SelStart = Len(txtRx)
yup, i did copy the txtSend.Text to txtRx.Text, i do this just wanna to display what i have sent out from this MSComm control.
As for the Procdata routine, it will be fire by the comEvReceive event on the MSComm control:
VB Code:
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive
Buf = MSComm1.Input
'//Parse the input data
ProcData
End Select
End Sub
I do this is, so that there will be not much routine under this event. again inside the Procdata routine, it also can scna the input buffer size and continue download the data from the input buffer and continue to process the received data. For more efficient, you can make th Procdata as a thread. Well this should be the way to handle heavy data flow through the MSComm control.
As for you fail to open the com 1 to 4, i need to info from you before i can give some comment on it
regards
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
|