|
Hello every1!
I am ecountering a problem trying to write data to a serial port (COM1).
The thing is, the same code works fine in Visual Studio 5...
Here is the code in problem:
<br />
char[] portName= "com1";<br />
osWrite1.hEvent=CreateEvent(NULL, TRUE, FALSE, NULL);<br />
if(osWrite1.hEvent==NULL)
MessageBoxW(L"Creating Write Event failed...", L"Failure",MB_OK|MB_ICONEXCLAMATION);<br />
<br />
hComm1= CreateFileA( portName, GENERIC_WRITE ,0,0,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,0); <br />
(CreateFile in VS5.0 was in fact CreateFileA, while in VS8 is CreateFileW, which takes another type for the first parameter)<br />
if (hComm1 == INVALID_HANDLE_VALUE)
MessageBoxW(L"CreateFile failed!Aborting...",L"Failure",MB_OK|MB_ICONEXCLAMATION);<br />
<br />
else {<setting baud="" rate,="" parity="" etc="">}<br />
</setting>
When running the code, the messageBox with "CreateFile failed! aborting..." appears. Any ideas what to do ?
Meanwhile I`m studying ways to do this using the modern way: using classes
Thanks!
Shpid3r
|
|
|
|
|
Permissions? Are you running as an Administrator, I think you have to be an admin in certain instances to talk to the serial port.
Otherwise does the port number exist?
|
|
|
|
|
I am logged in with administrator rights, and the port (Com1) exists.
The thing is that this part of code worked in a project built under VC++ 5.0 . Even now, if i build it, it doesn`t get stuck here... only my application...
|
|
|
|
|
try to use GetLastError API for find the exact error.
|
|
|
|
|
What information does GetLastError() give you?
|
|
|
|
|
|
shpid3r wrote: Any ideas what to do ?
Yes
TCHAR []portName =_T("COM1");
TCHAR portName[] =_T("COM1");
hComm1= CreateFile( portName, GENERIC_WRITE ,0,0,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,0);
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
modified on Sunday, April 13, 2008 6:14 PM
|
|
|
|
|
Uhm... I`m sorry, Pallini, but
TCHAR [] PortName = _T("COM1");
generates this warning:
warning C4091: '' : ignored on left of 'WCHAR' when no variable is declared
and subsequent errors:
error C2143: syntax error : missing ';' before '['
error C3409: empty attribute block is not allowed
error C2470: 'PortName' : looks like a function definition, but there is no parameter list; skipping apparent body
error C2059: syntax error : '='
I think you were trying to adapt the data type to the one CreateFile is waiting for... Well, I could use CreateFile(L"Com1"...) - which i`ve already tested - and it works... Still, the error remains.
|
|
|
|
|
You're right. Of course is
TCHAR portName[] = _T("COM1");
I've fixed my reply.
BTW your OP has that mistake too.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Because of the message Error (Access Denied), I`ve tried using COM2, instead. It works... I don`t know why COM1 isn`t available (I am not using any program which involves com1)... Anyway, the problem isn`t my piece of code.
Thanks for the suggestion on using GetLastError!
|
|
|
|
|
shpid3r wrote: char[] portName= "com1";
Should't this be:
char[] portName= "\\\\.\\COM1";
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
HEllO
I create program to encrypt a vedio file format (.avi),using AES algorithm , it was success to create the encrypt and decrypt file(both are avi too),but if I run the decrypted file it was played , if I run the encrypted file it was not played,,,,why??
Thanks in advance.....
The way of Professional softwares start in two:
Simple codes and develop it.
Simple but effective ideas.
|
|
|
|
|
ZaidIT wrote: if I run the encrypted file it was not played,,,,why??
You need to give more details about what your asking because at the moment I have created two possible conclusions in my mind as to your IQ level.
1.) Your possibly very intelligent and have built a new video encoder which converts standard AVI frames into a compressed/encrypted format. And your having trouble decoding the frames.
2.) You are possibly mentally deficient and incapable of ordinary reasoning.
So please clarify the context of your question so someone can form an appropriate answer.
Best Wishes,
-David Delaune
|
|
|
|
|
I am encrypting a video using AES...The file format that I am using is .avi.
In order to play the encrypted video I need to save the header information of the video before encryption to be able to display the video as a video format(.avi).and i am saving the 1st 56 bytes before encryption..
The problem is that the encrypted video is displayed as a video format(.avi) but its not playing..
I am getting error:- The file is corrupted and cannot play
I need to play the encrypted video...
The way of Professional softwares start in two:
Simple codes and develop it.
Simple but effective ideas.
|
|
|
|
|
Can I convert CStringW to CStringA?
Waiting 4 any help.
|
|
|
|
|
Yes. See for instance [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Hi,
How can i set/get a integer value from CEdit control?
|
|
|
|
|
Which version of VS are you using?
|
|
|
|
|
|
Right click on your Edit Box in "Resource Editor".
Choose "Add Variable" from the menu.
Assign a variable of type CString or int to it and define a name (e.g m_iVariable)
Click OK!
UpdateData(true) gets value from the edit box
UpdateData(false) sets it!
|
|
|
|
|
|
pther wrote:
How can i set/get a integer value from CEdit control?
Use SetWindowText() and GetWindowText() . See here for more.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
For set numbers you can use of SetDlgItemInt.
|
|
|
|
|
I need to convert CString to char in my project
below is my code
<br />
CString str="Test";<br />
char ch[64]<br />
strcpy(ch,str);<br />
that code work in VC6 but now I use VS2005 it show error about
"cannot convert parameter 2 from 'CString' to 'const char *'"
Please help me to solve this problem
|
|
|
|
|
You've already done it!
<br />
TCHAR *ch=str.GetBuffer();<br />
|
|
|
|