468,321 Members | 1,825 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,321 developers. It's quick & easy.

basic language chr$

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....
Jun 2 '06 #1
3 3273
joshua siew wrote:
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
Jun 2 '06 #2
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);
}

"Carl Daniel [VC++ MVP]" wrote:
joshua siew wrote:
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

Jun 2 '06 #3
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

"joshua siew" wrote:
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....

Jun 2 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

28 posts views Thread by Intermouse | last post: by
9 posts views Thread by me | last post: by
97 posts views Thread by Master Programmer | last post: by
1 post views Thread by howard w | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.