Click here to Skip to main content
12,997,042 members (129,431 online)
Rate this:
Please Sign up or sign in to vote.

I am trying to interface my microcontroller with in Web Form but have met with some difficulties.
My coding is working correctly in VB Windows Form but once ported to 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
<br />
Imports System<br />
Imports System.IO.Ports<br />
Imports System.Threading.Thread<br />
Imports System.ComponentModel<br />
<br />
Public Class frmMain<br />
<br />
    Dim WithEvents Serialport7 As New IO.Ports.SerialPort<br />
<br />
    Public Delegate Sub MyDelegate(ByVal ReceivedData As String)<br />
<br />
    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
<br />
    With Serialport7<br />
        .PortName = "Com7"<br />
        .BaudRate = 9600<br />
        .Parity = Parity.None<br />
        .DataBits = 8<br />
        .StopBits = StopBits.One<br />
    End With<br />
<br />
    Try<br />
        Serialport7.Open()<br />
    Catch ex As Exception<br />
        MsgBox(ex.ToString)<br />
    End Try<br />
<br />
End Sub<br />
<br />
Private  Sub Serialport7_DataReceived(ByVal sender As Object, ByVal e As  System.IO.Ports.SerialDataReceivedEventArgs) Handles  Serialport7.DataReceived<br />
<br />
    Me.BeginInvoke(New MyDelegate(AddressOf DisplayReading), Serialport7.ReadLine)<br />
<br />
End Sub<br />
<br />
Private Sub DisplayReading(ByVal ReceivedData As String)<br />
<br />
    If ReceivedData.Substring(0, 1) = "T" Then<br />
<br />
        RichTextBox1.Text = ReceivedData.Remove(0, 1)<br />
<br />
    ElseIf ReceivedData.Substring(0, 1) = "H" Then<br />
<br />
        RichTextBox2.Text = ReceivedData.Remove(0, 1)<br />
<br />
    End If<br />
<br />
    RichTextBox3.Text = System.DateTime.Now<br />
<br />
End Sub<br />
<br />
Private Sub MyFormClosing(ByVal sender As Object, ByVal e As ComponentModel.CancelEventArgs) Handles MyBase.Closing<br />
<br />
    If Serialport7.IsOpen Then Serialport7.Close()<br />
<br />
End Sub<br />
<br />
End Class<br />

The error being

<br />
'BeginInvoke' is not a member of '_Default'<br />

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.
Posted 27-Mar-13 20:59pm

1 solution

Rate this: bad
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:[^],[^] (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.

CPallini 28-Mar-13 4:06am
My 5.
Sergey Alexandrovich Kryukov 28-Mar-13 10:11am
Thank you, Carlo.
Sergey Alexandrovich Kryukov 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 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 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 coding ?
If not, are you able to provide some guidance to the coding ?
Sergey Alexandrovich Kryukov 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?

Member 9948376 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 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)?
Member 9948376 29-Mar-13 13:08pm

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 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?
Member 9948376 30-Mar-13 9:47am

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 ?

Member 9948376 30-Mar-13 11:30am

I have posted as a new question, the link is

Please do help me take a look. Thanks.
Sergey Alexandrovich Kryukov 30-Mar-13 21:10pm
Will you first accept this answer formally (green button)?

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170622.1 | Last Updated 30 Mar 2013
Copyright © CodeProject, 1999-2017
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