Communication with ARM9

Communication with ARM9

Postby Surasak » Thu Jun 30, 2011 9:36 am

I just order FWPPC for running on S3C2440 Friendly ARM9 with Windows CE 5.0-6.0, When test the samples SetComm.prg return is .f. and TestComm.prg notthing happen.
I try to use this code for capture the result but function OpenCom return value of hComm more than 9 and alway change.



#include "FWCE.ch"

#define BUFF_IN 1024
#define BUFF_OUT 1024
#define GENERIC_READ 0x80000000
#define GENERIC_WRITE 0x40000000
#define OPEN_EXISTING 3
#define FILE_ATTRIBUTE_NORMAL 0x00000080

#define NOPARITY 0
#define ODDPARITY 1
#define EVENPARITY 2
#define MARKPARITY 3
#define SPACEPARITY 4

#define ONESTOPBIT 0
#define ONE5STOPBITS 1
#define TWOSTOPBITS 2

function Main(IniFile)
public oWnd
public nComm,nError,cDcb
set date brit
set cent on

DEFINE WINDOW oWnd TITLE " ADVANCE SOLUTION INTERNATIONAL CO.,LTD. [www.asic-net.com]"

@ 50, 20 BUTTON "OPEN" OF oWnd SIZE 100,50 PIXEL ACTION OComm()
@ 150, 20 BUTTON "SEND" OF oWnd SIZE 100,50 PIXEL ACTION SComm()
@ 250, 20 BUTTON "RECEIVE" OF oWnd SIZE 100,50 PIXEL ACTION RComm()
@ 350, 20 BUTTON "CLOSE" OF oWnd SIZE 100,50 PIXEL ACTION CComm()

ACTIVATE WINDOW oWnd

close all
clear all
quit
return nil


function OComm
nComm = OpenCom()
msginfo(str(nComm))
return nil


Function RComm()
local cBuffer,nBytes
cBuffer = space(1024)
nBytes = ComRead( nComm, @cBuffer )
if nBytes>0
msginfo(left(cBuffer,nBytes),'Read communication')
endif
return nil


Function SComm
local nBytes
nBytes = ComSend( nComm, "1234567890" )
msginfo("Send "+str(nBytes),"Send message")
return nil


Function CComm
ComClose( nComm )
msginfo("Close Communication port")
return nil



Function OpenCom( nCom, nBauds, nParity, nDataByt, nStopBits, lIRmode )
LOCAL hComm, cComm
DEFAULT nCom := 1, nBauds := 2400, nParity := NOPARITY, nDataByt := 8, lIRmode := .f.
DEFAULT nStopBits := ONESTOPBIT
cComm := "Com"+ AllTrim( Str( nCom, 2 ) )+ ":"
hComm := CreateFile( cComm, nOr(GENERIC_WRITE, GENERIC_READ) , 0, 0, OPEN_EXISTING, 0,0 )
IF hComm ==-1
Msginfo("Fallo al abrir "+ cComm)
Return -1
ENDIF
IF lIRMode
IF !RAWIRON( hComm )
Msginfo( "Fallo al iniciar RAWIR")
ComClose( hComm )
RETURN -1
ENDIF
ENDIF
IF !SetComm( hComm, nBauds, nParity, nDataByt, nStopBits )
MsgInfo("Fallo al configurar "+ cComm)
ComClose( hComm )
RETURN -1
ENDIF
RETURN hComm


Function ComSend( hComm, cString )
LOCAL nBytesend, nBytes:= Len( cString )
nByteSend := WriteComm( hComm, @cString, nBytes )
Return ( nByteSend == nBytes )


Function ComRead( nHdlCom, nChars )
LOCAL nBytes, cBuffIn := Space(BUFF_IN)
nBytes := ReadComm( nHdlCom, @cBuffIn, nChars )
RETURN if( nBytes >0, Left( cBuffIn, nBytes ),"" )


FUNCTION ComClose( hComm )
RAWIROFF( hComm )
CloseHandle( hComm )
RETURN .t.


#pragma BEGINDUMP

#include <windows.h>
#include <winbase.h>
#include <hbapi.h>
#include <aygshell.h>

#define BUFF_IN 1024
#define BUFF_OUT 1024

HB_FUNC( SETCOMM )
{
DCB dcb;
COMMTIMEOUTS timeouts;

SetupComm(( HANDLE) hb_parnl( 1 ), BUFF_IN, BUFF_OUT ) ;

GetCommState( ( HANDLE ) hb_parnl( 1 ), &dcb );

dcb.BaudRate = hb_parnl( 2 );
dcb.Parity = hb_parni( 3 );
dcb.ByteSize = hb_parni( 4 );
dcb.StopBits = hb_parni( 5 );

dcb.fBinary = TRUE;
dcb.fParity = TRUE;
dcb.fOutxCtsFlow = FALSE;
dcb.fOutxDsrFlow = FALSE;
dcb.fDtrControl = DTR_CONTROL_DISABLE;
dcb.fDsrSensitivity = FALSE;
dcb.fTXContinueOnXoff = FALSE;
dcb.fOutX = FALSE;
dcb.fInX = FALSE;
dcb.fErrorChar = FALSE;
dcb.fNull = FALSE;
dcb.fRtsControl = RTS_CONTROL_DISABLE;
dcb.fAbortOnError = FALSE;

GetCommTimeouts(( HANDLE) hb_parnl, &timeouts);

timeouts.ReadIntervalTimeout = 0;
timeouts.ReadTotalTimeoutMultiplier = 0;
timeouts.ReadTotalTimeoutConstant = 1000;
timeouts.WriteTotalTimeoutMultiplier = 0;
timeouts.WriteTotalTimeoutConstant = 0;


SetCommTimeouts(( HANDLE) hb_parnl( 1 ), &timeouts );

hb_retl(SetCommState( ( HANDLE ) hb_parnl( 1 ), &dcb ));
}

HB_FUNC( READCOMM )
{
DWORD dw = 0;
ReadFile( ( HANDLE ) hb_parnl( 1 ), ( LPVOID ) hb_parc( 2 ), ( DWORD ) hb_parni( 3 ), &dw, NULL );

hb_retni( ( int ) dw ? dw : -1 );
}

HB_FUNC( WRITECOMM )
{
DWORD dw = 0;
WriteFile( (HANDLE ) hb_parnl( 1 ), ( LPVOID ) hb_parc( 2 ), ( DWORD ) hb_parni( 3 ), &dw, NULL );
hb_retni( ( int ) dw ? dw : -1);
}


HB_FUNC( RAWIRON )
{

hb_retl( EscapeCommFunction( ( HANDLE ) hb_parnl( 1 ), SETIR ) );
}

HB_FUNC( RAWIROFF )
{

hb_retl( EscapeCommFunction( ( HANDLE ) hb_parnl( 1 ), CLRIR ) );
}

#pragma ENDDUMP
Surasak
 
Posts: 29
Joined: Fri Jul 20, 2007 1:30 pm

Re: Communication with ARM9

Postby Antonio Linares » Sat Jul 02, 2011 6:03 am

When you run TestComm.prg, what msg do you see on the screen ?

Msginfo("Fallo al abrir "+ cComm)

Msginfo( "Fallo al iniciar RAWIR")

MsgInfo("Fallo al configurar "+ cComm)

(these msgs are inside TestComm.prg)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Communication with ARM9

Postby Surasak » Sat Jul 02, 2011 10:27 am

For SetComm.prg output display .f. in msginfo()
For original TestComm.prg nothing display
but after I insert
///////////////////////////
function main
local nComm
nComm=OpenCom()
msginfo(str(nComm))
return nil
///////////////////////////
the output is 5835267,5835523,5835779 and always change every time when I execute.
No error message in create function display.
Surasak
 
Posts: 29
Joined: Fri Jul 20, 2007 1:30 pm

Re: Communication with ARM9

Postby Antonio Linares » Sun Jul 03, 2011 1:00 am

Surasak,

If you don't get any MsgInfo() then it is fine, where does it fail ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Communication with ARM9

Postby Surasak » Sun Jul 03, 2011 3:01 pm

Program error when I use function ComSend and ComRead Tomorrow I will send you the error message
Surasak
 
Posts: 29
Joined: Fri Jul 20, 2007 1:30 pm

Re: Communication with ARM9

Postby Surasak » Mon Jul 04, 2011 3:56 am

I just found my mistake,
Now I can work on it.
Thank you very much for your help
Surasak
 
Posts: 29
Joined: Fri Jul 20, 2007 1:30 pm

Re: Communication with ARM9

Postby Antonio Linares » Mon Jul 04, 2011 7:42 am

Very good :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Pocket PC

Who is online

Users browsing this forum: No registered users and 17 guests