element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Achievement Levels
    • Benefits of Membership
    • Feedback and Support
    • Members Area
    • Personal Blogs
    • What's New on element14
  • Learn
    Learn
    • eBooks
    • Learning Center
    • Learning Groups
    • STEM Academy
    • Webinars, Training and Events
  • Technologies
    Technologies
    • 3D Printing
    • Experts & Guidance
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Arduino Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Project Groups
    • Raspberry Pi Projects
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Or 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
Experimenting with Gesture Sensors
  • Challenges & Projects
  • Design Challenges
  • Experimenting with Gesture Sensors
  • More
  • Cancel
Experimenting with Gesture Sensors
Challenge Blog Punch in Air #3 Working on Windows Drive for Serial Port
  • Challenge Blog
  • Forum
  • Documents
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Experimenting with Gesture Sensors requires membership for participation - click to join
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: fyaocn
  • Date Created: 3 Jan 2023 5:39 AM Date Created
  • Views 192 views
  • Likes 9 likes
  • Comments 0 comments
Related
Recommended

Punch in Air #3 Working on Windows Drive for Serial Port

fyaocn
fyaocn
3 Jan 2023

1 Brief 

This Experiment on punch in air has completed the first part, get to know what I have. It can be easy using Serial Tool like Putty to test this Gesture sensor Kits.

I choose to build my own windows drive so that I can customize the function and gesture of my own. But I have an unexpected long office-leave for over 6 weeks. The schedule is disrupted. Hence, part of the unfinished work is listed in this blog.

2 The windows Drive

There are several choices for Serial Drive in Windows 10 with different to and pro. Finally, I use native Windows drive, "window.h", there are enough documents on Microsoft website for detail. Just like all peripherals, create the thread for port, buffing the data, then destroy the thread after used. 

/*
* Windows Serial Port for Windows API
*
* Copyright (c) 2016 Ondrej Sterba <osterba@inbox.com>
*/

#ifndef SERIALPORT___H
#define SERIALPORT___H

#include <windows.h>

#define SERIALPORT_INTERNAL_TIMEOUT 100

class TSerialPort
{
private:
    HANDLE m_portHandle;
    HANDLE m_workingThread;
    DWORD  m_workingThreadId;
    
    int    m_timeoutMilliSeconds;
    int    m_maxPacketLength;
    
    void (*m_OnDataReceivedHandler)(const unsigned char* pData, int dataLength);
    void (*m_OnDataSentHandler)(void);
    
    CRITICAL_SECTION m_criticalSectionRead;
    CRITICAL_SECTION m_criticalSectionWrite;
    
    int __ReadBuffer(unsigned char* pData, int dataLength, int timeOutMS=-1);		
    int __WriteBuffer(const unsigned char* pData, int dataLength);	
    
    
public:	
    TSerialPort();
    ~TSerialPort();
    
    int GetMaxTimeout();
    void* GetDataReceivedHandler();
    void* GetDataSentHandler();
    
    bool Open(int comPortNumber, int baudRate, int timeoutMS=1000);
    
    bool OpenAsync( int comPortNumber, int baudRate, 
                    void (*OnDataReceivedHandler)(const unsigned char* pData, int dataLength),
                    void (*OnDataSentHandler)(void),            
                    int timeoutMS=100
                   );
    
    void Close();
    bool IsOpen();
    
    int ReadBuffer(unsigned char* pData, int dataLength, int timeOutMS=-1);		
    int WriteBuffer(const unsigned char* pData, int dataLength);	
    
    int ReadLine(char* pLine, int maxBufferSize, int timeOutMS=-1);
    int WriteLine(char* pLine, bool addCRatEnd=true);
    
    
};

DWORD WINAPI SerialPort_WaitForData( LPVOID lpParam );


#endif

Use of the windows serial drive API make the design clear as my main(),

#include "SerialPort.hpp""
#include <stdio.h>


int main(int argc, char* argv[])
{
    char response[64];
    
    TSerialPort com1;
    com1.Open(3, 9600, 1000);
    while(1)
    {        
        com1.WriteLine("050010");
        com1.ReadLine(response, sizeof(response));
        
        printf("Response: %s\r\n", response);
        Sleep(1000);
    }
    com1.Close();
    return 0;
}

This demo use COM1 as default serial port, the serial port can be scanned and probed. when MAX25405 is plugged. 

image

Then parse the contend of the serial port to get what the gesture is.

3 Integrated in Game Engine

I have built one simple out-of-box game with Godot Engine. It can be controlled with keyboard and mouse at same time. With the Gesture sensor kit added, there are third choice of input. The new hardware integration mechanism in Godot is GDNative C++. With customized bottom API code, such as my serial driver under windows.h, the game can use new hardware.

There is also choices of other game engine like Epic, Unreal, Unity, etc., they both work well. But need proper skill and commercial license.

4 Things to do.

The MAX25405 is definitely great design and balance the cost and performance. The use of MAX25405 in game is just one typical application, there are other affordable choices in entry control and simple Men-Machine interface. It would be interesting if I can make it.

Slow progress makes the experiment cease half-way. Quite a lot of functions yet not to be validated. I shall share the progress in later projects.

  • Sign in to reply
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 © 2023 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