I have to send this to COM port ( RS232 ) with xHarbour
Please guide me ...
Communication Parameters:
- Baud rate: 2400 bits/s;
- Data: 8 bits;
- End code: 1 bit;
- Checksum: Nil;
P.S: Networking Capacity: Up to 128 nos. LED signs in maximum. Sign address is addressable at the
controller card, ranging from 0 to 127 (lower 7 bits).
Format For Transmitting Package
Each package has no restriction in length, and can contain different data groups. But, the “Data 1”
should be Sign Address, and the end code is “0”. As follows;
“Data 1” + “Data 2” + “Data 3” - - - - - “Data n” + “0”
Protocol For Different Data Group:
There are 11 different data groups in total.
I: Data for sign address
II: Data for file
III: Data for special file
IV: Data for alarming
V: Data for time alarming
VI: Data for sign on
VII: Data for sign off
VIII: Data for date / time resetting
IX: Data for custom graphic
X: Data for testing
XI: Data for signs’ list
P.S: The length for each data group cannot exceed 8190 bytes (1FFE).
Code: Select all
Example I : Send Data For Sign Address
Format : “0” + “Sign Address” + “1”
Code Description
-------------------------------------------------------------
“0” Leading code for Sign Address
----------------------------------------------------------------------------
“Sign Address” 2 bytes (16 bits)
e.g: sign 0 = bit 0; sign 1 = bit 1…etc.
------------------------------------------------------------------------------------------------------------
“1” Clear all the previous messages
Remark: Previous messages will be retained if the bit is not “1
---------------------------------------------------------------------------------------------------------------
P.S: If there are 128 nos. LED signs linked together, sign address=”FFFFH”, and then followed by data group for signs’ list
How to send this-> "10" +"01H " + "0FFH" to test
"10" = Leading Code
"01H" = Testing Code
"0FFH" = Ending Code
#include "fivewin.ch"
function Main()
local oWnd,oDlg,nCom,oGet,cText := spac(200)
DEFINE WINDOW oWnd TITLE "Com Port"
DEFINE DIALOG oDlg FROM 180, 0 TO 350,1400 PIXEL OF oWnd
@ 0, 8 GET oGet VAR cText size 300,80 MEMO READONLY of oDlg
ACTIVATE DIALOG oDlg NOWAIT VALID oWnd:End()
ACTIVATE WINDOW oWnd MAXIMIZED ;
ON INIT ( nCom := APRICOM( oDlg, oGet), ;
IF( nCom < 0, oWnd:End(), ), InitCom(nCom) ) VALID Keluar()
return nil
static function InitCom(nCom)
WRITECOMM( nCom, "10" +"01H " + "0FFH" +chr(13) )
return nil
static function ExitKeluar()
if MsgYesNo("Exit ?")
dbCloseAll()
return .t.
endif
return .f.
STATIC FUNCTION APRICOM( oDlg, oGet )
LOCAL nCom, cDcb
BEGIN SEQUENCE
nCom = OPENCOMM( "COM1", 16384, 16384 )
IF nCom < 0
? "Error Open COM1"
BREAK
ENDIF
BUILDCOMMDCB( "COM1:2400,N,8,1", @cDcb )
IF !SETCOMMSTATE( nCom, cDcb )
? "Error Open COM1"
BREAK
ENDIF
oDlg:bCommNotify = { | nCom | Connect( nCom, oGet ),;
EnableCommNotification( nCom, oDlg:hWnd, 1, -1) }
IF !ENABLECOMMNOTIFICATION( nCom, oDlg:hWnd, 1, -1 )
? "Error Open COM1"
BREAK
ENDIF
RECOVER
nCom = -1
END SEQUENCE
RETURN nCom
STATIC FUNCTION CONNECT( nCom, oGet )
LOCAL cStr
ENABLECOMMNOTIFICATION( nCom, 0, 1, -1 )
cStr = RECEIVESTR( nCom )
oGet:append(cStr+CRLF)
RETURN NIL
STATIC FUNCTION SENDSTR( nCom, cString )
LOCAL nBytes := WRITECOMM( nCom, cString )
RETURN nBytes = LEN( cString )
STATIC FUNCTION RECEIVESTR( nCom )
LOCAL cBuf := SPACE( 1000 )
RETURN LEFT( cBuf, READCOMM( nCom, @cBuf ) )
Regards
Fafi