It is All about Traffic, and Programming
Search
Archives
0 visitors online now
0 guests, 0 members

VISSIM

Lane Closure Utility Updated for VISSIM 9

Lane Closure Utility was initially developed in 2006 as an amateur/hobby work by a then graduate student.  Surprisingly,  it had been found useful,  and has been used by quite a few industry engineers, graduate students,  and academic researchers in their work.  I would like to thank them again for giving me feedback and inputs.

I just updated this free little utility to work with VISSIM latest 9.x version.

PTV made a LOT, really a LOT of changes to VISSIM COM interfaces – which is annoying but understandable given their grand plan of overhauling and refactoring the system’s application framework inside out –  that however made this upgrade quite eventful trying back and forth to figure out a lot of undocumented changes. Anyway,  I managed to just upgrade the code to match the latest VISSIM version COM interfaces.

It can be downloaded here: vissim9-dist-x86-x64  Feel free to download and distribute.

For those interested – my previous post about this little utility is here, so you can learn how to use it (easy and simple!)  Another big surprise to me as I found today is that – the original post has been read for almost 5000 times!  Wow.  I would be even happier  if you’d left me some comments,  good or bad.

Lane Closure Utility for VISSIM 5.40 (32bit and 64bit)

 

VISSIM in VMWare: USB Passthrough Timeout with WiBu CodeMeter

Starting with VISSIM v8,  the CodeMeter dongle stores more licensing items than earlier versions. This may result in USB pass through timeout when running VISSIM from within a VMWare virtual machine.  We discuss this potential issue here and a fix is documented.

In a previous post, we have discussed running VISSIM in a VMWare Workstation  virtual environment:

2016-02-15_18-28-32

http://blog.wupingxin.net/2015/05/21/vmware-usb-passthrough-running-vissim-in-a-virtual-machine/

This should be working fine until PTV released VISSIM 8.0,  which is a great upgrade to v7 with a lot of nice additions and enhancements, especially the mesoscopic traffic simulation, to name just the most note-worthy.

For users of VISSIM v7,  the upgrade to V8 requires one unusual step to update the contents of the CodeMeter key.  And PTV apparently has more to feed into the dongle than old versions, thus after upgrading to VISSIM v8 with the “stuffed” CodeMeter dongle,  you might have problem launching VISSIM in a VMWare virtual machine,  something like this:  the code meter icon shows up in a yellowish-green color different than the normal color, while VISSIM complains “CmContainer entry not find Error 200”:2016-02-15_12-44-04

 

 

 

 

 

 

 

 

 

It is even more perplexing that there will be no problem running VISSIM with the same CodeMeter dongle, but on a direct physical computer. The virtual machine that you might encounter this issue includesWindows Server 2012 R2, Windows 10 x64 Pro. However, Windows 7 x64 virtual machine has no problem.

And you might see CodeMeter log output as follows:

2016-02-15 15:16:57: CodeMeter for Windows (B6.10.2018.501.32.180)
2016-02-15 15:16:57: Running on Microsoft Windows 10 Pro, 64-Bit
2016-02-15 15:16:57: Execution path: C:\Program Files (x86)\CodeMeter\Runtime\bin
2016-02-15 15:16:57: Found IPv4 address: 127.0.0.1 | 192.168.11.130
2016-02-15 15:16:57: Found IPv6 address: ::1 | fe80::a45b:71d5:41d1:150%3
2016-02-15 15:16:57: Used Communication Mode: IPv6 IPv4 SharedMemory
2016-02-15 15:16:57: Used IP address: default address
2016-02-15 15:16:57: Used IP port: 22350
2016-02-15 15:16:57: Used CmWAN port: 22351
2016-02-15 15:16:57: Multicast server search: not available
2016-02-15 15:16:57: Run as network server: no
2016-02-15 15:16:57: Run as CmWAN server: no
2016-02-15 15:16:57: Run as system service: yes
2016-02-15 15:16:57: Service startup delay:  0:08 minutes
2016-02-15 15:16:57: Box Access: use direct access mode
2016-02-15 15:16:59: Detecting CmContainer with Serial Number 2-2573687
2016-02-15 15:17:16: Runtime Event RT410-535 (2573687) occurred.
2016-02-15 15:17:46: Runtime Event RT410-535 (2573687) occurred.
2016-02-15 15:17:46: EBL-Trace: I1P1CX1CX1
2016-02-15 15:17:48: Event WB0407 (REPLUG) occurred: RePlug(2)
2016-02-15 15:17:48: Access from local(IPV6) to SubSystem (Handle 16)
2016-02-15 15:17:48: API Event WB218 (NO LICENSE AVAILABLE) occurred (returned to caller)
2016-02-15 15:17:48: Handle 16 released
2016-02-15 15:17:48: Access from local(IPV6) to SubSystem (Handle 17)
2016-02-15 15:17:48: API Event WB218 (NO LICENSE AVAILABLE) occurred (returned to caller)
2016-02-15 15:17:48: Handle 17 released
2016-02-15 15:17:48: Access from local(IPV6) to SubSystem (Handle 18)
2016-02-15 15:17:48: API Event WB218 (NO LICENSE AVAILABLE) occurred (returned to caller)
2016-02-15 15:17:48: Handle 18 released
2016-02-15 15:17:48: Box Event HW04-529 (2573687) occurred.
2016-02-15 15:17:49: API Error 105 (INVALID PARAMETER) occurred!
2016-02-15 15:17:49: Access from local(IPV6) to SubSystem (Handle 22)
2016-02-15 15:17:49: API Error 105 (INVALID PARAMETER) occurred!
2016-02-15 15:17:49: Access from local(IPV6) to SubSystem (Handle 26)
2016-02-15 15:17:49: Access from local(IPV6) to SubSystem (Handle 27)
2016-02-15 15:17:49: API Event WB218 (NO LICENSE AVAILABLE) occurred (returned to caller)
2016-02-15 15:17:49: Handle 27 released
2016-02-15 15:17:49: API Error 115 (WRONG HANDLE TYPE) occurred!
2016-02-15 15:17:49: Access from local(IPV6) to SubSystem (Handle 31)
2016-02-15 15:17:49: API Event WB218 (NO LICENSE AVAILABLE) occurred (returned to caller)
2016-02-15 15:17:49: Handle 31 released
2016-02-15 15:17:55: API Error 105 (INVALID PARAMETER) occurred!
2016-02-15 15:17:55: Access from local(IPV6) to SubSystem (Handle 35)
2016-02-15 15:17:55: Access from local(IPV6) to SubSystem (Handle 36)
2016-02-15 15:17:55: API Event WB218 (NO LICENSE AVAILABLE) occurred (returned to caller)
2016-02-15 15:17:55: Handle 36 released
2016-02-15 15:17:55: API Error 115 (WRONG HANDLE TYPE) occurred!
2016-02-15 15:17:55: API Error 105 (INVALID PARAMETER) occurred!
2016-02-15 15:17:55: Access from local(IPV6) to SubSystem (Handle 40)
2016-02-15 15:17:55: API Event WB218 (NO LICENSE AVAILABLE) occurred (returned to caller)
2016-02-15 15:17:55: Handle 40 released

The problem  is really caused by USB timeouts when reading a large quantity of licenses.  This happens when CmStick uses the VMWare USB pass-through communication mode between CodeMeter Run-time Server (that is running inside the virtual machine) and CM-Stick (that is plugged via the host physical computer’s USB port).   That is why I believe that PTV has added a lot more license items into the CmStick than earlier versions, since this didn’t happen before.  The solution (thanks to the heads up from Mr. John Battista from WiBu USA) is to use the “File I/O” communication mode (UseUmsDA = 0) :

CodeMeter communication mode (on the virtual machine) can be changed  as follows:

1. In the virtual machine Guest OS, open the windows registry using regedit.exe

2. Go To: HKEY_LOCAL_MACHINE\SOFTWARE\WIBU-SYSTEMS\CodeMeter\Server\CurrentVersion

3. Set the “UseUmsDA” variable to 0

4. Restart CodeMeter Service, or restart the virtual machine directly

Then everything is working again.  Have fun!

Dissecting Vissim COM Internal from Inside Out (3)

In order to study the life cycle of CCOMVissim,  we have to track the calling stack of comsvr.dll.  This DLL is the host of CCOMVissim and other helper classes of Vissim COM functionalities. Please note it is not possible and not an option to perform static code analysis using a typical debugger. This is because CodeMeter hardware chip employs sophisticated anti-debugging mechanism, black-listing all known static/dynamic analysis debuggers such as OllyDBG or IDAPro .  We’d have to return to comsrv.DLL  – and recall in this post – the 58 exported functions, something like below:

vissim-com-export-index-1-30

As an effective approach (for interoperability among Vissim’s own various licensed modules),  let’s start creating a DLL project, using the same name “comsrv.DLL”,  as the one in the Exe folder of Vissim installation.

As a good background reading on exporting  C++ classes in a DLL,  here is an detailed post CodeProject: Export C++ classes from a DLL

Following this new Visual Studio C++ DLL project,  create a new class called CCOMVissim  – pay attention to the class definition, and the empty methods, and the declaration “__declspec(dllexport)“.  By default, the calling convention is “thiscall“.  Because we know Vissim is compiled in Visual C++ compiler apriori, thus name mangling wouldn’t be an issue (because of the same C++ compiler).

2015-06-05_14-59-13

Now, compile this project, and a dll called comsrv.dll is generated.  After this new DLL is generated,  de-compile it to verify the exported functions (see the figure below):

2015-06-05_15-02-18

We just created a “proxy” DLL with the same name as Vissim’s original comsrv.dll.  We emulated some of the original exported functions and classes.  The point is,  as long as the same list of  functions  are exported by this new dll, it is “loadable” by Vissim.  Therefore, we are  enableed to append additional code to track, manage, and manipulate the calling stack of those class methods or functions relevant to the life-cycle of IVissimPtr. This will help accomplish the objective of enabling interoperability of Vissim COM functionalities within Vissim’s various DLL-based modules,  including Signal Control API DLL, External Driver DLL and such.

If you could understand up to this point,  there should be no problem for you to move on to a final working solution to the question asked in the beginning.  The efforts are yours, and the omissions are mine.  One last hint:

Rename the original “comsrv.dll” to a different name, e.g., “comsrv_org.dll”.  Redirect calls from inside the proxy comsrv.dll to the original dll.

Dissecting Vissim COM Internal from Inside Out (2)

Let’s look at a typical Vissim COM programming code snippet in C++. It is taken from the Vissim manual, with some reformatting.

For Vissim end users, C++ is not an ideal choice of language for COM applications.  You’d have to handle all the complexities involved with COM  interface management. C++/COM programming has never been something as easy as a breeze with a steep learning curve.  On the other hand,  C++/COM is excellent that it does not hide COM implementation details,  while providing the best performance than any other languages. It is simply native to the COM world.

vissim-com-vc-snippet-1vissim-com-vc-snippet-2

In this beautiful C++ code snippet, Smart Pointer is used.  QueryAttach is a helper function shipped with this sample; it encapsulates the tedious QueryInterface process, and wraps up the returned Vissim interface as a smart pointer.

Clearly, the code illustrates the work-flow invoking Vissim as an automation server (see my another post on Vissim COM Instance Model).  When you call CreateInstance,  a Vissim process is started, where the default interface IVissim is instantiated and returned as the smart pointer IVissimPtr.

To say the least,  IVissimPtr is the “Open Sesame” to the wonderland of Vissim COM programming.

The  flow of all Vissim COM programming starts from getting an instance of IVissim interface.

It is fairly easy to get an IVissim interface by invoking Vissim as an automation server – just having an external COM client to call   CreateInstance.

VISSIMLIB::IVissimPtr pVissim declares the smart pointer to the default  IVissim interface.  COM smart pointer encapsulates COM operations including AddRef, Release etc. Don’t confuse yourself VISSIMLIB::IVissimPtr with IVissimIVissimPtr is generated by macro _COM_SMARTPTR_TYPEDEF(IVissim, __uuidof(IVissim)), while IVissim is declared as the following:

struct __declspec(uuid("a023e2ec-8002-4bb1-a584-b85ce59681ee"))
IVissim : IObjectBase
{
    //
    // Property data
    //

    __declspec(property(get=GetNet))
    INetPtr Net;
    __declspec(property(get=GetSimulation))
    ISimulationPtr Simulation;
    __declspec(property(get=GetEvaluation))
    IEvaluationPtr Evaluation;
    __declspec(property(get=GetGraphics))
    IGraphicsPtr Graphics;
    __declspec(property(get=GetPresentation))
    IPresentationPtr Presentation;

    //
    // Wrapper methods for error-handling
    //

    HRESULT New ( );
    HRESULT LoadNet (
        _bstr_t NetPath,
        VARIANT_BOOL Additive );
    HRESULT SaveNet ( );
    HRESULT SaveNetAs (
        _bstr_t NetPath );
    HRESULT LoadLayout (
        _bstr_t LayoutPath );
    HRESULT SaveLayout (
        _bstr_t LayoutPath );
    HRESULT ImportANM (
        _bstr_t NetPath,
        _bstr_t RoutesPath,
        _bstr_t InputPath,
        ImportType ImportType,
        int importOptions,
        int evaluationInterval );
    HRESULT BringToFront ( );
    HRESULT Exit ( );
    INetPtr GetNet ( );
    ISimulationPtr GetSimulation ( );
    IEvaluationPtr GetEvaluation ( );
    IGraphicsPtr GetGraphics ( );
    HRESULT ImportSynchro (
        _bstr_t synchroFile,
        _bstr_t workingDirectory,
        VARIANT_BOOL adaptiveImport );
    IPresentationPtr GetPresentation ( );
    HRESULT ExportVisum (
        _bstr_t NetPath,
        VisumExportType ExportType );
    HRESULT ImportResults (
        _bstr_t Path );
    HRESULT VissimTest (
        int TestNo,
        _bstr_t Param1,
        _bstr_t Param2,
        _bstr_t Param3 );
    HRESULT SuspendUpdateGUI ( );
    HRESULT ResumeUpdateGUI (
        VARIANT_BOOL enforceRedraw );

    //
    // Raw methods provided by interface
    //

      virtual HRESULT __stdcall raw_New ( ) = 0;
      virtual HRESULT __stdcall raw_LoadNet (
        /*[in]*/ BSTR NetPath,
        /*[in]*/ VARIANT_BOOL Additive ) = 0;
      virtual HRESULT __stdcall raw_SaveNet ( ) = 0;
      virtual HRESULT __stdcall raw_SaveNetAs (
        /*[in]*/ BSTR NetPath ) = 0;
      virtual HRESULT __stdcall raw_LoadLayout (
        /*[in]*/ BSTR LayoutPath ) = 0;
      virtual HRESULT __stdcall raw_SaveLayout (
        /*[in]*/ BSTR LayoutPath ) = 0;
      virtual HRESULT __stdcall raw_ImportANM (
        /*[in]*/ BSTR NetPath,
        /*[in]*/ BSTR RoutesPath,
        /*[in]*/ BSTR InputPath,
        /*[in]*/ ImportType ImportType,
        /*[in]*/ int importOptions,
        /*[in]*/ int evaluationInterval ) = 0;
      virtual HRESULT __stdcall raw_BringToFront ( ) = 0;
      virtual HRESULT __stdcall raw_Exit ( ) = 0;
      virtual HRESULT __stdcall get_Net (
        /*[out,retval]*/ struct INet * * Net ) = 0;
      virtual HRESULT __stdcall get_Simulation (
        /*[out,retval]*/ struct ISimulation * * Simulation ) = 0;
      virtual HRESULT __stdcall get_Evaluation (
        /*[out,retval]*/ struct IEvaluation * * Evaluation ) = 0;
      virtual HRESULT __stdcall get_Graphics (
        /*[out,retval]*/ struct IGraphics * * Graphics ) = 0;
      virtual HRESULT __stdcall raw_ImportSynchro (
        /*[in]*/ BSTR synchroFile,
        /*[in]*/ BSTR workingDirectory,
        /*[in]*/ VARIANT_BOOL adaptiveImport ) = 0;
      virtual HRESULT __stdcall get_Presentation (
        /*[out,retval]*/ struct IPresentation * * Presentation ) = 0;
      virtual HRESULT __stdcall raw_ExportVisum (
        /*[in]*/ BSTR NetPath,
        /*[in]*/ VisumExportType ExportType ) = 0;
      virtual HRESULT __stdcall raw_ImportResults (
        /*[in]*/ BSTR Path ) = 0;
      virtual HRESULT __stdcall raw_VissimTest (
        /*[in]*/ int TestNo,
        /*[in]*/ BSTR Param1,
        /*[in]*/ BSTR Param2,
        /*[in]*/ BSTR Param3 ) = 0;
      virtual HRESULT __stdcall raw_SuspendUpdateGUI ( ) = 0;
      virtual HRESULT __stdcall raw_ResumeUpdateGUI (
        /*[in]*/ VARIANT_BOOL enforceRedraw ) = 0;
};

In addition to invoking Vissim as an automation server,  In-Menu/Event-based COM scripting has a different mechanism.

In the In-Menu/Event-based COM script,  there is no explicit instantiation of IVissim. As a matter of fact,  there is a “Vissim” object already created, ready to be referenced in the script.

That is a mystery, isn’t?

To trace how and when “Vissim” object is created in the scripting context, we need to trace the life cycle of  the class CCOMVissim. That is the key to the original question – i.e.,  how to call all those COM functions inside an external DLL.

We’ll continue with our journey looking into the life cycle of the class CCOMVissim.  Right now, please just look at IVissim declaration again, and remember the following:

IVissim declaration stipulates nothing but just a memory blueprint. The sequence of all its virtual members are the slots of the v-table of IVissim’s implementation class.  This, is the “Open Sesame”.

Dissecting Vissim COM Internal from Inside Out (1)

There was an interesting discussion at PTV Vissim LinkedIn group – how to access Vissim COM interface inside a DLL, e.g., a Signal Control DLL,  an External Driver DLL etc.  To properly answer this question, some in-depth understanding of the COM technology,  C++ compiler internals, and Vissim binary level details are in order.

To begin with, Component Object Model (COM) is just a binary-level coding standard for out-of-process and in-process communication. It’s been out there for many years but somehow never become popular due to its daunting learning-curve for ordinary programmers,  and then Microsoft began promoting .NET, which is essentially similar idea revamped at the level of Common Language Run-time (CLR) and Intermediate Language (IL).

In the nostalgia good-old days,  COM/C++ programming required too steep learning curve to weed out sub-par programmers.  Nowadays programming is so much easier with various .NET languages or scripting languages that do not require low-level knowledge of hardware or compiler internals. The barrier to programing is quite low nowadays; anyone with common  sense can pick up programming,  develop some apps, and sell such on streets.

In the context of Vissim,  PTV wraps up the simulation elements and workflow into various interfaces. These interfaces are implemented (in C++) at binary level thus any language that supports COM (by their respective compilers) will be able to use Vissim’s COM interface to interact with Vissim functionality.

In the  earlier days of Vissim, its COM interfaces allow a client application to invoke Vissim as an automation server (as an out-of-process use case). Then PTV added In-Menu scripting, that supports invoking COM inside the active Vissim instance, using Python, VBS, or JS.

Starting Vissim 6, PTV completely refactored and redesigned Vissim, almost rebuild the software from scratch, inside out.  As part of this process, more gems are added,  one of such, is the so-called “event-based” COM scripting. “Event-based” COM scripting is a use case of in-process COM; it was added since Vissim v7.

Once again, with the In-Menu COM/Event-based Scripting,  and many other new designs/architectures, Vissim has set up a solid foundation significantly better than its v5 and any earlier generations, making itself readily primed for the future. A big congratulation is due to the PTV development team for this achievement, seriously.

Some of my earlier post discussed Vissim COM Internal as well.

As of today, Vissim 7-09 appears as the most impressive redemption of a legacy software (I mean, particularly, Vissim v4 and earlier versions) – and presents itself, with so many improvements and beef-ups, and as a powerful, sleek and increasingly popular tool for its users that have been yelling and crying for  years while its competitors eating up its market share.

Aside from COM interface, Vissim also provides various APIs e.g., Signal Control API, Emission API, External Driver API etc. These APIs have to be compiled in DLL to be loaded by Vissim host, which calls back the exported functions when certain events fire.

It is interesting that “event-based” COM scripting is capable of providing a unified interface for all the above APIs.  In future, it is possible that PTV might gradually phase out all these DLL-based APIs so everything is done through a unified event-based COM scripting. Granted, that is just my personal perspective.

Now, coming back to the million dollar question –  can we access COM interface from inside an API DLL? For example,  from inside External Driver DLL,  how can we access some, if not all of the COM functions?

The answer is: yes,  that is doable, but with some twist.

Now you start to have a faint of heart,  aren’t you?  Before we roll up our sleeves and jump to the 1-2-3 steps, I want you to take a look at the following snapshots – they are the key to the solution.

The following are the 58 exported functions from comsrv.dll, which is located in Vissim installation Exe folder. Most of these exported functions, are class methods of several classes, primarily:

  • CComVissim
  • CComNetObjHelper
  • CComVehicleContainer
  • CComSignalController
  • CComPedestrianContainer
  • CComException

💡 comsrv.dll is the “hub” of all Vissim COM functionality.

With the above in mind,   let me lead you to the interesting journey to figure out comsvr.dll  and Vissim COM invocation flow, till we reach the final solution to the original question.

vissim-com-export-index-1-30

vissim-com-export-index-31-58

 

(to be continued)

VMWare USB Passthrough: Running Vissim in a Virtual Machine

I bet it is not uncommon for someone to have a faint of heart at the idea of using VISSIM in a virtualized environment:

Using a virtual machine, it becomes easier and more orderly to debug and test various COM client applications, customized API DLLs and such, without messing around ordinary simulation projects . On the other hand, using a second virtual machine dedicated to traffic simulation models,  the project portfolio is organized and streamlined, while the IT administration load is simplified since a uniform work space is maintained between different modelers.

The following shows two snapshots of Vissim running inside a VMware 11.1.0 virtual machine.  In them, the Vissim instance was running smooth like a charm, without tangible performance hit, even running a 3D animation.

2015-05-22_15-33-35

VISSSIM 3D Animation in Virtual Machine

2015-05-22_15-28-37

VISSIM 2D Animation in Virtual Machine

In the above example, the hardware specification of the running computer is:

Host

  • WIN7x64
  • Intel i7-3920XM Quad Core@2.90GHz/3.1GHz
  • 32GB RAM(large host RAM will prevent frequent memory swapping)
  • Samsung 850 Pro SSD 1TB (SSD makes a big difference)

Guest

  • OS:Windows Server 2012 R2;
  • RAM: 8GB;
  • CPU: Enable the option “Virtualize Intel -VTx/EPT or AMD-V/RVI;
    • If the physical processor is enabled with EPT, this would give near native performance;
  • Graphic 3D and Graphic Memory setting as follows:

Virtual Machine Graphics Setting

The following is useful tips for improving Guest performance.

Add the following 3 lines in C:\ProgramData\VMware\VMware Workstation\settings.ini;

  • mainMem.useNamedFile = “FALSE”

This would disable the on-disk memory-swap file *.vmem, while forcing the virtual memory to be backed up by the host swap space. This means, if the host has enough physical RAM (e.g., 32GB),  all nominal guest-RAM will be allocated in host-memory hence improves performance.

  • MemTrimRate = “0”

This would disable memory page trimming. Memory trimming will return unused virtual machine memory to the host machine. By disabling such, the I/O is saved and will improve performance especially if the host is short of RAM.

  • scsi0:0.virtualSSD =  1

This is to explicitly let Guest OS know the virtual disk is SSD.

In order for the guest OS to see the hardware dongle,  the so-called USB Passthrough feature of VMWare is needed.  Of course, if the license is a network one, then this is a non issue – as long as the CodeMeter license server is configured , and the guest OS’ firewall set up properly.

To use USB Passthrough feature of VMWare, make sure the following services are enabled, or alternatively, make sure they are not disabled (See following figure) 💡 :

  • VMware Authorization Service
  • VMware USB Arbitration Service

 

2015-05-22_15-36-07

VMware Servivces Required for USB Passthrough

With the USB dongle plugged in the host’s USB port,  let go the “passthrough” by checking the “WIBU-Systems CodeMeter-Stick”, under VM->Removable Device.

2015-05-22_15-34-57

Connect the “Passthrough” CodeMeter Key in Virtual Machine

Brain-Wave Controlled Traffic Simulation: Control a Vissim Simulated Car (2)–Open Box

Emotiv  EPOC Neuroheadset  (Special LImited Edition) is priced a little over $400, and shipped in a nice box.  The package includes the headset, a sensor box with 16 sensors, a USB wireless receiver, and a charger. If you are willing to pay a little more, you can get an enhanced edition with firmware providing the raw EEG data. But I chose not to.

 

The following picture shows the package box.  The design is nice and the model in the picture looks cool.

10604536_10205375448368578_4169426888157101417_o

 

As you can see, the headset is sleek and looks with some Sci-Fi taste.  Can you see the he sensor sockets?

1529814_10205375449008594_7259397696980105817_o

This picture shows how it looks after all the sensor pads are put into the sockets.  They have to be soaked with the supplied saline liquid.

10714089_10205375450928642_1712280249339140873_o

 

This picture shows the SDK control panel. The diagram shows the sensor signals.

2014-11-06_22-10-19

The picture below shows the real-time charts of my brain activities, the Y axis represents the intensity of the signal. Different color of charts represents different emotions such as frustration, excitement, meditation etc.

Untitled

 

Clearly, the EEG data of my brain activities suggest I am amidst  potpourri emotions including frustration, excitement, boredom and others. Gee, I think I love this little Gadget.

 

(to be continued).

Brain-Wave Controlled Traffic Simulation: Control a Vissim Simulated Car (1)

Ever watched the movie “Carrie”, a classic produced in 1976 from Stephen King’s 1974’s horror novel?  An abused 17-year-old girl with telekinesis, gets pushed to the limit by a humiliating prank,  and finally took her revenge with her power – turning her school’s prom into a bloody night of killing.

You might want to develop telekinesis on your own,  so as to get back on whoever you get pissed of with – Good Luck on That!  Here is a nice tip on How to Develop Telekinesisjust let me know how it works!!

What we are going to talk about today is the so-called Brain-Computer-Interface (BCI), which is about using your brain wave patterns to train a computer program, while the latter directs some device doing some nice, dirty, and/or even horny (you wish!)  jobs for you   😆  

Here is an excerpt from Wikipedia:

A brain–computer interface (BCI), sometimes called a mind-machine interface (MMI), or sometimes called a direct neural interface (DNI), synthetic telepathy interface (STI) or a brain–machine interface (BMI), is a direct communication pathway between the brain and an external device. BCIs are often directed at assisting, augmenting, or repairing human cognitive or sensory-motor functions.

BCI uses Electroencephalography(EEG), which detects voltage fluctuations resulting from ionic current flows within neurons of brain. Whenever your neurons fire,  weak electrical signals in millisecond-range resolution propagates all the way to the scalp.This signal is at higher resolution than CT or MRI.

Therefore, BCI is pretty much about signal processing, machine learning and pattern recolonization recognition.

EEG was invented in early 1900’s, hence it is not something new.  However, when the time comes to 2010’s,  the industry has come out with cost-effective and portable EEG devices (unlike those used in medical applications).  Novel applications are thus enabled.  The following pictures (source:http://emotiv.com/) illustrate a conventional EEG and a portable EEG device.

compare1 compare2

The following picture shows Emotiv EPOC EEG device, manufactured by Emotiv, featuring

16 wet electrodes, 14 EEG electrodes read brain waves, two-axis gyroscope to read head movements, 4 mental states, 13 conscious thoughts or facial expressions, 4 processing suites

The wonderful thing is, this little device sells for only $399 desktop or $499 for Bluetooth Smart, with full programming SDKs. You can even integrate it with wearable devices (such as Google Glass).

epoc

And, that is what I am gonna do.  I am going to use this little gadget, and its SDKs to interface with VISSIM microscopic traffic simulator via its COM interface and Driver API – so I can:

  • Command a simulated car to brake, accelerate and stop,  using my brain wave – termed otherwise,  by simply staring at my computer screen like a dork 😯 .

That is right.  I am going to present an interesting demo here that Brain-Computer-Interface for the first time,  being used in traffic simulation to control a simulated car…… (I really wish one day I could use the same to command my boss to pay me more  😈 )

Stay tuned. It is going to be realllllly FUN.

(to be continued)

Initial Setting up of Vissim COM in .NET environment

VISSIM’s kernel is pretty much written using  C++ (a lot of template programming),  including its COM part.  Its UI is written in .NET for a better user experience, though. The VISSIM COM API manual is mostly about using it with Visual Basic or VBA,  which has long been depreciated by Microsoft since Visual Studio 6.0.

For .NET environment,  no detailed description is provided as to how to import the COM lib.   Anyway, here are the list of the snapshots to show how to import Vissim type lib in .NET (VS 2012), to start VISSIM COM client programming.  It applies to all .NET languages, such as C# or VB.NET.

1. Create a new C# (or VB.NET project).

2014-03-18_17-58-38

2. You will see something like below.

2014-03-18_18-00-01

3. Right click “References”,  choose “Add Reference”..

2014-03-18_18-00-19

 

4.  Choose “Browse”.

2014-03-18_18-01-02

5. Browse to where Vissim is installed,  select “Vissim.exe” . Click “Add” , and click “OK”.

2014-03-18_18-01-30

6. You will now see “VISSIMLIB” is added to the references list.  From this point on,  you can start referencing VISSIMLIB interfaces as in the C# example of the VISSIM manual.  Have fun.

2014-03-18_18-01-57

VISSIM 6 SP11 Memory Leak – False Alarm

VISSIM 6.0 has some nice features as advertised by PTV sales – but the truth is it presents itself  with more headaches than convenience for its existing users.  To name a few – almost a complete re-design of new user interfaces,  frustrating performance (VERY slow execution even on a high-spec machine),  menu items of placeholders of functionalities not implemented yet ,  and so many other annoying glitches…

The latest Service Pack 11 was released a couple of days ago, and I noticed that it has a major memory leak issue (see below updated information abut this matter) – I am referring to VISSIM 32bit  on Windows 7 x64 OS (I didn’t check the 64bit version) – to replicate,  simply launch four instances, and close the instances one after another by either click the Close button on the upper right corner,  or from File->Exit.  No need to load network files.

NOTE: VISSIM only supports up to 4 concurrent instances.

Now, open the Task Manager, and you will see the 4 Vissim instances dangling there, forever, each consuming approximately 200 MB RAM, and 22 threads, and 131  GDI objects. To make it worse,

  • You will NOT be able to launch any new Vissim instances because of these 4 invisible dangling zombie Vissim instances.

And,

  • You COM client applications will be screwed up as they will get confused when trying to connect Vissim instances and they will never succeed, causing the COM applications freezing out there.

 

2014-02-04_21-39-26

 

**********************          UPDATE         ***************************

This “memory leak” turns out to having nothing to do with Vissim.  It is a ridiculous non-tech problem.

I was traveling in China, and I was using Vissim North American edition.  When the Vissim 6.0 software was launched and closed,  Vissim 6.0 will try to connect to some “foreign” servers that were probably on the “white list” of the Chinese ISP  (if you don’t know about China’s Golden Shield System, a.k.a known as Great Wall Firewall system and its DNS hijacking – please google).  That caused the very slow loading up, and never-end-closing of Vissim instances (sometimes, this doesn’t happen at all, but most of the time, it did)