a gente necesita para enviar mensajes y recibir información con esta estructura
Example #1
Query Message 02 14 07 06 10 00 00 02 00 02 (CRC16)
Where:
02 = Address
14 = Function Code 20 (14 hex)
07 = Byte Count
06 = Reference Type
10,00 = Register Address (Input Hi Range)
00,02 = File Number (Access Data Value)
00 02 = Register Count (Floating Point Data)
(CRC16)
Response Message 02 14 06 05 06 47 64 00 00 (CRC16)
Where:
02 = Address
14 = Function Code 20 (14 Hex)
06 = Byte Count
05 = Sub Message Length
06 = Reference Type
47 64 00 00 = 100.0 (Value of Input Hi Range)
(CRC16)
Alguien sabe cómo puedo hacer esto utilizando el puerto serie COM1
Byte Frame em porta serial
Moderator: Rathinagiri
Re: Byte Frame em porta serial
If I understand you good, you can use hbcomm for serial communication.
There is a piece of my code for opening COM port, sendig and receiveing data :
now you can use this function to send data:
and this function for read data from serial port
There is a piece of my code for opening COM port, sendig and receiveing data :
Code: Select all
cPortName := "COM1"
nBaud := 9600
oWinPort := win_com():Init(cPortName, nBaud, NOPARITY, 8, ONESTOPBIT)
if !oWinPort:Open
msgstop("Error opening COM port!" )
return .F.
else
// COM port opened successfully
oWinPort:QueueSize( 1000, 1000 )
oWinPort:Purge()
//TimeOuts( nReadInterval, nReadMultiplier, nReadConstant, nWriteMultiplier, nWriteConstant )
oWinPort:Timeouts(1500,1000,20000,1000,20000)
// set control of communication flow
oWinPort:RTSFlow(.t.)
oWinPort:DTRFlow(.t.)
oWinPort:XonXoffFlow(.t.)
// set modem lines states
oWinPort:SetDTR(.t.)
oWinPort:SetDTR(.t.)
oWinPort:SetRTS(.t.)
endif
Code: Select all
oWinPort:Write("any string to send via COM Port")
Code: Select all
cAnswer := ""
oWinPort:Read(@cAnswer, nNumberOfBytesToRead)
Re: Byte Frame em porta serial
I've placed two useful functions below:
and second
Code: Select all
function ComClose
local nCount := 0, cAnswer := ""
if oWinPort <> NIL
oWinPort:QueueStatus( , , , , , @nCount, )
oWinPort:Read(@cAnswer, nCount)
oWinPort:Purge()
oWinPort:RTSFlow(.f.)
oWinPort:DTRFlow(.f.)
oWinPort:XonXoffFlow(.f.)
oWinPort:SetDTR(.f.)
oWinPort:SetDTR(.f.)
oWinPort:SetRTS(.f.)
oWinPort:Close()
endif
oWinPort := NIL
return .t.
Re: Byte Frame em porta serial
Sorry, I don't know why a software of this forum not accept my next post...
while sending post, I get:
A function to calculate CRC is in attachment:
while sending post, I get:
Code: Select all
Not Acceptable
An appropriate representation of the requested resource /posting.php could not be found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
- Attachments
-
- com.zip
- (1.77 KiB) Downloaded 353 times
Re: Byte Frame em porta serial
compiled your example but not connecting on port COM1 COM2 and COM3. where I think the command that is using the serial port thanks for the help
#include <hmg.ch>
Function Main
PRivate oWinPort
Load Window Main
Inicia_port()
Main.Center
Main.Activate
Return
Function Inicia_port()
cPortName := "COM3"
nBaud := 9600
oWinPort := win_com():Init(cPortName, nBaud, .F., 8, 1)
if !oWinPort:Open
msgstop("Error opening COM port!" )
return .F.
else
// COM port opened successfully
oWinPort:QueueSize( 1000, 1000 )
oWinPort:Purge()
//TimeOuts( nReadInterval, nReadMultiplier, nReadConstant, nWriteMultiplier, nWriteConstant )
oWinPort:Timeouts(1500,1000,20000,1000,20000)
// set control of communication flow
oWinPort:RTSFlow(.t.)
oWinPort:DTRFlow(.t.)
oWinPort:XonXoffFlow(.t.)
// set modem lines states
oWinPort:SetDTR(.t.)
oWinPort:SetDTR(.t.)
oWinPort:SetRTS(.t.)
endif
Return(oWinPort)
Function Leporta()
cAnswer := ""
//oWinPort:Read(@cAnswer, nNumberOfBytesToRead)
main.text_1.Value := oWinPort:Read(@cAnswer, 8)
Return
#include <hmg.ch>
Function Main
PRivate oWinPort
Load Window Main
Inicia_port()
Main.Center
Main.Activate
Return
Function Inicia_port()
cPortName := "COM3"
nBaud := 9600
oWinPort := win_com():Init(cPortName, nBaud, .F., 8, 1)
if !oWinPort:Open
msgstop("Error opening COM port!" )
return .F.
else
// COM port opened successfully
oWinPort:QueueSize( 1000, 1000 )
oWinPort:Purge()
//TimeOuts( nReadInterval, nReadMultiplier, nReadConstant, nWriteMultiplier, nWriteConstant )
oWinPort:Timeouts(1500,1000,20000,1000,20000)
// set control of communication flow
oWinPort:RTSFlow(.t.)
oWinPort:DTRFlow(.t.)
oWinPort:XonXoffFlow(.t.)
// set modem lines states
oWinPort:SetDTR(.t.)
oWinPort:SetDTR(.t.)
oWinPort:SetRTS(.t.)
endif
Return(oWinPort)
Function Leporta()
cAnswer := ""
//oWinPort:Read(@cAnswer, nNumberOfBytesToRead)
main.text_1.Value := oWinPort:Read(@cAnswer, 8)
Return
Re: Byte Frame em porta serial
rename the file that accepts the attachment
mol wrote:Sorry, I don't know why a software of this forum not accept my next post...
while sending post, I get:A function to calculate CRC is in attachment:Code: Select all
Not Acceptable An appropriate representation of the requested resource /posting.php could not be found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.