Send and receive data to serial port
Moderator: Rathinagiri
Send and receive data to serial port
Staff need to send data to serial port with data type decimal hexadecimal binary I'm using the lib hbcomm wonder if this lib sends the data as only want to send or sends data to type character if the character lib hbcomm only someone could send me help as hmg use to send data via serial port with binary data type decimal and hexadecimal through the serial port
thanks to all
thanks to all
Last edited by jairpinho on Mon Dec 12, 2011 11:19 am, edited 1 time in total.
Re: Send data to serial port with data type decimal hexadeci
Please try to write it again with some dots and commas
It's strong incomprehensible what are you looking for
I'f you are using translator (it looks like a google translator), please try to use shorter sentences.
Best regards, Marek
It's strong incomprehensible what are you looking for
I'f you are using translator (it looks like a google translator), please try to use shorter sentences.
Best regards, Marek
Re: Send data to serial port with data type decimal hexadeci
mol wrote:Please try to write it again with some dots and commas
It's strong incomprehensible what are you looking for
I'f you are using translator (it looks like a google translator), please try to use shorter sentences.
Best regards, Marek
need to send data of type hexadecimal or binary serial port, I'm using the lib hbcomm but not working.
Re: Send data to serial port with data type decimal hexadeci
you can watch this 100% working code:
in attachment...
in attachment...
- Attachments
-
- MOL-DF.zip
- (2.17 KiB) Downloaded 472 times
Re: Send data to serial port with data type decimal hexadeci
here is the function sendind data
Data is passed as a parameter
Data is passed as a parameter
Code: Select all
function SendDataViaComPort
param cDataToSend
local lRet := .t.
oWinPort := win_com():Init(cPortName,CBR_9600, EVENPARITY , 7, ONESTOPBIT)
if !oWinPort:Open
lRet := .f.
MsgBox("Error while opening COM Port" )
return lRet
else
// "Open succeeded"
oWinPort:RTSFlow(.F.)
oWinPort:DTRFlow(.F.)
oWinPort:XonXoffFlow(.t.)
oWinPort:SetDTR(.t.)
if !(oWinPort:Write(cDataToSend) == len(cDataToSend))
lRet := .f.
MsgBox("Unsuccessfully :-(")
endif
ENDIF
//oWinPort:QueueStatus(@lCTSHold, @lDSRHold, @lDCDHold, @lXoffHold, @lXoffSent, @nInQueue, @nOutQueue)
oWinPort:Close()
return lRet
Re: Send data to serial port with data type decimal hexadeci
where I get the syntax of win_com ()
Re: Send data to serial port with data type decimal hexadeci
If I remember, Iwas reading sources of harbour ant I found win_com() there...
Re: Send and receive data to serial port
"Mol" of the group or someone can help me how to receive data through the function wincom
Re: Send and receive data to serial port
I think, you can use something like that:
Code: Select all
cPortName := "COM1"
nSpeed := 9600
oWinPort := win_com():Init(cPortName, nSpeed, NOPARITY, 8, ONESTOPBIT)
if !oWinPort:Open
msgstop("Error while opening COM Port" )
return .f.
else
// Opened successfully
// set queue size and timeouts
oWinPort:QueueSize( 1000, 1000 )
oWinPort:Purge()
//TimeOuts( nReadInterval, nReadMultiplier, nReadConstant, nWriteMultiplier, nWriteConstant )
oWinPort:Timeouts(1500,1000,20000,1000,20000)
//set COM lines and flow control
oWinPort:RTSFlow(.t.)
oWinPort:DTRFlow(.t.)
oWinPort:XonXoffFlow(.t.)
oWinPort:SetDTR(.t.)
oWinPort:SetDTR(.t.)
oWinPort:SetRTS(.t.)
endif
// you can read answer from COM Port byte by byte
cAnswer := ""
cCharFromCOM := ""
nBytesToRead := 1
do while .t.
oWinPort:Read(@cCharFromCOM, nBytesToRead)
cAnswer += cCharFromCOM
if len(cCharFromCOM) < nBytesToRead
// end of data ...
exit
endif
enddo
Msginfo("Message from COM Port: "+ cAnswer)
Re: Send and receive data to serial port
The function is not presenting data
Code: Select all
*************************************************************
Function SendDataViaComPort2()
cPortName := "COM2"
nSpeed := 19200
oWinPort := win_com():Init(cPortName, nSpeed, NOPARITY, 8, ONESTOPBIT)
if !oWinPort:Open
msgstop("Error while opening COM Port" )
return .f.
else
// Opened successfully
// set queue size and timeouts
oWinPort:QueueSize( 1000, 1000 )
oWinPort:Purge()
//TimeOuts( nReadInterval, nReadMultiplier, nReadConstant, nWriteMultiplier, nWriteConstant )
oWinPort:Timeouts(15,10,20,10,20)
//set COM lines and flow control
oWinPort:RTSFlow(.t.)
oWinPort:DTRFlow(.t.)
oWinPort:XonXoffFlow(.t.)
oWinPort:SetDTR(.t.)
oWinPort:SetDTR(.t.)
oWinPort:SetRTS(.t.)
endif
cDataToSend := CHR(1)+CHR(1)+CHR(0)+CHR(0)+CHR(0)+CHR(100)+CHR(61) + CHR(225)
IF !(oWinPort:Write(cDataToSend) == len(cDataToSend))
lRet := .f.
MsgBox("sem sucesso :-(")
endif
// you can read answer from COM Port byte by byte
cAnswer := ""
cCharFromCOM := ""
nBytesToRead := 1
do while .t.
oWinPort:Read(@cCharFromCOM, nBytesToRead)
cAnswer += cCharFromCOM
if len(cCharFromCOM) < nBytesToRead
// end of data ...
exit
endif
enddo
Msginfo("Message from COM Port: "+ cAnswer)
oWinPort:Close()
RETURN