|
How can I check if a device is connected to my serial port?
Using CreateFile on COM1 I can get a HANDLE to the file, but I don't know how to use that to tell if something is actually connected.
Thanks!
Kelly Ryan
|
|
|
|
|
Send some command to ur device. if it did not respond then its not working either connected or not connected.
-Prakash
|
|
|
|
|
The problem is that I know basically nothing about the device. I was hoping there was a generic WinAPI command or something that I could send to see if it was responding, like a ping or whatnot.
Kelly Ryan
|
|
|
|
|
but i am not sure if createfile will succeed if the device is not connected to the com port.
-Prakash
|
|
|
|
|
CreateFile should succeed as long as there is a COM port. The only problem you will have is if the COM port is already being used by another application. If it is, CreateFile will fail. If the COM port does not exist, CreateFile will fail.
What exactly do you want to detect is on the COM port and why?
8bc7c0ec02c0e404c0cc0680f7018827ebee
|
|
|
|
|
You have to get informations regarding the device connected to your COM port. Otherwise there is now way to detect the device is connected or not. But in case of USB device, u can get information of USB device connected without knowing the details.
|
|
|
|
|
This is just a guess, but does the following help:
OVERLAPPED ov = {0};
HANDLE hCom = CreateFile("COM1", ..., FILE_FLAG_OVERLAPPED, ...);
SetCommMask(hCom, EV_CTS | EV_DSR);
o.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
if (WaitCommEvent(hCom, &dwEventMask, &o))
{
}
"The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb
|
|
|
|
|
I was able to use this in a separate thread along with a timer to accomplish what I needed, thanks!
Kelly Ryan
|
|
|
|
|
Hi all,
I want to use __asm int 21h in the visual c++ but I can't.
How can I do that?
Please help me on this.
Thank you.
Every new thing you learn,Gives you a new personality.
|
|
|
|
|
|
dSolariuM wrote: I want to use __asm int 21h in the visual c++
What is that you want to do with that DOS interrupt? what service are you trying to use?
Windows has pretty much all the APIs that you could do with DOS interrupt 21h, Try that intead.
-Prakash
|
|
|
|
|
Are you running MSDOS? If not, you won't have much luck with INT21
We've moved beyond character mode screens and simple little disk structs.
Learn Win32 API
|
|
|
|
|
HI,
I need to read .doc,.xls,.pdf etc... file and then encrypt/decrypt the same but I am not able to read the file properly using CFile object.
How to read these files? what are the functions to read the same?
Any example if possible. I am not using Doc/View architecure. I am developing MFC Dialog based application.
Your help and time is much appreciated.
Thanks & Best Regards,
Mahesh
|
|
|
|
|
they are not text files, they are binary files, so, if you use fscanf() , cin or such basic functions, you'll get "strange" data.
search for any api provided with Office...
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]
|
|
|
|
|
Amarelia wrote: ...but I am not able to read the file properly using CFile object.
Why not?
"The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb
|
|
|
|
|
Hi,
Thanks for the reply,
I do it the following way...
CStdioFile fileToRead;
char * StringBlock = new char[64000];
fileToRead.Open(sCurrPath, CFile::modeRead | CFile::typeBinary, &feError);
nBytesRead = fileToRead.Read((unsigned short *)StringBlock, 60000);
The value of nBytesRead = 60000 after the last statement executes, but the StringBlock contains only few junk characters only. May be it encounters NULL or something like that which truncates it to only few chars. According to this the function reads the file correctly but the problem is in storing the data. I want to read maximum data possible at one go for the sake of my app's speed .
Please give appropriate solution.
Best regards and Thanks,
Mahesh
|
|
|
|
|
If the Read() tells you that it did read 60000 bytes, then that's the truth.
Your current problem is to display those bytes. Since most word processing files (all of them) contains a lot of binary information, your buffer is bound to have a lot of '\0'-chars.
Just trust nBytesRead.
|
|
|
|
|
You can get text from MS Office files by using COM, but this requires office installed.
Next, on new systems you can check IFilter interface - system uses it to index office files.
Finaly, you can use third party libraries. I can recommend http://www.wordcnv.com[^] - their libraries are very fast and support is the simply the best I have seen.
Igor Green
http://www.grigsoft.com/ - files and folders comparison tools
|
|
|
|
|
|
Hi,
i guess you need to go through automation please see any standard MFC book and you can sail through easily,reading of excelfile is most time consuming if they have large data ,if posible convert them to CSV ( if you can ) and then parse them as you do on a text file . actually you can convert all the above formats to text format and parse ,for that you need to CreateDispatch on the respective application object and ask them to save the coressponding data in text formats .
Regards,
FarPointer
|
|
|
|
|
I don't want to work with any afx_msg, I just want to test if the mouse button is clicked in the moment, something like if(GetKeyState(VK_SHIFT)&0x8000) function, but this is for keyboard using.
How can J do that,
Thank you
|
|
|
|
|
ZaebanB wrote: I just want to test if the mouse button is clicked in the moment...
Have you considered the WM_LBUTTONDOWN message?
"The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb
|
|
|
|
|
No, J don't want to catch any message.
|
|
|
|
|
Use GetAsyncKeyState .
Steve
|
|
|
|
|