CString UNICODE WriteFile problem...

Hi all,

I am trying to send command to a manchine via serial port.
I have created a serial port class called as CSerPort,and it has a function
SendString() as below. My problem is here that when i try to send a string
,such as "AT+X",  via this function,the machine does not respond. If i write
the command directly to the WriteFile function as a parameter;

....
..
if( (WriteFile(hCOMx,"AT+X",sCommand.GetLength(),&wWrittenBytes, NULL)) ==
NULL)
...
...

then it responds properly.

I have an ASCII version of this class and it works very well. I tried to
assign the sCommand to a ASCII variable,but the result was the same. Where
am i making mistake? Pls tell me.

Thanks...

The function is :

BOOL CSerPort::SendString(CString sCommand)
{
#ifdef _UNICODE
#undef _UNICODE

DWORD wWrittenBytes = NULL; //Bytes written

 //write to the port(iComPortNum)
 if( (WriteFile(hCOMx,sCommand,sCommand.GetLength(),&wWrittenBytes, NULL))
== NULL)
 {
 ......................
 }
 else
 {
........................
 }

#endif
}


0
2/3/2004 8:52:41 AM
vc.mfc 33608 articles. 0 followers. Follow

1 Replies
809 Views

Similar Articles

[PageSpeed] 55

Hi,

The problem itself is not clear from your message.
Are you trying to solve the UNICODE / ASCII issue ?

Anyway just try this...


f( (WriteFile(hCOMx,sCommand.GetBuffer(1024),sCommand.GetLength(),&wWrittenB
ytes, NULL))  == NULL)
{

}

Cheers
Jagadeesh


"feather" <feather1234@hotmail.com> wrote in message
news:e8yjXMj6DHA.2044@TK2MSFTNGP10.phx.gbl...
> Hi all,
>
> I am trying to send command to a manchine via serial port.
> I have created a serial port class called as CSerPort,and it has a
function
> SendString() as below. My problem is here that when i try to send a string
> ,such as "AT+X",  via this function,the machine does not respond. If i
write
> the command directly to the WriteFile function as a parameter;
>
> ...
> .
> if( (WriteFile(hCOMx,"AT+X",sCommand.GetLength(),&wWrittenBytes, NULL)) ==
> NULL)
> ..
> ..
>
> then it responds properly.
>
> I have an ASCII version of this class and it works very well. I tried to
> assign the sCommand to a ASCII variable,but the result was the same. Where
> am i making mistake? Pls tell me.
>
> Thanks...
>
> The function is :
>
> BOOL CSerPort::SendString(CString sCommand)
> {
> #ifdef _UNICODE
> #undef _UNICODE
>
> DWORD wWrittenBytes = NULL; file://Bytes written
>
>  file://write to the port(iComPortNum)
>  if( (WriteFile(hCOMx,sCommand,sCommand.GetLength(),&wWrittenBytes, NULL))
> == NULL)
>  {
>  ......................
>  }
>  else
>  {
> .......................
>  }
>
> #endif
> }
>
>


0
jagadeeshvn (256)
2/3/2004 6:05:35 PM
Reply:

Similar Artilces:

Problem with refreshing animated bitmap
Hello, I've got quite a problem with which I've been strugling whole day and can't pass through it. I've got a problem with OnPaint which doesn't work as it should be ( after trying countless samples from @groups, and various sites. Here's the code: void My_CMainWnd::OnPaint () { CPaintDC dc(this); dcMem->CreateCompatibleDC(&dc); CBitmap *pOldBitmap = new CBitmap; pOldBitmap = dcMem->SelectObject(myEng->TloBitmap); CRect rcClient; GetClientRect(&rcClient); myEng->BBitmap->DrawTransparent(dcMem,myEng->Balls->BCoordinates- >x,myEng...

CString
How can I covert argv[0] to LPCSTR? Hi, Shouldn't CString(argv[0]) do the trick? Sander Verhagen [ Verhagen@nonono.Sander.com ] "Oliver Young" <please@no.spam.com> wrote in message news:er3JuEogDHA.616@TK2MSFTNGP11.phx.gbl... > > How can I covert argv[0] to LPCSTR? > > > Shouldn't CString(argv[0]) do the trick? OK. And how can I convert CString into LPCSTR? I need LPCSTR. I need to convert from char** ( argv[0] ) into LPCSTR. Please, forget CString, and MFC if possible. > How can I covert argv[0] to LPCSTR? LPCSTR...

Copy And Paste problem ?
Hello, Using Excel 2007. Sure it's something I am doing wrong, but can't seem to figure out what. I do a Copy on two selected columns. The dashed outline shows up fine. But when I try to do a Paste to two other blank columns, as soon as I click on them, the dashed outline disappears, and there is (therefore) no Paste option. The column is about 500 rows long. What is really funny is that if I do a Copy of only 5 rows, e.g., it sometimes (but not all the time) will do the Paste. I have everything formatgted as "General" I have Protection in everything un-checked. Any ...

Calculating age problem
Greeting, I am trying to calculate the date different between two date with format ddmmyy to show the age and I am using the following function in unbounded textbox: =DateDiff("yyyy", [Birthdate], Now())+ Int( Format(now(), "mmdd") < Format( [Birthdate], "mmdd") ) When I put the above code in the sources control of the text box , there is a syntax error Can any body help me please? Since we're not there, it might help to know what the error message says ... "there is a syntax error" can cover a lot of issues... (By the way, your expres...

Unicode support
Hello, I'm trying to send an excel sheet in Franch and German threw a java application. However, special characters are displayed incorrectly. Does excel support unicode, and which type of it? Thanks. <nirpe@amdocs.com> wrote in news:db3501c3efda$82a0c870$a001280a@phx.gbl: > I'm trying to send an excel sheet in Franch and German > threw a java application. However, special characters are > displayed incorrectly. Does excel support unicode, and > which type of it? A little bit. I believe it uses UTF-16 internally. You may have to use an Asian version of E...

Click on link problems #2
When I click on a url link in email---a box opens saying "Open Link Browser". And also a browser window. How do I get rid of the smaller link browser? Read your reply on your post of the 17th? -- Robert Sparnaaij [MVP-Outlook] www.howto-outlook.com Tips of the month: -What do the Outlook Icons Mean? -Create an Office 2003 CD slipstreamed with Service Pack 1 ----- "Robin" <robinhood2@juno.com> wrote in message news:atmnk0pgs4m272iunkegt0rvq4ssjqisig@4ax.com... > When I click on a url link in email---a box opens saying "Open Link > Browser". A...

A Problem with Office 2003
There is a conflict between Word and Outlook that really "bugs" me. If Outlook is running Word will not run correctly. I hate having to shut down Outlook in order to use Word. For what it is worth, I can make the window smaller [minimize] but when Word is as big as it can get, there is space between the top edge of the window and the top of the display and the bottom of the window is out of sight at the bottom of the display. If you click & hold on the blue band on the top of the window, you cannot drag it up, down, or sideways; it is as if it is frozen. The only way to be...

complex problem
Hi all, I have four variables each with it's own column of data, all the same length. Each row will give me a new calculated value, say C5 = C1+C2+C3+C4 for example. Then I want to do a correllation function in C6 that compares C5 to data I already have and store that correllation number in an array. Then shift C1 down a row, recalculate C5, recalculate C6, store new correlation number Then shift C1 down another row, recalc, store Shift C1 down three times, then start shifting C2 down three times, then C3, then C4. I would love for this to happen in arrays becaus...

sending CString to CStatic label control from worker thread
I need to send a CString from a thread to a static label on the main dialog form. I think I have the thread working okay, but I am unsure how to send the CString to the dialog control. I have seen information on using PostMessage and SendMessage, but I don't really understand how to use these functions. Obviously I can't do like I tried below and I can't get a pointer to the control from the thread function, so just how do I say send the word "hello" to the SetWindowText() function of the label control on the dialog form. I have looked on the Internet and in se...

Public Folder Problem #2
Had three Exchange servers, 1, 2 and 3. All 5.5 with most recent SP running on Win 2K. 1 was and still is the primary 2 went away and was in it's own site (site connector to 1) 3 is a new and in the same site as 1 Followed the white paper on moving an Exchange server from one site to another. Moved all the public folders from 2 to 1 and removed the replicators. I feel like I should be providing more info here but that was pretty much all there was to it. Everyone with proper permissions can see all the Public Folders, including the ones from the old site that had been moved. However, i...

MS Groove problem
Hi all, my computer crashed and i had to install a new hard drive. I've reinstalled Groove but had to create a new "participant" user account. It now shows my old account(manager) as Offline and asks me to verify the name conflict. I'm using Groove over shared computers vs an enterprise. How do i get access or reinstate my original user account as manager? Guessing once i do, i would need to close the newly created user account. Thanks for the Help!!! ...

Access Versions Problem
Hi I have Access 2002 installed and when I create a new database the file format is 2000 Why is that? Samuel Dear Samuel: If you navigate to Tools>Options>General, you can set the default format to Access 2002-2003, if you like. The default format of Access 2000 was probably done to maximize compatibility. HTH Fred Boer "Samuel" <samuel.shulman@ntlworld.com> wrote in message news:uUlY8MerHHA.4100@TK2MSFTNGP06.phx.gbl... > Hi > > I have Access 2002 installed and when I create a new database the file > format is 2000 > > Why is that? > &g...

Security problem
I have a problem can't seem to figure out. I am an admin, and I'm having some security issues with the our exchange 2003 server only. I have no problems with our Primary Domain Controller (w2k3 std) or our gateway server running ISA 2004 (w2k3 Std). From my XP workstation, if i try to remotely manage the Exchange server (via right click 'my computer'->manage->Action->connect to another computer) the mmc console comes up but if I try to review the event logs, or access the services list, or anything for that matter... I get an access denied error. If I remote desktop...

phone textbox default value problem
I have a phone field and I have a default area code set and when I tab to the field the area code is highlighted and I have to click off of it to enter data. How can I have it so when I tab to the field I can immediatly start typing the phone number after the area code? If the area code is different than the default I figure I could just back space and change it. 90% of the time the default will be correct. I have the input mask as !\(999") "000\-0000;0;_ and the default value as (916), I am leaving the formatting info in because I have to import the data and it has the...

Problem with Event handling in a custom control
Hi, I am building a GUI which uses the same combination of controls at multiple locations. For example, it has a custom gauge. This has a progress bar, a button ( allows the user to display the peak/rms/ instantaneous value of the parameter) and a label displaying the value. All three controls are surrounded by a group box. This combination is used on multiple tabs. To make my job easier, I built a custom control. I am able to layout the controls correctly but I am facing a problem when trying to handle the button click events. As I am assigning the resource ID to the button on initializatio...

Tools/Options/Calculation/Auto Problem
Whenever I start a blank spreadsheet or a cvs spreadsheet in Excel2000 the calculation mode is always manual. I always have to go to Tools/Options/Calculation and click on the Automatics box. If I start Excel/2000, it comes up with a blank spreadsheet called book1.xls I've tried saving the blank book1.xls in the windows/applications data/microsoft/excel directory as book1.xls with the Automatic box checked. But after I save the book1.xls in that directory and close Excel, when I start Excel again it comes up with a blank spreadsheet called book1.xls but the calculation mode is set to M...

CString (again)
I have a class: class TestClass{ public: TestClass(){}; virtual ~TestClass(){}; BOOL CalcArea(double * pArea); void ReversePoints(); void OrderFromLowest(); std::vector<CoordinateClass> Pts; double OrientationType; BOOL XFlip; BOOL YFlip; double LTilt; double RTilt; double Buffer; int Style; CString Name; }; Now when I go like this: TestClass * pNew = new TestClass; pNew->Name = "anything in here will cause an error"; At runtime i get an unhandled exception which is comign from CString::AssignCopy() How do i fix this? Can't seem to reproduce this ...

CRM Installation Problem
Attempting to install CRM 3.0 on SBS system. Receive the following error while running the Diagnostic Wizard: Microsoft CRM Server User Input The organization unit does not exist. I haven't found any references in KB articles or in the CRM installation docs pertaining to this. So, what organizational unit is the diagnostic wizard looking for, and how do I resolve this??? thanks. ...

problem with <restriction>
Greetings. Below is the schema snippet I am trying to explore attributegroups and attribute's use property. However I am getting a validation error saying "undefined value for base encountered", pointing to <xs:restriction>. Please help. <?xml version="1.0" encoding="UTF-8"?> <xs:schema elementFormDefault="qualified" attributeFormDefault="unqualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:attributeGroup name="grp"> <xs:attribute name="x" type="xs:string"/>...

Printing Problems #5
Hi there I have a problem with Excel. Everytime i print the print out is not the same as the print preview. The alignment is totally out. I have printed the same document from a laptop and matched up the settings exactly but the error still persist. I have printed with differnet PC and it has the same problem, but there is one PC the Prints perfectly. Is there a setting for adjusting the alignment for only one section of Excel. Or is it the printer that is causing problems. Without knowing any of the real specifics, I'd guess it was a variation of the printer or printer driver. Ca...

std::string vs Cstring
Hello, I have recently been encouraged to utilise String classes, as opposed to C type char arrays due to some difficulty debugging some buffer overflows. I have looked into std::string and CString, but what are the benefits and drawbacks? The main problem I have is that I do a lot of data formatting using sprintf, for which I see no substitute using std::string, - MR On Thu, 30 Dec 2004 23:25:21 -0000, "Mark Randall" <strike@rapiercom.freeserve.co.uk> wrote: >Hello, > >I have recently been encouraged to utilise String classes, as opposed to C >type cha...

Outlook 2003 Printing Problem #2
I am using OUtlook 2003 and cannot print my emails. Can somebody help. Thank You, Lori what happens when you try? -- Diane Poremsky [MVP - Outlook] Author, Teach Yourself Outlook 2003 in 24 Hours Need Help with Common Tasks? http://www.outlook-tips.net/beginner/ Outlook 2007: http://www.slipstick.com/outlook/ol2007/ Outlook Tips by email: dailytips-subscribe-request@lists.outlooktips.net Outlook Tips: http://www.outlook-tips.net/ Outlook & Exchange Solutions Center: http://www.slipstick.com Subscribe to Exchange Messaging Outlook newsletter: EMO-NEWSLETTER-SUBSCRIBE-REQUEST@PEACH.E...

Macro problem
Hi, I have a spreadsheet for keeping track of my golf scores. The spreadsheet uses a macro for copying the scores to a database sheet and to a statistics sheet. When running this macro the process fails on the statistics sheet. It involves copying 2 matrices from the scorecard sheet to the statistics sheet. If I uninstall the security updates for Excel 2007 in Windows 7 the spreadsheet works like a charm. I usually just removes all excel updates and unchecks updates for excel in Windows Update. However, now I have this update, that keeps installing itself after a reboot (KB982308). I ...

Server maintenance
Greetings: I've recently installed an Exchange 2k3 Server and was wondering what kind of maintanence needed to be performed and at what intervals to keep the server in tip - top shape. We have less than 20 users and some even hook up through POP3. Let me know if I can provide additional information. -- Regards, Jerry M. Gartner There really shouldn't need to be any periodic maintenance. There are your standard monitoring tasks that need to take place (check event logs, etc.), but Exchange performs online maintenance on a nightly basis by default. This optimizes th...

CRM Router Problem / Verification
When I browse to the http://crmex:80/MSCRMConnector/ICrmEmailDispatch.SRF file (mailserverurl on the CRM server), the following message is displayed in the browser? {{handler "C:\PROGRA~1\MICROS~4\MSCRMC~1 CrmEmailDispatch.dll"/CrmEmailDispatch}} Is this correct? If not, please tell me what should happen. I've been through every email post in here and still cannot send messages from CRM. The associated Event Log message when trying is: Event Type: Error Event Source: Microsoft CRM Event Category: None Event ID: 2 Date: 2/22/2004 Time: 2:42:55 PM User: N/A Comput...