473,230 Members | 1,524 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,230 software developers and data experts.

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 3447
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Danny | last post by:
Hi all, I would like to write C++ code and call it from VBDOS, or even QB 4.5 or PDS 7.1, including plain-type parameter passing. My C/C++ compiler is MS-C/C++ v8.00c, and I have VBDOS...
28
by: Intermouse | last post by:
I have recently purchased an aspi wrapper control for vb. I haven't had much experience with hex and memory addresses and that's my problem. The piece of code that baffles me is: With ASPI1...
2
by: paddy_nyr | last post by:
I converted an Access 97 db to Access 2002 db and I now get the following error message when I try and run a query. Thanks Here's my query. SELECT DISTINCTROW tblCo_Info.Co_id, & Chr(13) &...
5
by: Christian Blackburn | last post by:
Hi Gang, I would like to use a caesar cipher on the mailto: links in my website to prevent crawlers from farming the e-mails off my site. Can someone tell me the equivalents to Chr() and Asc()...
9
by: me | last post by:
I am working as an intern at a place using Access 2003 code builder. Looking at the cold of the old project t(hat we are redoing), I see Chr(39) Chr(91) Chr(45) Chr(93)
97
by: Master Programmer | last post by:
An friend insider told me that VB is to be killled off within 18 months. I guess this makes sence now that C# is here. I believe it and am actualy surprised they ever even included it in VS 2003 in...
28
by: Randy Reimers | last post by:
(Hope I'm posting this correctly, otherwise - sorry!, don't know what else to do) I wrote a set of programs "many" years ago, running in a type of basic, called "Thoroughbred Basic", a type of...
10
by: Esmael | last post by:
Hi to all, /*****************************/ OS-WIn XP SP2 VB6 SP6 /*****************************/ Is their anyone who can help me with this: Source code written on VB6.
2
by: ozipos | last post by:
I am trying to print text to a docket printer with the following command printer.print "trying to print" but I keep getting an error. Actually I want to print special keys so that the cah draw...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.