locked
SerialPort1 access in a module?

    Question

  • Greetings,

     

    The Situation:

    I have a simple program that uses SerialPort1. I dragged the SerialPort1 icon over to Form1. Within Form1 I can open the serial port, receive Serialport events and send data out the Serial Port.

     

    The Problem: 

    I created a module in the project and within the module is a public Subroutine. The thought was that I could call the subroutine from Form1 and pass it an array of values I want to be sent out the serial port in the subroutine.  The problem is that using the SerialPort1 comands (which works just fine in Form1) yeilds the error, " Error 1 Name 'SerialPort1' is not declared." The error occurs whether I make the SerialPort1 Properties Modifier as Friend or Public.

     

    The Question: 

    How do I get the module to "know about" SerialPort1??

     

    Many Thanks!

     

    Cheers,

    Beethoven

    Saturday, September 08, 2007 2:33 AM

Answers

  • Thanks to a co-worker here is the answer:

     

    I needed to itentify WHERE the serialport1 "exists" (i.e. in Form1), so instead of saying:

     

    Module foo_Module  ' DID NOT WORK

    Public Sub Send2fooCommand(ByRef CMDarray() As Byte)

     

    SerialPort1.Write(CKSUM) ' Send out checksum

     

    (etc....)

    ----------------------------------------------------------------

    I instead needed to say:

     

    Module foo_Module  ' DOES WORK

    Public Sub Send2fooCommand(ByRef CMDarray() As Byte)

     

    Form1.SerialPort1.Write(CKSUM) ' Send out checksum

     

    (etc....)

    ----------------------------------------------------------------
    Tuesday, September 11, 2007 12:30 AM

All replies

  • Thanks to a co-worker here is the answer:

     

    I needed to itentify WHERE the serialport1 "exists" (i.e. in Form1), so instead of saying:

     

    Module foo_Module  ' DID NOT WORK

    Public Sub Send2fooCommand(ByRef CMDarray() As Byte)

     

    SerialPort1.Write(CKSUM) ' Send out checksum

     

    (etc....)

    ----------------------------------------------------------------

    I instead needed to say:

     

    Module foo_Module  ' DOES WORK

    Public Sub Send2fooCommand(ByRef CMDarray() As Byte)

     

    Form1.SerialPort1.Write(CKSUM) ' Send out checksum

     

    (etc....)

    ----------------------------------------------------------------
    Tuesday, September 11, 2007 12:30 AM
  • Hi Beethoven,

     

    I’m glad hear that you have solved the issue by yourself and a co-worker. Cheers!

     

    Thank you for sharing your experience here. It will be very beneficial to other community members having similar questions.

     

    Regards,

    Martin

    Wednesday, September 12, 2007 3:04 AM