basic language chr$

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

simple...what does basic chr$ used in visual c++ ????
i need to send chr$(5) to serial port/comm port but using visual c++
language...

thanks in advanced....
 
joshua said:
simple...what does basic chr$ used in visual c++ ????
i need to send chr$(5) to serial port/comm port but using visual c++
language...

thanks in advanced....

In C and C++ char is an integer type so...

char ch = 5;

is legal, and is the same value as chr$(5) in Basic.

Note that this is different from

char ch = '5';

which is also legal, but is a different character value: the value 53 in
ASCII or Unicode, where the other example is, of course, the value 5.

-cd
 
dear cd,
so how does I send this string to the comm port....

"<ENQ>02FFTT1ABCDE07"

and since this string is a PLC command there will be repond from the PLC if
this is send successfull. The PLC device Receive Data indicator stated it's
received but no respond??!???!! definately need help....below is my code.

//this is where I pass the data....
m_CommPort->Write( Encoding::ASCII->GetBytes(ch) );
m_CommPort->Write( Encoding::ASCII->GetBytes ("02FFTT1ABCDE07" ) );


Below is my class funciton....

// This function writes the passed array of bytes to the
// Comm Port to be written.
System::Void Write(Byte Buffer[])
{
DWORD iBytesWritten, iRc;

if (mhRS == (HANDLE)-1)
{
throw new ApplicationException(S"Please initialize and open port before
using this method");
}
else
{
// Transmit data to COM Port
if (meMode == Mode::Overlapped)
{
// Overlapped write
if (pHandleOverlappedWrite(Buffer))
throw new ApplicationException(S"Error in overlapped write");
}
else
{
// Clears IO buffers
PurgeComm(mhRS, PURGE_RXCLEAR | PURGE_TXCLEAR);

// Convert name from String to Ansi char string
System::Text::ASCIIEncoding* encoder = new System::Text::ASCIIEncoding();
Byte __pin* abytes = &Buffer[0];
iRc = WriteFile(mhRS, (char*)abytes, Buffer->Length, &iBytesWritten, 0);
if (iRc == 0)
{
String* strErr = String::Format(S"Write Error - Bytes Written {0} of
{1}", iBytesWritten.ToString(), Buffer->Length.ToString());
throw new ApplicationException(strErr);
}
}
}
}

// This function writes the passed string to the
// Comm Port to be written.
System::Void Write(String* Buffer)
{
System::Text::ASCIIEncoding* oEncoder = new System::Text::ASCIIEncoding();
Byte aByte[] = oEncoder->GetBytes(Buffer);
this->Write(aByte);
}
 
safe_cast<System::Char>(5)
(via our Instant C++ VB to C++/CLI converter)
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter
 
Back
Top