- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I have two different problems. I am trying to get data from a measuring device connected to a com port. It came with an original software which runs at the command prompt and spits out the data. I am trying to replace that with a CVF6.6 program that other than collecting the data also does other things with it.
So far I have been able to successfully capture the data with CVF except that when I first start up my laptop. I have to start that consle program and quit it by pressing Control C. After that my application runs fine.
So I believe my program does not do some initialization of the com 1 port that the console app does. Can anyone guess what that could be.
My code uses
SPORT_SET_STATE(1,19200,0,8,1)
SPORT_CONNECT(1,0)
SPORT_READ_LINE
and once done reading the data it does
SPORT_CANCEL_IO(1)
and SPORT_RELEASE(1)
If anyone can point out what else is required for the proper initialization, that would be very helpful.
2. I thought of a way out by launching the console application prior to my data collection and terminating it. So I have used ShellExecute and the console application can be launched. To kill it I need to press Control C and I want to do that keystroke programatically.
So I invoked
iret=SendMessage(NULL,WM_IME_KEYDOWN,VK_CONTROL,0)
and
iret=SendMessage(NULL,WM_IME_KEYDOWN_VK_C,0)
The compiler gives me an error saying VK_C does not have a type and must have an explicit type. It does not give any error for VK_CONTROL or VK_RETURN.
Is there something I am doing wrong and also what is the procedure to emulate a Cntrl+C keystroke.
Also is there another way of killing a process automatically that has been started with Shell Execute.
Thanks for any help.
Sumit
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm not familiar with serial port communications and SPORT routines. However, there's also SPORT_SET_TIMEOUTS which seems relevant.
I assume you have1) ran the console application and 2) called SPORT_GET* from a test app to retrieve the settings, then 3) copied these into your SPORT_SET* settings, right?
Having the settings appropriately set via SPORT_SET is of course better than cludge with Ctrl+C. However:
1) You cannot SendMessage to a console application, especially not with first parameter null 2) even if it were a GUI app, it should be WM_KEYDOWN, not WM_IME_KEYDOWN
You need keybd_event or SendInput API instead, which really simulates keyboard strokes:
interface subroutine keybd_event(i1,i2,i3,i4) !dec$attributes stdcall, decorate, alias: "keybd_event":: keybd_event integer:: i1, i2, i3, i4 end subroutine end interface call keybd_event(VK_CONTROL, 0, 0, 0) call keybd_event(IACHAR("c"), 0, 0, 0) call keybd_event(IACHAR("c"), 0, KEYEVENTF_KEYUP, 0) call keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0)
IACHAR is obviously the missing chain -- VK_virtual-keycodes for alphabetic characters are equal to ASCII codes.
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Jugoslav,
Your comment about get_sport_state got me thinking and I found that my iresult value on set_sport_state was non zero indicating an error. Then I realised that the set_sport_state should be invoked after SPORT_CONNECT and not before.
Now everything works fine.
Thanks for leading the thought process.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page