Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Digital I/O

Posted on 1998-12-04
7
Medium Priority
?
279 Views
Last Modified: 2008-02-01
I'm writing an application using Borland's C++ Builder.  I've used the DCB structure in the past for serial communications, but how do I handle hardware devices such as digital/analog cards?  I'm using a CIO-DIO48 which has 48 digital inputs and a CIO-DAS16 which has 16 digital outputs.  I can easily write a DOS appl using outportb and inportb to send and receive bytes, but these aren't compatable with Builder.
What resources are there that will allow me to read the digital inputs and write to the digital outputs?
0
Comment
Question by:schmim04
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 1179222
Can you use Windows API: OpenComm, WriteComm, ReadComm ? If can , this is solution. I not, you can tray
OpenFile/_lopen to "COM1"/"LPT1" and standart
read/write functions.
0
 
LVL 86

Expert Comment

by:jkr
ID: 1179223
Specialized I/O boards usually come with a device driver that makes the hardware accessible through a defined interface...
As you mentioned C++ Builder, i assume your target platform is Win32. There, the device is usually exposed through a driver which is accessible via 'CreateFile()'. After obtaining a file handle through this function call, you'll have to use 'DeviceIoControl()' using special control codes (see the boards' documentation) to read/write data from/to the device.
0
 
LVL 1

Author Comment

by:schmim04
ID: 1179224
Thank you for the function you mentioned.  I never saw it before.  However your response doesn't get me anywhere.  The one card has 48 digital inputs and a base address of 300h.  There are 6 8-bit ports on this card which exist at this base address plus some number.  I need to be able to read these ports on an individual basis (if possible), (or does the function just read them all each time?) and I don't see any functions that would allow this.  What if the boards documentation doesn't say which control code to use off the list?  If there is a way, please tell.    
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:schmim04
ID: 1179225
Adjusted points to 300
0
 
LVL 86

Expert Comment

by:jkr
ID: 1179226
Well, is there _no_ driver plus documentation shipped with the board???
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 1179227
Hi. Thid part of My programm test COM1/COM2 and
 read/write in case, that connectionb exists.
 Programm works with Kass(Kupa) and Weight(Mishkal).
 This is only my case, and can be
  szInitCupa or szInitMishkal you must set other,
  by Doc of you controller.
 Alex

static int idComDev[2] ={ -1,-1};      //no!
static DCB  dcb;
static int nPortMishkal = -1;
static int nPortCupa = -1;
#define MAX_LEN_INPUT    81
/*=========================================================================*/
/*  Name       : DefineController                                 */
/*  Parameters : None                                                        */
/*  Return     : None                                             */
/*=========================================================================*/
void DefineController(void)
{
  int err;
  char
    *szInitCupa    = "COM%d:9600, N, 8, 1",
    *szInitMishkal = "COM%d:1200, E, 8, 1";
 char buff[MAX_LEN_INPUT];            //Com Command

  for (int i = 0; i < 2;i++)
    if (idComDev[i] >= 0)            //Post opened?
      {
      CloseComm(idComDev[i]);      //close
      idComDev[i] = -1;            //no!
      }
      //read from ini File port of Weight(default 1)
  UINT bMishkal  = ReadSpsModeInt("Main", "PortMishkal",1);
      //read from ini File port of CASS(default 2)
  UINT bCupa  = ReadSpsModeInt("Main", "PortCupa",2);
  if (bMishkal >= 1 && bMishkal <= 4)
    nPortMishkal = bMishkal;
  if (bCupa >= 1 && bCupa <= 4)
    nPortCupa = bCupa;
  if (nPortCupa == nPortMishkal && nPortMishkal != -1)
    nPortMishkal = -1;                  //error
                              //mishkal
  if ( nPortMishkal > 0)
    {
      wsprintf(buff, "COM%d", nPortMishkal);
      idComDev[0] = OpenComm(buff,MAX_LEN_INPUT , MAX_LEN_OUTPUT);
      if (idComDev[0] >= 0)  //open?
      {
        wsprintf(buff, szInitMishkal,nPortMishkal);
        err = BuildCommDCB(buff, &dcb);
        if (err >= 0)
          err = SetCommState(&dcb);
        if (err < 0)                        //Error?
          {
            CloseComm(idComDev[0]);
            idComDev[0]  = -1;
          }
       }
      if (idComDev[0] >= 0)            //OK?
      TestMishkal(idComDev[0]);
    }
                              //Cupa
  if (nPortCupa > 0)
    {
      wsprintf(buff, "COM%d", nPortCupa);
      idComDev[1] = OpenComm(buff,MAX_LEN_INPUT , MAX_LEN_OUTPUT);
      if (idComDev[1] >= 0)  //open?
      {
        wsprintf(buff, szInitCupa,nPortCupa);
        err = BuildCommDCB(buff, &dcb);
        if (err >= 0)
          err = SetCommState(&dcb);
        if (err < 0)                        //Error?
          {
            CloseComm(idComDev[1]);
            idComDev[1]  = -1;
          }
       }
    }
} // end DefineController
void TestMishkal(int &idComDev)
{                              //send acknoledge
  char buff[MAX_LEN_INPUT];            //Com Command
  memset(buff, 0, sizeof(buff));
  buff[0] = buff[19] = 7;
  int err = WriteComm(idComDev,buff,20);
  if (err >= 0)                  //OK!
    {
      long lTime0,lTime1;

      time(&lTime0); lTime1 = lTime0; // delay
      while(lTime1 < lTime0+2) time(&lTime1);

      memset(buff, 0, sizeof(buff));
                                    //read reaction
      err = ReadComm (idComDev,buff,20);
      if (*buff == 0)
      err = -1;
      else if (err >= 0 && !TestCheckSum(buff))//test: must be from R
      err = -1;
      if (err < 0)             //close Bennet
      {
        CloseComm(idComDev);
        idComDev = -1;      //no!
      }
      if (err >= 0)                  //for next weight
      WriteComm(idComDev,buff,20);
    }
}

0
 
LVL 2

Accepted Solution

by:
ivi earned 600 total points
ID: 1179228
It is a standard answer:

1. Use a software shipped with your board
2. Write your own device driver
3. Use a commercial tools named WinRT from Blue Water Systems
4. Use shareware TVicHW32 for Delphi/BCBuilder/VB/C++
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question