View Full Version : PPL online help
David Chua
10-02-2006, 10:25 AM
Hi,
I notice that there isn't any info pertaining to Event, Serial communication in the help system. As I'm doing quite a bit of serial port programming I would appreciate if someone could tell me about serial comms event on receiving data within a "form" environment.
I've created a test program for this purpose, I can transmit data without any problem however, I have no idea how to create an event driven function for receiving data from the serial port while the main program is doing something.
Please help looking into the attach file and provide your kind assistant.
Thanks and Warmest Regards.
David Chua.
David Chua
10-02-2006, 11:42 AM
Sorry, the attach file did not get through with the previous message. Here it comes... [br]1159785734_33_FT483_term.zip
kornalius
10-02-2006, 08:30 PM
Hi David,
I think your best bet is to create a timer that will check every 100 ms let's say for input chars from the port.
In your WM_TIMER message put something like this:
// Wait for characters from port
new(event$, TInt);
if (GetCommMask(p$, EV_RXCHAR))
s$ = "";
// Read from port
new(iBytesRead$, TInt);
new(Buffer$, TByte);
repeat
ReadFile(p$, &Buffer$, 1, &iBytesRead$, NULL);
s$ = s$ % Buffer$;
until (BytesRead$ == 0);
// s$ will contain the whole buffer received
end;
You can create a new timer using the following:
SetTimer(hWnd$, 3000, 100, NULL);
This will create a timer for form hWnd$ with an ID of 3000, it will be triggered every 100 ms.
You will have to check the ID in the WM_TIMER message with the following:
if (wParam$ == 3000)
end;
If you want to disable the timer just do this:
KillTimer(hWnd$, 3000);
David Chua
10-03-2006, 12:57 AM
Thanks, will try out.
Cheers.
David Chua
10-03-2006, 09:41 AM
Hi,
I've tested with your recommendation and found that the statement:"if (GetCommMask(p$, EV_RXCHAR))" doesn't seems to work, the timer interrupt works fine. When I remove the above mention line, I can see data reading from port (forced read, if you know what I mean).
I'll continue to explore, I may want to suspect that the statement "SetCommMask" having some problem! The chip (the hardware itself) or the low level driver could not update the EV_RXCHAR bit. Thanks anyway, will work further.
By the way, this is the part I've put in:
WM_TIMER:
wmId$ = loword(wParam$);
wmEvent$ = HIWORD(wParam$);
case(wmId$)
3000:
// Check if characters available at port
if(GetCommMask(p$, EV_RXCHAR))
// Read existing data
rx$ = GetText(EDIT_Rx$);
// Read from port
new(iBytesRead$, TInt);
new(Buffer$, TByte);
repeat
ReadFile(p$, &Buffer$, 1, &iBytesRead$, NULL);
rx$ = rx$ % chr(Buffer$);
until(iBytesRead$ == 0);
// rx$ will contain existing + new data received
SetText(EDIT_Rx$, rx$);
return(ok$);
end;
Cheers.
kornalius
10-03-2006, 11:41 AM
Try to MSDN the function GetCommMask for more information. Maybe EV_RXCHAR is not what is needed. I don't have a serial port device to test with so it's really hard for me to tell you exactly what is needed. If you have more questions, please keep this thread going, having 100% working RS232 communication with PPL would be awesome.
David Chua
10-03-2006, 12:06 PM
OK, will try that further. I've got most of the info from MSDN earlier. I'll publish the program once I've finish the debugging, maybe someone else might be interested in serial port programming.
Cheers.
David Chua
10-03-2006, 02:10 PM
Initial conclusion: Serial port programming issue.
It doesn't work by checking the "GetCommMask" function. I check the port buffer instead and here is how I do:
WM_TIMER:
wmId$ = loword(wParam$);
wmEvent$ = HIWORD(wParam$);
case(wmId$)
3000:
// Check if characters available at port
new(iBytesRead$, TInt);
new(Buffer$, TByte);
ReadFile(p$, &Buffer$, 1, &iBytesRead$, NULL);
if(iBytesRead$)
rx$ = GetText(EDIT_Rx$);
rx$ = rx$ % chr(Buffer$);
repeat
ReadFile(p$, &Buffer$, 1, &iBytesRead$, NULL);
rx$ = rx$ % chr(Buffer$);
until(iBytesRead$ == 0);
// rx$ will contain existing + new data received
SetText(EDIT_Rx$, rx$);
return(ok$);
end;
A bit more work though but works, at lease for this initial stage. I'll still be finding out how to use "event" for serial port receiving. I've attach the file for those who are interested in serial port programming. Do let me know if you have better method of serial programming with PPL.
Cheers.[br]1159881052_33_FT483_term.zip
kornalius
10-03-2006, 03:15 PM
It will be hard to be simpler unless we write a library for it with simplified functions for users. This is how Windows does it, it's hard to do it differently.
When you are done and your program is working good, let me know and send me the code, I will try to put together a library with simplified PPL functions to include in future releases.
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.