|
My assignment is to write an interface sending 16-byte command messages and receiving 54-byte response messages at 230.4 Kbaud down two RS422 buses. At one time I considered bit-banging the interface on an 8-bit 8051-family microprocessor. Now I'm trying to do it in Visual C++ .NET. It will run on a laptop running Windows XP, using the Quatech DPS-200/300 Dual Channel RS-422/485 PCMCIA Asynchronous Adaptor, connected to a external device manufactured by another company.
I've been reading MSDN documentation for days. Searching for RS-422 leads me to documentation about CIM, WMI, MOF, file and directory I/O, and other things that have no direct bearing on my assignment. Trying to mine small nuggets of useful information out of these reams of documentation is worse than trying to learn multithreading from just the MSDN documentation (which I just did).
I need a simple (perhaps over-simplified, or even simplistic) instruction on how to create/establish/connect to the communication resource, transmit messages at specific times, receive messages, and terminate everything before shut down. I don't need to know how to use Windows Management Instrumentation to establish an enterprise environment--this is low-level I/O to an ad-hoc device. My software will me installed on two, maybe three systems throughout it's entire lifecycle.
At one time I thought I would need Windows CE or XP Embedded (along with something like TenAsys's or VentureCom's RTX real-time extensions), because my system has about 900 microseconds from receipt of a response message to begin transmitting the next command message. I may need these things anyway, since the worst-case scenario has that time down to 36.1 microseconds.
Norman Hines
Jacobs Sverdrup Naval Systems Group
|
|
|
|
|
Norman Hines wrote:
I need a simple (perhaps over-simplified, or even simplistic) instruction on how to create/establish/connect to the communication resource, transmit messages at specific times, receive messages, and terminate everything before shut down.
Serial ports are opened using CreateFile(), specifying "COMx" as the filename, where x is the number of the COM port. Reading, writing is done using ReadFile(), WriteFile() and CloseHandle() as for normal files.
As for sending messages at specific times, I don't know what the best way would be, especially with sub-millisecond performance required. Windows is notorious for having dodgy, inaccurate timing at best. A sleep for a single millisecond can last upwards of 20ms depending on system load. If you need a round-trip response time of 36.1us, the only way forward using Windows (that I can see) would be to use a realtime enviroment such as VentureCom's RTX extensions that you mentioned.
However, you could have a look at the performance counters or the multimedia timers. They may be able to cope with the timing precision required under low system load, but if other applications preempt your application, there's really nothing you can do about it. Even increasing your process' scheduler priority may not be enough.
Hope this helps,
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
The very first thing stops me dead. CreateFile's first parameter is a pointer to the name of the port to be opened. What name do I use for a PCMCIA card slot? Is it "PCMCIA1"? Or is it some kind of COM port, and I just need to look up the number?
BTW, I'm getting a jump on the software development on a computer without the PCMCIA hardware, while I wait for the ordered equipment to arrive.
Norman Hines
Jacobs Sverdrup Naval Systems Group
|
|
|
|
|
RS422 is simply an RS232 port with differential electrical signalling. It's still a serial port like any other. You just need to find the correct COM port number and it should all work OK.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
For my RS422, I'll be using a 2-port RS-422/485 serial PCMCIA card, inserted into the PCMCIA port on the side of a laptop. Are you telling me that this PCMCIA card slot is accessed as a COM port? Were would I find out which COM port (or ports!) they are? Is this defined in the hardware? Do I call up Dell and ask them into which COM port they wired the PCMCIA card slot? Do I wait until I have the laptop itself and experimentally test "COM1" through "COM9" until I find the right one?
Norman Hines
Jacobs Sverdrup Naval Systems Group
|
|
|
|
|
Norman Hines wrote:
Are you telling me that this PCMCIA card slot is accessed as a COM port?
No. The card driver will make the ports appear as though they were individual serial ports. It makes no difference if it's PCI, PCMCIA, ISA, USB etc... The difference in architecture is abstracted by the driver that comes with the card. All you need to worry about is which serial port number Windows associates with the physical ports.
Norman Hines wrote:
Were would I find out which COM port (or ports!) they are?
Unfortunately, there isn't a way that I know of. AFAIK, you'll need to rely on a configurable option that the user can set to input the correct one to use. WMI might be able to associate the COM port number with the PCMCIA card information, but I haven't used WMI before so I'm not sure.
Norman Hines wrote:
Do I wait until I have the laptop itself and experimentally test "COM1" through "COM9" until I find the right one?
Yep. Sounds stupid, doesn't it? Windows allocates port numbers first-come-first-serve. So if you add a new serial port and you have COM1 and COM2 already, the new one is COM3, no matter where it gets added.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Hi guys
I have developed one appication in which I have used many array variables and also used malloc and calloc functions to reserev memory and also tried to free all the memory. But because of some bug in it. After certain long time my application stops running. And if i see in Task Manager it shows all memory used.
So I want to debug my application putting some debug statement in file or some statements through which I can get the exact memory at perticular sentence. Is there any such function which gives currently used memory or something which can help me...
Regards
Mahesh
|
|
|
|
|
Hi Mahesh..
I am not sure about the code part, but I am sure that if you can patiently go through your code, then 80% of your problem will be solved. Just remember that every time you use malloc, make sure that you are using calloc somewhere for that particular pointer.
Regards
Mahadevan
|
|
|
|
|
Hi, I am trying to understand a C/C++ concept with pointers.
I have a function that expects a LCPSTR.
If I hard code a statement such as
LCPSTR temp = "213234";
it works great.
However I have a char array I would like to
use for this value that is input from a user. How can I convert
a char array to a LCPSTR type?
Is this a valid approach?
___
CHAR bob[25];
//...put something in bob - like "123456"...
LCPSTR temp2 = (LCPSTR) &bob[0];
Then pass temp2 to the function that requests a LCPSTR?
Will that only grab the first item ("1") in the array or all of it ("123456")???
____
I'm not sure if I have made sense.
In general - what do you do when you have a char array or char *
and a function is asking for a const char * ? How do you make that conversion?
|
|
|
|
|
rtb333 wrote:
In general - what do you do when you have a char array or char *
and a function is asking for a const char * ? How do you make that conversion?
In C/C++ arrays are very similar to pointers. You don't actually have to convert anything in this case. The following code will work without problems:
CHAR bob[25];
LPCSTR temp2 = bob; Also, you can pass a char* to a function requiring a const char* without converting anything.
Hope this helps,
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Hi,
My SDI mfc program opens up an external ansi c++ program using shellexecuteex. The user opens a dialog in the mfc program, sets parameters for the external program, and clicks go. This works fine, and the external program opens up in a command prompt window, runs, then closes its window.
I would like to display the contents of the command prompt window inside the dialog with which the user set parameters for the external program. Ideally the output of the external program would appear in an edit box or static text on the dialog itself. This is just to improve the aesthetics of the mfc program and give it a more integrated look and feel.
Does anybody know if this is possible?
Thanks!
Mick
|
|
|
|
|
|
Hi,
I am working on an MDI application and derived a class CDrawView from CFormView because I need the inherent dialog template for displaying an ActiveX control. I go into the dialog resource, and insert an ActiveX control then add a member variable for it in the class wizard. This automatically adds the DDX_Control line to DoDataExchange.
void CDrawView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDrawView)
DDX_Control(pDX, IDC_NTGRAPHCTRL1, m_graphCtrl);
//}}AFX_DATA_MAP
}
However, no matter what ActiveX control I insert, it always indicates that hWndCtrl == NULL.
HWND CDataExchange::PrepareCtrl(int nIDC)
{
ASSERT(nIDC != 0);
ASSERT(nIDC != -1); // not allowed
HWND hWndCtrl;
m_pDlgWnd->GetDlgItem(nIDC, &hWndCtrl);
if (hWndCtrl == NULL)
{
TRACE1("Error: no data exchange control with ID 0x%04X.\n", nIDC);
ASSERT(FALSE);
AfxThrowNotSupportedException();
}
m_hWndLastControl = hWndCtrl;
m_bEditLastControl = FALSE; // not an edit item by default
ASSERT(hWndCtrl != NULL); // never return NULL handle
return hWndCtrl;
}
Anyone have any ideas why it might be doing this? Perhaps I'm not doing this properly. This control works in a regular dialog.
Thanks in advance!
|
|
|
|
|
Hi,
Just a bit of important information which I didn't think was relevant before.
My app also uses a COM server for some services. In my MFC app class's InitInstance I set the thread model. When I comment this out the ActiveX controls seem to work, but then I can't connect to the COM server.
BOOL CNFITGuiApp::InitInstance()
{
::CoInitializeEx(NULL, COINIT_MULTITHREADED);
.........
I understand that ActiveX and COM are very related. And this may be why commenting the threading model assignment will work.
Thanks.
|
|
|
|
|
Hello can somebody please provide me an example written in any language(preferably C++) that shows how to use overlay mode? Like winamp's AVS plugin does. Thanks!
|
|
|
|
|
char SystemDir[255] = {0};
GetSystemDirectory(SystemDir, sizeof(SystemDir));
|
|
|
|
|
Can someone please tell me why the following code is causing an access violation. I am using WTL 7.1
int DrawImage()
{
using namespace Gdiplus;
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
WCHAR ImgFile[] = L"C:\\test\\test.bmp";
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
Image* img = new Image(ImgFile, 0);
Font myFont(L"Arial", 16);
PointF origin(0.0f, 0.0f);
SolidBrush blackBrush(Color(255, 0, 0, 0));
WCHAR string[] = L"This is a test";
Graphics g(img);
g.DrawString(string, -1 , &myFont, origin, &blackBrush);
// Get the class identifier for the BMP encoder.
CLSID bmpClsid;
ZeroMemory(&bmpClsid, sizeof(bmpClsid));
GetEncoderClsid(L"image/bmp", &bmpClsid);
img->Save(L"C:\\test\\test1.bmp", &bmpClsid);
GdiplusShutdown(gdiplusToken);
return 0;
}
int CWTLTestView::GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
unsigned int num = 0; // number of image encoders
unsigned int size = 0; // size of the image encoder array in bytes
Gdiplus::GetImageEncodersSize(&num, &size);
if(size == 0)return -1;
Gdiplus::ImageCodecInfo* imageCodecInfo = new Gdiplus::ImageCodecInfo[size];
Gdiplus::GetImageEncoders(num, size, imageCodecInfo);
for(unsigned int i = 0; i < num; ++i)
{
if( wcscmp(imageCodecInfo[i].MimeType, format) == 0 )
{
*pClsid = imageCodecInfo[i].Clsid;
delete [] imageCodecInfo ;
return i;
}
}
delete [] imageCodecInfo;
return -1;
}
Forever Developing
|
|
|
|
|
What line is causing the AV?
|
|
|
|
|
After it leaves the the function. It happens after the function exits. The debugger breaks in
gdiplusgraphics.h
~Graphics()
{
DllExports::GdipDeleteGraphics(nativeGraphics);
}
Thanks Nick
Forever Developing
|
|
|
|
|
Fixed my own problem need to free the Graphics, Font, Brush object before calling shutdown.
Forever Developing
|
|
|
|
|
I'm using Visual C++.net 2002. How do I setup up the file path so that the program knows to go to the system32 folder for any Windows OS. Right now I'm tell it where to look for my OS "Win 2000 pro". But if I install it on another machine with XP. Folder paths are different. Thanks for any help.
("C:\\WINNT\\system32\\ARMSettings.ini");
|
|
|
|
|
Try
System.Environment.GetFolderPath(SpecialFolder.System)
Forever Developing
|
|
|
|
|
|
Hello guys/girls
I have one project that will appritiate coments and tips from you how to make it.This project is for gaining extra points for my Security course.
The project is made of 2 parts.
First part to make a script in perl (cgi) and upload to the website ,where the scripts only has one field asking for password (only 3 digits), if the correct password is entered then it gives you success and failed if you don't enter the correct password.
I have made that script and uploaded but the hardest part is comming ...
The second part of the project is to make a VC++ application that will connect to that site and will run all 1000 combination (000-999) and gives me back the correct password(where the site will return success).I know that this is not so hard to do it but i am newbie in windows programming.
I have been studing only C++ (not VC++) and i will appritiate some guideness and tips/tutorials to get the extra points on my course !
Thanks in advance
Two beer or not two beer
|
|
|
|
|
You can use this[^] article to create a little C++ class that will connect to the site and try to login with a user-specified password. It's a simple matter of exercising the object in a loop to cover all 1000 combinations.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|