Sybase NNTP forums - End Of Life (EOL)

The NNTP forums from Sybase - forums.sybase.com - are now closed.

All new questions should be directed to the appropriate forum at the SAP Community Network (SCN).

Individual products have links to the respective forums on SCN, or you can go to SCN and search for your product in the search box (upper right corner) to find your specific developer center.

Serial communication issue

10 posts in Appeon (partner product) Last posting was on 2009-07-20 12:05:59.0Z
Laurent Posted on 2009-06-23 16:11:45.0Z
Sender: 18f4.4a40fb05.1804289383@sybase.com
From: Laurent
Newsgroups: sybase.public.appeon
Subject: Serial communication issue
X-Mailer: WebNews to Mail Gateway v1.1t
Message-ID: <4a40fec1.1b9f.1681692777@sybase.com>
NNTP-Posting-Host: forums-3-dub.sybase.com
X-Original-NNTP-Posting-Host: forums-3-dub.sybase.com
Date: 23 Jun 2009 09:11:45 -0700
X-Trace: forums-3-dub.sybase.com 1245773505 10.22.241.188 (23 Jun 2009 09:11:45 -0700)
X-Original-Trace: 23 Jun 2009 09:11:45 -0700, forums-3-dub.sybase.com
Lines: 17
Path: forums-1-dub!forums-master!forums-3-dub.sybase.com!not-for-mail
Xref: forums-1-dub sybase.public.appeon:2334
Article PK: 13386

Hi,

I'm actually testing Appeon for Powerbuilder 6.2.
In my PB application we use serial communication to send
information to printers and scales. I use the following win
api functions (external functions) in a non visual user
object : CreateFile(...) to open local communication port
and WriteFile(...) to send information to the port.

This serial communication is no longer working after I
migrate my application to Appeon 6.2. There is no issue with
the CreateFile call but the WriteFile call return me false
and I don't know why. When I try to catch the last error
code using GetLAstError() function it returned me 0.


Can someone help me ?


Steven Posted on 2009-06-24 07:19:42.0Z
Sender: 37c4.4a38650b.1804289383@sybase.com
From: Steven
Newsgroups: sybase.public.appeon
Subject: Re: Serial communication issue
X-Mailer: WebNews to Mail Gateway v1.1t
Message-ID: <4a41d38a.399d.1681692777@sybase.com>
References: <4a40fec1.1b9f.1681692777@sybase.com>
NNTP-Posting-Host: forums-3-dub.sybase.com
X-Original-NNTP-Posting-Host: forums-3-dub.sybase.com
Date: 24 Jun 2009 00:19:42 -0700
X-Trace: forums-3-dub.sybase.com 1245827982 10.22.241.188 (24 Jun 2009 00:19:42 -0700)
X-Original-Trace: 24 Jun 2009 00:19:42 -0700, forums-3-dub.sybase.com
Lines: 9
Path: forums-1-dub!forums-master!forums-3-dub.sybase.com!not-for-mail
Xref: forums-1-dub sybase.public.appeon:2336
Article PK: 13385

Hi Laurent,

Could you provide with the following info?
1. Scripts that define code in the global or local external
functions.
2. Scripts that call the external functions

Regards,
Steven


Laurent Posted on 2009-06-24 12:46:27.0Z
Sender: 18f4.4a40fb05.1804289383@sybase.com
From: Laurent
Newsgroups: sybase.public.appeon
Subject: Re: Serial communication issue
X-Mailer: WebNews to Mail Gateway v1.1t
Message-ID: <4a422023.7156.1681692777@sybase.com>
References: <4a41d38a.399d.1681692777@sybase.com>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="-=_forums-3-dub.sybase.com4a422023"
NNTP-Posting-Host: forums-3-dub.sybase.com
X-Original-NNTP-Posting-Host: forums-3-dub.sybase.com
Date: 24 Jun 2009 05:46:27 -0700
X-Trace: forums-3-dub.sybase.com 1245847587 10.22.241.188 (24 Jun 2009 05:46:27 -0700)
X-Original-Trace: 24 Jun 2009 05:46:27 -0700, forums-3-dub.sybase.com
Lines: 301
Path: forums-1-dub!forums-master!forums-3-dub.sybase.com!not-for-mail
Xref: forums-1-dub sybase.public.appeon:2337
Article PK: 21640

Hi Steven,

Please find attached :
. the script that define code in the local external
functions of the user object (local_external_functions.txt)
. the scripts of the user object functions that call the
external functions :
- uof_write_com_function.txt calls
. uof_open_com_function.txt to open the serial
port
. uof_writecom_function.txt (here there is no
underscore between write and com) to write
information to the serial port
. uof_close_com_function.txt to close the serial
(com) port


Best regards.

> Hi Laurent,
>
> Could you provide with the following info?
> 1. Scripts that define code in the global or local
> external functions.
> 2. Scripts that call the external functions
>
> Regards,
> Steven

////////////////
//
// Name: uof_opencom Function
//
// Purpose: Function to open the a communication port for peripherals
//
// Parameters: STRING s_port nom du port à ouvrir.
// STRING s_config configuration du port à ouvrir.
// INTEGER i_devnum identificateur du port a ouvrir (passé par référence)
// INTEGER i_hardware hardware flow control flag (0=unchanged, 1=enable)
// LONG l_timeout reading constant timeout in miliseconds
//
// Return: INTEGER: 0: Open successfull
// -1: Open fail
//
// Called by : f_print_last
//
// Calls to : none
//
// History
// Date Name Description
// ----------------------------------------------
// 20/04/1998 Olivier BAUDOIN Creation
// 23/03/1999 Miguel SAENZ Hardware flow control
// 20/11/1999 Miguel SAENZ Variable response constant timeout
//
////////////////


//CONSTANT ulong FILE_FLAG_OVERLAPPED = 1073741824 // 40000000 Hex
CONSTANT ulong FILE_FLAG_OVERLAPPED = 128 // 80 Hex (NORMAL)
CONSTANT ulong READ_WRITE = 3221225472 // C0000000 Hex
CONSTANT ulong OPEN_EXISTING = 3
CONSTANT int HARDWARE_FLOW_CONTROL = 20 // 14 Hex

boolean lb_retour
string ls_null
string def
int rc, ret, net
os_dcb dcb
os_commtimeouts timeout

// define null
setnull( ls_null)

// open the communication port
i_devnum = CreateFileA( s_port, READ_WRITE, 0, ls_null, &
OPEN_EXISTING, FILE_FLAG_OVERLAPPED, ls_null)

// check error
IF i_devnum < 0 THEN
RETURN -213
END IF

MessageBox("abcd"," uof_opencom(...) code retour : " +string(i_devnum))

// only for serial ports
IF left( s_port, 3) = "COM" THEN

// get the timer parameters
lb_retour = getcommtimeouts( i_devnum , timeout)

// set the timer parameters in milliseconds
timeout.writetotaltimeoutmultiplier = 50
timeout.writetotaltimeoutconstant = 100000
timeout.readtotaltimeoutmultiplier = 50
timeout.readtotaltimeoutconstant = l_timeout

// set the new timer parameters
lb_retour = setcommtimeouts( i_devnum , timeout)

// check error
IF NOT lb_retour THEN

// on error close port and return
uof_closecom( i_devnum)
RETURN -212
END IF

// set the buffers for the serial port
lb_retour = setupcomm( i_devnum, 1024, 1024)

// check error
IF NOT lb_retour THEN

// on error close port and return
uof_closecom( i_devnum)
RETURN -214
END IF

// get serial port status
lb_retour = getcommstate( i_devnum, dcb)

// fill the structure with the new parameters
def = s_config
lb_retour = BuildCommDCBA( def, dcb)

// set hardware flow control
IF i_hardware > 0 THEN
dcb.bits1 = char( HARDWARE_FLOW_CONTROL)
END IF

// set the new parameters
lb_retour = SetCommState( i_devnum , dcb )

// check error
IF NOT lb_retour THEN

// on error close port and return
uof_closecom( i_devnum)
RETURN -215
END IF
END IF

RETURN 0

//=================================================================
//But : fermeture d'un port (// ou série)
//
//PARAMETRES:
// integer : i_devnum identificateur du port à fermer
//
//COMMENTAIRES:
// Cette fonction permet de fermer un port série et de le configurer
// ou un port //.
// Cette fonction utilise la structure s_dcb
//
//RETOURS:
// int: 0 fermeture correcte
// -101 erreur de fermeture
//
//HISTORIQUE:
// Olivier BAUDOIN 20/04/98 -Création
//
//=================================================================

int net
boolean lb_retour

lb_retour = closehandle( i_devnum )

IF not lb_retour THEN
//Problème dans la fermeture du port
return(-101)
end if
Return (0)

//==================================================================
//But : Chargement d'un fichier sur une imprimante (32 bits)
//
//PARAMETRES:
// integer: ai_devnum identifiant du port serie (COMx, LPTx)
// blob: ablb_string chaine à envoyer à l'imprimante
// integer: ai_nbchar nb de caractères à envoyer à l'imprimante
//
//COMMENTAIRES:
// Cette fonction permet d'envoyer un fichier binaire
// ou texte sur un port parallèle ou série.
// Cette fonction utilise la structure lstr_comstat
// et la structure lstr_overlapped
//
//RETOURS:
// int: 0 chargement correcte
//
// -401 erreur lors du transfert
//
//HISTORIQUE:
// Olivier BAUDOIN 21/04/98 -Création
//
//===================================================================

boolean lb_retour
integer li_retour
string ls_error_mask
string ls_null, ls_err_str
ulong lul_bytes_written
long ll_retcode, ll_bytes_written

constant ulong PURGE_TXCLEAR = 4
constant long FORMAT_MESSAGE_FROM_SYSTEM = 4096

Any temp
os_comstat lstr_comstat
os_overlapped lstr_overlapped

ll_retcode = 0
setnull(ls_null)

//lb_retour = clearCommError(ai_devnum, ls_error_mask , lstr_comstat)
//IF lstr_comstat.cbinque <> 0 OR &
// lstr_comstat.cboutque <> 0 OR &
// lstr_comstat.fctshold <> 0 OR &
// lstr_comstat.fdsrhold <> 0 OR &
// lstr_comstat.feof <> 0 OR &
// lstr_comstat.frlshold <> 0 OR &
// lstr_comstat.ftxim <> 0 OR &
// lstr_comstat.fxoffhold <> 0 OR &
// lstr_comstat.fxoffsend <> 0 OR &
// ls_error_mask <> "" THEN
//
// setnull(ls_null)
//END IF

MessageBox("uof_writecom","handle de fichier : "+string(ai_devnum))

//lb_retour = writefile(ai_devnum , ablb_string , ai_nbchar , lul_bytes_written , ls_null)
lb_retour = writefile(ai_devnum , ablb_string , ai_nbchar , ll_bytes_written , lstr_overlapped)
ll_retcode = getlasterror()
MessageBox("uof_writecom"," code retour writefile : "+string(lb_retour))
MessageBox("uof_writecom"," code retour getlasterror : "+string(ll_retcode))

temp = 0
ls_err_str = Fill(Char(0),255)
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, temp, ll_retcode, 0, ref ls_err_str, 255, 0)
MessageBox("error", ls_err_str)


//DO
// lb_retour = clearCommError(ai_devnum, ls_error_mask , lstr_comstat)
//LOOP while lstr_comstat.cboutque > 0 and ls_error_mask = ""
//
//lb_retour = purgecomm(ai_devnum , PURGE_TXCLEAR)

IF ls_error_mask <> "" THEN
RETURN(-401)
END IF

RETURN(0)

////////////////
//
// Name: uof_write_com User object function
//
// Purpose: Function to write data into the specified serial port
//
// Parameters: STRING s_port: Serial port ( COM1, COM2,... )
// STRING s_buffer: Data to send to the com port
//
// Return: INTEGER: 1: Successfull
// -1: Fail
//
// Called by : the user object functions in the descendant objects
//
// Calls to : API functions to handle serial ports
//
// History
// Date Name Description
// ----------------------------------------------
// 05/03/1999 MASH First Version
// 15/05/2000 MASH Retry loop on failure
//
////////////////

int li_ret, li_devnum
blob lb_buffer

li_ret = 0

// retry loop
DO WHILE TRUE

// open the serial port
//li_ret = inv_winap.of_opencom( is_port, is_config, li_devnum, ii_hardware, 500)
li_ret = uof_opencom( is_port, is_config, li_devnum, ii_hardware, 500)

IF li_ret < 0 THEN
//inv_winap.of_closecom( li_devnum)
uof_closecom( li_devnum)

li_ret = f_err_message( "RC", 205, string( li_ret))
IF li_ret = 1 THEN CONTINUE

RETURN -1
END IF

// change format to blob
if f_isarabic() then s_buffer=f_convert_form(s_buffer)
lb_buffer = blob( s_buffer)

// send the string to the port
//li_ret = inv_winap.of_WriteCom( li_devnum, lb_buffer, len( lb_buffer))
li_ret = uof_WriteCom( li_devnum, lb_buffer, len( lb_buffer))
IF li_ret < 0 THEN
inv_winap.of_closecom( li_devnum)

li_ret = f_err_message( "RC", 206, string( li_ret))
IF li_ret = 1 THEN CONTINUE

RETURN -1
END IF

EXIT
LOOP

// close the serial port
//inv_winap.of_closecom( li_devnum)
uof_closecom( li_devnum)

RETURN 1

// KERNEL32.DLL functions
protected FUNCTION int CreateFileA(string lpszName , ulong dwacces , ulong dwsharemode , string lpsecurityattributes , ulong dwcreate , ulong dwattrsandflags , string htemplatefile) LIBRARY "KERNEL32.dll" alias for "CreateFileA;Ansi"
protected FUNCTION boolean SetupComm( int idComDev , ulong dwinqueue , ulong doutqueue ) LIBRARY "kernel32.dll"
protected FUNCTION boolean BuildCommDCBA( string lpdef , ref os_dcb lpdcb) LIBRARY "kernel32.dll" alias for "BuildCommDCBA;Ansi"
protected FUNCTION boolean GetCommState(int idComDev, ref os_dcb lpdcb) LIBRARY "kernel32.dll" alias for "GetCommState;Ansi"
protected FUNCTION boolean SetCommState(int idComDev , ref os_dcb lpdcb) LIBRARY "kernel32.dll" alias for "SetCommState;Ansi"
protected FUNCTION boolean CloseHandle(int idComDev) LIBRARY "kernel32.dll" alias for "CloseHandle;Ansi"
protected FUNCTION boolean ReadFile(int idcomdev , ref blob lpBuffer , ulong nnumberbytestoread , ref ulong NumberBytesread , ref string lsnull) LIBRARY "kernel32.dll" alias for "ReadFile;Ansi"

protected FUNCTION boolean WriteFile(int idcomdev , ref blob lpBuffer , long nnumberbytestowrite , ref long NumberByteswritten , ref os_overlapped lpoverlaped) LIBRARY "kernel32.dll"
//protected FUNCTION boolean WriteFile(int idcomdev , ref blob lpBuffer , ulong nnumberbytestowrite , ref ulong NumberByteswritten , ref string lsnull) LIBRARY "kernel32.dll" alias for "WriteFile;Ansi"
protected FUNCTION boolean GetCommTimeouts( int idcommdev , ref os_commtimeouts lpcommtimeouts) LIBRARY "kernel32.dll" alias for "GetCommTimeouts;Ansi"
protected FUNCTION boolean SetCommTimeouts( int idcommdev , ref os_commtimeouts lpcommtimeouts) LIBRARY "kernel32.dll" alias for "SetCommTimeouts;Ansi"
protected FUNCTION boolean ClearCommError(int idcomdev , ref string lperrors , ref os_comstat lpstat) LIBRARY "kernel32.dll" alias for "ClearCommError;Ansi"
protected FUNCTION boolean PurgeComm(int idcomdev, uLong dwFlags) LIBRARY "kernel32.dll" alias for "PurgeComm;Ansi"
protected FUNCTION long GetLastError() LIBRARY "kernel32.dll" alias for "GetLastError;Ansi"
protected FUNCTION long FormatMessage(Long dwFlags ,ref Any lpSource , Long dwMessageId, Long dwLanguageId , ref String lpBuffer, Long nSize , Long Arguments) LIBRARY "kernel32.dll" alias for "FormatMessageA"


Steven Posted on 2009-06-25 09:30:48.0Z
Sender: 412d.4a434397.1804289383@sybase.com
From: Steven
Newsgroups: sybase.public.appeon
Subject: Re: Serial communication issue
X-Mailer: WebNews to Mail Gateway v1.1t
Message-ID: <4a4343c8.415c.1681692777@sybase.com>
References: <4a422023.7156.1681692777@sybase.com>
NNTP-Posting-Host: forums-3-dub.sybase.com
X-Original-NNTP-Posting-Host: forums-3-dub.sybase.com
Date: 25 Jun 2009 02:30:48 -0700
X-Trace: forums-3-dub.sybase.com 1245922248 10.22.241.188 (25 Jun 2009 02:30:48 -0700)
X-Original-Trace: 25 Jun 2009 02:30:48 -0700, forums-3-dub.sybase.com
Lines: 11
Path: forums-1-dub!forums-master!forums-3-dub.sybase.com!not-for-mail
Xref: forums-1-dub sybase.public.appeon:2340
Article PK: 21641

Hi Laurent,

Please change the code in the local external functions to
the following to resolve this issue.
protected FUNCTION boolean WriteFile(int idcomdev , ref
blob lpBuffer , long nnumberbytestowrite , ref long
NumberByteswritten , ref os_overlapped lpoverlaped) LIBRARY
"kernel32.dll;" alias for "WriteFile;Ansi"

Regards,
Steven


Laurent Posted on 2009-06-25 11:16:59.0Z
Sender: 18f4.4a40fb05.1804289383@sybase.com
From: Laurent
Newsgroups: sybase.public.appeon
Subject: Re: Serial communication issue
X-Mailer: WebNews to Mail Gateway v1.1t
Message-ID: <4a435cab.53a5.1681692777@sybase.com>
References: <4a4343c8.415c.1681692777@sybase.com>
NNTP-Posting-Host: forums-3-dub.sybase.com
X-Original-NNTP-Posting-Host: forums-3-dub.sybase.com
Date: 25 Jun 2009 04:16:59 -0700
X-Trace: forums-3-dub.sybase.com 1245928619 10.22.241.188 (25 Jun 2009 04:16:59 -0700)
X-Original-Trace: 25 Jun 2009 04:16:59 -0700, forums-3-dub.sybase.com
Lines: 37
Path: forums-1-dub!forums-master!forums-3-dub.sybase.com!not-for-mail
Xref: forums-1-dub sybase.public.appeon:2341
Article PK: 21642

Hi Steven,

I changed the code in the local external functions but I
still have the same issue.
<<<<
protected FUNCTION boolean WriteFile(int idcomdev , ref
blob lpBuffer , long nnumberbytestowrite , ref long
NumberByteswritten , ref os_overlapped lpoverlaped) LIBRARY
"kernel32.dll" alias for "WriteFile;Ansi"
>>>>

I also tried with this :
<<<<
protected FUNCTION boolean WriteFile(int idcomdev , ref
blob lpBuffer , ulong nnumberbytestowrite , ref ulong
NumberByteswritten , ref string lsnull) LIBRARY
"kernel32.dll" alias for "WriteFile;Ansi"
>>>
It works properly when I launch my application with PB 11.5.
but it doesn't when I launch it from Appeon.

How can I be sure that my application opens the local serial
port and write information in it ?

Regards.

> Hi Laurent,
>
> Please change the code in the local external functions to
> the following to resolve this issue.
> protected FUNCTION boolean WriteFile(int idcomdev , ref
> blob lpBuffer , long nnumberbytestowrite , ref long
> NumberByteswritten , ref os_overlapped lpoverlaped)
> LIBRARY "kernel32.dll;" alias for "WriteFile;Ansi"
>
> Regards,
> Steven