how to open multiple ports simultaneously?
if I try:
nCom1 := OpenComm( "COM1", 1024 , 128)
nCom2 := OpenComm( "COM2", 1024 , 128)
then
nCom1=1
nCom2=1
how to open multiple ports
- Robert Frank
- Posts: 95
- Joined: Fri Nov 23, 2007 4:43 am
- Location: Gdynia-Poland
- Contact:
Re: how to open multiple ports
OpenPort() return handle of port
try:
COM_OPEN(1)
COM_OPEN(2)
Be sure that you have both of com ports installed in operating system
Function COM_OPEN(xPORT)
Local pNAME
Local nError,cDCB
Local xRESZTA:=.T.
Do Case
Case xPORT=1
pNAME:="COM1"
Case xPORT=2
pNAME:="COM2"
Case xPORT=3
pNAME:="COM3"
Case xPORT=4
pNAME:="COM4"
Case xPORT=5
pNAME:="COM5"
Case xPORT=6
pNAME:="COM6"
Case xPORT=7
pNAME:="COM7"
Case xPORT=8
pNAME:="COM8"
Case xPORT=9
pNAME:="COM9"
EndCase
hPORT:= OpenComm( pNAME, 2048, 2048 )
If ! BuildCommDcb( pNAME+cSPEED, @cDcb )
nError = GetCommError( hPORT )
MsgInfo( "BuildCommDcb Error: " + Str( nError ) )
xRESZTA:=.F.
EndIf
If ! SetCommState( hPORT, cDcb )
nError = GetCommError( hPORT )
MsgInfo( "SetCommState Error: " + Str( nError ) )
xRESZTA:=.F.
EndIf
If xRESZTA
oWND:oMSGBAR:cMSGDEF:=PNAME+" : Opened"
oWND:oMSGBAR:Refresh(.T.)
Else
oWND:oMSGBAR:cMSGDEF:=PNAME+" : Error"
oWND:oMSGBAR:Refresh(.T.)
EndIf
Return xRESZTA
try:
COM_OPEN(1)
COM_OPEN(2)
Be sure that you have both of com ports installed in operating system
Function COM_OPEN(xPORT)
Local pNAME
Local nError,cDCB
Local xRESZTA:=.T.
Do Case
Case xPORT=1
pNAME:="COM1"
Case xPORT=2
pNAME:="COM2"
Case xPORT=3
pNAME:="COM3"
Case xPORT=4
pNAME:="COM4"
Case xPORT=5
pNAME:="COM5"
Case xPORT=6
pNAME:="COM6"
Case xPORT=7
pNAME:="COM7"
Case xPORT=8
pNAME:="COM8"
Case xPORT=9
pNAME:="COM9"
EndCase
hPORT:= OpenComm( pNAME, 2048, 2048 )
If ! BuildCommDcb( pNAME+cSPEED, @cDcb )
nError = GetCommError( hPORT )
MsgInfo( "BuildCommDcb Error: " + Str( nError ) )
xRESZTA:=.F.
EndIf
If ! SetCommState( hPORT, cDcb )
nError = GetCommError( hPORT )
MsgInfo( "SetCommState Error: " + Str( nError ) )
xRESZTA:=.F.
EndIf
If xRESZTA
oWND:oMSGBAR:cMSGDEF:=PNAME+" : Opened"
oWND:oMSGBAR:Refresh(.T.)
Else
oWND:oMSGBAR:cMSGDEF:=PNAME+" : Error"
oWND:oMSGBAR:Refresh(.T.)
EndIf
Return xRESZTA
Robert Frank
Re: how to open multiple ports
The problem is that nCom1 and nCom2 have the same value. It is necessary that this value is different.
- Robert Frank
- Posts: 95
- Joined: Fri Nov 23, 2007 4:43 am
- Location: Gdynia-Poland
- Contact:
Re: how to open multiple ports
Try to use my example and check what BuildCommDcb and GetCommError will say.
Robert Frank
Re: how to open multiple ports
definite problem is that it functions opncomm (.....) always returns the value 1. Why!? I do not know! I use FWH6.12
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: how to open multiple ports
Sorry but this is a way older FHW release. I don't think Fivetech is able to support it.mtajkov wrote:I use FWH6.12
EMG