Event service routine
- Posted by Marijan Lopac <marijan.lopac1 at zg.hinet.hr> May 01, 2003
- 640 views
This is a multi-part message in MIME format. ------=_NextPart_000_000F_01C30FDC.D1E6C710 charset="iso-8859-1" Hello all, I have a problem with event service routine ! I implement = PCOMM.DLL(MOXA) library contributed from Kondor Attila and communication = with serial port work very well, but his pcomm.ew lack any event service = rutine . Down at bottom is help for C++ for creating event service = routine in case when terminator character is received. =20 After I successfully register event service with : sio_term_irq_=3Ddefine_c_func(Pcomm,"sio_term_irq",{C_INT,C_INT,C_INT}, = C_INT) global function sio_term_irq( integer port,atom TermIrq, atom code) ret=3Dc_func(sio_term_irq_,{port,TermIrq,code}) if ret=3DSIO_BADPORT then warnErr("Port is not opened in advance") end if if ret=3DSIO_WIN32FAIL then warnErr("Calling Win32 function failed") end if if ret=3DSIO_BADPARM then warnErr("Bad parameter") end if return ret end function sci_rup=3Dsio_term_irq( 1,??? , 59) ??? any number form 1 to 50 and return 0(SIO_OK) which mean event service enabled, after if = terminator character is received programm crash with message "EXW.EXE = generate errors . . . ". After that I don't now how to handle ( = possible with call_back but I don't now HOW ...) Language Syntax C/C++ int WINAPI sio_term_irq(int port, VOID (CALLBACK *func)(int port), = char code) Argument: port =3D COM port number func =3D event service routine entry If the func is NULL, it will disable this routine. code =3D terminator code Return: SIO_OK OK SIO_BADPORT Port is not opened in advance SIO_WIN32FAIL Calling Win32 function failed Call GetLastError to get the error code Example: C/C++ /* Define event service routine */ /* Recommend to declare this function as global function */ VOID CALLBACK TermIrq(int port) { } /* Enable event service routine */ ret =3D sio_term_irq( 2, TermIrq, 'A'); if (ret !=3D SIO_OK) { /* Fail */ } /* After event service routine enabled, TermIrq() will be activated = whenever terminator character is received. */ /* Disable event service routine */ ret =3D sio_term_irq( 2, NULL, 0 ); Manny farewell from = Croatia ! ------=_NextPart_000_000F_01C30FDC.D1E6C710 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=3DContent-Type content=3D"text/html; = charset=3Diso-8859-1"> <META content=3D"MSHTML 6.00.2800.1170" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#e0edeb> <DIV><FONT face=3DArial size=3D2><FONT face=3D"Times New Roman" = size=3D3>Hello=20 all,</FONT><BR></FONT></DIV> <DIV><FONT face=3DArial size=3D2>I have a problem with</FONT><FONT = face=3DArial=20 size=3D2> event service routine ! I implement = PCOMM.DLL(<EM>MOXA</EM>)=20 library contributed from <STRONG>Kondor = Attila </STRONG>and<STRONG>=20 </STRONG>communication with serial port work very well, but his pcomm.ew = lack any event service rutine . Down at bottom is = help for=20 C++ for creating event service routine in case when terminator = character=20 is received. </FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>After I successfully register event = service with=20 :</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial color=3D#800080=20 size=3D2>sio_term_irq_=3D<STRONG>define_c_func</STRONG>(Pcomm,"sio_term_i= rq",{C_INT,C_INT,C_INT},=20 C_INT)</FONT></DIV> <DIV><FONT face=3DArial color=3D#800080 size=3D2><FONT = color=3D#008080>global function=20 sio_term_irq( integer port,atom TermIrq, atom=20 code)<BR> &nbs= p; =20 ret=3Dc_func(sio_term_irq_,{port,TermIrq,code})<BR> if=20 ret=3DSIO_BADPORT then<BR> warnErr("Port is = not opened=20 in advance")<BR> end=20 if<BR> if ret=3DSIO_WIN32FAIL =20 then<BR> warnErr("Calling Win32 function=20 failed")<BR> end=20 if<BR> if ret=3DSIO_BADPARM =20 then<BR> warnErr("Bad=20 parameter")<BR> end if</FONT></FONT></DIV> <DIV><FONT face=3DArial color=3D#800080 size=3D2><FONT=20 color=3D#000000> </FONT><FONT=20 color=3D#008080> &nb= sp; =20 return ret<BR> end function</FONT></FONT></DIV> <DIV><FONT face=3DArial color=3D#800080 size=3D2><FONT=20 color=3D#008080></FONT></FONT> </DIV> <DIV><FONT face=3DArial color=3D#800080 size=3D2><FONT=20 color=3D#008080><STRONG>sci_rup=3Dsio_term_irq( 1,??? ,=20 59)</STRONG></FONT></FONT></DIV> <DIV><FONT face=3DArial color=3D#008080 size=3D2>??? any number form 1 = to=20 50</FONT></DIV> <DIV><FONT face=3DArial color=3D#800080 size=3D2><FONT = color=3D#008080><FONT=20 color=3D#000000>and return 0(SIO_OK) which mean event service = enabled, after=20 if terminator character is received programm crash with = message=20 "<EM><FONT color=3D#ff0000>EXW.EXE generate errors . . .</FONT></EM> = ".=20 After that I don't now how to handle ( possible with = <U>call_back</U> but=20 I don't now HOW ...)</FONT></DIV> <DIV><FONT color=3D#000000></FONT><FONT color=3D#000000></FONT><FONT=20 color=3D#000000></FONT><FONT color=3D#000000></FONT><FONT = color=3D#000000></FONT><FONT=20 color=3D#000000></FONT><FONT color=3D#000000></FONT><FONT = color=3D#000000></FONT><FONT=20 color=3D#000000></FONT><BR></FONT><BR></DIV></FONT> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><EM><FONT color=3D#0000ff><FONT face=3DArial=20 size=3D2>Language Syntax<BR>C/C++ int WINAPI sio_term_irq(int = port, VOID=20 (CALLBACK *func)(int port), char code)<BR></FONT><FONT face=3DArial=20 size=3D2>Argument:</FONT></FONT></EM></DIV> <DIV><FONT face=3DArial color=3D#0000ff size=3D2><EM>port =3D COM port=20 number</EM></FONT></DIV> <DIV><FONT face=3DArial color=3D#0000ff size=3D2><EM>func =3D event = service routine=20 entry</EM></FONT></DIV> <DIV><FONT face=3DArial color=3D#0000ff size=3D2><EM>If the func is = NULL, it will=20 disable this routine.</EM></FONT></DIV> <DIV><FONT face=3DArial color=3D#0000ff size=3D2><EM>code =3D terminator = code</EM></FONT></DIV> <DIV><FONT face=3DArial color=3D#0000ff = size=3D2><EM>Return:</EM></FONT></DIV> <DIV><FONT face=3DArial color=3D#0000ff=20 size=3D2><EM>SIO_OK OK<BR>SIO_BADPORT Port is not opened in=20 advance<BR>SIO_WIN32FAIL Calling Win32 function failed<BR>Call = GetLastError=20 to get the error code</EM></FONT></DIV> <DIV><FONT face=3DArial color=3D#0000ff = size=3D2><EM>Example:</EM></FONT></DIV> <DIV><FONT face=3DArial color=3D#0000ff = size=3D2><EM>C/C++</EM></FONT></DIV> <DIV><FONT face=3DArial color=3D#0000ff size=3D2><EM>/* Define event = service routine=20 */</EM></FONT></DIV> <DIV><FONT face=3DArial color=3D#0000ff size=3D2><EM>/* Recommend to = declare this=20 function as global function */</EM></FONT></DIV> <DIV><FONT face=3DArial color=3D#0000ff size=3D2><EM>VOID CALLBACK = TermIrq(int=20 port)<BR>{<BR>}</EM></FONT><FONT face=3DArial size=3D2><BR><EM><FONT=20 color=3D#0000ff>/* Enable event service routine */</FONT></EM></DIV> <DIV><EM><FONT color=3D#0000ff>ret =3D sio_term_irq( 2, TermIrq, = =91A=92);<BR>if (ret !=3D=20 SIO_OK) {<BR> /* Fail */<BR>}</FONT></EM></DIV> <DIV><EM><FONT color=3D#0000ff>/* After event service routine enabled, = TermIrq()=20 will be activated whenever terminator character is received.=20 */</FONT></EM></DIV> <DIV><EM><FONT color=3D#0000ff>/* Disable event service routine=20 */</FONT></EM></DIV> <DIV><EM><FONT color=3D#0000ff>ret =3D sio_term_irq( 2, NULL, 0=20 );</FONT></EM></FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2> =20 = =20 = =20 Manny farewell = from=20 Croatia !</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> ------=_NextPart_000_000F_01C30FDC.D1E6C710-- -- Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com