Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi,
 
I am trying to interface my microcontroller with ASP.net in Web Form but have met with some difficulties.
My coding is working correctly in VB Windows Form but once ported to ASP.net Web form, it encounters error.
 
Basically, im taking in 2 inputs from microcontroller and update the Web Form through use of serial port.
 
Below is my coding for VB

Imports System
Imports System.IO.Ports
Imports System.Threading.Thread
Imports System.ComponentModel
 
Public Class frmMain
 
Dim WithEvents Serialport7 As New IO.Ports.SerialPort
 
Public Delegate Sub MyDelegate(ByVal ReceivedData As String)
 
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
With Serialport7
.PortName = "Com7"
.BaudRate = 9600
.Parity = Parity.None
.DataBits = 8
.StopBits = StopBits.One
End With
 
Try
Serialport7.Open()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
 
End Sub
 
Private Sub Serialport7_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles Serialport7.DataReceived
 
Me.BeginInvoke(New MyDelegate(AddressOf DisplayReading), Serialport7.ReadLine)
 
End Sub
 
Private Sub DisplayReading(ByVal ReceivedData As String)
 
If ReceivedData.Substring(0, 1) = "T" Then
 
RichTextBox1.Text = ReceivedData.Remove(0, 1)
 
ElseIf ReceivedData.Substring(0, 1) = "H" Then
 
RichTextBox2.Text = ReceivedData.Remove(0, 1)
 
End If
 
RichTextBox3.Text = System.DateTime.Now
 
End Sub
 
Private Sub MyFormClosing(ByVal sender As Object, ByVal e As ComponentModel.CancelEventArgs) Handles MyBase.Closing
 
If Serialport7.IsOpen Then Serialport7.Close()
 
End Sub
 
End Class

 
The error being
 

'BeginInvoke' is not a member of '_Default'

 
How can i resolve this ?
Can anyone tell me how do i port the codes correctly from Window form to a Web form ?
 
I seek anyone's help earnestly.
Thanks.
Posted 27-Mar-13 21:59pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You need to know that BeginInvoke is the member of System.Windows.Forms.Control or System.Windows.Threading.Dispatcher:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher.aspx[^] (WPF).
 
On its use, please see my past answers:
Control.Invoke() vs. Control.BeginInvoke()[^],
Problem with Treeview Scanner And MD5[^].
 
To port the code to ASP.NET you would need to write it again. The programming models are too different to discuss it seriously. First of all, you need to learn how Web and HTTP work, as well as .NET and programming in general. So far, you have problem understanding classes and their members, so I would advice not to rush into ASP.NET and other advanced topics. Further detail would depend on your goal you did not share with us. At least, do you understand that you can only work with your serial port on server side? I don't know what is connected to it and why.
 
Your code has other problems, I don't want to discuss them now, especially if you want to migrate to ASP.NET; so I just answered your questions.
 
—SA
  Permalink  
Comments
CPallini at 28-Mar-13 4:06am
   
My 5.
Sergey Alexandrovich Kryukov at 28-Mar-13 10:11am
   
Thank you, Carlo.
—SA
Sergey Alexandrovich Kryukov at 28-Mar-13 10:12am
   
[OP commented:]
 
Hi Sergey,
 
Thanks for reply.
 
I understand im still a far way off from understanding about Web and its uses.
Im an Electronics student and this is my final year project involving Microcontroller and ASP.net Web Form.
 
Basically, im taking in 2 inputs from microcontroller and update the Web Form through use of serial port.
 
Just to give you a clearer idea of what my project involves, the whole ASP.net Web Form will only be as a local host on my PC alone with no LAN or shared access. So it will be just a single page Web Form that will display 2 readings continuously coming from a Microcontroller through the Serial Port.
 
I have spent much effort learning about C++ programming for the Microcontroller side and the VB coding in WinForm. Hence, i am left with limited time to learn about Web Form and its style.
 
Are you able to help me re-code my VB coding into a ASP.net coding ?
If not, are you able to provide some guidance to the coding ?
Sergey Alexandrovich Kryukov at 28-Mar-13 10:16am
   
First of all, please don't post questions as "Solution", to avoid abuse reports, etc. Also, I would not see your post, as it wasn't a reply to mine, so I did not get a notification.
 
To start with, please tell me what the serial port is connected to, what microcontroller, what this microcontroller is going to do and why. Do you understand that only the server side code can work with the port?
 
—SA
Member 9948376 at 29-Mar-13 9:01am
   
Hi Sergey,
 
Im sorry about the correct posting column as this is my first post on this forum.
 
To give you a clearer idea of what my project involves,
- A microcontroller (Microchip 18f4520) takes in 2 reading from 2 sensors namely, a temperature and a humidity sensor.
- The microcontroller is seated on a target board of which includes a serial port.
- The readings are taken in by microcontroller and output to the serial port.
- The serial port is connected to my PC via a serial port to USB converted cable.
- Im supposed to display the readings onto the Web Page by writing coding to retrieve the readings from the serial port.
- But for demo purpose, the Web Page will be accessed only on the PC that is writing the coding, ie. my PC alone and not necessary from other PCs or LAN connection. It will be a local host (if i use the term correct) to my PC only.
- Initially i have written the coding on VB thinking it is just a simple porting over to the Web Site mode in Visual Studio as told by my lecturer but i realized it is not.
 
If i have not explained clear enough to your understanding, please let me know.
 
I really hope to have your help now as most of my time were spent on the coding for Microcontroller interfacing and Visual Basic and i have limited time left for writing report and to learn a whole new concept in Web Paging.
If it is been tedious for you, maybe you can show me some samples to follow.
 
Thank you for your attention.
Sergey Alexandrovich Kryukov at 29-Mar-13 10:21am
   
First of all, it's not clear why it has to be a Web site at all. Why cannot it be a custom service, which is much easier and gives more opportunities? Do you want to expose the temperature and humidity to internet, or just to local machines (LAN)?
—SA
Member 9948376 at 29-Mar-13 13:08pm
   
Hi,
 
The objective of my project is to demonstrate that it can be displayed via the Web site ultimately. But for demo purpose currently, it is enough to be just as local host on my PC alone which doesnt have to be accessed from other PCs or Web services.
 
May i ask what is meant by custom service ?
Sergey Alexandrovich Kryukov at 29-Mar-13 13:42pm
   
Anyway, I don't see a problem. Develop ASP.NET application, it allows you to communicate with the controller on the server side via a serial port. Host it on IIS (there other ways to host ASP.NET, in Apache and more...). Any problems?
—SA
Member 9948376 at 30-Mar-13 9:47am
   
Hi,
 
I have change the coding and done some testing, are you able to help me take a look at it posted below under Solution 2 ?
 
Thanks.
Member 9948376 at 30-Mar-13 11:30am
   
Hi,
 
I have posted as a new question, the link is
 
http://www.codeproject.com/Questions/569995/MicrocontrollerplustoplusASP-netplusWebplusFormplu
 
Please do help me take a look. Thanks.
Sergey Alexandrovich Kryukov at 30-Mar-13 21:10pm
   
Will you first accept this answer formally (green button)?
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 OriginalGriff 120
3 PIEBALDconsult 110
4 BillWoodruff 85
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 30 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100