Announcement

Collapse
No announcement yet.

C to Basic-- #Define

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • C to Basic-- #Define

    I have a C #define, is there a way to translate it to basic?

    The define:

    #define IOCTL_SERIAL_CONFIGURE_ON CTL_CODE(FILE_DEVICE_SERIAL_PORT,102,METHOD_BUFFERED,FILE_ANY_ACCESS)

    The function that uses the define:

    BOOL TurnOnSerial(HANDLE m_hPort, int bOn)
    {
    DWORD cbActual;

    if(bOn == 1)
    return DeviceIoControl(m_hPort, IOCTL_SERIAL_CONFIGURE_ON, NULL, 0, NULL, 0, &cbActual, NULL);
    else
    return DeviceIoControl(m_hPort, IOCTL_SERIAL_CONFIGURE_OFF, NULL, 0, NULL, 0, &cbActual, NULL);
    }


    Thanks, some day I'll learn C++ but why when PB is so great!

    Doug
    Doug McDonald
    KD5NWK
    www.redforksoftware.com

  • #2
    %ioctl_serial_configure_on = &h001b0198
    Forum: http://www.jose.it-berater.org/smfforum/index.php

    Comment


    • #3
      Code

      It could look like this...

      Code:
      '#define IOCTL_SERIAL_CONFIGURE_ON CTL_CODE(FILE_DEVICE_SERIAL_PORT, 101, _
      '                                           METHOD_BUFFERED, FILE_ANY_ACCESS)
      '#define IOCTL_SERIAL_CONFIGURE_OFF CTL_CODE(FILE_DEVICE_SERIAL_PORT, 102, _
      '                                            METHOD_BUFFERED, FILE_ANY_ACCESS)
       
      #COMPILE EXE '#Win 8.03# #CC 4.03#
      #DIM ALL
      #INCLUDE "WIN32API.INC" '#2005-01-27#
       
      %METHOD_BUFFERED            = 0
      %FILE_ANY_ACCESS            = 0
      %FILE_DEVICE_SERIAL_PORT    = 27
      %IOCTL_SERIAL_CONFIGURE_ON  = &h001B0194 'Use this or use CTL_CODE function to find the value
      %IOCTL_SERIAL_CONFIGURE_OFF = &h001B0198 'Use this or use CTL_CODE function to find the value
      '______________________________________________________________________________
       
      FUNCTION CTL_CODE(BYVAL dwDeviceType AS DWORD, BYVAL dwFunction AS DWORD, _
                        BYVAL dwMethod AS DWORD, BYVAL dwAccess AS DWORD) AS DWORD
       'Thank to Erwin van de Wiel for this function
       SHIFT LEFT dwDeviceType, 16
       SHIFT LEFT dwAccess, 14
       SHIFT LEFT dwFunction, 2
       FUNCTION = dwDeviceType OR dwAccess OR dwFunction OR dwMethod
      END FUNCTION
      '______________________________________________________________________________
       
      FUNCTION TurnOnSerial(m_hPort AS DWORD, bOn AS LONG) AS LONG 'Return nonzero if succeeds
        LOCAL cbActual                   AS DWORD
        LOCAL IOCTL_SERIAL_CONFIGURE_ON  AS DWORD
        LOCAL IOCTL_SERIAL_CONFIGURE_OFF AS DWORD
       
        IOCTL_SERIAL_CONFIGURE_ON  = CTL_CODE(%FILE_DEVICE_SERIAL_PORT, 101, %METHOD_BUFFERED, %FILE_ANY_ACCESS)
        IOCTL_SERIAL_CONFIGURE_OFF = CTL_CODE(%FILE_DEVICE_SERIAL_PORT, 102, %METHOD_BUFFERED, %FILE_ANY_ACCESS)
       
        IF bOn <> 0 THEN
          'To enable the serial port
          FUNCTION = DeviceIoControl(m_hPort, IOCTL_SERIAL_CONFIGURE_ON, BYVAL %NULL, 0, BYVAL %NULL, 0, cbActual, BYVAL %NULL)
        ELSE
          'To disable the serial port
          FUNCTION = DeviceIoControl(m_hPort, IOCTL_SERIAL_CONFIGURE_OFF, BYVAL %NULL, 0, BYVAL %NULL, 0, cbActual, BYVAL %NULL)
        END IF
       
      END FUNCTION
      '______________________________________________________________________________
       
      FUNCTION PBMAIN() AS LONG
       LOCAL m_hPort AS DWORD
       LOCAL bOn     AS LONG
       LOCAL Retval  AS LONG
       
       m_hPort = 12345
       bOn = %TRUE
       
       Retval = TurnOnSerial(m_hPort, bOn)
       IF Retval THEN
         ? "Success"
       ELSE
         ? "Error"
       END IF
       
      END FUNCTION
      '______________________________________________________________________________
      Last edited by Pierre Bellisle; 13 Sep 2007, 06:54 PM.

      Comment


      • #4
        Thank you both

        Doug
        Doug McDonald
        KD5NWK
        www.redforksoftware.com

        Comment


        • #5
          Thank You to all you guys....I never knew these functions exist
          Thank you Doug for finding and asking.
          and
          Thank you Pierre for a workable answer

          Just when I thought I could learn all I could learn about a Serial Port, this gives me new ideas (Those that know me, know why )

          Doug, that aside, I assume the #Define you are asking about is in a header file? (not sure if my next hint applies to .cpp files as well but), I found a "Hidden Gem" of sorts in the last day or 2 that I am definitely adding to my toolbox.

          In the PB Downloads is Kev Peel's C to PB translator for header files (not sure if it does anything for cpp) but my 1st test was PHENOMENAL since it got rid of 90% of my confusion of translating

          Definitely something worth looking into....even if it's just to get acquainted to language differences.

          Also, what is it you are trying to do? (Maybe I have a few inputs or 2, or gazillion for what they are worth about serial ports) so I thought I would ask if I could help save a few steps, or compare routes I take that you take a different route.
          Engineer's Motto: If it aint broke take it apart and fix it

          "If at 1st you don't succeed... call it version 1.0"

          "Half of Programming is coding"....."The other 90% is DEBUGGING"

          "Document my code????" .... "WHYYY??? do you think they call it CODE? "

          Comment

          Working...
          X