element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Personal Blogs
  • Community Hub
  • More
Personal Blogs
Legacy Personal Blogs Third Year Systems Project - 3: Begining to look like Something
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: djfraz
  • Date Created: 17 Oct 2017 7:19 AM Date Created
  • Views 448 views
  • Likes 0 likes
  • Comments 4 comments
Related
Recommended

Third Year Systems Project - 3: Begining to look like Something

djfraz
djfraz
17 Oct 2017

Some fun news first, We now have a logo for the "Company" (as this is a mock project, its a mock company). We are Called Alpha Vending Solutions

image

 

I have just managed to get working the Maintenance mode Software using visual c#. The fix to get the serial port object to work was annoyingly simple once I found it.

The main use of this software will be to test functionality of the system, Send servo commands, read sensors and such. As we still are not fully sure on what software we will need, it has been made as a MDI (Multiple Document Interface) to allow more forms and controls to be added as needed.

image

The fix i found for getting the serial ports to work over multiple forms was to pass the Serial Port which has been opened in the main form to the other forms as an argument, see bellow

On the Form to be opened

 

using System.IO.Ports;
SerialPort serial = new SerialPort();
public Servo(SerialPort port)
        {
            InitializeComponent();
            serial = port;
        }

On the Main Form

using System.IO.Ports;
SerialPort sp = new SerialPort();
private void servoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Servo SVR = new Servo(sp)
            {
                MdiParent = this
            };


            SVR.Show();
        }

 

So in the main form 'sp' is opened with the required com port, using the menu. Then it is passed to the other forms when they are opened, and set to another serial port object. So far this solution is working for me and i hope to keep it that way.

 

The only issue I can see being with this, is that it requires me to use the readline() and Writeline() method in every form and have the required exception handling every time. although after the trouble I had trying to get this to work in the first place, i really don't mind having the extra work. I could also see an error happening if you open the form before opening the Com port.

 

This afternoon we will be interfacing the MBed with the software to read the colour sensor and display the results, and i will be sitting down with the mechanical design team to work out the state machine i will need to implement on the FPGA. Ill try and post about them as well

  • Sign in to reply

Top Comments

  • DAB
    DAB over 7 years ago +1
    Nice update. When getting into projects with new tools and software, you always need to allocate some learning time. Often you discover that what the product promises is different from what the product…
  • michaelkellett
    michaelkellett over 7 years ago +1
    Re the serial port. Normally you would only allow access to a hardware resource to just one module or object of your code. Any other forms or modules would only get access by calling that. The way I would…
  • djfraz
    djfraz over 7 years ago in reply to michaelkellett

    We are using a Command/Response Protocol for working with the sensors, the rest of the forms will most likely just be sending data out, servo controls, we might implicate a error response if the command is out of range of the command.

     

    I had originally tried to have a command simply waiting on a input from the serial port so as to have a simple terminal application, but it just became too much of a pain in the backside, and was one of the things causing me stress when first trying to get the application running.

     

    At the moment I am happy with the way i have been able to implement it, or at least until it crashes for some random reason. If i build another c# program with multiple forms to control a serial port i may look to find another way.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • michaelkellett
    michaelkellett over 7 years ago

    Re the serial port.

     

    Normally you would only allow access to a hardware resource to just one module or object of your code.

     

    Any other forms or modules would only get access by calling that.

     

    The way I would design it is for the communications from PC to Mbed to use a strict "command/response" protocol. The PC will send commands and the Mbed will respond. The Mbed will never send a message except in response to a command and it will always respond within a defined (short) time. This allows you to use  blocking calls to a "sendcommand" method in your serial comms object (or module or task or whatever).

     

    If you are using threads in c# you can do better and allow many objects to access the "sendcommand" method simultaneously but it gets much more complicated because the serial comms object has to be able to queue the requests and send the responses to the right places.

     

    If more than one object has access to the hardware then there is no reasonable way of sharing the hardware (because you cant tell if some other object just sent a command and is waiting for  a reply.)

     

    C# is very big and complicated and offers many ways of dealing with asynchronous communications (that's where you send a command and don't wait for the answer) but you should be able to accomplish all you need with a much simpler (blocking) model.

     

    MK

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • djfraz
    djfraz over 7 years ago in reply to DAB

    Biggest problem i had was just understanding object orientation in c#, and i was thinking that it should be more complex than it was. Though i was jumping up and down when it finally worked, and we managed to get the colour sensor working on the mbed, even with me not realizing that mbed uses c++ (though it was also c#) will post about it in a bit.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 7 years ago

    Nice update.

     

    When getting into projects with new tools and software, you always need to allocate some learning time.

    Often you discover that what the product promises is different from what the product can deliver.

     

    DAB

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube