![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
Before I start my question, I would like to thank every member in the perfect website. .................................................. .................................................. .................................................. .................................................. .............. I’m working on my final project and I’m facing a problem. I am trying to design a program that can detect the incoming call, receive data and display it by using MSComm (com3) in visual basic.net. The program can detect the incoming call but the problem here that the program can’t receive the data and display it. At the same time, the same program will receive data from 8051 in com1 I tried to change many things but still the program couldn’t receive the data. If anyone can help me to solve this problem, I will be pleased for your help. I attached this post with my program .................................................. .................................................. .................................................. .................................................. .............. Dim Phase As String Dim Stage As String Dim ReceiveBuffer As String Const ReceivingInterval = 100 Private Sub Command1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Command1.Click Dim strBuffer As String Dim InString As String Dim i As Integer MSComm2.Settings = "9600,N,8,1" MSComm2.CommPort = 3 MSComm2.Handshaking = 2 MSComm2.DTREnable = True MSComm2.RTSEnable = True MSComm2.InputLen = 0 'Default anyway MSComm2.RThreshold = 1 'Fire OnComm event with a single character in input buffer MSComm2.SThreshold = 1 MSComm2.PortOpen = True Transact("ATE0", 300) 'command to tell the modem not to echo the "AT" back Stage = "Initialising Modem" Transact("ATS0=2", 300) ' Set Modem S0 register to 2 (Answer on two rings) End Sub Sub Transact(ByVal SendText As String, ByVal TimeOut As Integer) WriteLog("Sending: " & SendText) Timer1.Interval = TimeOut 'milliseconds ReceiveBuffer = "" MSComm2.Output = SendText & Chr(13) & Chr(10) Timer1.Enabled = True Phase = "Sending" End Sub Private Sub MSComm2_OnComm(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MSComm2.OnComm showasc("OnComm: " & MSComm2.CommEvent) Select Case MSComm2.CommEvent Case 1 '1 Send event. Case 2 '2 Receive event. Phase = "Receiving" ReceiveBuffer = ReceiveBuffer & MSComm2.Input WriteLog("ReceiveBuffer: " & ReceiveBuffer) Timer1.Enabled = False Timer1.Interval = ReceivingInterval Timer1.Enabled = True Case 3 '3 Change in clear-to-send line. Case 4 '4 Change in data-set ready line. Case 5 '5 Change in carrier detect line. Case 6 '6 Ring detect. Case 7 '7 End of file. 'errors Case 1001 '1001 A Break signal was received. Case 1004 '1004 Framing Error. The hardware detected a framing error. Case 1006 '1006 Port Overrun. A character was not read from the hardware before the next character arrived and was lost. Case 1008 '1008 Receive Buffer Overflow. There is no room in the receive buffer. Case 1009 '1009 Parity Error. The hardware detected a parity error. Case 1010 '1010 Transmit Buffer Full. The transmit buffer was full while trying to queue a character. Case 1011 '1011 Unexpected error retrieving Device Control Block (DCB) for the port. End Select End Sub Function TrimLeft(ByVal Intext As String) As String Dim Text As String If Len(Intext) > 0 Then Text = Intext Do While Asc(Text) <= 32 Text = Mid$(Text, 2) Loop TrimLeft = Text End If End Function Function TrimBoth(ByVal Intext As String) As String Dim text As String text = Intext Do While Asc(Mid$(text, Len(text), 1)) <= 57 text = Mid$(text, 1, Len(text) - 1) Loop Do While Asc(Mid$(text, 1, 1)) <= 57 text = Mid$(text, 2) Loop TrimBoth = text End Function Dim line = 0 Sub WriteLog(ByVal Text As String) Dim strBuffer As String strBuffer = TrimBoth(Text) strBuffer = Text line = line + 1 If Len(strBuffer) > 0 Then Label1.Text = line & " " & strBuffer End If End Sub Sub Listen(ByVal TimeOut As Integer) WriteLog("Listening: " & TimeOut & " millisecs") Timer1.Interval = TimeOut 'milliseconds ReceiveBuffer = "" Timer1.Enabled = True Phase = "Receiving" End Sub Private Sub showasc(ByVal text As String) Dim i As Integer label2.Text = "" label2.Text = label2.Text & " " & text & " " End Sub Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed Dim strBuffer As String WriteLog("Timer: Interval: " & Timer1.Interval & " Stage: " & Stage & " Phase: " & Phase) Select Case Phase Case "Sending" WriteLog("Nothing Received") Case "Receiving" strBuffer = ReceiveBuffer WriteLog("Received: " & strBuffer) End Select showasc(strBuffer) Timer1.Enabled = False End Sub Private Sub DataIn() Dim strbuffer As String Do While True Select Case Stage Case "Initialising Modem" If Mid$(strbuffer, Len(strbuffer) - 1, 2) = "OK" Then Transact("ATS0=2", 300) ' Set Modem S0 register to 2 (Answer on two rings) Stage = "Setting S Reg" Phase = "Sending" Else WriteLog("Modem not responding") End If Case "Setting S Reg" Select Case Mid$(strbuffer, 1, 2) Case "OK" Stage = "Listening" Phase = "Receiving" Listen(100) Case Else 'some sort of error End Select Case "Listening" Select Case strbuffer Case "OK" Case "RING" WriteLog("Incoming call") ReceiveBuffer = "" Case "CONNECT" 'The connect message may have some protocol information appended. WriteLog("Connected") DataIn() End Select End Select Loop End Sub Function TrimRight(ByVal Intext As String) As String 'strip blanks, tabs, line feeds etc from end of string Dim Text As String Text = Intext If Len(Intext) > 0 Then Do While Asc(Mid$(Text, 1)) <= 32 Text = Mid$(Text, Len(Text) - 1) Loop TrimRight = Text End If End Function Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ReceiveBuffer = "" Label1.Text = "" label2.Text = "" Timer2.Enabled = True End Sub Private Sub label2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles label2.TextChanged End Sub Private Sub dial_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dial.Click MSComm3.Output = "ATDT" + TextBox1.Text + Chr(13) End Sub Private Sub hang_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hang.Click MSComm3.Output = "ATH" + TextBox1.Text + Chr(13) End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click TextBox1.Text = "" End Sub Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) MSComm3.PortOpen = True End Sub Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) MSComm3.PortOpen = False End Sub Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) End Sub Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) End Sub Private Sub MSComm3_OnComm(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MSComm3.OnComm MSComm3.CommPort = True MSComm3.Input = "cpa00000000" + Chr(13) End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click MSComm2.Output = vbCr + "ATZ" + vbCr End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click End End Sub Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick Label1.Text = "" label2.Text = "" MSComm2.Output = vbCr Timer2.Enabled = False End Sub End Class | |
| |
| | #2 |
|
try asking your question in a software related forum THIS FORUM IS FOR MICROCONTROLLERS just incase you can't read I think I've spelt it out
__________________ " The only way to avoid human error is to avoid the use of humans" | |
| |
| | #3 |
|
"cena" .. how is ur call receiving ckt works . post ur circuit .
__________________ Gods own Country Incredible !ndia www.flickr.com/photos/_akg/ "Give a man a fish, and he will eat for a day. Teach that man to fish, and he will eat for a lifetime." | |
| |
| | #4 |
|
thanks (akg) for your post. .................................................. .................................................. ....... I post my circuit. When the level switch (2) is 1 (logic 1), the 8051 gives a command to the modem to make a call. The modem will send the house phone number, date and time. In the other side, my program in vb.net will detect that call by atuo answer and receive data from the modem and last thing that data will be displayed. | |
| |
| | #5 |
|
i'm confused by ur posts. u have said that the program can receive data from 8051 , but it cannot receive data ["The program can detect the incoming call but the problem here that the program can’t receive the data and display it. At the same time, the same program will receive data from 8051 in com1 "], the 8051 is the interface between the pc and modem , right ..? so what is the problem.?
__________________ Gods own Country Incredible !ndia www.flickr.com/photos/_akg/ "Give a man a fish, and he will eat for a day. Teach that man to fish, and he will eat for a lifetime." | |
| |
| | #6 |
|
In my program in visual basic.Net, I use to com ports. The first com port is only for the telephone line. In this case, I use com3 because my modem works with this port. The second com port is only for serial port between 8051 and the computer. .................................................. .................................................. .................................................. .................................................. .............. My project has two microcontrollers (8051). The first 8051 is connected to modem, two water level sensors and valve. I attched the circuit for this section. When the low water level sensor gives logic 1, the 8051 give a command to the modem to establish connection with another computer through the telephone line and there are some information that the 8051 will send them to that computer which are: house telephone number, time and date. The other computer(I call it central unit) should receive the call and data, and then disply them. Every thing is fine, just only one thing I couldn't understand, the program detect the call, but it can't read and display the data. I used hypier terminal and I got all the data from the other modem. The other 8051 is connected to many water flow sensors. The 8051 measures the pluses from every sensor at a time, then it will send the measurements to the central unit through the serial port (com1). The program will receive all data from both 8051s and display it. .................................................. .................................................. .................................................. .................................................. .............. I'm sorry because I didn't explain the problem in a right way. Thanks (akg) for your posts and help. | |
| |
| | #7 |
|
ok.. u said that u can receive the data correctly when hyperterm is used. does the modem responds correctly when ur program is run .? and what's result during debugging, especialy the oncomm event function
__________________ Gods own Country Incredible !ndia www.flickr.com/photos/_akg/ "Give a man a fish, and he will eat for a day. Teach that man to fish, and he will eat for a lifetime." | |
| |
| | #8 |
|
My modem responds correctly and the program detects the call. About comEvents, they are fine. I think the problem is that the program can't read the incoming data from the buffer after detecting the call and I need command to clear the buffer after detecting the call and then, receive the dat. Anohter point, if i tried to initialize the modem again, i will get error message. | |
| |
| | #9 | ||
| Quote:
if commevents are fine , u are getting the characters one by one . right ? and u don't need to clear the buffer , because, as soon as data arrives in the modem buffer , it is transferred into OS buffer . Quote:
__________________ Gods own Country Incredible !ndia www.flickr.com/photos/_akg/ "Give a man a fish, and he will eat for a day. Teach that man to fish, and he will eat for a lifetime." | |||
| |
| | #10 |
|
Thanks (akg) for your information and notes. I hope the program will work fine. | |
| |
|
| Tags |
| read, vbnet |
| Thread Tools | |
| Display Modes | |
| |