Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Converting 'Basic' to 'C++' - Total n00b

Options
  • 19-10-2011 3:13pm
    #1
    Closed Accounts Posts: 5,132 ✭✭✭


    So basically the idea of this 'basic' code below is to convert a given voltage to frequency (it's for a lab);

    [PHP]INPUT "FREQ. (16-2000) IN CP/S"; A:F=A*10000 : A=(((1/A)*3906*256)): A=A+.5

    REM test pro' to output square wave on output 1 ---clk.in on #0 >>>>#1 out'
    X=INT(A/65536!): Y=INT((A-X*65536!)/256): Z=INT(A-((x*65536!)+(y*256)))
    RES=(INT(F/A))/20000
    PRINT "X=";X, "T=";Y, "Z=";, "A=";A
    PRINT:PRINT "
    PRINT"

    OUT 775,16+32+6
    OUT 772, Z:OUT 772,Y
    OUT 775, X+2 : OUT 773,0[/PHP]

    There may be some errors in the above code, as I'm reading it from an ancient photocopy and some of the characters are obscured. I'd want to use it in a C++ programme.

    Note: OUT 775 and OUT 772 corresponding to ports on a Digital to Analogue device.

    By the way, I'm a total n00b at basic. Can anyone give me some tips?

    (@mods; sorry if this is in the wrong forum)


Comments

  • Registered Users Posts: 5,376 ✭✭✭DublinDilbert


    Is the basic program running on an old dos machine?

    Do you want to run a c++ program under windows xp to write to the d to a device? Or are you using dos or Linux as the OS?

    You'll have issues trying to write directly to the d/a hardware under windows, you'll need a device driver to do the raw reads and writes, there are free ones available.

    In your c++ program I woukd start by looking at the cin and cout functions for keyboard input and data output.

    What c++ compiler/IDE have you installed?


  • Closed Accounts Posts: 5,132 ✭✭✭Killer Pigeon


    Is the basic program running on an old dos machine?

    Do you want to run a c++ program under windows xp to write to the d to a device? Or are you using dos or Linux as the OS?

    You'll have issues trying to write directly to the d/a hardware under windows, you'll need a device driver to do the raw reads and writes, there are free ones available.

    In your c++ program I woukd start by looking at the cin and cout functions for keyboard input and data output.

    What c++ compiler/IDE have you installed?

    OK,

    I'm not running basic. As I said in the OP, the basic code is from an ancient photocopy and I don't know what system it was running on, but it was probably used on an old dos.

    The OS is Windows 7. The C++ compiler is Dev-C++. I've tested out a very small C++ function on the DtoA and it works fine with Windows 7. However, I was given this 'basic' code as it is needed to convert Voltage to Frequency (DtoA needs to command a signal generator to convert a certain voltage to frequency). It's just I haven't a clue about basic and I don't know how to translate it to C++. I hope this is clear.


  • Registered Users Posts: 5,376 ✭✭✭DublinDilbert


    The basic code looks a very complex for what you need to do.

    So you want to output a voltage level, which will command the signal gen to a specfic freq. Do you have a manual for the d/a and signal gen, you should be able to come you with a simple formula to convert the desired frequency to a voltage.

    Have you tried to come up with a formula in excel to do the above? If you can get it to work in excel, doing it in cpp should be easy.

    Dont get caught up in the basic code, if you do it in excel and cpp you'll know exactly how it works.


  • Moderators, Technology & Internet Moderators Posts: 1,334 Mod ✭✭✭✭croo


    So basically the idea of this 'basic' code below is to convert a given voltage to frequency (it's for a lab);

    [PHP]INPUT "FREQ. (16-2000) IN CP/S"; A:F=A*10000 : A=(((1/A)*3906*256)): A=A+.5

    REM test pro' to output square wave on output 1 ---clk.in on #0 >>>>#1 out'
    X=INT(A/65536!): Y=INT((A-X*65536!)/256): Z=INT(A-((x*65536!)+(y*256)))
    RES=(INT(F/A))/20000
    PRINT "X=";X, "T=";Y, "Z=";, "A=";A
    PRINT:PRINT "
    PRINT"

    OUT 775,16+32+6
    OUT 772, Z:OUT 772,Y
    OUT 775, X+2 : OUT 773,0[/PHP]

    There may be some errors in the above code, as I'm reading it from an ancient photocopy and some of the characters are obscured. I'd want to use it in a C++ programme.

    Note: OUT 775 and OUT 772 corresponding to ports on a Digital to Analogue device.

    By the way, I'm a total n00b at basic. Can anyone give me some tips?

    (@mods; sorry if this is in the wrong forum)
    I've not done BASIC in 25 years but it looks like just a load of math!

    Tip1 ":" in BASIC is the same as ";" in C++

    INPUT "FREQ. (16-2000) IN CP/S"; A
    Is the equivalent to a printf and scanf to get a value into a variable A

    INT() is to cast to an Integer.

    REM is a REMark.

    and PRINT is printf.

    After that it's just lots of calculations which I guess would be the same in C++ as in BASIC!?

    One additional point that might be of use is 65536 is 64k which was often a maximum value in those old days.


  • Closed Accounts Posts: 5,132 ✭✭✭Killer Pigeon


    croo wrote: »
    I've not done BASIC in 25 years but it looks like just a load of math!

    Tip1 ":" in BASIC is the same as ";" in C++

    INPUT "FREQ. (16-2000) IN CP/S"; A
    Is the equivalent to a printf and scanf to get a value into a variable A

    INT() is to cast to an Integer.

    REM is a REMark.

    and PRINT is printf.

    After that it's just lots of calculations which I guess would be the same in C++ as in BASIC!?

    One additional point that might be of use is 65536 is 64k which was often a maximum value in those old days.

    Thanks-a-mil, appreciate it.


  • Advertisement
  • Registered Users Posts: 1,216 ✭✭✭carveone


    The ! suffix on the 65536 would indicate it's a quickbasic program. $ was for string, % integer, ! was single precision (float), # double.

    Never seen the suffix on a value before, just on variable names. Weird, especially since single was the default in most basics.


  • Registered Users Posts: 1,657 ✭✭✭komodosp


    Haven't done C++ in a while and BASIC in a while longer..
    Something like
    #include <iostream.h>
    
    main() {
    
    cout << "FREQ. (16-2000) IN CP/S";  
    cin >> A;
    F = A*10000;
    A = (((1/A) * 3906 * 256;
    A += 0.5;
    
    // test pro' to output square wave on output 1 -- clik.in on #0 >>>>##1 out'
    
    X= (int)(A/65536); 
    Y= (int)((A - X * 65536) / 256);
    Z= (int)(A - ((X * 65536) + (Y * 256)));
    RES=(int)((F / A) / 20000);
    
    cout << "X=" << X << "   T=" << Y << "    Z=" << Z << "   A=" << A << "\n\n\n";
    cout << "---------------------------------------" << endl;
    
    /* not really sure what to replace following code with...
    
    OUT 775,16+32+6
    OUT 772, Z:OUT 772,Y
    OUT 775, X+2 : OUT 773,0  
    
    */
    
    }
    

    Whatever happens to RES?


  • Closed Accounts Posts: 5,132 ✭✭✭Killer Pigeon


    carveone wrote: »
    The ! suffix on the 65536 would indicate it's a quickbasic program. $ was for string, % integer, ! was single precision (float), # double.

    Never seen the suffix on a value before, just on variable names. Weird, especially since single was the default in most basics.

    Someone told me today that the ! suffix after an integer value just stands for ".0", in this case "65536.0".


  • Registered Users Posts: 2,426 ✭✭✭ressem


    Under windows 7 (32 bit, I hope you're using), and recent other versions of windows you need to go through a workaround to access port addresses.

    Download "inpout32_source_and_bins" from
    http://logix4u.net/Legacy_Ports/Parallel_Port/Inpout32.dll_for_Windows_98/2000/NT/XP.html

    You'll want both the dll from the
    \inpout32_source_and_bins\inpout32_source_and_bins\binaries\Dll
    directory and the lib from
    \inpout32_source_and_bins\inpout32_source_and_bins\test applications\VC_test_app

    Then replace your basic
    out [portaddress] [data to send]

    with

    Out32(short PortAddress, short data)

    as in the sample code.


Advertisement