Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / June 2006

Tip: Looking for answers? Try searching our database.

basic language chr$

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
joshua siew - 02 Jun 2006 06:10 GMT
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....
Carl Daniel [VC++ MVP] - 02 Jun 2006 06:22 GMT
> 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
joshua siew - 02 Jun 2006 08:18 GMT
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);
        }

> > simple...what does basic chr$ used in visual c++ ????
> > i need to send chr$(5) to serial port/comm port but using visual c++
[quoted text clipped - 16 lines]
>
> -cd
David Anton - 02 Jun 2006 18:20 GMT
safe_cast<System::Char>(5)
(via our Instant C++ VB to C++/CLI converter)
Signature

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

> 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....

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.