HelloFish

ftComputing : Programme für die fischertechnik-Interfaces und -konstruktionskästen
  
ftComputing.de
Home
Back
Sitemap
Index
Links
Impressum
Mail
 

HelloFish for umFish30 cs style

The following HelloFish version is designed for use with VC++ 6.0

Setting up the VC++ Project

Easiest way : copy the whole ccFish30.ZIP in a new directory.

Some more details for a new VC++ 6.0 console project :

  • New Workspace : Console
  • Be sure umFish30.DLL can be accessed 
    to be situated in directory \Debug or \WinNT\System32
  • Add to the project : umFishVC.h, umFish30.lib, umFish30VC.cpp
  • Compile (F7)

Connect the Interface

The interface is suggested to be on COM2. In other cas change csOpenInterface(2, 1, 0, 0); to csInterface(1, 1, 0, 0); for connection with COM1.

The HelloFish expects 3 lamps on M1 to M3 and an switch on E1.

The Source

The interesting parts of umFish30VC.cpp

#include <windows.h>
#include <iostream.h>
#include "umFish30VC.h"

int ft;

void main() {
cout << "---- HelloFish started ----" << endl;
cout << "umFish30 v" << csVersion() << endl;
ft = csOpenInterface(2, 1, 0, 0);
if(ft == ftiError) {
   
cout << "Interface Problem, exit" << endl;
   
return;
}
cout << "OpenInterface succeeded" << endl;

cout << "--- Loop for the three lamps on M1 to M3" << endl;
for(int j=1; j<=4; j++)
{
   
cout << "Round : " << j << endl;
   
csSetMotors(ft, 0);
   
Sleep(300);
    for(int i=1; i<=3; i++)
    {
   
     csSetMotor(ft, i, ftiOn);
   
     Sleep (500);
   
}

}

csSetMotors(ft, 0);
cout << "END : Input E1 = TRUE" << endl;
while(!csGetInput(ft, 1));
csCloseInterface(ft);
}

Explanations

#include <windows.h> : Standard include
#include <iostream.h>
: include for cout / cin
#include <iostream.h>
: umFish30.DLL declarations.

int ft; : Handle to umFish30

ft = csOpenInterface(2, 1, 0, 0);
if(ft == ftiFehler) {
   
cout << "Interface Problem, exit" << endl;
   
return;
}

Connection to the interface. Parameters : COM2, with AnalogScan, no Slave, Poll default.
Returns the Handle to umFish30. If it is == ftiError the connection failed.

for(int j=1; j<=4; j++) {...}
  Repeat lamp switching 4 times

csSetMotors(ft, 0);
Sleep(300);
for(int i=1; i<=3; i++)
{
   
csSetMotor(ft, i, ftiOn);
   
Sleep (500);
}

Clear all M-Outputs (Lamps) and pause for 0.3 secs.
Switch on lamps on M1 – M2 – M3, pause after each switch for 0.5 secs.

csSetMotors(ft, 0);
cout << "END : Input E1 = TRUE" << endl;
while(!csGetInput(ft, 1));
csCloseInterface(ft);

Ending the program :
- Switch off all M-Outputs
– Write message
– Wait for E-Input E1 to be true.
– Cancel the connection to the interface.

Last Update : 12.01.2008