[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
CppComPort

(C++) Access the COM port

When you use Microsoft's Visual C++ check this link: http://msdn2.microsoft.com/en-us/library/aa363195.aspx

You might also use assembler code:

//When you have a LED soldered between GND and DTR this will cause it to flicker.
//A speaker will create a high pitched tone
int main()
{
  while(1)
  {
    //Write 0 to register 4
    asm
    {
      mov dx, 0x3FC //Write to index 4
      mov al, 0     //The value 0
      out dx,al
    }
    //Write 1 to register 4
    asm
    {
      mov dx, 0x3FC //Write to index 4
      mov al, 1     //The value 1
      out dx,al
    }
  }
  return 0;
}


Reading one of seven registers (I know the code is not beautiful or so, so please post a better solution ):
int readRegister(const int& reg) const
{
  char myVal = 0;
  if (reg==0)
  {
    asm
    {
      mov dx, 0x3F8 + 0
      in al, dx
      mov myVal,al
    }
    return myVal;
  }
  if (reg==1)
  {
    asm
    {
      mov dx, 0x3F8 + 1
      in al, dx
      mov myVal,al
    }
    return myVal;
  }
  if (reg==2)
  {
    asm
    {
      mov dx, 0x3F8 + 2
      in al, dx
      mov myVal,al
    }
    return myVal;
  }
  if (reg==3)
  {
    asm
    {
      mov dx, 0x3F8 + 3
      in al, dx
      mov myVal,al
    }
    return myVal;
  }
  if (reg==4)
  {
    asm
    {
      mov dx, 0x3F8 + 4
      in al, dx
      mov myVal,al
    }
    return myVal;
  }
  if (reg==5)
  {
    asm
    {
      mov dx, 0x3F8 + 5
      in al, dx
      mov myVal,al
    }
    return myVal;
  }
  if (reg==6)
  {
    asm
    {
      mov dx, 0x3F8 + 6
      in al, dx
      mov myVal,al
    }
    return myVal;
  }
  assert(!"Should not get here");
  return 0;
}


'COM Port' links

External links



last edited (May 1, 2007) by bilderbikkel, Number of views: 4550, Current Rev: 9 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.