473,408 Members | 2,009 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,408 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 3455
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.